public override void Initialize() { CheckDisposed(); base.Initialize(); //m_inMemoryCache.InitializeAnnotationDefs(); InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml", new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" }); m_wsVern = Cache.DefaultVernWs; m_wsTrans = Cache.DefaultAnalWs; m_text = new Text(); Cache.LangProject.TextsOC.Add(m_text); m_para = new StTxtPara(); StText text = new StText(); m_text.ContentsOA = text; text.ParagraphsOS.Append(m_para); m_trans = new CmTranslation(); m_para.TranslationsOC.Add(m_trans); kflidFT = StTxtPara.SegmentFreeTranslationFlid(Cache); kflidSegments = StTxtPara.SegmentsFlid(Cache); m_btPoss = Cache.LangProject.TranslationTagsOA.LookupPossibilityByGuid( LangProject.kguidTranBackTranslation); m_trans.TypeRA = m_btPoss; m_fWasUseScriptDigits = Cache.LangProject.TranslatedScriptureOA.UseScriptDigits; Cache.LangProject.TranslatedScriptureOA.UseScriptDigits = false; // do we need to set status? }
/// <summary> /// Make one for converting the specified paragraph. /// </summary> /// <param name="para"></param> public BtConverter(IStTxtPara para) { m_para = para; m_cache = para.Cache; kflidFT = StTxtPara.SegmentFreeTranslationFlid(m_cache); kflidSegments = StTxtPara.SegmentsFlid(m_cache); m_cpe = m_cache.LanguageWritingSystemFactoryAccessor.UnicodeCharProps; m_scr = para.Cache.LangProject.TranslatedScriptureOA; }
public override void Initialize() { CheckDisposed(); base.Initialize(); InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml", new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" }); m_wsVern = Cache.DefaultVernWs; m_wsTrans = Cache.DefaultAnalWs; m_book = new ScrBook(); Cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS.Append(m_book); m_section = new ScrSection(); m_book.SectionsOS.Append(m_section); m_para = new StTxtPara(); m_text = new StText(); m_section.ContentOA = m_text; m_text.ParagraphsOS.Append(m_para); m_hvoSegDefn = CmAnnotationDefn.TextSegment(Cache).Hvo; m_hvoFtDefn = Cache.GetIdFromGuid(new Guid(LangProject.kguidAnnFreeTranslation)); kflidFT = StTxtPara.SegmentFreeTranslationFlid(Cache); kflidSegments = StTxtPara.SegmentsFlid(Cache); }
public static void UpdateMainTransFromSegmented(StTxtPara para, int[] wss) { if (!para.IsValidObject()) { return; // in merge, paragraph may be modified then deleted. } FdoCache cache = para.Cache; BtConverter.EnsureMainParaSegments(para, wss[0]); ISilDataAccess sda = cache.MainCacheAccessor; List <int> segments = para.Segments; int kflidFT = StTxtPara.SegmentFreeTranslationFlid(cache); ITsString tssContents = para.Contents.UnderlyingTsString; IScripture scr = para.Cache.LangProject.TranslatedScriptureOA; ICmTranslation originalBT = para.GetBT(); // Can be null string sUnfinished = BackTranslationStatus.Unfinished.ToString(); foreach (int ws in wss) { ITsStrBldr bldr = TsStrBldrClass.Create(); bool wantNextSpace = false; // suppresses space before the first thing we add. bool haveBtText = false; // Text that isn't segment label text foreach (int hvoSeg in segments) { // If it's a label, insert it directly. Suppress following space. int beginOffset = sda.get_IntProp(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset); int endOffset = sda.get_IntProp(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset); ITsString tssFt; // Whether we want to insert a space before the current segment is determined by the previous one. // Save that value so we can set wantSpace appropriately for the following one. bool wantSpace = wantNextSpace; if (SegmentBreaker.HasLabelText(tssContents, beginOffset, endOffset)) { tssFt = (new CmBaseAnnotation(cache, hvoSeg)).TextAnnotated; tssFt = scr.ConvertCVNumbersInStringForBT(CorrectFootnotes(tssFt), ws); wantNextSpace = false; } else { int hvoFt = sda.get_ObjectProp(hvoSeg, kflidFT); tssFt = sda.get_MultiStringAlt(hvoFt, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws); haveBtText |= (tssFt.Length > 0); wantNextSpace = EndsWithNonSpace(tssFt); } if (tssFt.Length > 0) { if (wantSpace) { // The preceding segment should typically be followed by a space. if (!StartsWithSpaceOrOrc(tssFt)) { bldr.Replace(bldr.Length, bldr.Length, " ", null); } } bldr.ReplaceTsString(bldr.Length, bldr.Length, tssFt); } } // If the back translation doesn't have text, we don't want to create verse // segment labels. This prevents the problem where the book thinks it has a // back translation because of automatically generated verse labels (TE-8283). if (!haveBtText) { // This check might not be needed, but it shouldn't hurt anything. if (originalBT != null) { if (originalBT.Translation.GetAlternative(ws).Length > 0) { string origStatus = originalBT.Status.GetAlternative(ws); if (!String.IsNullOrEmpty(origStatus) && origStatus != sUnfinished) { originalBT.Status.SetAlternative(sUnfinished, ws); } } } continue; } ITsString newFt = bldr.GetString(); ICmTranslation trans; if (newFt.Length == 0) { trans = para.GetBT(); if (trans == null) { return; // don't bother creating one to store an empty translation! } } else { trans = para.GetOrCreateBT(); } // Don't write unless it changed...PropChanged can be expensive. if (!trans.Translation.GetAlternative(ws).UnderlyingTsString.Equals(newFt)) { trans.Translation.SetAlternative(newFt, ws); trans.Status.SetAlternative(sUnfinished, ws); } } }
/// ----------------------------------------------------------------------------------- /// <summary> /// This is the main interesting method of displaying objects and fragments of them. /// Here a text is displayed by displaying its paragraphs; /// and a paragraph is displayed by invoking its style rule, making a paragraph, /// and displaying its contents. /// </summary> /// <param name="vwenv">view environment</param> /// <param name="hvo">id of object to be displayed</param> /// <param name="frag">fragment of data</param> /// ----------------------------------------------------------------------------------- public override void Display(IVwEnv vwenv, int hvo, int frag) { CheckDisposed(); switch (frag) { case (int)StTextFrags.kfrFootnote: { if (HandleEmptyText(vwenv, hvo)) { break; } vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this, (int)StTextFrags.kfrFootnotePara); break; } case (int)StTextFrags.kfrText: { if (HandleEmptyText(vwenv, hvo)) { break; } if (m_fLazy) { vwenv.AddLazyVecItems((int)StText.StTextTags.kflidParagraphs, this, (int)StTextFrags.kfrPara); } else { vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this, (int)StTextFrags.kfrPara); } break; } case (int)StTextFrags.kfrFootnoteMarker: { StFootnote footnote = new StFootnote(Cache, hvo); if (footnote.DisplayFootnoteMarker) { DisplayFootnoteMarker(vwenv); } break; } case (int)StTextFrags.kfrLabel: { // The label is not editable. vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); vwenv.AddString(m_tssLabel); break; } case (int)StTextFrags.kfrPara: case (int)StTextFrags.kfrFootnotePara: { InsertParagraphBody(vwenv, hvo, frag, true, ContentType, this); break; } case (int)StTextFrags.kfrTranslation: { vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, Editable ? (int)TptEditable.ktptIsEditable : (int)TptEditable.ktptNotEditable); // Display the translation, or its user prompt if (!InsertTranslationUserPrompt(vwenv, hvo)) { vwenv.AddStringAltMember((int)CmTranslation.CmTranslationTags.kflidTranslation, m_wsDefault, this); } break; } case (int)StTextFrags.kfrSegmentFreeTranslations: // Hvo is a CmBaseAnnotation of one segment of an StTxtPara. if (IsLabelSegment(hvo)) { CmBaseAnnotation segment = (CmBaseAnnotation)CmBaseAnnotation.CreateFromDBObject(Cache, hvo, false); vwenv.AddString(GetBackTransLabelText(segment)); vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 1200, 0, 0); // a narrow space, font-neutral } else { vwenv.AddObjProp(StTxtPara.SegmentFreeTranslationFlid(Cache), this, (int)StTextFrags.kfrFreeTrans); vwenv.AddString(OneSpaceString); } break; case (int)StTextFrags.kfrFreeTrans: // Hvo is a CmIndirectAnnotation whose Contents are the free/back translation. vwenv.set_IntProperty((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(SystemColors.Window)); ITsString tssVal = vwenv.DataAccess.get_MultiStringAlt(hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS); if (tssVal.Length == 0 && !SuppressPrompt(hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment)) { vwenv.NoteDependency(new int[] { hvo }, new int[] { (int)CmAnnotation.CmAnnotationTags.kflidComment }, 1); vwenv.AddProp(SimpleRootSite.kTagUserPrompt, this, (int)CmAnnotation.CmAnnotationTags.kflidComment); // Almost invisibly narrow, but the Views code doesn't know it is invisible so it should prevent the prompts collapsing // into the margin. vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 100, 0, 0); } else { ITsStrBldr bldr = tssVal.GetBldr(); bldr.Replace(0, bldr.Length, "", null); // reduce to empty string in ws. // We want it to change back to the prompt if all is deleted. vwenv.NoteStringValDependency(hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS, bldr.GetString()); vwenv.AddStringAltMember((int)CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS, this); // This little separator is useful here, too. Temporarily the comment may be displayed this way even when empty, // and if there is ordinary text following, it is difficult to get an IP displayed in an empty run. vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 100, 0, 0); } break; } }