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 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);
        }
        public void InsertFootnote_WithRangeSelectionInBt()
        {
            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);
            IStTxtPara   footnote2Para = AddParaToMockedText(footnote2, ScrStyleNames.NormalFootnoteParagraph);

            // Put some text into this footnote, so there will be a segment created.
            footnote2Para.Contents = Cache.TsStrFactory.MakeString("fun stuff", Cache.DefaultVernWs);
            Assert.AreEqual(2, book.FootnotesOS.Count);

            // Construct the initial back translation
            int wsBt = Cache.DefaultAnalWs;

            AddSegmentFt(para, 1, "one", wsBt);
            AddSegmentFt(para, 3, "two", wsBt);
            m_draftView.RefreshDisplay();

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, 1, 0, 3,
                                                           true, false, true, VwScrollSelOpts.kssoDefault); // select 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, 0,
                                                           true, false, true, VwScrollSelOpts.kssoDefault); // select the word "two" -- end before anchor
            int iBtFootnote2;

            m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote2);
            VerifyRequestedSegmentedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 3, 4);
            Assert.AreEqual(1, iBtFootnote2);

            // Confirm that the footnote callers were inserted in the correct locations.
            VerifySegment(para, 1, "one" + StringUtils.kChObject, wsBt);
            VerifySegment(para, 3, "two" + StringUtils.kChObject, wsBt);
            FdoTestHelper.VerifyFootnoteInSegmentFt(footnote1, para, 1, wsBt, 3);
            FdoTestHelper.VerifyFootnoteInSegmentFt(footnote2, para, 3, wsBt, 3);

            // Confirm that the footnote back translations contain the text that was selected
            // when they were inserted.
            Assert.AreEqual(0, footnote1[0].SegmentsOS.Count,
                            "Because the vernacular footnote had no text, there is no segment, so there was no place to put the selected BT text.");
            ISegment segFootnote2 = footnote2[0].SegmentsOS[0];

            AssertEx.AreTsStringsEqual(DraftViewTests.GetReferencedTextFootnoteStr("two", wsBt),
                                       segFootnote2.FreeTranslation.get_String(wsBt));
        }
        public void InsertFootnote_OutOfOrder()
        {
            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);

            // Footnotes go here:    a  b    c  d     e
            AddVerse(para, 1, 1, "Asi me dijo mi mama.");
            IScrFootnote footnote1 = AddFootnote(book, para, 4);

            AddParaToMockedText(footnote1, ScrStyleNames.NormalFootnoteParagraph);
            IScrFootnote footnote2 = AddFootnote(book, para, 8);

            AddParaToMockedText(footnote2, ScrStyleNames.NormalFootnoteParagraph);
            IScrFootnote footnote3 = AddFootnote(book, para, 14);

            AddParaToMockedText(footnote3, ScrStyleNames.NormalFootnoteParagraph);
            IScrFootnote footnote4 = AddFootnote(book, para, 18);

            AddParaToMockedText(footnote4, ScrStyleNames.NormalFootnoteParagraph);
            IScrFootnote footnote5 = AddFootnote(book, para, 25);

            AddParaToMockedText(footnote5, ScrStyleNames.NormalFootnoteParagraph);
            Assert.AreEqual(5, book.FootnotesOS.Count);

            // Construct the initial back translation
            // Footnotes go here:    d   e    c  b  a
            AddSegmentFt(para, 1, "My mom told me so.", Cache.DefaultAnalWs);
            m_draftView.RefreshDisplay();

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, 1, 17, 17,
                                                           true, false, true, VwScrollSelOpts.kssoDefault); //set the IP after the word "so"
            int iBtFootnote1;

            m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote1);
            Assert.AreEqual(0, iBtFootnote1);
            VerifyRequestedSegmentedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 1, 18);
            m_draftView.RefreshDisplay();

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, 1, 14, 14,
                                                           true, false, true, VwScrollSelOpts.kssoDefault); //set the IP after the word "me"
            int iBtFootnote2;

            m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote2);
            Assert.AreEqual(1, iBtFootnote2);
            VerifyRequestedSegmentedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 1, 15);
            m_draftView.RefreshDisplay();

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, 1, 11, 11,
                                                           true, false, true, VwScrollSelOpts.kssoDefault); //set the IP after the word "told"
            int iBtFootnote3;

            m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote3);
            Assert.AreEqual(2, iBtFootnote3);
            VerifyRequestedSegmentedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 1, 12);
            m_draftView.RefreshDisplay();

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, 1, 2, 2,
                                                           true, false, true, VwScrollSelOpts.kssoDefault); //set the IP after the word "My"
            int iBtFootnote4;

            m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote4);
            Assert.AreEqual(3, iBtFootnote4);
            VerifyRequestedSegmentedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 1, 3);
            m_draftView.RefreshDisplay();

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidContent, 0, 1, 7, 7,
                                                           true, false, true, VwScrollSelOpts.kssoDefault); //set the IP after the word "mom"
            int iBtFootnote5;

            m_draftView.TeEditingHelper.InsertFootnote(ScrStyleNames.NormalFootnoteParagraph, out iBtFootnote5);
            Assert.AreEqual(4, iBtFootnote5);
            VerifyRequestedSegmentedBTSelection(0, 0, ScrSectionTags.kflidContent, 0, 1, 8);
            m_draftView.RefreshDisplay();

            // Confirm that the footnote callers were inserted in the correct locations.
            VerifySegment(para, 1, "My" + StringUtils.kChObject + " mom" + StringUtils.kChObject + " told" +
                          StringUtils.kChObject + " me" + StringUtils.kChObject + " so" + StringUtils.kChObject + ".",
                          Cache.DefaultAnalWs);
            FdoTestHelper.VerifyFootnoteInSegmentFt(footnote1, para, 1, Cache.DefaultAnalWs, 21);
            FdoTestHelper.VerifyFootnoteInSegmentFt(footnote2, para, 1, Cache.DefaultAnalWs, 17);
            FdoTestHelper.VerifyFootnoteInSegmentFt(footnote3, para, 1, Cache.DefaultAnalWs, 13);
            FdoTestHelper.VerifyFootnoteInSegmentFt(footnote4, para, 1, Cache.DefaultAnalWs, 2);
            FdoTestHelper.VerifyFootnoteInSegmentFt(footnote5, para, 1, Cache.DefaultAnalWs, 7);
        }