Example #1
0
        public void GetAnnotationLocationInfo_BTLongerThanVern()
        {
            int wsBt = Cache.DefaultAnalWs;
            // Add a section
            IScrSection    section    = m_scr.ScriptureBooksOS[0].SectionsOS[1];
            IStTxtPara     para       = section.ContentOA[0];
            ICmTranslation transPara1 = para.GetOrCreateBT();

            // The text "11BT Verse one" is already added, but we add a couple more verses...
            AddRunToMockedTrans(transPara1, wsBt, " ", null);
            AddRunToMockedTrans(transPara1, wsBt, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedTrans(transPara1, wsBt, "BT verse two. ", null);
            m_draftView.RefreshDisplay();

            // Set up a simple selection in the first back translation paragraph.
            m_draftView.SelectRangeOfChars(0, 1, 0, 0, 25);

            ICmObject topObj, bottomObj;
            int       wsSelector;
            int       startOffset, endOffset;
            ITsString tssQuote;
            BCVRef    startRef, endRef;

            m_draftView.TeEditingHelper.GetAnnotationLocationInfo(out topObj, out bottomObj, out wsSelector,
                                                                  out startOffset, out endOffset, out tssQuote, out startRef, out endRef);

            Assert.AreEqual(transPara1, topObj);
            Assert.AreEqual(transPara1, bottomObj);
            Assert.AreEqual(wsBt, wsSelector);
            Assert.AreEqual(0, startOffset);
            Assert.AreEqual(25, endOffset);
            Assert.AreEqual(new BCVRef(2, 1, 1), startRef);
            Assert.AreEqual(new BCVRef(2, 1, 2), endRef);
            Assert.AreEqual("BT Verse one. BT verse", tssQuote.Text);
        }
Example #2
0
        public void FindNextBackTrans_SectionContentToHead_HeadFinished()
        {
            // Mark the first section head paragraph BT as finished and add a second section
            // head paragraph
            IScrSection    section2 = m_exodus.SectionsOS[1];
            IStTxtPara     para     = section2.HeadingOA[0];
            ICmTranslation trans    = para.GetOrCreateBT();

            m_draftView.SetTransStatus(trans, BackTranslationStatus.Finished);
            para = AddSectionHeadParaToSection(section2, "Heading 2B", ScrStyleNames.SectionHead);
            AddBtToMockedParagraph(para, Cache.DefaultAnalWs);
            m_draftView.RefreshDisplay();

            m_draftView.SetInsertionPoint(ScrSectionTags.kflidContent,
                                          0, 0, 0);

            m_draftView.CallNextUnfinishedBackTrans();
            SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(1, m_draftView.ParagraphIndex);
            Assert.AreEqual(ScrSectionTags.kflidHeading,
                            m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsFalse(m_draftView.TeEditingHelper.InBookTitle);
        }
Example #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add an empty back translation to the paragraph, or return the existing one.
        /// </summary>
        /// <param name="owner">the owning paragraph</param>
        /// <param name="wsTrans"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected ICmTranslation AddBtToMockedParagraph(IStTxtPara owner, int wsTrans)
        {
            ICmTranslation trans = owner.GetOrCreateBT();

            trans.Translation.set_String(wsTrans, TsStringUtils.EmptyString(wsTrans));
            return(trans);
        }
Example #4
0
        public void FindNextMissingBtFootnoteMarker_BtSectionHeadToContent()
        {
            IScrSection section = m_exodus.SectionsOS[1];

            ITsStrFactory strfact     = TsStrFactoryClass.Create();
            IStTxtPara    contentPara = section.ContentOA[0];
            ITsStrBldr    strBldr     = contentPara.Contents.GetBldr();
            IStFootnote   foot        = m_exodus.InsertFootnoteAt(0, strBldr, 7);

            contentPara.Contents = strBldr.GetString();
            IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);

            footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs);

            ICmTranslation trans = contentPara.GetOrCreateBT();

            m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0);

            m_draftView.CallNextMissingBtFootnoteMarker();

            SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(2, helper.IchAnchor, "IP should be after chapter and verse number.");
            Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_draftView.ParagraphIndex);
            Assert.AreEqual(ScrSectionTags.kflidContent,
                            m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation);
        }
Example #5
0
        public void FindNextMissingBtFootnoteMarker_BtSectionHeadToNowhere()
        {
            IScrSection section = m_exodus.SectionsOS[1];

            ITsStrFactory strfact     = TsStrFactoryClass.Create();
            IStTxtPara    contentPara = section.ContentOA[0];
            ITsStrBldr    strBldr     = contentPara.Contents.GetBldr();
            IStFootnote   foot        = m_exodus.InsertFootnoteAt(0, strBldr, 7);

            contentPara.Contents = strBldr.GetString();
            IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);

            footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs);

            ICmTranslation trans = contentPara.GetOrCreateBT();
            ITsStrBldr     bldr  = trans.Translation.get_String(Cache.DefaultAnalWs).GetBldr();

            TsStringUtils.InsertOrcIntoPara(foot.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 2, 2, Cache.DefaultAnalWs);
            trans.Translation.set_String(Cache.DefaultAnalWs, bldr.GetString());

            m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0);

            m_draftView.CallNextMissingBtFootnoteMarker();

            SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_draftView.ParagraphIndex);
            Assert.AreEqual(ScrSectionTags.kflidHeading, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation);
        }
Example #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add an empty back translation to the paragraph, or return the existing one.
        /// </summary>
        /// <param name="owner">the owning paragraph</param>
        /// <param name="wsTrans"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected ICmTranslation AddBtToMockedParagraph(IStTxtPara owner, int wsTrans)
        {
            ICmTranslation trans = owner.GetOrCreateBT();

            trans.Translation.set_String(wsTrans, Cache.TsStrFactory.MakeString(string.Empty, wsTrans));
            return(trans);
        }
Example #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Append a run of text to a back translation of a paragraph.
        /// </summary>
        /// <param name="para">given paragraph</param>
        /// <param name="ws">given writing system for the back translation</param>
        /// <param name="runText">given text to append to back translation</param>
        /// ------------------------------------------------------------------------------------
        public void AppendRunToBt(IStTxtPara para, int ws, string runText)
        {
            ICmTranslation trans      = para.GetOrCreateBT();
            ITsStrBldr     bldr       = trans.Translation.get_String(ws).GetBldr();
            ITsTextProps   ttp        = StyleUtils.CharStyleTextProps(null, ws);
            int            bldrLength = bldr.Length;

            bldr.ReplaceRgch(bldrLength, bldrLength, runText, runText.Length, ttp);
            trans.Translation.set_String(ws, bldr.GetString());
        }
Example #8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a Back Translation for the stuff in Exodus with the following layout:
        ///
        ///		    (BT Title)
        ///		   BT Heading 1
        ///	BT Intro text
        ///		   BT Heading 2
        ///	(1)1BT Verse one.2BT Verse two.
        ///	3BT Verse three.More BT of verse three.
        ///	4BT Verse four.5BT Verse five.
        ///		   BT Heading 3
        ///	6BT Verse six.7BT Verse seven.
        ///
        ///	(1) = chapter number 1
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void CreateExodusBT(int wsAnal)
        {
            CreatePartialExodusBT(wsAnal);

            IScrBook book = m_scr.FindBook(2);
            // Finish book title translation
            IStTxtPara     para  = book.TitleOA[0];
            ICmTranslation trans = para.GetOrCreateBT();

            AddRunToMockedTrans(trans, wsAnal, "BT Title", null);

            // Finish section two translation
            IScrSection section = book.SectionsOS[1];

            para  = section.ContentOA[0];
            trans = para.GetOrCreateBT();
            AddRunToMockedTrans(trans, wsAnal, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedTrans(trans, wsAnal, "BT Verse two.", null);

            para  = section.ContentOA[1];
            trans = para.GetOrCreateBT();
            AddRunToMockedTrans(trans, wsAnal, "3", ScrStyleNames.VerseNumber);
            AddRunToMockedTrans(trans, wsAnal, "BT Verse three.", null);
            AddRunToMockedTrans(trans, wsAnal, "More BT verse three.", null);

            para  = section.ContentOA[2];
            trans = para.GetOrCreateBT();
            AddRunToMockedTrans(trans, wsAnal, "4", ScrStyleNames.VerseNumber);
            AddRunToMockedTrans(trans, wsAnal, "BT Verse four.", null);
            AddRunToMockedTrans(trans, wsAnal, "5", ScrStyleNames.VerseNumber);
            AddRunToMockedTrans(trans, wsAnal, "BT Verse five.", null);

            // Finish section three translation
            section = book.SectionsOS[2];
            para    = section.ContentOA[0];
            trans   = para.GetOrCreateBT();
            AddRunToMockedTrans(trans, wsAnal, "6", ScrStyleNames.VerseNumber);
            AddRunToMockedTrans(trans, wsAnal, "BT Verse six.", null);
            AddRunToMockedTrans(trans, wsAnal, "7", ScrStyleNames.VerseNumber);
            AddRunToMockedTrans(trans, wsAnal, "BT Verse seven.", null);
        }
Example #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add a back translation footnote in the given translation for the given footnote.
        /// Inserts a ref ORC in the translation and sets the the BT text in the footnote.
        /// </summary>
        /// <param name="trans">The given back translation of an StTxtPara</param>
        /// <param name="ichPos">The 0-based character offset into the back translation string
        /// at which we will insert the reference ORC</param>
        /// <param name="ws">writing system of the BT and ORC</param>
        /// <param name="footnote">The given footnote</param>
        /// <param name="footnoteBtText">text for the back translation of the footnote</param>
        /// <returns>the back translation of the given footnote</returns>
        /// ------------------------------------------------------------------------------------
        public ICmTranslation AddBtFootnote(ICmTranslation trans, int ichPos, int ws, IStFootnote footnote, string footnoteBtText)
        {
            AddBtFootnote(trans, ichPos, ws, footnote);

            // Add the given footnote BT text to the footnote.
            IStTxtPara     para            = (IStTxtPara)footnote.ParagraphsOS[0];
            ICmTranslation footnoteTrans   = para.GetOrCreateBT();
            ITsStrBldr     tssFootnoteBldr = footnoteTrans.Translation.get_String(ws).GetBldr();

            tssFootnoteBldr.ReplaceRgch(0, 0, footnoteBtText, footnoteBtText.Length, StyleUtils.CharStyleTextProps(null, ws));
            footnoteTrans.Translation.set_String(ws, tssFootnoteBldr.GetString());
            return(footnoteTrans);
        }
Example #10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a Back Translation for the stuff in Exodus with the following layout:
        ///
        ///			()
        ///		   BT Heading 1
        ///	BT Intro text
        ///		   BT Heading 2
        ///	(1)1BT Verse one.
        ///
        ///	(1) = chapter number 1
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void CreatePartialExodusBT(int wsAnal)
        {
            IScrBook       book    = m_scr.FindBook(2);
            IScrSection    section = book.SectionsOS[0];
            IStTxtPara     para    = section.HeadingOA[0];
            ICmTranslation trans   = para.GetOrCreateBT();

            AddRunToMockedTrans(trans, wsAnal, "BT Heading 1", null);

            para  = section.ContentOA[0];
            trans = para.GetOrCreateBT();
            AddRunToMockedTrans(trans, wsAnal, "BT Intro text", null);

            section = book.SectionsOS[1];
            para    = section.HeadingOA[0];
            trans   = para.GetOrCreateBT();
            AddRunToMockedTrans(trans, wsAnal, "BT Heading 2", null);

            para  = section.ContentOA[0];
            trans = para.GetOrCreateBT();
            AddRunToMockedTrans(trans, wsAnal, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedTrans(trans, wsAnal, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedTrans(trans, wsAnal, "BT Verse one.", null);
        }
Example #11
0
		private void FixtureSetupInternal()
		{
			//IWritingSystem wsEn = Cache.WritingSystemFactory.get_Engine("en");
			// Setup default analysis ws
			//m_wsEn = Cache.ServiceLocator.GetInstance<ILgWritingSystemRepository>().GetObject(wsEn.WritingSystem);
			m_wsVern = Cache.DefaultVernWs;
			m_wsTrans = Cache.DefaultAnalWs;

			m_text = Cache.ServiceLocator.GetInstance<ITextFactory>().Create();
			//Cache.LangProject.TextsOC.Add(m_text);
			var stText = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create();
			m_text.ContentsOA = stText;
			m_para = Cache.ServiceLocator.GetInstance<IScrTxtParaFactory>().CreateWithStyle(stText, ScrStyleNames.NormalParagraph);

			m_trans = m_para.GetOrCreateBT();
			Cache.LangProject.TranslatedScriptureOA.UseScriptDigits = false;
			m_tsf = Cache.TsStrFactory;
		}
        public void MakeLabelFromText_AnnotationOnBackTrans()
        {
            IScrScriptureNote note = Cache.ServiceLocator.GetInstance <IScrScriptureNoteFactory>().Create();

            m_scr.BookAnnotationsOS[0].NotesOS.Add(note);
            note.BeginRef = 01001011;
            note.EndRef   = 01001011;
            IStTxtPara para = (IStTxtPara)m_gen.SectionsOS[1].ContentOA.ParagraphsOS[0];

            note.BeginObjectRA = para.GetOrCreateBT();
            ITsString tss = m_vc.CallMakeLabelFromText("GEN 1:11", "WhoCares", note);

            Assert.AreEqual(2, tss.RunCount);
            Assert.AreEqual("GEN 1:11", tss.get_RunText(0));
            Assert.AreEqual("WhoCares",
                            tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptNamedStyle));
            CheckFinalSpaceInReferenceLabel(tss);
        }
Example #13
0
        public void FootnoteTranslationTest()
        {
            // get an existing footnote
            IScrBook     book     = m_scr.ScriptureBooksOS[1];     // book of Exodus
            IScrFootnote footnote = AddFootnote(book, (IStTxtPara)book.TitleOA.ParagraphsOS[0], 0, "This is a footnote");
            IStTxtPara   para     = (IStTxtPara)footnote.ParagraphsOS[0];

            // add a translation to the footnote
            ICmTranslation translation = para.GetOrCreateBT();
            int            analWs      = Cache.DefaultAnalWs;

            translation.Translation.set_String(analWs, TsStringHelper.MakeTSS("abcde", analWs));

            FwStyleSheet styleSheet = new FwStyleSheet();

            styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles);

            // Prepare the test by creating a footnote view
            using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache, true))
            {
                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, true, false, true);

                // Now the real test:
                IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord();
                ITsString    tss;
                sel.GetSelectionString(out tss, string.Empty);
                Assert.AreEqual("abcde", tss.Text);
            }
        }
Example #14
0
        public void UpdateUserPrompt_NormalBT_Pasting()
        {
            // Set up section head with an empty paragraph
            IScrSection section = AddSectionToMockedBook(m_book);
            IStTxtPara  para    = AddSectionHeadParaToSection(section, "", ScrStyleNames.SectionHead);

            int          defAnalWs = Cache.DefaultAnalWs;
            IVwRootBox   rootb;
            IVwSelection vwsel;
            IVwRootSite  rootsite;

            SetUpResultsForUpdateUserPromptTests(5, "TE2ST", out rootb, out vwsel, out rootsite);

            DummyTeStVc stVc = new DummyTeStVc(Cache, defAnalWs, rootb);
            // set up the text to paste - will be TE2ST with vernacular WS
            ITsPropsFactory propFact = TsPropsFactoryClass.Create();
            ITsTextProps    ttp      = propFact.MakeProps(null, defAnalWs, 0);

            ITsStrBldr bldr = TsStrBldrClass.Create();

            bldr.ReplaceRgch(0, 0, "TEST", 4, ttp);
            ttp = propFact.MakeProps(ScrStyleNames.VerseNumber, defAnalWs, 0);
            bldr.ReplaceRgch(2, 2, "2", 1, ttp);
            ITsString tssPasted = bldr.GetString();

            // Now simulate the user pasting over the user prompt
            ICmTranslation bt = para.GetOrCreateBT();

            stVc.UpdateProp(vwsel, bt.Hvo, SimpleRootSite.kTagUserPrompt, CmTranslationTags.kflidTranslation, tssPasted);

            // Verify that the text is in the paragraph and that the character formatting survives.
            AssertEx.AreTsStringsEqual(tssPasted, bt.Translation.get_String(defAnalWs));

            m_vwenvMock.VerifyAllExpectations();
            VerifyArgsSentToRequestSelectionAtEndOfUow(rootsite, rootb, defAnalWs, 5, CmTranslationTags.kflidTranslation, "TE2ST");
        }
Example #15
0
        public void UpdateUserPrompt_NormalBT_Typing()
        {
            // Set up section head with an empty paragraph
            IScrSection section = AddSectionToMockedBook(m_book);
            IStTxtPara  para    = AddSectionHeadParaToSection(section, "",
                                                              ScrStyleNames.SectionHead);

            int          defAnalWs = Cache.DefaultAnalWs;
            IVwRootBox   rootb;
            IVwSelection vwsel;
            IVwRootSite  rootsite;

            SetUpResultsForUpdateUserPromptTests(5, "b", out rootb, out vwsel, out rootsite);

            DummyTeStVc   stVc    = new DummyTeStVc(Cache, defAnalWs, rootb);
            ITsIncStrBldr strBdlr = TsIncStrBldrClass.Create();

            strBdlr.SetIntPropValues(SimpleRootSite.ktptUserPrompt, (int)FwTextPropVar.ktpvDefault, 1);
            strBdlr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, Cache.DefaultUserWs);
            strBdlr.Append("b");
            ITsString tssTyped    = strBdlr.GetString();
            ITsString tssExpected = TsStringUtils.MakeTss("b", defAnalWs);

            // Now simulate the user typing over the user prompt
            ICmTranslation bt = para.GetOrCreateBT();

            stVc.UpdateProp(vwsel, bt.Hvo, SimpleRootSite.kTagUserPrompt, CmTranslationTags.kflidTranslation, tssTyped);

            // verify that the text is in the paragraph and that there is no longer a user prompt.
            string diff;

            Assert.IsTrue(TsStringHelper.TsStringsAreEqual(tssExpected, bt.Translation.get_String(defAnalWs), out diff), diff);

            m_vwenvMock.VerifyAllExpectations();
            VerifyArgsSentToRequestSelectionAtEndOfUow(rootsite, rootb, defAnalWs, 5, CmTranslationTags.kflidTranslation, "b");
        }
Example #16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Make sure the marker for a footnote exists in the back translation and refers to the
        /// footnote properly.
        /// </summary>
        /// <param name="footnote">given footnote whose marker we want to verify in the BT</param>
        /// <param name="para">vernacular paragraph which owns the back translation</param>
        /// <param name="ws">writing system of the back transltion</param>
        /// <param name="ich">Character position where ORC should be in the specified back
        /// translation</param>
        /// ------------------------------------------------------------------------------------
        public static void VerifyBtFootnote(IStFootnote footnote, IStTxtPara para, int ws, int ich)
        {
            Guid           guid  = footnote.Cache.GetGuidFromId(footnote.Hvo);
            ITsString      tss   = para.Contents.UnderlyingTsString;
            ICmTranslation trans = para.GetOrCreateBT();
            ITsString      btTss = trans.Translation.GetAlternative(ws).UnderlyingTsString;

            int    iRun = btTss.get_RunAt(ich);
            string sOrc = btTss.get_RunText(iRun);

            Assert.AreEqual(StringUtils.kchObject, sOrc[0]);
            ITsTextProps orcPropsParaFootnote = btTss.get_Properties(iRun);
            string       objData = orcPropsParaFootnote.GetStrPropValue(
                (int)FwTextPropType.ktptObjData);

            Assert.IsNotNull(objData);
            Assert.AreEqual((char)(int)FwObjDataTypes.kodtNameGuidHot, objData[0]);
            // Send the objData string without the first character because the first character
            // is the object replacement character and the rest of the string is the GUID.
            Guid newFootnoteGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1));

            Assert.AreEqual(guid, newFootnoteGuid);
            Assert.AreEqual(footnote.Hvo, footnote.Cache.GetIdFromGuid(newFootnoteGuid));
        }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets up a range selection in the specified back translation.
		/// </summary>
		/// <param name="wsStart">The writing system of the BT where the selection is to start,
		/// or -1 to start in the vernacular.</param>
		/// <param name="wsEnd">The writing system of the BT where the selection is to end,
		/// or -1 to end in the vernacular.</param>
		/// <param name="bookStart">The starting book.</param>
		/// <param name="iBookStart">The index of the starting book.</param>
		/// <param name="sectionStart">The starting section.</param>
		/// <param name="iSecStart">The index of the starting section.</param>
		/// <param name="paraStart">The starting paragraph.</param>
		/// <param name="iParaStart">The index of the starting paragraph.</param>
		/// <param name="ichStart">The starting character offset.</param>
		/// <param name="setupForHeadingStart">if set to <c>true</c> setup selection to start in
		/// section heading; otherwise, set up selection in contents.</param>
		/// <param name="bookEnd">The ending book.</param>
		/// <param name="iBookEnd">The index of the ending book.</param>
		/// <param name="sectionEnd">The ending section.</param>
		/// <param name="iSecEnd">The index of the ending section.</param>
		/// <param name="paraEnd">The ending paragraph.</param>
		/// <param name="iParaEnd">The index of the para end.</param>
		/// <param name="ichEnd">The ending character offset.</param>
		/// <param name="setupForHeadingEnd">if set to <c>true</c> setup selection to end in
		/// section heading; otherwise, set up selection in contents.</param>
		/// ------------------------------------------------------------------------------------
		public void SetupRangeSelection(int wsStart, int wsEnd, IScrBook bookStart, int iBookStart,
			IScrSection sectionStart, int iSecStart, IStTxtPara paraStart, int iParaStart, int ichStart,
			bool setupForHeadingStart, IScrBook bookEnd, int iBookEnd, IScrSection sectionEnd,
			int iSecEnd, IStTxtPara paraEnd, int iParaEnd, int ichEnd, bool setupForHeadingEnd)
		{
			DynamicMock fakeSelHelper = new DynamicMock(typeof(SelectionHelper));
			int cLevelsTop = wsStart > 0 ? 5 : 4;
			// Setup the anchor
			SelLevInfo[] topInfo = new SelLevInfo[cLevelsTop];
			int iLev = 0;
			if (wsStart > 0)
			{
				topInfo[iLev].tag = -1;
				topInfo[iLev].ihvo = 0;
				topInfo[iLev].hvo = paraStart.GetOrCreateBT().Hvo;
				iLev++;
			}
			topInfo[iLev].tag = StTextTags.kflidParagraphs;
			topInfo[iLev].ihvo = iParaStart;
			topInfo[iLev].hvo = paraStart.Hvo;
			topInfo[++iLev].tag = setupForHeadingStart ? ScrSectionTags.kflidHeading :
				ScrSectionTags.kflidContent;
			topInfo[iLev].ihvo = 0;
			topInfo[iLev].hvo = setupForHeadingStart ? sectionStart.HeadingOA.Hvo :
				sectionStart.ContentOA.Hvo;
			topInfo[++iLev].tag = ScrBookTags.kflidSections;
			topInfo[iLev].ihvo = iSecStart;
			topInfo[iLev].hvo = sectionStart.Hvo;
			topInfo[++iLev].tag = BookFilter.Tag;
			topInfo[iLev].ihvo = iBookStart;
			topInfo[iLev].hvo = bookStart.Hvo;

			// Setup the end
			int cLevelsBottom = wsEnd > 0 ? 5 : 4;
			SelLevInfo[] bottomInfo = new SelLevInfo[cLevelsBottom];
			iLev = 0;
			if (wsEnd > 0)
			{
				bottomInfo[iLev].tag = -1;
				bottomInfo[iLev].ihvo = 0;
				bottomInfo[iLev].hvo = paraEnd.GetOrCreateBT().Hvo;
				iLev++;
			}
			bottomInfo[iLev].tag = StTextTags.kflidParagraphs;
			bottomInfo[iLev].ihvo = iParaEnd;
			bottomInfo[iLev].hvo = paraEnd.Hvo;
			bottomInfo[++iLev].tag = setupForHeadingEnd ? ScrSectionTags.kflidHeading :
				ScrSectionTags.kflidContent;
			bottomInfo[iLev].ihvo = 0;
			bottomInfo[iLev].hvo = setupForHeadingEnd ? sectionEnd.HeadingOA.Hvo :
				sectionEnd.ContentOA.Hvo;
			bottomInfo[++iLev].tag = ScrBookTags.kflidSections;
			bottomInfo[iLev].ihvo = iSecEnd;
			bottomInfo[iLev].hvo = sectionEnd.Hvo;
			bottomInfo[++iLev].tag = BookFilter.Tag;
			bottomInfo[iLev].ihvo = iBookEnd;
			bottomInfo[iLev].hvo = bookEnd.Hvo;

			fakeSelHelper.SetupResult("NumberOfLevels", cLevelsTop);
			fakeSelHelper.SetupResultForParams("GetNumberOfLevels", cLevelsTop,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetNumberOfLevels", cLevelsTop,
				SelectionHelper.SelLimitType.Anchor);
			fakeSelHelper.SetupResultForParams("GetNumberOfLevels", cLevelsBottom,
				SelectionHelper.SelLimitType.Bottom);
			fakeSelHelper.SetupResultForParams("GetNumberOfLevels", cLevelsBottom,
				SelectionHelper.SelLimitType.End);
			fakeSelHelper.SetupResult("ReduceSelectionToIp", fakeSelHelper.MockInstance,
				typeof(SelectionHelper.SelLimitType), typeof(bool), typeof(bool));
			fakeSelHelper.SetupResult("LevelInfo", topInfo);
			fakeSelHelper.SetupResult("IchAnchor", ichStart);
			fakeSelHelper.SetupResult("IchEnd", ichEnd);
			fakeSelHelper.SetupResult("Ws", wsStart);
			fakeSelHelper.SetupResult("IsValid", true);
			fakeSelHelper.SetupResult("AssocPrev", false);
			fakeSelHelper.Ignore("get_IsRange");
			fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo,
				SelectionHelper.SelLimitType.Anchor);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo,
				SelectionHelper.SelLimitType.Bottom);
			fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo,
				SelectionHelper.SelLimitType.End);
			fakeSelHelper.SetupResultForParams("GetTextPropId", wsStart > 0 ?
				CmTranslationTags.kflidTranslation : StTxtParaTags.kflidContents,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetTextPropId", wsStart > 0 ?
				CmTranslationTags.kflidTranslation : StTxtParaTags.kflidContents,
				SelectionHelper.SelLimitType.Anchor);
			fakeSelHelper.SetupResultForParams("GetTextPropId", wsEnd > 0 ?
				CmTranslationTags.kflidTranslation : StTxtParaTags.kflidContents,
				SelectionHelper.SelLimitType.Bottom);
			fakeSelHelper.SetupResultForParams("GetTextPropId", wsEnd > 0 ?
				CmTranslationTags.kflidTranslation : StTxtParaTags.kflidContents,
				SelectionHelper.SelLimitType.End);
			fakeSelHelper.SetupResultForParams("GetIch", ichStart,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetIch", ichStart,
				SelectionHelper.SelLimitType.Anchor);
			fakeSelHelper.SetupResultForParams("GetIch", ichEnd,
				SelectionHelper.SelLimitType.Bottom);
			fakeSelHelper.SetupResultForParams("GetIch", ichEnd,
				SelectionHelper.SelLimitType.End);
			fakeSelHelper.SetupResultForParams("GetWritingSystem", wsStart == -1 ? m_cache.DefaultVernWs : wsStart,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetWritingSystem", wsStart == -1 ? m_cache.DefaultVernWs : wsStart,
				SelectionHelper.SelLimitType.Anchor);
			fakeSelHelper.SetupResultForParams("GetWritingSystem", wsEnd == -1 ? m_cache.DefaultVernWs : wsEnd,
				SelectionHelper.SelLimitType.Bottom);
			fakeSelHelper.SetupResultForParams("GetWritingSystem", wsEnd == -1 ? m_cache.DefaultVernWs : wsEnd,
				SelectionHelper.SelLimitType.End);
			m_currentSelection = (SelectionHelper)fakeSelHelper.MockInstance;
		}
Example #18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add an empty back translation to the paragraph, or return the existing one.
		/// </summary>
		/// <param name="owner">the owning paragraph</param>
		/// <param name="wsTrans"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		protected ICmTranslation AddBtToMockedParagraph(IStTxtPara owner, int wsTrans)
		{
			ICmTranslation trans = owner.GetOrCreateBT();
			trans.Translation.set_String(wsTrans, Cache.TsStrFactory.MakeString(string.Empty, wsTrans));
			return trans;
		}
Example #19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Append a run of text to a back translation of a paragraph.
		/// </summary>
		/// <param name="para">given paragraph</param>
		/// <param name="ws">given writing system for the back translation</param>
		/// <param name="runText">given text to append to back translation</param>
		/// ------------------------------------------------------------------------------------
		public void AppendRunToBt(IStTxtPara para, int ws, string runText)
		{
			ICmTranslation trans = para.GetOrCreateBT();
			ITsStrBldr bldr = trans.Translation.get_String(ws).GetBldr();
			ITsTextProps ttp = StyleUtils.CharStyleTextProps(null, ws);
			int bldrLength = bldr.Length;
			bldr.ReplaceRgch(bldrLength, bldrLength, runText, runText.Length, ttp);
			trans.Translation.set_String(ws, bldr.GetString());
		}
Example #20
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set the IP to the end of the section. Check for vernacular or BT.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void SetIpAtEndOfPara(int bookIndex, int sectionIndex, int paraIndex, IStTxtPara para)
		{
			int paraLength;
			if (IsBackTranslation)
			{
				ICmTranslation trans = para.GetOrCreateBT();
				paraLength = trans.Translation.get_String(ViewConstructorWS).Length;
			}
			else
				paraLength = para.Contents.Length;

			SetInsertionPoint(bookIndex, sectionIndex, paraIndex, paraLength, true);
		}
Example #21
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the hvo of the (for now, back translation) translation of a paragraph
        /// </summary>
        /// <param name="paraHvo"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected int GetTranslationForPara(int paraHvo)
        {
            IStTxtPara para = m_cache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraHvo);

            return(para.GetOrCreateBT().Hvo);
        }
Example #22
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a footnote reference marker (ref orc)
		/// </summary>
		/// <param name="footnote">given footnote</param>
		/// <param name="para">paragraph owning the translation to insert footnote marker into</param>
		/// <param name="ws">given writing system for the back translation</param>
		/// <param name="ichPos">The 0-based character offset into the translation</param>
		/// ------------------------------------------------------------------------------------
		protected void InsertTestBtFootnote(IStFootnote footnote, IStTxtPara para, int ws,
			int ichPos)
		{
			ICmTranslation trans = para.GetOrCreateBT();
			ITsStrBldr bldr = trans.Translation.get_String(ws).GetBldr();
			footnote.InsertRefORCIntoTrans(bldr, ichPos, ws);
			trans.Translation.set_String(ws, bldr.GetString());
		}
Example #23
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Make sure the marker for a footnote exists in the back translation and refers to the
		/// footnote properly.
		/// </summary>
		/// <param name="footnote">given footnote whose marker we want to verify in the BT</param>
		/// <param name="para">vernacular paragraph which owns the back translation</param>
		/// <param name="ws">writing system of the back transltion</param>
		/// <param name="ich">Character position where ORC should be in the specified back
		/// translation</param>
		/// ------------------------------------------------------------------------------------
		public static void VerifyBtFootnote(IStFootnote footnote, IStTxtPara para, int ws, int ich)
		{
			Guid guid = footnote.Cache.GetGuidFromId(footnote.Hvo);
			ITsString tss = para.Contents.UnderlyingTsString;
			ICmTranslation trans = para.GetOrCreateBT();
			ITsString btTss = trans.Translation.GetAlternative(ws).UnderlyingTsString;

			int iRun = btTss.get_RunAt(ich);
			string sOrc = btTss.get_RunText(iRun);
			Assert.AreEqual(StringUtils.kchObject, sOrc[0]);
			ITsTextProps orcPropsParaFootnote = btTss.get_Properties(iRun);
			string objData = orcPropsParaFootnote.GetStrPropValue(
				(int)FwTextPropType.ktptObjData);
			Assert.IsNotNull(objData);
			Assert.AreEqual((char)(int)FwObjDataTypes.kodtNameGuidHot, objData[0]);
			// Send the objData string without the first character because the first character
			// is the object replacement character and the rest of the string is the GUID.
			Guid newFootnoteGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1));
			Assert.AreEqual(guid, newFootnoteGuid);
			Assert.AreEqual(footnote.Hvo, footnote.Cache.GetIdFromGuid(newFootnoteGuid));
		}