/// <summary> /// This is the main entry point called by the setter on the StTxtPara.Contents used when the /// GetDiffsInTsStrings is also needed by another method that is called. /// </summary> public static void AdjustAnalysis(IStTxtPara para, ITsString oldContents, TsStringDiffInfo diffInfo) { AnalysisAdjuster adjuster = new AnalysisAdjuster(para, oldContents, diffInfo); BackTranslationAndFreeTranslationUpdateHelper.Do(para, adjuster.AdjustAnalysisInternal); }
/// <summary> /// Make one for adjusting the specified paragraph to its current contents from the specified /// old contents /// </summary> private AnalysisAdjuster(IStTxtPara para, ITsString oldContents, TsStringDiffInfo diffInfo) { m_para = para; m_oldContents = oldContents; m_newContents = m_para.Contents; m_changedFontOnly = false; if(diffInfo != null && ( diffInfo.IchFirstDiff != 0 || diffInfo.CchDeleteFromOld != diffInfo.CchInsert || m_oldContents == null || m_newContents == null || m_oldContents.Length == 0 || !m_oldContents.GetChars(0, m_oldContents.Length).Equals(m_newContents.GetChars(0, m_newContents.Length)))) { m_paraDiffInfo = diffInfo; } else { //We didn't really change it, maybe the ws changed, but all the characters are identical //let's let the user keep their analysis m_paraDiffInfo = new TsStringDiffInfo(0, 0, 0); m_changedFontOnly = true; // a flag to let later adjustment ops remember this } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the contents of this StTxtPara for a specific change where we can determine the /// difference better than the automated way. /// </summary> /// ------------------------------------------------------------------------------------ private void SetContentsInternal(ITsString newContents, TsStringDiffInfo diffInfo, bool fAdjustAnalyses) { ITsString originalValue = m_Contents; m_Contents = newContents; ((IServiceLocatorInternal)Services).UnitOfWorkService.RegisterObjectAsModified(this, StTxtParaTags.kflidContents, originalValue, newContents); OnContentsChanged(originalValue, m_Contents, diffInfo, fAdjustAnalyses); }
private static void VerifyStringDiffs(ITsString tss1, ITsString tss2, TsStringDiffInfo diffInfoExpected, string id) { var diffInfo = TsStringUtils.GetDiffsInTsStrings(tss1, tss2); if (diffInfoExpected == null) Assert.Null(diffInfo, id); else { Assert.NotNull(diffInfo, id); Assert.AreEqual(diffInfoExpected.IchFirstDiff, diffInfo.IchFirstDiff, id + " ichMin"); Assert.AreEqual(diffInfoExpected.CchInsert, diffInfo.CchInsert, id + " cchIns"); Assert.AreEqual(diffInfoExpected.CchDeleteFromOld, diffInfo.CchDeleteFromOld, id + " cchDel"); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Virtual method to allow subclasses to handle the side effects of setting the /// paragraph contents /// </summary> /// ------------------------------------------------------------------------------------ protected virtual void OnContentsChanged(ITsString originalValue, ITsString newValue, TsStringDiffInfo diffInfo, bool fAdjustAnalyses) { if (Owner is StText) ((StText)Owner).OnParagraphContentsChanged(this, originalValue, newValue); int oldSegmentCount = SegmentsOS.Count; if (fAdjustAnalyses) AnalysisAdjuster.AdjustAnalysis(this, originalValue, diffInfo); MarkCharStylesInUse(diffInfo.IchFirstDiff, diffInfo.CchInsert); if (SegmentsOS.Count < oldSegmentCount) { // A segment was removed. The removed segment could have some translated // material that is now gone. This will mean that the CmTranslation and // segmented translation are now out of sync. We can't do this code in // RemoveObjectSideEffectsInternal() because at that point the segments // are in an inconsistent state. ICmTranslation bt = GetBT(); if (bt != null) { BackTranslationAndFreeTranslationUpdateHelper.Do(this, () => ScriptureServices.UpdateMainTransFromSegmented(this, bt.Translation.AvailableWritingSystemIds)); } } }