/// ------------------------------------------------------------------------------------ /// <summary> /// A helper method for book merger tests- /// Verifies the contents of the given sub-difference /// for a two-sided subDiff representing a text comparison. This overload does not /// check for the starting and ending references for sub-diffs that are created without /// that information. /// </summary> /// <param name="rootDiff">The root difference.</param> /// <param name="iSubDiff">The sub difference to verify.</param> /// <param name="subDiffType">Type of the sub difference.</param> /// <param name="footnoteCurr">The footnote curr.</param> /// <param name="ichMinCurr">The beginning character offset of the difference in the /// current.</param> /// <param name="ichLimCurr">The ending character offset of the difference in the /// current.</param> /// <param name="footnoteRev">The footnote rev.</param> /// <param name="ichMinRev">The beginning character offset of the difference in the /// revision.</param> /// <param name="ichLimRev">The ending character offset of the difference in the /// current.</param> /// <remarks>char styles are not verified here; test code should just check /// those directly if relevant</remarks> /// ------------------------------------------------------------------------------------ public static void VerifySubDiffFootnote(Difference rootDiff, int iSubDiff, DifferenceType subDiffType, IScrFootnote footnoteCurr, int ichMinCurr, int ichLimCurr, IScrFootnote footnoteRev, int ichMinRev, int ichLimRev) { Difference subDiff = rootDiff.SubDiffsForORCs[iSubDiff]; // the Current para stuff Assert.AreEqual((footnoteCurr != null) ? footnoteCurr.ParagraphsOS[0] : null, subDiff.ParaCurr); Assert.AreEqual(ichMinCurr, subDiff.IchMinCurr); Assert.AreEqual(ichLimCurr, subDiff.IchLimCurr); // the Revision para stuff Assert.AreEqual((footnoteRev != null) ? footnoteRev.ParagraphsOS[0] : null, subDiff.ParaRev); Assert.AreEqual(ichMinRev, subDiff.IchMinRev); Assert.AreEqual(ichLimRev, subDiff.IchLimRev); // section stuff should be null Assert.IsNull(subDiff.SectionsRev); Assert.IsNull(subDiff.SectionsCurr); // subDiffs may not have subDiffs, so far Assert.IsNull(subDiff.SubDiffsForORCs); Assert.IsNull(subDiff.SubDiffsForParas); Assert.AreEqual(subDiffType, subDiff.DiffType); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { ITsStrFactory strfact = TsStrFactoryClass.Create(); //Jude IScrBook jude = AddBookToMockedScripture(65, "Jude"); AddTitleToMockedBook(jude, "Jude"); // Jude Scripture section IScrSection section = AddSectionToMockedBook(jude); AddSectionHeadParaToSection(section, "First section", "Section Head"); IStTxtPara judePara = AddParaToMockedSectionContent(section, "Paragraph"); AddRunToMockedPara(judePara, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(judePara, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(judePara, "This is the first verse", null); // Insert footnote into para 1 of Jude ITsStrBldr bldr = judePara.Contents.GetBldr(); IScrFootnote foot = jude.InsertFootnoteAt(0, bldr, 10); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is text for the footnote.", Cache.DefaultVernWs); judePara.Contents = bldr.GetString(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// A helper method for book merger tests- /// Verifies the contents of the given difference /// for a one-sided subDiff representing a footnote in the Revision. /// </summary> /// ------------------------------------------------------------------------------------ public static void VerifySubDiffFootnoteRev(Difference rootDiff, int iSubDiff, IScrFootnote footnoteRev) { Difference subDiff = rootDiff.SubDiffsForORCs[iSubDiff]; // verify the basics Assert.AreEqual(0, subDiff.RefStart); Assert.AreEqual(0, subDiff.RefEnd); Assert.AreEqual(DifferenceType.NoDifference, subDiff.DiffType); // the Current para stuff Assert.AreEqual(null, subDiff.ParaCurr); Assert.AreEqual(0, subDiff.IchMinCurr); Assert.AreEqual(0, subDiff.IchLimCurr); // the Revision para stuff Assert.AreEqual(((IScrTxtPara)footnoteRev.ParagraphsOS[0]), subDiff.ParaRev); Assert.AreEqual(0, subDiff.IchMinRev); Assert.AreEqual(((IScrTxtPara)footnoteRev.ParagraphsOS[0]).Contents.Length, subDiff.IchLimRev); // style names should be null Assert.IsNull(subDiff.StyleNameCurr); Assert.IsNull(subDiff.StyleNameRev); // section stuff should be null Assert.IsNull(subDiff.SectionsRev); Assert.IsNull(subDiff.SectionsCurr); // subDiffs may not have subDiffs, so far Assert.IsNull(subDiff.SubDiffsForORCs); //check the root difference for consistency with this subDiff Assert.IsTrue(rootDiff.DiffType == DifferenceType.TextDifference || rootDiff.DiffType == DifferenceType.FootnoteMissingInCurrent); }
public void DeleteFootnoteWithoutORC() { IScrBook book = (IScrBook)m_scr.ScriptureBooksOS[0]; int originalFootnoteCount = book.FootnotesOS.Count; // Insert a new footnote into the collection and view IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().Create(); book.FootnotesOS.Insert(0, footnote); IScrTxtPara para = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( footnote, ScrStyleNames.CrossRefFootnoteParagraph); para.Contents = TsStringHelper.MakeTSS("My footnote", Cache.DefaultVernWs); m_footnoteView.RefreshDisplay(); MakeFootnoteSelection(0, 0, 0); // verify that a footnote was added to the collection Assert.AreEqual(originalFootnoteCount + 1, book.FootnotesOS.Count); m_footnoteView.DeleteFootnote(); // verify that the footnote was deleted Assert.AreEqual(originalFootnoteCount, book.FootnotesOS.Count); Assert.IsFalse(footnote.IsValidObject); }
public void DeleteFootnoteFromContextMenuRangeSelection() { SelectionHelper selHelper = new SelectionHelper(); selHelper.AssocPrev = true; selHelper.NumberOfLevels = 3; SelLevInfo[] anchorLevInfo = new SelLevInfo[3]; anchorLevInfo[2].tag = m_footnoteView.BookFilter.Tag; anchorLevInfo[2].ihvo = 1; anchorLevInfo[1].tag = ScrBookTags.kflidFootnotes; anchorLevInfo[1].ihvo = 2; anchorLevInfo[0].tag = StTextTags.kflidParagraphs; anchorLevInfo[0].ihvo = 0; selHelper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo); selHelper.IchAnchor = 1; selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, StTxtParaTags.kflidContents); SelLevInfo[] endLevInfo = new SelLevInfo[3]; endLevInfo[2].tag = m_footnoteView.BookFilter.Tag; endLevInfo[2].ihvo = 1; endLevInfo[1].tag = ScrBookTags.kflidFootnotes; endLevInfo[1].ihvo = 6; endLevInfo[0].tag = StTextTags.kflidParagraphs; endLevInfo[0].ihvo = 0; selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo); selHelper.IchEnd = 7; selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); // Now that all the preparation to set the selection is done, set it. selHelper.SetSelection(m_footnoteView, true, true); Application.DoEvents(); // First get the footnotes we're deleting. IScrFootnote[] footnotes = new IScrFootnote[5]; Guid[] guidFootnotes = new Guid[5]; IStTxtPara[] paras = new IStTxtPara[5]; for (int i = 0; i < 5; i++) { footnotes[i] = Cache.ServiceLocator.GetInstance <IScrFootnoteRepository>().GetObject(m_Jude.FootnotesOS[i + 2].Hvo); guidFootnotes[i] = footnotes[i].Guid; paras[i] = footnotes[i].ParaContainingOrcRA; } m_footnoteView.DeleteFootnote(); foreach (IScrFootnote footnote in footnotes) { Assert.IsFalse(footnote.IsValidObject); } // now make sure that we don't find the footnote markers for (int i = 0; i < 5; i++) { VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i]); VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i], m_wsEn); VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i], m_wsDe); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="FootnoteLocationInfo"/> class. /// </summary> /// ------------------------------------------------------------------------------------ public FootnoteLocationInfo(IScrFootnote footnote, int iBook, int iSection, int iPara, int ich, int tag) { m_footnote = footnote; m_iBook = iBook; m_iSection = iSection; m_iPara = iPara; m_ich = ich; m_tag = tag; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Displays the footnote reference. /// </summary> /// <param name="vwenv">The view environment.</param> /// <param name="hvoFootnote">The HVO of the footnote.</param> /// ------------------------------------------------------------------------------------ internal void DisplayFootnoteReference(IVwEnv vwenv, int hvoFootnote) { IScrFootnote footnote = m_cache.ServiceLocator.GetInstance <IScrFootnoteRepository>().GetObject(hvoFootnote); ITsString tssRef = TsStringUtils.MakeTss(footnote.GetReference(m_wsDefault), m_wsDefault, ScrStyleNames.FootnoteTargetRef); vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); vwenv.AddString(tssRef); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Scrolls a footnote paragraph into view. /// </summary> /// <param name="diff">The sub-diff, which contains the id of the paragraph in the /// footnote which is to be scrolled into view. Or null if no footnote is specified.</param> /// ------------------------------------------------------------------------------------ public void ScrollToFootnotePara(Difference diff) { CheckDisposed(); // TODO: TE-4610 temporary? ignore scrolling when no footnote in this diff //Debug.Assert(diff != null); if (diff == null) { return; } // Get the paragraph which contains the difference. IScrTxtPara para = diff.ParaCurr != null ? diff.ParaCurr : diff.ParaRev; // Get the footnote which contains the paragraph. IScrFootnote footnote = (IScrFootnote)para.Owner; // Find the index of the paragraph. int iPara = para.IndexInOwner; if (iPara < 0) { return; } // Find index of the footnote. int iFootnote = footnote.IndexInOwner; if (iFootnote < 0) { return; } // Create selection pointing to this footnote. SelectionHelper selHelper = new SelectionHelper(); selHelper.AssocPrev = false; selHelper.NumberOfLevels = 2; selHelper.TextPropId = StTxtParaTags.kflidContents; selHelper.LevelInfo[0].tag = StTextTags.kflidParagraphs; selHelper.LevelInfo[0].ihvo = iPara; selHelper.LevelInfo[1].tag = ScrBookTags.kflidFootnotes; selHelper.LevelInfo[1].ihvo = iFootnote; // note: We don't care about seting the ich stuff for this temporary selection. // (The view constructor takes care of highlighting the proper ich range.) // Our mission here is only to scroll to the paragraph. selHelper.IchAnchor = 0; selHelper.IchEnd = 0; // Set the selection. selHelper.SetSelection(this, true, true); ScrollSelectionIntoView(null, VwScrollSelOpts.kssoNearTop); }
public void InsertFootnote_InBt() { IScrBook book = AddBookToMockedScripture(1, "Genesis"); AddTitleToMockedBook(book, "Genesis"); m_draftView.BookFilter.Add(book); IScrSection section = AddSectionToMockedBook(book); AddSectionHeadParaToSection(section, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph in the vernacular. IScrTxtPara parentPara = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddVerse(parentPara, 1, 1, "uno"); AddVerse(parentPara, 0, 2, "dos"); IScrFootnote footnote1 = AddFootnote(book, parentPara, 5); AddParaToMockedText(footnote1, ScrStyleNames.NormalFootnoteParagraph); IScrFootnote footnote2 = AddFootnote(book, parentPara, 10); AddParaToMockedText(footnote2, ScrStyleNames.NormalFootnoteParagraph); Assert.AreEqual(2, book.FootnotesOS.Count); // Construct the initial back translation int wsBt = Cache.DefaultAnalWs; ICmTranslation trans = AddBtToMockedParagraph(parentPara, wsBt); AddRunToMockedTrans(trans, wsBt, "one two", null); ITsStrBldr btTssBldr = trans.Translation.get_String(wsBt).GetBldr(); trans.Translation.set_String(wsBt, btTssBldr.GetString()); m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint(0, 0, 0, 3, false); //set the IP after the word "one" int iBtFootnote1; m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote1); VerifyRequestedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 4); m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint(0, 0, 0, 8, false); // set the IP after the word "two" int iBtFootnote2; m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote2); VerifyRequestedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 9); // Confirm that the footnote callers were inserted in the correct locations. Assert.AreEqual("one" + StringUtils.kChObject + " two" + StringUtils.kChObject, trans.Translation.get_String(wsBt).Text); FdoTestHelper.VerifyBtFootnote(footnote1, parentPara, wsBt, 3); FdoTestHelper.VerifyBtFootnote(footnote2, parentPara, wsBt, 8); }
public void GoToNextFootnote_AtLastFootnote() { IScrBook philemon; IStFootnote footnote1, footnote2; CreateBookWithTwoFootnotes(out philemon, out footnote1, out footnote2); m_editingHelper.SetupSelectionInFootnote(footnote2, philemon, 0, 0, 0); IScrFootnote nextfootnote = m_editingHelper.GoToNextFootnote(); Assert.IsNull(nextfootnote, "Footnote was found when it should not have been"); }
public void SpaceAfterFootnoteMarker() { IScrBook book = m_scr.ScriptureBooksOS[0]; IScrFootnote footnote = AddFootnote(book, (IStTxtPara)book.TitleOA.ParagraphsOS[0], 0, "This is a footnote"); footnote.FootnoteMarker = Cache.TsStrFactory.MakeString("a", Cache.WritingSystemFactory.GetWsFromStr("en")); // Prepare the test by creating a footnote view FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache)) { footnoteView.StyleSheet = styleSheet; footnoteView.Visible = false; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. footnoteView.MakeRoot(); footnoteView.CallLayout(); // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, false, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); selHelper.IchAnchor = 0; selHelper.IchEnd = 5; SelLevInfo[] selLevInfo = new SelLevInfo[3]; Assert.AreEqual(4, selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End)); Array.Copy(selHelper.GetLevelInfo(SelectionHelper.SelLimitType.End), 1, selLevInfo, 0, 3); selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selLevInfo); selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); selHelper.SetSelection(true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("a ", tss.Text.Substring(0, 2)); // make sure the marker and the space are read-only (maybe have to select each run // separately to make this test truly correct) ITsTextProps[] vttp; IVwPropertyStore[] vvps; int cttp; SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); Assert.IsTrue(cttp >= 2); Assert.IsFalse(SelectionHelper.IsEditable(vttp[0], vvps[0]), "Footnote marker is not read-only"); Assert.IsFalse(SelectionHelper.IsEditable(vttp[1], vvps[1]), "Space after marker is not read-only"); } }
public void GoToNextFootnote_FirstFootnote() { IScrBook philemon; IStFootnote footnote1, footnote2; CreateBookWithTwoFootnotes(out philemon, out footnote1, out footnote2); m_editingHelper.SetupSelectionInFootnote(footnote1, philemon, 0, 0, 0); IScrFootnote nextfootnote = m_editingHelper.GoToNextFootnote(); Assert.IsNotNull(nextfootnote, "Couldn't find footnote"); Assert.AreEqual(philemon.FootnotesOS[1], nextfootnote); }
public void InsertFootnote() { IScrBook book = AddBookToMockedScripture(1, "Genesis"); AddTitleToMockedBook(book, "Genesis"); m_draftView.BookFilter.Add(book); IScrSection section = AddSectionToMockedBook(book); // Construct a paragraph in the vernacular. IScrTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); // Footnote goes here: | AddVerse(para, 1, 1, "uno"); // Footnote goes here: | AddVerse(para, 0, 2, "dos"); IScrFootnote footnote1 = AddFootnote(book, para, 5); AddParaToMockedText(footnote1, ScrStyleNames.NormalFootnoteParagraph); IScrFootnote footnote2 = AddFootnote(book, para, 10); AddParaToMockedText(footnote2, ScrStyleNames.NormalFootnoteParagraph); Assert.AreEqual(2, book.FootnotesOS.Count); // Construct the initial back translation AddSegmentFt(para, 1, "one", Cache.DefaultAnalWs); AddSegmentFt(para, 3, "two", Cache.DefaultAnalWs); m_draftView.RefreshDisplay(); m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, 1, 3, 3, true, false, true, VwScrollSelOpts.kssoDefault); //set the IP after the word "one" int iBtFootnote1; m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote1); Assert.AreEqual(0, iBtFootnote1); VerifyRequestedSegmentedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 1, 4); m_draftView.RefreshDisplay(); m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, 3, 3, 3, true, false, true, VwScrollSelOpts.kssoDefault); //set the IP after the word "two" int iBtFootnote2; m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote2); Assert.AreEqual(1, iBtFootnote2); VerifyRequestedSegmentedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 3, 4); // Confirm that the footnote callers were inserted in the correct locations. VerifySegment(para, 1, "one" + StringUtils.kChObject, Cache.DefaultAnalWs); VerifySegment(para, 3, "two" + StringUtils.kChObject, Cache.DefaultAnalWs); FdoTestHelper.VerifyFootnoteInSegmentFt(footnote1, para, 1, Cache.DefaultAnalWs, 3); FdoTestHelper.VerifyFootnoteInSegmentFt(footnote2, para, 3, Cache.DefaultAnalWs, 3); }
public void GoToPreviousFootnote_AtFirstFootnote() { IScrBook philemon; IStFootnote footnote1, footnote2; CreateBookWithTwoFootnotes(out philemon, out footnote1, out footnote2); // set the selection to the first footnote and go to previous. There are // none so it should return null m_editingHelper.SetupSelectionInFootnote(footnote1, philemon, 0, 0, 0); IScrFootnote prevfootnote = m_editingHelper.GoToPreviousFootnote(); Assert.IsNull(prevfootnote); }
public void GoToPreviousFootnote_LastFootnote() { IScrBook philemon; IStFootnote footnote1, footnote2; CreateBookWithTwoFootnotes(out philemon, out footnote1, out footnote2); // set the selection to the second footnote and go to previous. The footnote // should be the first footnote. m_editingHelper.SetupSelectionInFootnote(footnote2, philemon, 0, 0, 0); IScrFootnote prevfootnote = m_editingHelper.GoToPreviousFootnote(); Assert.AreEqual(footnote1.Hvo, prevfootnote.Hvo); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor for the FootnoteInfo structure /// </summary> /// <param name="scrFootnote">given footnote</param> /// ------------------------------------------------------------------------------------ public FootnoteInfo(IScrFootnote scrFootnote) { footnote = scrFootnote; IStPara para = footnote.ParagraphsOS[0]; if (para.StyleRules != null) { paraStylename = para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); } else { paraStylename = null; Debug.Fail("StyleRules should never be null."); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make the DispPropOverrides we need to give the specified run of characters the /// display properties defined by the initializer. /// </summary> /// <param name="para">The paragraph.</param> /// <param name="paraMinHighlight">The index (in logical characters, relative to /// para.Contents) of the first character whose properties will be overridden.</param> /// <param name="paraLimHighlight">The character "limit" (in logical characters, /// relative to para.Contents) of the text whose properties will be overridden.</param> /// <param name="initializer">A delegate that modifies the display props of characters /// between ichMin and ichLim.</param> /// ------------------------------------------------------------------------------------ protected void MakeDispPropOverrides(IScrTxtPara para, int paraMinHighlight, int paraLimHighlight, DispPropInitializer initializer) { if (paraLimHighlight < paraMinHighlight) { throw new ArgumentOutOfRangeException("paraLimHighlight", "ParaLimHighlight must be greater or equal to paraMinHighlight"); } int offsetToStartOfParaContents = 0; if (para.Owner is IScrFootnote && para.IndexInOwner == 0) { IScrFootnote footnote = (IScrFootnote)para.Owner; string sMarker = footnote.MarkerAsString; if (sMarker != null) { offsetToStartOfParaContents += sMarker.Length + OneSpaceString.Length; } offsetToStartOfParaContents += footnote.RefAsString.Length; } // Add the needed properties to each run, within our range ITsString tss = para.Contents; TsRunInfo runInfo; int ichOverrideLim; int ichOverrideMin = Math.Min(Math.Max(paraMinHighlight, 0), tss.Length); int prevLim = 0; do { tss.FetchRunInfoAt(ichOverrideMin, out runInfo); ichOverrideLim = Math.Min(paraLimHighlight, runInfo.ichLim); Debug.Assert(ichOverrideLim <= tss.Length, "If we get a run it should be in the bounds of the paragraph"); // Prevent infinite loop in case of bad data in difference if (ichOverrideLim == prevLim) { break; } prevLim = ichOverrideLim; DispPropOverride prop = DispPropOverrideFactory.Create( ichOverrideMin + offsetToStartOfParaContents, ichOverrideLim + offsetToStartOfParaContents); initializer(ref prop); m_DispPropOverrides.Add(prop); // advance Min for next run ichOverrideMin = ichOverrideLim; }while (ichOverrideLim < paraLimHighlight); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates and initializes a footnote. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_vernWs = Cache.DefaultVernWs; // create footnote IFdoServiceLocator servloc = Cache.ServiceLocator; m_footnote = servloc.GetInstance<IScrFootnoteFactory>().Create(); m_book = AddBookToMockedScripture(1, "Genesis"); m_book.FootnotesOS.Add(m_footnote); m_footnote.FootnoteMarker = TsStringUtils.MakeTss("a", m_vernWs); m_scr.DisplaySymbolInFootnote = true; m_scr.DisplayFootnoteReference = false; // create one empty footnote para m_footnotePara = m_footnote.AddNewTextPara(ScrStyleNames.NormalFootnoteParagraph); m_footnotePara.Contents = TsStringUtils.MakeTss(string.Empty, m_vernWs); }
public void InsertFootnote_BeforeExistingFootnoteInBt() { IScrBook book = AddBookToMockedScripture(1, "Genesis"); AddTitleToMockedBook(book, "Genesis"); m_draftView.BookFilter.Add(book); IScrSection section = AddSectionToMockedBook(book); // Construct a paragraph in the vernacular. IScrTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddVerse(para, 1, 1, "uno"); // Footnote goes here: | AddVerse(para, 0, 2, "dos"); IScrFootnote footnote1 = AddFootnote(book, para, para.Contents.Length); AddParaToMockedText(footnote1, ScrStyleNames.CrossRefFootnoteParagraph); Assert.AreEqual(1, book.FootnotesOS.Count); // Construct the initial back translation int wsBt = Cache.DefaultAnalWs; AddSegmentFt(para, 1, "one", wsBt); const int kiSegmentWithFn = 3; AddSegmentFt(para, kiSegmentWithFn, "two", wsBt); ISegment segment = para.SegmentsOS[kiSegmentWithFn]; ITsString tssSegment = segment.FreeTranslation.get_String(wsBt); ITsStrBldr bldr = tssSegment.GetBldr(); TsStringUtils.InsertOrcIntoPara(footnote1.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, bldr.Length, bldr.Length, wsBt); segment.FreeTranslation.set_String(wsBt, bldr.GetString()); m_draftView.RefreshDisplay(); m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, kiSegmentWithFn, 0, 0, true, false, true, VwScrollSelOpts.kssoDefault); //set the IP after the cross-reference footnote int iDummy; Assert.IsNull(m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iDummy)); // Confirm that nothing else was inserted. VerifySegment(para, 1, "one", wsBt); VerifySegment(para, kiSegmentWithFn, "two" + StringUtils.kChObject, wsBt); FdoTestHelper.VerifyFootnoteInSegmentFt(footnote1, para, kiSegmentWithFn, wsBt, bldr.Length - 1); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes footnotes when there is a range selection. /// </summary> /// <param name="helper"></param> /// ------------------------------------------------------------------------------------ private void DeleteFootnoteRange(SelectionHelper helper) { int nTopLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top); int nBottomLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Bottom); // Get the index of the book containing the first footnote in the selection. // Then get the index of the footnote within that book. int iFirstBook = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels - 1].ihvo; int iFirstFootnote = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels - 2].ihvo; // Get the index of the book containing the last footnote in the selection. // Then get the index of the footnote within that book. int iLastBook = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels - 1].ihvo; int iLastFootnote = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels - 2].ihvo; // Loop through the books containing footnotes in the selection. for (int iBook = iFirstBook; iBook <= iLastBook; iBook++) { IScrBook book = BookFilter.GetBook(iBook); int iBeg = iFirstFootnote; if (iFirstBook != iLastBook && iBook > iFirstBook) { iBeg = 0; } int iEnd = iLastFootnote; if (iFirstBook != iLastBook && iBook < iLastBook) { iEnd = book.FootnotesOS.Count - 1; } // Loop through the footnotes from the selection that are in the // current book. Go in reverse order through the collection. for (int i = iEnd; i >= iBeg; i--) { // TODO: check filter for each HVO IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteRepository>().GetObject(book.FootnotesOS[i].Hvo); book.FootnotesOS.Remove(footnote); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates and initializes a footnote. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_vernWs = Cache.DefaultVernWs; // create footnote ILcmServiceLocator servloc = Cache.ServiceLocator; m_footnote = servloc.GetInstance <IScrFootnoteFactory>().Create(); m_book = AddBookToMockedScripture(1, "Genesis"); m_book.FootnotesOS.Add(m_footnote); m_footnote.FootnoteMarker = TsStringUtils.MakeString("a", m_vernWs); m_scr.DisplaySymbolInFootnote = true; m_scr.DisplayFootnoteReference = false; // create one empty footnote para m_footnotePara = m_footnote.AddNewTextPara(ScrStyleNames.NormalFootnoteParagraph); m_footnotePara.Contents = TsStringUtils.MakeString(string.Empty, m_vernWs); }
public void InsertFootnote_AtEndBtWithLongCallers() { m_scr.FootnoteMarkerSymbol = "@#$"; m_scr.FootnoteMarkerType = FootnoteMarkerTypes.SymbolicFootnoteMarker; IScrBook book = AddBookToMockedScripture(1, "Genesis"); AddTitleToMockedBook(book, "Genesis"); m_draftView.BookFilter.Add(book); IScrSection section = AddSectionToMockedBook(book); AddSectionHeadParaToSection(section, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph in the vernacular. IScrTxtPara parentPara = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddVerse(parentPara, 1, 1, "uno"); AddVerse(parentPara, 0, 2, "dos"); IScrFootnote footnote1 = AddFootnote(book, parentPara, parentPara.Contents.Length); AddParaToMockedText(footnote1, ScrStyleNames.NormalFootnoteParagraph); Assert.AreEqual(1, book.FootnotesOS.Count); // Construct the initial back translation int wsBt = Cache.DefaultAnalWs; ICmTranslation trans = AddBtToMockedParagraph(parentPara, wsBt); AddRunToMockedTrans(trans, wsBt, "a", null); ITsStrBldr btTssBldr = trans.Translation.get_String(wsBt).GetBldr(); TsStringUtils.InsertOrcIntoPara(footnote1.Guid, FwObjDataTypes.kodtNameGuidHot, btTssBldr, btTssBldr.Length, btTssBldr.Length, wsBt); trans.Translation.set_String(wsBt, btTssBldr.GetString()); m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint(0, 0, 0, btTssBldr.Length, false); //set the IP after the footnote int iBtFootnote2; m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote2); m_draftView.RefreshDisplay(); // Confirm that the footnote callers were inserted in the correct locations. Assert.AreEqual("a" + StringUtils.kChObject, trans.Translation.get_String(wsBt).Text); FdoTestHelper.VerifyBtFootnote(footnote1, parentPara, wsBt, btTssBldr.Length - 1); }
public void ExportRtfBtFootnotes() { // Set up the vernacular text. AddTitleToMockedBook(m_book, "Genesis"); AddRunToMockedPara(m_para, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(m_para, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(m_para, "yi kuch batchit he.", null); IScrFootnote footnote1 = AddFootnote( m_book, m_para, 2, "pehla pao wala note"); // Set up back translation. int wsBt = Cache.DefaultAnalWs; ICmTranslation transPara1 = AddBtToMockedParagraph(m_para, wsBt); AddRunToMockedTrans(transPara1, wsBt, "1", ScrStyleNames.ChapterNumber); AddRunToMockedTrans(transPara1, wsBt, "1", ScrStyleNames.VerseNumber); AddRunToMockedTrans(transPara1, wsBt, "This is some text.", null); AddBtFootnote(transPara1, 4, wsBt, footnote1, "First footnote"); m_scr.DisplaySymbolInFootnote = true; // Export the back translation of the footnote. m_exporter = new DummyExportRtf(m_fileName, Cache, m_styleSheet, wsBt); m_exporter.CallExportFootnote(footnote1, wsBt); m_exporter.CloseOutputFile(); int markerStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.FootnoteMarker).IndexInOwner + 1; int footnoteStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.NormalFootnoteParagraph).IndexInOwner + 1; using (TextReader file = FileUtils.OpenFileForRead(m_fileName, Encoding.ASCII)) { string line1 = file.ReadLine(); string line2 = file.ReadLine(); // the first line is the marker emitted into the text stream. // Footnote markers now have the footnote marker style applied Assert.AreEqual(@"\*\cs" + markerStyleNumber + @" a}", line1); Assert.AreEqual(@"{\footnote \pard\plain \s" + footnoteStyleNumber + @"\f1\fs20{" + @"\*\cs" + markerStyleNumber + @" a" + @"}{ }{First footnote}", line2); } }
public void ExportFootnote_Unicode() { int markerStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.FootnoteMarker).IndexInOwner + 1; int footnoteStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.NormalFootnoteParagraph).IndexInOwner + 1; ITsStrFactory stringFactory = TsStrFactoryClass.Create(); // Create a book with a section that has a paragraph with some text and a footnote! AddRunToMockedPara(m_para, "My text for footnotes", string.Empty); IScrFootnote footnote = AddFootnote(m_book, m_para, 2); m_scr.FootnoteMarkerType = FootnoteMarkerTypes.SymbolicFootnoteMarker; m_scr.FootnoteMarkerSymbol = "¶"; m_scr.DisplaySymbolInFootnote = true; footnote.FootnoteMarker = stringFactory.MakeString(null, Cache.DefaultVernWs); IScrTxtPara footnotePara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( footnote, ScrStyleNames.NormalFootnoteParagraph); string footnoteText = "C\u00f2\u00f3\u013a footnot\u0113"; footnotePara.Contents = stringFactory.MakeString(footnoteText, Cache.DefaultVernWs); m_exporter = new DummyExportRtf(m_fileName, Cache, m_styleSheet); m_exporter.CallExportFootnote(footnote); // Verify the contents of the temp file m_exporter.CloseOutputFile(); using (TextReader file = FileUtils.OpenFileForRead(m_fileName, Encoding.ASCII)) { string line1 = file.ReadLine(); string line2 = file.ReadLine(); // the first line is the marker emitted into the text stream. // Footnote markers now have the footnote marker style applied Assert.AreEqual(@"\*\cs" + markerStyleNumber + @" \uc0\u182 }", line1); Assert.AreEqual(@"{\footnote \pard\plain \s" + footnoteStyleNumber + @"\f1\fs20{" + @"\*\cs" + markerStyleNumber + @" \uc0\u182 " + @"}{ }{Co\uc0\u768 o\uc0\u769 l\uc0\u769 footnote\uc0\u772 }", line2); } }
public void GetFootnoteMarkerFromGuid() { IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().Create(); m_scr.ScriptureBooksOS[0].FootnotesOS.Add(footnote); footnote.FootnoteMarker = Cache.TsStrFactory.MakeString("a", Cache.WritingSystemFactory.GetWsFromStr("en")); // Add the guid property so we can get it out as a string. ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); byte[] objData = TsStringUtils.GetObjData(footnote.Guid, 1); propsBldr.SetStrPropValueRgch(1, objData, objData.Length); // Get the guid property as a string. string sObjData; propsBldr.GetStrPropValue(1, out sObjData); StVc vc = new StVc(Cache.WritingSystemFactory.UserWs) { Cache = Cache }; ITsString footnoteMarker = vc.GetStrForGuid(sObjData.Substring(1)); // Call to GetStrForGuid doesn't generate a footnote marker based on the // Scripture Footnote properties since the method to do that is in TeStVc. int dummy; Assert.AreEqual(StringUtils.kszObject, footnoteMarker.Text); ITsTextProps props = footnoteMarker.get_Properties(0); Assert.AreEqual(2, props.IntPropCount); Assert.AreEqual(Cache.DefaultUserWs, props.GetIntPropValues((int)FwTextPropType.ktptWs, out dummy)); Assert.AreEqual(0, props.GetIntPropValues((int)FwTextPropType.ktptEditable, out dummy)); Assert.AreEqual(1, props.StrPropCount); FwObjDataTypes odt; Guid footnoteGuid = TsStringUtils.GetGuidFromProps(props, null, out odt); Assert.IsTrue(odt == FwObjDataTypes.kodtPictEvenHot || odt == FwObjDataTypes.kodtPictOddHot); Assert.AreEqual(footnote.Guid, footnoteGuid); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find the next footnote starting from the given paragraph and position. /// </summary> /// <param name="iPara">Index of paragraph to start search.</param> /// <param name="ich">Character index to start search.</param> /// <param name="fSkipCurrentPosition">If <c>true</c> we search forwards starting with the /// run after ich, otherwise we start with the current run.</param> /// <returns>Next footnote in string, or <c>null</c> if footnote can't be found.</returns> /// ------------------------------------------------------------------------------------ public IScrFootnote FindNextFootnote(ref int iPara, ref int ich, bool fSkipCurrentPosition) { if (ParagraphsOS.Count == 0) { return(null); } IScrTxtPara para = (IScrTxtPara)ParagraphsOS[iPara]; IScrFootnote footnote = para.FindNextFootnoteInContents(ref ich, fSkipCurrentPosition); while (footnote == null && iPara < ParagraphsOS.Count - 1) { iPara++; ich = 0; para = (IScrTxtPara)ParagraphsOS[iPara]; footnote = para.FindNextFootnoteInContents(ref ich, false); } return(footnote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes a footnote or footnotes within a text selection. /// </summary> /// ------------------------------------------------------------------------------------ protected void DeleteFootnoteAux() { SelectionHelper helper = SelectionHelper.Create(this); if (helper == null) { return; // Better then crashing :) } int fnLevel = helper.GetLevelForTag(ScrBookTags.kflidFootnotes); if (helper.Selection.IsRange) { DeleteFootnoteRange(helper); } else { // There's no range selection, so delete only one footnote IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteRepository>().GetObject(helper.LevelInfo[fnLevel].hvo); ((IScrBook)footnote.Owner).FootnotesOS.Remove(footnote); } if (RootBox.Height <= 0) { DraftView.Focus(); } else { int iBook = helper.LevelInfo[fnLevel + 1].ihvo; IScrBook book = m_bookFilter.GetBook(iBook); int iFootnote = helper.LevelInfo[fnLevel].ihvo; // If the last footnote in the book was deleted find a footnote to move to if (iFootnote >= book.FootnotesOS.Count) { FindNearestFootnote(ref iBook, ref iFootnote); } FootnoteEditingHelper.ScrollToFootnote(iBook, iFootnote, 0); } }
public void FixOrcsWithoutProps_OrphanedFootnotesWithNoOrcs() { IScrBook exodus = CreateExodusData(); CreateFootnote(exodus, 0, 0, 0, 4, ScrStyleNames.NormalFootnoteParagraph, false); IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().Create(); exodus.FootnotesOS.Add(footnote); //IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS.Append(new StTxtPara()); //para.Contents = TsStringUtils.MakeTss("Poor orphaned footnote 1") TeScrInitializer scrInit = new TestTeScrInitializer(Cache); List <string> report = (List <string>)ReflectionHelper.GetResult(scrInit, "FixOrcsWithoutProps"); VerifyResourceForFixedOrphans(); Assert.AreEqual(1, report.Count); Assert.AreEqual("EXO - Footnote 2 has no corresponding marker in the vernacular text", report[0]); Assert.AreEqual(2, exodus.FootnotesOS.Count); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create test data in a right-to-left script. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { IWritingSystem defWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; // Add basic data for Genesis m_genesis = AddBookToMockedScripture(1, "Genesis"); AddTitleToMockedBook(m_genesis, m_StartText); IScrSection section = AddSectionToMockedBook(m_genesis); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddFormatTextToMockedPara(m_genesis, para, @"\c12\v13-14\*" + m_WordsText, m_UrWsHvo); // Add footnote IScrFootnote footnote = AddFootnote(m_genesis, para, 10); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( footnote, ScrStyleNames.NormalFootnoteParagraph); ITsStrFactory strfact = TsStrFactoryClass.Create(); footPara.Contents = strfact.MakeString(m_WordsText, m_UrWsHvo); }
public void DeleteFootnoteInRangeSelectionAcrossMultipleBooks() { SetupSelectionForRangeAcrossBooks(); IScripture scr = Cache.LangProject.TranslatedScriptureOA; IScrFootnote[] footnotes = new IScrFootnote[4]; Guid[] guidFootnotes = new Guid[4]; IScrTxtPara[] paras = new IScrTxtPara[4]; // First get the footnotes we're deleting from JAMES. IScrBook book = scr.ScriptureBooksOS[1]; footnotes[0] = book.FootnotesOS[31]; footnotes[1] = book.FootnotesOS[32]; // First get the footnotes we're deleting from JUDE. book = (IScrBook)scr.ScriptureBooksOS[2]; footnotes[2] = book.FootnotesOS[0]; footnotes[3] = book.FootnotesOS[1]; for (int i = 0; i < 4; i++) { guidFootnotes[i] = footnotes[i].Guid; paras[i] = footnotes[i].ContainingParagraph; } m_footnoteView.DeleteFootnote(); foreach (IScrFootnote footnote in footnotes) { Assert.IsFalse(footnote.IsValidObject); } // now make sure that we don't find the footnote markers for (int i = 0; i < 4; i++) { Assert.IsFalse(IsFootnoteMarkerInText(paras[i], guidFootnotes[i]), "Footnote marker didn't get deleted from text"); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find the previous footnote starting from the given paragraph and character position. /// </summary> /// <param name="iPara">Index of paragraph to start search, or -1 to start search in /// last paragraph.</param> /// <param name="ich">Character index to start search, or -1 to start at the end of /// the paragraph.</param> /// <param name="fSkipCurrentPosition">If <c>true</c> we search backwards starting with the /// run before ich, otherwise we start with the run ich is in.</param> /// <returns>Last footnote in string, or <c>null</c> if footnote can't be found.</returns> /// ------------------------------------------------------------------------------------ public IScrFootnote FindPreviousFootnote(ref int iPara, ref int ich, bool fSkipCurrentPosition) { if (ParagraphsOS.Count <= iPara) { return(null); } if (iPara == -1) { iPara = ParagraphsOS.Count - 1; } IScrTxtPara para = (IScrTxtPara)ParagraphsOS[iPara]; IScrFootnote footnote = para.FindPrevFootnoteInContents(ref ich, fSkipCurrentPosition); while (footnote == null && iPara > 0) { para = (IScrTxtPara)ParagraphsOS[--iPara]; ich = para.Contents.Length; footnote = para.FindPrevFootnoteInContents(ref ich, false); } return(footnote); }
public void DeleteFootnoteInRangeSelectionAcrossMultipleBooks() { SetupSelectionForRangeAcrossBooks(); IScripture scr = Cache.LangProject.TranslatedScriptureOA; IScrFootnote[] footnotes = new IScrFootnote[4]; Guid[] guidFootnotes = new Guid[4]; IScrTxtPara[] paras = new IScrTxtPara[4]; // First get the footnotes we're deleting from JAMES. IScrBook book = scr.ScriptureBooksOS[1]; footnotes[0] = book.FootnotesOS[31]; footnotes[1] = book.FootnotesOS[32]; // First get the footnotes we're deleting from JUDE. book = (IScrBook)scr.ScriptureBooksOS[2]; footnotes[2] = book.FootnotesOS[0]; footnotes[3] = book.FootnotesOS[1]; for (int i = 0; i < 4; i++) { guidFootnotes[i] = footnotes[i].Guid; paras[i] = footnotes[i].ContainingParagraph; } m_footnoteView.DeleteFootnote(); foreach (IScrFootnote footnote in footnotes) Assert.IsFalse(footnote.IsValidObject); // now make sure that we don't find the footnote markers for (int i = 0; i < 4; i++) { Assert.IsFalse(IsFootnoteMarkerInText(paras[i], guidFootnotes[i]), "Footnote marker didn't get deleted from text"); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the Chapter Verse Reference representation for a footnote (ie. sectionCV-CV Footnote(footnoteCV)) /// Or Title representation (ie. Title Footnote(OwnOrd)) /// </summary> /// ------------------------------------------------------------------------------------ public string ContainingRefAsString(IScrFootnote footnote) { footnote.IgnoreDisplaySettings = true; // so we can access GetReference. string parentContext = ""; string footnoteRef = ""; IScrSection containingSection; IStText containingTitle; if (footnote.TryGetContainingSection(out containingSection)) { parentContext = ChapterVerseBridgeAsString(containingSection); footnoteRef = footnote.GetReference(m_cache.DefaultUserWs).Trim(); } else if (footnote.TryGetContainingTitle(out containingTitle)) { parentContext = Strings.ksScriptureTitle; footnoteRef = footnote.OwnOrd.ToString(CultureInfo.InvariantCulture); } return String.Format("{0} {1}({2})", parentContext, Strings.ksScriptureFootnote, footnoteRef); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Delete all footnotes between firstFootnoteToDelete and lastFootnoteToDelete. /// </summary> /// <remarks>Use this version of DeleteFootnotes() when there is no need to clean up /// ORCs in corresponding BTs, such as when the deletion being performed is deleting /// only entire paragraphs.</remarks> /// <param name="book">Book that contains the sections to delete</param> /// <param name="firstFootnoteToDelete">First footnote that will be deleted /// (might be null).</param> /// <param name="lastFootnoteToDelete">Last footnote that will be deleted /// (might be null).</param> /// ------------------------------------------------------------------------------------ private void DeleteFootnotes(IScrBook book, IScrFootnote firstFootnoteToDelete, IScrFootnote lastFootnoteToDelete) { DeleteFootnotes(book, firstFootnoteToDelete, lastFootnoteToDelete, null, null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Delete all footnotes between firstFootnoteToDelete and lastFootnoteToDelete. Clean /// up BT ORCs for the paragraphs specified. /// </summary> /// <param name="book">Book that contains the sections to delete</param> /// <param name="firstFootnoteToDelete">First footnote that will be deleted /// (might be null).</param> /// <param name="lastFootnoteToDelete">Last footnote that will be deleted /// (might be null).</param> /// <param name="firstPara">First (possibly partial) paragraph being deleted that /// might contain ORCs for the first footnotes. Any footnotes being deleted whose ORCs /// are in this paragraph will have their corresponding BT ORCs removed as well. /// If zero, we don't bother to remove any corresponding BT ORCs in the first para.</param> /// <param name="lastPara">Last (possibly partial) paragraph being deleted that /// might contain ORCs for the last footnotes. Any footnotes being deleted whose ORCs /// are in this paragraph will have their corresponding BT ORCs removed as well. /// If zero, we don't bother to remove any corresponding BT ORCs in the last para.</param> /// ------------------------------------------------------------------------------------ private void DeleteFootnotes(IScrBook book, IScrFootnote firstFootnoteToDelete, IScrFootnote lastFootnoteToDelete, IStTxtPara firstPara, IStTxtPara lastPara) { Debug.Assert((firstFootnoteToDelete == null && lastFootnoteToDelete == null) || (firstFootnoteToDelete != null && lastFootnoteToDelete != null)); if (firstFootnoteToDelete != null) { int lastFootnote = lastFootnoteToDelete.IndexInOwner; int firstFootnote = firstFootnoteToDelete.IndexInOwner; for (int i = lastFootnote; i >= firstFootnote; i--) { // This code fixes TE-4882. IScrFootnote footnote = book.FootnotesOS[i]; book.FootnotesOS.Remove(footnote); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor for the FootnoteInfo structure /// </summary> /// <param name="scrFootnote">given footnote</param> /// <param name="sParaStylename">paragraph style of the footnote</param> /// ------------------------------------------------------------------------------------ public FootnoteInfo(IScrFootnote scrFootnote, string sParaStylename) { footnote = scrFootnote; paraStylename = sParaStylename; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a paragraph with the given text, and append it to the given footnote's /// content. /// </summary> /// <param name="footnote">footnote to append to</param> /// <param name="format">(See CreateText for the definition of the format string)</param> /// <param name="ws">writing system for the paragraph text</param> /// <returns>the new paragraph</returns> /// ------------------------------------------------------------------------------------ private IScrTxtPara AppendParagraph(IScrFootnote footnote, string format, int ws) { // insert a new para in the footnote IScrTxtPara para = (IScrTxtPara)AddParaToMockedText(footnote, "Note General Paragraph"); para.Contents = CreateFormatText(null, para.Contents.GetBldr(), format, ws); return para; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write all the paragraphs in the given footnote. /// </summary> /// ------------------------------------------------------------------------------------ private void ExportFootnote(IScrFootnote scrFootnote) { m_footnoteIndex = scrFootnote.IndexInOwner + 1; // TE allows only one paragraph in a footnote! Debug.Assert(scrFootnote.ParagraphsOS.Count < 2); foreach (IStTxtPara para in scrFootnote.ParagraphsOS) ExportParagraph(para, null, false); m_footnoteIndex = -1; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** "); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. var disposable = m_pauseEvent as IDisposable; if (disposable != null) disposable.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_ParaBldr = null; m_cache = null; m_styleSheet = null; m_scr = null; m_undoManager = null; m_importCallbacks = null; m_ScrSectionHeadParaProxy = null; m_DefaultIntroSectionHeadParaProxy = null; m_DefaultScrParaProxy = null; m_DefaultIntroParaProxy = null; m_BTStrBldrs = null; m_SavedParaBldr = null; m_CurrFootnote = null; m_ttpChapterNumber = null; m_sPrevBook = null; m_scrBook = null; m_currSection = null; m_isDisposed = true; }
public void DeleteFootnoteFromContextMenuRangeSelection() { SelectionHelper selHelper = new SelectionHelper(); selHelper.AssocPrev = true; selHelper.NumberOfLevels = 3; SelLevInfo[] anchorLevInfo = new SelLevInfo[3]; anchorLevInfo[2].tag = m_footnoteView.BookFilter.Tag; anchorLevInfo[2].ihvo = 1; anchorLevInfo[1].tag = ScrBookTags.kflidFootnotes; anchorLevInfo[1].ihvo = 2; anchorLevInfo[0].tag = StTextTags.kflidParagraphs; anchorLevInfo[0].ihvo = 0; selHelper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo); selHelper.IchAnchor = 1; selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, StTxtParaTags.kflidContents); SelLevInfo[] endLevInfo = new SelLevInfo[3]; endLevInfo[2].tag = m_footnoteView.BookFilter.Tag; endLevInfo[2].ihvo = 1; endLevInfo[1].tag = ScrBookTags.kflidFootnotes; endLevInfo[1].ihvo = 6; endLevInfo[0].tag = StTextTags.kflidParagraphs; endLevInfo[0].ihvo = 0; selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo); selHelper.IchEnd = 7; selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); // Now that all the preparation to set the selection is done, set it. selHelper.SetSelection(m_footnoteView, true, true); Application.DoEvents(); // First get the footnotes we're deleting. IScrFootnote[] footnotes = new IScrFootnote[5]; Guid[] guidFootnotes = new Guid[5]; IStTxtPara[] paras = new IStTxtPara[5]; for (int i = 0; i < 5; i++) { footnotes[i] = Cache.ServiceLocator.GetInstance<IScrFootnoteRepository>().GetObject(m_Jude.FootnotesOS[i + 2].Hvo); guidFootnotes[i] = footnotes[i].Guid; paras[i] = footnotes[i].ParaContainingOrcRA; } m_footnoteView.DeleteFootnote(); foreach (IScrFootnote footnote in footnotes) Assert.IsFalse(footnote.IsValidObject); // now make sure that we don't find the footnote markers for (int i = 0; i < 5; i++) { VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i]); VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i], m_wsEn); VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i], m_wsDe); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Call the ExportFootnote method /// </summary> /// <param name="footnote">The footnote.</param> /// <param name="wsBt">The writing system of the back translation to export.</param> /// ------------------------------------------------------------------------------------ public void CallExportFootnote(IScrFootnote footnote, int wsBt) { m_rtfStyleTable.ConnectStyles(); base.ExportFootnote(footnote, wsBt); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write the first paragraph in the given footnote. (TE allows only 1 paragraph in /// footnotes!) /// </summary> /// ------------------------------------------------------------------------------------ private void ExportFootnote(IScrFootnote foot) { IStTxtPara para = foot.ParagraphsOS[0] as IStTxtPara; string sStyle = para.StyleName; if (String.IsNullOrEmpty(sStyle)) sStyle = "scrFootnote"; else sStyle = m_xhtml.GetValidCssClassName(sStyle); ITsStrBldr bldr = foot.MakeFootnoteMarker(m_cache.DefaultVernWs); string sFootnoteMarker = bldr.Text; ITsString tssPara = para.Contents; m_writer.WriteLine("<span class=\"{0}\" id=\"{1}\" title=\"{2}\">", sStyle, "F" + foot.Guid.ToString().ToUpperInvariant(), sFootnoteMarker); m_xhtml.MapCssToLang(sStyle, LanguageCode(TsStringUtils.GetWsAtOffset(tssPara, 0))); WriteTsStringAsXml(tssPara, 4); m_writer.WriteLine("</span>"); // The following class is inserted by the XSLT processing. m_xhtml.MapCssToLang("scrFootnoteMarker", LanguageCode(m_cache.DefaultVernWs)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Export a footnote object. /// </summary> /// <param name="footnote">the footnote</param> /// <param name="exportMode">The export mode.</param> /// <param name="iWs">index into the available analysis writing systems (should be -1 if /// exportMode is ExportMode.VernacularOnly</param> /// ------------------------------------------------------------------------------------ private void ExportFootnote(IScrFootnote footnote, ExportMode exportMode, int iWs) { int nParas = footnote.ParagraphsOS.Count; Debug.Assert(nParas > 0); string paraStyleName = null; string footnoteMarker = null; ITsString tss; bool fNormalCharStyle = false; // whether previous run was a normal character style // Eventually we might support multiple paragraphs... for (int iPara = 0; iPara < nParas; iPara++) { // Get the footnote paragraph IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[iPara]; if (iWs == -1) // get the vernacular para tss = para.Contents; else { // get the specified back translation ICmTranslation trans = para.GetBT(); int wsAlt = m_requestedAnalWS[iWs]; tss = (trans != null) ? trans.Translation.get_String(wsAlt) : null; } if (iPara == 0) { // Map the style name to a marker. paraStyleName = footnote.ParaStyleId; // Output the opening sf marker for the footnote. string fm = GetMarkerForStyle(paraStyleName).Substring(1); if (exportMode == ExportMode.InterleavedVernAndBt && iWs != -1) footnoteMarker = kBackTransMarkerPrefix + fm + GetIcuSuffix(iWs); else footnoteMarker = @"\" + fm; string footnoteField = footnoteMarker + " "; // Output the footnote caller (footnote marker type or literal marker) string sCaller; switch (m_scr.DetermineFootnoteMarkerType(paraStyleName)) { // output character specified by USFM 2.0 standard case FootnoteMarkerTypes.AutoFootnoteMarker: sCaller = "+"; break; case FootnoteMarkerTypes.NoFootnoteMarker: sCaller = "-"; break; case FootnoteMarkerTypes.SymbolicFootnoteMarker: default: sCaller = m_scr.DetermineFootnoteMarkerSymbol(paraStyleName); break; } footnoteField += sCaller + " "; if (MarkupSystem == MarkupType.Paratext) m_file.Write(footnoteField); else { m_file.WriteLine(); m_file.WriteLine(footnoteField); } // Output the chapter/verse reference if the footnote displays it. // But never output the ref for footnotes in a title or section heading. // And never output the ref for footnotes in an intro paragraph (which will // be the case when the verse number is zero). string reference = footnote.RefAsString; if (footnote.DisplayFootnoteReference && reference != null && reference != string.Empty) { bool dummy = false; OutputFootnoteCharStyleRun(footnote.ParaStyleId, true, ScrStyleNames.FootnoteTargetRef, reference, exportMode, iWs, ref dummy, ref fNormalCharStyle); } // ENHANCE: First run of footnote paragraph may not be normal footnote text; If it is // a general character style (or default para chars), we want to precede it with an \ft; // but if it's a footnote character style, we don't. In order to know the difference, // we would need to access the stylesheet to get the context, so for now we'll just // output the \ft all the time since it doesn't seem to cause any problems in Paratext. //if (MarkupSystem == MarkupType.Paratext) // OutputFootnoteCharStyleRun(footnote.ParaStyleId, ksDefaultFootnoteCharacters, string.Empty); } if (tss == null) { Debug.Assert(iWs != -1, "tss can only be null if this is a BT export (this footnote never had a BT created)"); continue; } // Flag indicating whether we're already in the context of an \ft, \fk, fqa, \xt, etc. field bool fInFootnoteContentField = false; // Output all of the runs in the footnote string. for (int iRun = 0; iRun < tss.RunCount; iRun++) { ITsTextProps runProps = tss.get_Properties(iRun); string runText = tss.get_RunText(iRun); if (runText == null) continue; string styleName = runProps.GetStrPropValue( (int)FwTextPropType.ktptNamedStyle); // Output the run text within char style markers if (styleName == null) { if (fInFootnoteContentField) { // If we are in a footnote content field in Paratext format and // the previous run was not a standard character style, // then we need to insert a marker to indicate the next content field. if (MarkupSystem == MarkupType.Paratext && !fNormalCharStyle) { Debug.Assert(paraStyleName != null); Debug.Assert(m_markerMappings.ContainsKey(paraStyleName + "\uffff" + ksDefaultFootnoteCharacters)); m_file.Write(m_markerMappings[paraStyleName + "\uffff" + ksDefaultFootnoteCharacters] + " "); } m_file.Write(runText); } else { OutputFootnoteCharStyleRun(footnote.ParaStyleId, true, ksDefaultFootnoteCharacters, runText, exportMode, iWs, ref fInFootnoteContentField, ref fNormalCharStyle); } } else { // if the style has a customized mapping based on the type of the // note (either General Footnote or Cross-Reference), use it. bool fLookupBasedOnParaStyleContext = m_markerMappings.ContainsKey( paraStyleName + "\uffff" + styleName); OutputFootnoteCharStyleRun(footnote.ParaStyleId, fLookupBasedOnParaStyleContext, styleName, runText, exportMode, iWs, ref fInFootnoteContentField, ref fNormalCharStyle); } } } // if there were no paragraphs for the footnote, bail out, nothing happened if (nParas == 0) return; // Close the footnote - Paratext markup needs an end marker if (MarkupSystem == MarkupType.Paratext) m_file.Write(footnoteMarker + "*"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the referenced footnote given the properties of a back translation text run /// containing an Object Replacement Character (ORC). /// </summary> /// <param name="ttp">The text properties of the footnote.</param> /// <param name="footnote">[out] footnote referenced in the text properties or null /// if footnote is not found.</param> /// <returns><c>true</c> if the footnote was located; <c>false</c> otherwise</returns> /// ------------------------------------------------------------------------------------ private bool GetReferencedFootnote(ITsTextProps ttp, out IScrFootnote footnote) { FwObjDataTypes odt; Guid footnoteRef = TsStringUtils.GetGuidFromProps(ttp, new FwObjDataTypes[] { FwObjDataTypes.kodtNameGuidHot }, out odt); Debug.Assert(footnoteRef != Guid.Empty, "Unable to find referenced footnote."); return m_cache.ServiceLocator.GetInstance<IScrFootnoteRepository>().TryGetFootnote( footnoteRef, out footnote); }