/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Override to end the undoable UOW, Undo everything, and 'commit',
		/// which will essentially clear out the Redo stack.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void TestTearDown()
		{
			m_philemon = null;
			m_section = null;
			m_para = null;

			base.TestTearDown();
		}
		public override void Exit()
		{
			CheckDisposed();

			m_philemon = null;
			m_section = null;
			m_para = null;

			base.Exit();
		}
Esempio n. 3
0
		public override void Exit()
		{
			CheckDisposed();

			m_introSection = null;
			m_genesis = null;
			m_section = null;
			m_secondSection = null;

			base.Exit();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			base.CreateTestData();

			m_philemon = m_scrInMemoryCache.AddBookToMockedScripture(57, "Philemon");
			m_scrInMemoryCache.AddTitleToMockedBook(m_philemon.Hvo, "Philemon");
			m_section = m_scrInMemoryCache.AddSectionToMockedBook(m_philemon.Hvo);
			m_para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_section.Hvo,
				ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(m_para, "this is text", null);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Override to start an undoable UOW.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void TestSetup()
		{
			base.TestSetup();

			m_editingHelper.m_fUsingMockedSelection = true;
			m_philemon = AddBookToMockedScripture(57, "Philemon");
			AddTitleToMockedBook(m_philemon, "Philemon");
			m_section = AddSectionToMockedBook(m_philemon);
			m_para = AddParaToMockedSectionContent(m_section,
				ScrStyleNames.NormalParagraph);
			AddRunToMockedPara(m_para, "this is text", null);
		}
		/// <summary>
		///
		/// </summary>
		public override void TestSetup()
		{
			base.TestSetup();

			m_wsVern = Cache.DefaultVernWs;
			m_wsTrans = Cache.DefaultAnalWs;
			m_book = Cache.ServiceLocator.GetInstance<IScrBookFactory>().Create(1);
			m_section = Cache.ServiceLocator.GetInstance<IScrSectionFactory>().Create();
			m_book.SectionsOS.Add(m_section);
			m_section.ContentOA = m_text = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create(); ;
			m_para = m_text.AddNewTextPara(ScrStyleNames.NormalParagraph);
		}
Esempio n. 7
0
		/// <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 override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_section = null;

			base.Dispose(disposing);
		}
Esempio n. 8
0
		public override void TestSetup()
		{
			base.TestSetup();
			// Create book of Genesis with 3 sections. First section contains one content para,
			// second section contains head and two content paragraphs (with one footnote each),
			// third section contains head and one content paragraph (with one footnote).
			m_genesis = AddBookToMockedScripture(1, "Genesis");
			AddTitleToMockedBook(m_genesis, "Genesis");

			// Intro section
			m_introSection = AddSectionToMockedBook(m_genesis, true);
			IStTxtPara para = AddParaToMockedSectionContent(m_introSection,
				ScrStyleNames.IntroParagraph);
			AddRunToMockedPara(para, "Introduction para", null);
			AddFootnote(m_genesis, para, 10);

			// First section
			m_section = AddSectionToMockedBook(m_genesis);
			AddSectionHeadParaToSection(m_section, "Heading",
				ScrStyleNames.SectionHead);
			para = AddParaToMockedSectionContent(m_section,
				ScrStyleNames.NormalParagraph);
			AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber);
			AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber);
			AddRunToMockedPara(para, "This is the first paragraph.", null);
			AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber);
			AddRunToMockedPara(para, "Verse two.", null);
			AddFootnote(m_genesis, para, 5);

			para = AddParaToMockedSectionContent(m_section,
				ScrStyleNames.NormalParagraph);
			AddRunToMockedPara(para, "5", ScrStyleNames.VerseNumber);
			AddRunToMockedPara(para, "This is the last paragraph.", null);
			AddFootnote(m_genesis, para, 10);

			// Second section
			m_secondSection = AddSectionToMockedBook(m_genesis);
			AddSectionHeadParaToSection(m_secondSection, "Heading of last section",
				ScrStyleNames.SectionHead);
			para = AddParaToMockedSectionContent(m_secondSection,
				ScrStyleNames.NormalParagraph);
			AddRunToMockedPara(para, "This is the paragraph of the last section", null);
			AddFootnote(m_genesis, para, 20);
		}
		public override void Initialize()
		{
			CheckDisposed();
			base.Initialize();
			InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml",
				new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" });
			m_wsVern = Cache.DefaultVernWs;
			m_wsTrans = Cache.DefaultAnalWs;
			m_book = new ScrBook();
			Cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS.Append(m_book);
			m_section = new ScrSection();
			m_book.SectionsOS.Append(m_section);
			m_para = new StTxtPara();
			m_text = new StText();
			m_section.ContentOA = m_text;
			m_text.ParagraphsOS.Append(m_para);
			m_hvoSegDefn = CmAnnotationDefn.TextSegment(Cache).Hvo;
			m_hvoFtDefn = Cache.GetIdFromGuid(new Guid(LangProject.kguidAnnFreeTranslation));
			kflidFT = StTxtPara.SegmentFreeTranslationFlid(Cache);
			kflidSegments = StTxtPara.SegmentsFlid(Cache);
		}
Esempio n. 10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Resets importer state variables for the new book
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual void ResetStateVariablesForNewBook()
		{
			m_currSection = null;
			m_iCurrSection = -1;
			m_iCurrFootnote = 0;
			m_fInSectionHeading = false;
			m_fInScriptureText = false;
			m_fCurrentSectionIsIntro = true;
		}
Esempio n. 11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Merges the section the with following section if they are in the same context.
		/// </summary>
		/// <param name="helper">The selection helper.</param>
		/// <param name="book">The book.</param>
		/// <param name="iSection">The index of the current section.</param>
		/// <param name="section">The current section.</param>
		/// <param name="fDeleteForward">if set to <c>true</c> the user pressed the delete key,
		/// otherwise the backspace key.</param>
		/// <returns><c>true</c> if we merged the sections, otherwise <c>false</c>.</returns>
		/// ------------------------------------------------------------------------------------
		private bool MergeWithFollowingSectionIfInSameContext(SelectionHelper helper, ScrBook book,
			int iSection, IScrSection section, bool fDeleteForward)
		{
			IScrSection nextSection = book.SectionsOS[iSection + 1];
			// Merge the sections if they have the same context.
			if (SectionsHaveSameContext(nextSection, section))
			{
				bool wasInHeading = InSectionHead;
				int lastParaIndex = section.HeadingOA.ParagraphsOS.Count - 1;
				MergeHeadingWithFollowingSection(helper, book, section, iSection);
				// Now we have to re-establish a selection
				if (wasInHeading && fDeleteForward)
				{
					// delete key was pressed at end of section head, place IP at
					// end of what was the original heading
					section = book.SectionsOS[iSection];
					StTxtPara lastPara =
						(StTxtPara)section.HeadingOA.ParagraphsOS[lastParaIndex];
					SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading,
						BookFilter.GetBookIndex(book.Hvo), iSection, lastParaIndex);
					CurrentSelection.IchAnchor = lastPara.Contents.Length;
					CurrentSelection.SetSelection(true);
				}
				else
				{
					// delete key was pressed in empty section content, place IP
					// at beginning of what was following section heading
					SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading,
						BookFilter.GetBookIndex(book.Hvo), iSection, lastParaIndex + 1);
				}
				return true;
			}
			return false;
		}
Esempio n. 12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Merges heading of given section into the heading of the follwing section and then
		/// deletes the given section. We assume that the content of the current section is
		/// empty.
		/// </summary>
		/// <param name="helper"> </param>
		/// <param name="book"></param>
		/// <param name="section"></param>
		/// <param name="ihvoSection"></param>
		/// ------------------------------------------------------------------------------------
		private void MergeHeadingWithFollowingSection(SelectionHelper helper, ScrBook book,
			IScrSection section, int ihvoSection)
		{
			// Get the following section and move the paragraphs.
			IScrSection sectionNext = book.SectionsOS[ihvoSection + 1];
			IStText textNext = sectionNext.HeadingOA;
			if (textNext == null)
			{
				// Prevent crash when dealing with corrupt database (TE-4869)
				// Since the next section doesn't have a heading text, we simply move the entire
				// text object from the current section head to the next section.
				m_cache.ChangeOwner(section.HeadingOAHvo, sectionNext.Hvo,
					(int)ScrSection.ScrSectionTags.kflidHeading);
			}
			else
			{
				IStText textOldHeading = section.HeadingOA;
				int cOldHeadingParas = textOldHeading.ParagraphsOS.Count;
				m_cache.MoveOwningSequence(textOldHeading.Hvo, (int)StText.StTextTags.kflidParagraphs,
					0, cOldHeadingParas - 1,
					textNext.Hvo, (int)StText.StTextTags.kflidParagraphs, 0);
			}
			// protected for some reason...textNext.ParagraphsOS.Append(text.ParagraphsOS.HvoArray);
			book.SectionsOS.RemoveAt(ihvoSection);
		}
Esempio n. 13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create book of Genesis with 3 sections. First section contains one content para,
		/// second section contains head and two content paragraphs (with one footnote each),
		/// third section contains head and one content paragraph (with one footnote).
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			m_genesis = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis");
			m_scrInMemoryCache.AddTitleToMockedBook(m_genesis.Hvo, "Genesis");

			// Intro section
			m_introSection = m_scrInMemoryCache.AddIntroSectionToMockedBook(m_genesis.Hvo);
			StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_introSection.Hvo,
				ScrStyleNames.IntroParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "Introduction para", null);
			m_scrInMemoryCache.AddFootnote(m_genesis, para, 10);
			m_introSection.AdjustReferences();

			// First section
			m_section = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(m_section.Hvo, "Heading",
				ScrStyleNames.SectionHead);
			para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_section.Hvo,
				ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, "This is the first paragraph.", null);
			m_scrInMemoryCache.AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, "Verse two.", null);
			m_scrInMemoryCache.AddFootnote(m_genesis, para, 5);

			para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_section.Hvo,
				ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "5", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, "This is the last paragraph.", null);
			m_scrInMemoryCache.AddFootnote(m_genesis, para, 10);
			m_section.AdjustReferences();

			// Second section
			m_secondSection = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(m_secondSection.Hvo, "Heading of last section",
				ScrStyleNames.SectionHead);
			para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_secondSection.Hvo,
				ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "This is the paragraph of the last section", null);
			m_scrInMemoryCache.AddFootnote(m_genesis, para, 20);
			m_secondSection.AdjustReferences();
		}
Esempio n. 14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Inserts one or more paragraphs at the end of a section.  New sections for the book
		/// may also be created.
		/// </summary>
		/// <param name="book"></param>
		/// <param name="section"></param>
		/// <param name="ttpSrcArray">Array of props of each para to be inserted</param>
		/// <param name="tssParas">Array of TsStrings for each para to be inserted</param>
		/// <param name="sectionIndex"></param>
		/// <param name="cAddedSections"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private bool InsertParagraphsAtSectionEnd(ScrBook book, IScrSection section,
			ITsTextProps[] ttpSrcArray, ITsString[] tssParas, int sectionIndex, out int cAddedSections)
		{
			cAddedSections = 0;
			bool isIntro = false;

			for (int i = 0; i < ttpSrcArray.Length; i++)
			{
				IStStyle style = m_scr.FindStyle(ttpSrcArray[i]);
				if (style.Structure == StructureValues.Heading)
				{
					// If content has been added to section, create a new section.  Otherwise,
					// add the new paragraph to the end of the current section heading.
					if (section.ContentOA.ParagraphsOS.Count > 0)
					{
						isIntro = (style.Context == ContextValues.Intro);
						// Create a new section and add the current paragraph to the heading
						section = ScrSection.CreateEmptySection(book,
							sectionIndex + cAddedSections);
						CreateParagraph(section.HeadingOA, -1, ttpSrcArray[i], tssParas[i]);
						// Need additional prop changed event to get screen to refresh properly
						m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, book.Hvo,
							(int)ScrBook.ScrBookTags.kflidSections,
							sectionIndex + cAddedSections, 1, 0);
						cAddedSections++;
					}
					else
					{
						// Create heading paragraph at end of section heading
						CreateParagraph(section.HeadingOA, -1, ttpSrcArray[i], tssParas[i]);
					}
				}
				else
				{
					// Create content paragraph for the current section
					CreateParagraph(section.ContentOA, -1, ttpSrcArray[i], tssParas[i]);
				}
			}

			// create an empty paragraph if section content is empty
			if (section.ContentOA.ParagraphsOS.Count == 0)
			{
				string styleName =
					isIntro ? ScrStyleNames.IntroParagraph : ScrStyleNames.NormalParagraph;
				StTxtParaBldr bldr = new StTxtParaBldr(m_cache);
				bldr.ParaProps = StyleUtils.ParaStyleTextProps(styleName);
				ITsTextProps charProps = StyleUtils.CharStyleTextProps(styleName,
					m_cache.DefaultVernWs);
				bldr.AppendRun(string.Empty, charProps);
				bldr.CreateParagraph(section.ContentOAHvo);
			}

			return true;
		}
Esempio n. 15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Searches section backwards for last footnote reference.
		/// </summary>
		/// <param name="section"></param>
		/// <param name="iPara">out: The index of the para containing the footnote.</param>
		/// <param name="ich">out: The character index where the footnote was found.</param>
		/// <param name="tag">out: whether the footnote was found in heading or contents</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public static ScrFootnote FindLastFootnoteInSection(IScrSection section, out int iPara,
			out int ich, out int tag)
		{
			tag = (int)ScrSection.ScrSectionTags.kflidContent;
			ScrFootnote footnote = FindLastFootnoteInText(section.ContentOA, out iPara, out ich);
			if (footnote == null)
			{
				tag = (int)ScrSection.ScrSectionTags.kflidHeading;
				footnote = FindLastFootnoteInText(section.HeadingOA, out iPara, out ich);
			}
			return footnote;
		}
Esempio n. 16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates the small book.
		/// </summary>
		/// <param name="nBookNumber">The book number.</param>
		/// <param name="bookName">Name of the book.</param>
		/// <param name="section2">The section2.</param>
		/// ------------------------------------------------------------------------------------
		private IScrBook CreateSmallBook(int nBookNumber, string bookName, out IScrSection section2)
		{
			IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(nBookNumber, bookName);
			m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, bookName);
			IScrSection section1 = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(section1.Hvo, "Heading 1",
				ScrStyleNames.SectionHead);
			StTxtPara para11 = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo,
				ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para11, "1", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para11, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para11, "Verse one.", null);
			section1.AdjustReferences();

			section2 = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(section2.Hvo, "Heading 2",
				ScrStyleNames.SectionHead);
			StTxtPara para21 = m_scrInMemoryCache.AddParaToMockedSectionContent(section2.Hvo,
				ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para21, "2", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para21, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para21, "Verse one.", null);
			m_scrInMemoryCache.AddRunToMockedPara(para21, "2", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para21, "Verse two.", null);
			StTxtPara para22 = m_scrInMemoryCache.AddParaToMockedSectionContent(section2.Hvo,
				ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para22, "3", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para22, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para22, "Verse one.", null);

			return book;
		}
        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);
        }
        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));
        }
Esempio n. 19
0
        public void VerseIterator_ForSetOfStTexts()
        {
            // Create section 1 for Genesis.
            IScrSection section1 = CreateSection(m_genesis, "My aching head!");

            // build paragraph for section 1
            StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);

            paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph;
            paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse 1. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            IScrTxtPara para1 = (IScrTxtPara)paraBldr.CreateParagraph(section1.ContentOA);

            // Create section 2 for Genesis.
            IScrSection section2 = CreateSection(m_genesis, "My aching behind!");

            // build paragraph for section 2
            paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph;
            paraBldr.AppendRun("3", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse 1. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            IScrTxtPara para2 = (IScrTxtPara)paraBldr.CreateParagraph(section2.ContentOA);

            // Create section 3 for Genesis.
            IScrSection section3 = CreateSection(m_genesis, "");

            // build paragraph for section 3
            paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph;
            IScrTxtPara para3 = (IScrTxtPara)paraBldr.CreateParagraph(section3.ContentOA);

            // Create an iterator to test group of StTexts
            List <IStText> list = new List <IStText>(6);

            // this is not a typical list for TE, just a bunch of StTexts for this test
            list.Add(section1.HeadingOA);
            list.Add(section2.HeadingOA);
            list.Add(section3.HeadingOA);
            list.Add(section1.ContentOA);
            list.Add(section2.ContentOA);
            list.Add(section3.ContentOA);
            m_bookMerger.CreateVerseIteratorForSetOfStTexts(list);

            // Verify section 1 heading
            ScrVerse scrVerse = m_bookMerger.NextVerseInSet();

            DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section1.HeadingOA[0],
                                          01002001, 01002001, "My aching head!", 0, false, true, 0);

            // Verify section 2 heading
            scrVerse = m_bookMerger.NextVerseInSet();
            DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section2.HeadingOA[0],
                                          01003001, 01003001, "My aching behind!", 0, false, true, 1);

            // section 3 heading is empty, but returns an empty ScrVerse
            scrVerse = m_bookMerger.NextVerseInSet();
            DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section3.HeadingOA[0],
                                          01003001, 01003001, null, 0, false, true, 2);

            // Verify section 1 content
            scrVerse = m_bookMerger.NextVerseInSet();
            DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section1.ContentOA[0],
                                          01002001, 01002001, "2Verse 1. ", 0, true, false, 0);

            // Verify section 2 content
            scrVerse = m_bookMerger.NextVerseInSet();
            DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section2.ContentOA[0],
                                          01003001, 01003001, "3Verse 1. ", 0, true, false, 1);

            // Verify section 3 content--an empty ScrVerse
            scrVerse = m_bookMerger.NextVerseInSet();
            DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section3.ContentOA[0],
                                          01003001, 01003001, null, 0, false, false, 2);

            // Verify there are no more scrVerses
            scrVerse = m_bookMerger.NextVerseInSet();
            Assert.IsNull(scrVerse);
        }
		public void PageElementsDontOverlap_FootnotesInTwoDivisions()
		{
			IScripture scr = Cache.LangProject.TranslatedScriptureOA;

			// delete all books
			scr.ScriptureBooksOS.Clear();

			IScrSection dummySection;
			IScrBook genesis = CreateSmallBook(1, "Genesis", out dummySection);

			// Add a footnote in the first book, first section, first paragraph
			IScrSection section = genesis.SectionsOS[0];
			IStFootnote footnote = AddFootnote(genesis,
				(IStTxtPara)section.ContentOA.ParagraphsOS[0], 2);
			IStTxtPara para = AddParaToMockedText(footnote,
							ScrStyleNames.NormalFootnoteParagraph);
			AddRunToMockedPara(para, "Another footnote", para.Cache.DefaultVernWs);

			// Add a footnote in the first book, last section, 1st paragraph
			section = genesis.SectionsOS[genesis.SectionsOS.Count - 1];
			footnote = AddFootnote(genesis,
				(IStTxtPara)section.ContentOA.ParagraphsOS[0], 1);
			para = AddParaToMockedText(footnote,
				ScrStyleNames.NormalFootnoteParagraph);
			AddRunToMockedPara(para, "This is the footnote", para.Cache.DefaultVernWs);

			ConfigurePublication(true, true);
			m_pub.PageHeight = 72000 * 3; // 3 inches
			m_pub.PageWidth = 72000 * 4; // 4 inches

			// Add a second division (that displays the same as the first)
			DummyDivision secondDiv = new DummyDivision(new DummyLazyPrintConfigurer(Cache,
				false, true), 2);
			secondDiv.TopMargin = m_division.TopMargin;
			secondDiv.BottomMargin = m_division.BottomMargin;
			secondDiv.InsideMargin = m_division.InsideMargin;
			secondDiv.OutsideMargin = m_division.OutsideMargin;
			m_pub.AddDivision(secondDiv);
			m_pub.Configure();

			m_pub.CreatePages();
			m_pub.PrepareToDrawPages(0, m_pub.AutoScrollMinSize.Height * 2);

			Assert.GreaterOrEqual(m_pub.Pages.Count, 2);

			Page firstPage = m_pub.Pages[0];
			int cFoonotesOnThisPage = m_division.m_testPageFootnoteInfo[firstPage.Handle] +
				secondDiv.m_testPageFootnoteInfo[firstPage.Handle];
			Assert.AreEqual(3, cFoonotesOnThisPage, "Should display three footnotes on first page");

			// None of the page elements on the first page should intersect
			CheckThatPageElementsDontOverlap(firstPage);

			// PageElement 0: first column of first division; 2: first column of second division;
			// 4: footnotes

			Assert.AreEqual(m_pub.PageHeightInPrinterPixels - m_division.TopMarginInPrinterPixels
				- m_division.BottomMarginInPrinterPixels, firstPage.PageElements[0].ColumnHeight
				+ firstPage.PageElements[2].ColumnHeight + firstPage.PageElements[4].ColumnHeight +
				firstPage.FreeSpace.Height);
		}
Esempio n. 21
0
        public void VerseIterator()
        {
            // Create section 1 for Genesis.
            IScrSection section1 = CreateSection(m_genesis, "My aching head!");

            // build paragraph for section 1
            StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);

            paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph;
            paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse 1. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse 2. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("3-4", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                    Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse 3-4.",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            IScrTxtPara hvoS1Para = (IScrTxtPara)paraBldr.CreateParagraph(section1.ContentOA);


            // Create an iterator to test heading
            m_bookMerger.CreateVerseIteratorForStText(section1.HeadingOA);

            // Verify section 1 heading
            ScrVerse scrVerse = m_bookMerger.NextVerseInStText();

            Assert.AreEqual(section1.HeadingOA[0], scrVerse.Para);
            Assert.AreEqual(01002001, scrVerse.StartRef);
            Assert.AreEqual(01002001, scrVerse.EndRef);
            Assert.AreEqual("My aching head!", scrVerse.Text.Text);
            Assert.AreEqual(0, scrVerse.VerseStartIndex);

            // Verify there are no more scrVerses
            scrVerse = m_bookMerger.NextVerseInStText();
            Assert.IsNull(scrVerse);

            // Create an iterator to test content
            m_bookMerger.CreateVerseIteratorForStText(section1.ContentOA);

            // Verify section 1 content
            scrVerse = m_bookMerger.NextVerseInStText();
            Assert.AreEqual(hvoS1Para, scrVerse.Para);
            Assert.AreEqual(01002001, scrVerse.StartRef);
            Assert.AreEqual(01002001, scrVerse.EndRef);
            Assert.AreEqual("2Verse 1. ", scrVerse.Text.Text);
            Assert.AreEqual(0, scrVerse.VerseStartIndex);
            Assert.AreEqual(1, scrVerse.TextStartIndex);

            scrVerse = m_bookMerger.NextVerseInStText();
            Assert.AreEqual(01002002, scrVerse.StartRef);
            Assert.AreEqual(01002002, scrVerse.EndRef);
            Assert.AreEqual("2Verse 2. ", scrVerse.Text.Text);
            Assert.AreEqual(10, scrVerse.VerseStartIndex);

            scrVerse = m_bookMerger.NextVerseInStText();
            Assert.AreEqual(01002003, scrVerse.StartRef);
            Assert.AreEqual(01002004, scrVerse.EndRef);
            Assert.AreEqual("3-4Verse 3-4.", scrVerse.Text.Text);
            Assert.AreEqual(20, scrVerse.VerseStartIndex);

            // Verify there are no more scrVerses
            scrVerse = m_bookMerger.NextVerseInStText();
            Assert.IsNull(scrVerse);
        }
Esempio n. 22
0
        public void MoveNext_SpacesInVerses_ChapterNumberSeparate()
        {
            IScrSection sectionCur = AddSectionToMockedBook(m_genesis);

            // Create a section head for this section
            AddSectionHeadParaToSection(sectionCur, "My aching head!", ScrStyleNames.SectionHead);

            StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);

            paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph;
            paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse One. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun(" Verse Two. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("3", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse Three.",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("4", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("     ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            IScrTxtPara para = (IScrTxtPara)paraBldr.CreateParagraph(sectionCur.ContentOA);

            using (ScrVerseSet verseSet = new ScrVerseSet(para))
            {
                // Iterate through the verses in the paragraph
                ScrVerse verse;

                Assert.IsTrue(verseSet.MoveNext());
                verse = verseSet.Current;
                Assert.AreEqual("1", verse.Text.Text);
                Assert.AreEqual(01001001, verse.StartRef);
                Assert.AreEqual(01001001, verse.EndRef);

                Assert.IsTrue(verseSet.MoveNext());
                verse = verseSet.Current;
                Assert.AreEqual("Verse One. ", verse.Text.Text);
                Assert.AreEqual(01001001, verse.StartRef);
                Assert.AreEqual(01001001, verse.EndRef);

                Assert.IsTrue(verseSet.MoveNext());
                verse = verseSet.Current;
                Assert.AreEqual("2 Verse Two. ", verse.Text.Text);
                Assert.AreEqual(01001002, verse.StartRef);
                Assert.AreEqual(01001002, verse.EndRef);

                Assert.IsTrue(verseSet.MoveNext());
                verse = verseSet.Current;
                Assert.AreEqual("3Verse Three.", verse.Text.Text);
                Assert.AreEqual(01001003, verse.StartRef);
                Assert.AreEqual(01001003, verse.EndRef);

                Assert.IsTrue(verseSet.MoveNext());
                verse = verseSet.Current;
                Assert.AreEqual("4     ", verse.Text.Text);
                Assert.AreEqual(01001004, verse.StartRef);
                Assert.AreEqual(01001004, verse.EndRef);

                Assert.IsFalse(verseSet.MoveNext());
            }
        }
Esempio n. 23
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void CreateTestData()
        {
            ITsStrFactory strfact = TsStrFactoryClass.Create();

            //James
            IScrBook book = AddBookToMockedScripture(59, "James");

            AddTitleToMockedBook(book, "James");

            // James first section
            IScrSection section = AddSectionToMockedBook(book);

            AddSectionHeadParaToSection(section, "Paul tells people", "Section Head");
            IStTxtPara para = AddParaToMockedSectionContent(section, "Paragraph");

            AddRunToMockedPara(para, "1", "Chapter Number");
            AddRunToMockedPara(para, "1", "Verse Number");
            AddRunToMockedPara(para, "and the earth was without form and void and darkness covered the face of the deep", null);

            // James section2
            IScrSection section2 = AddSectionToMockedBook(book);

            AddSectionHeadParaToSection(section2, "Paul tells people more", "Section Head");
            IStTxtPara para2 = AddParaToMockedSectionContent(section2, "Paragraph");

            AddRunToMockedPara(para2, "2", "Chapter Number");
            AddRunToMockedPara(para2, "1", "Verse Number");
            AddRunToMockedPara(para2, "paul expounds on the nature of reality", null);
            IStTxtPara para3 = AddParaToMockedSectionContent(section2, "Paragraph");

            AddRunToMockedPara(para3, "2", "Verse Number");
            AddRunToMockedPara(para3, "the existentialists are all wrong", null);

            // insert footnotes into para 2 of James
            ITsStrBldr jamesBldr = para2.Contents.GetBldr();
            int        iFootIch  = 10;

            for (int i = 0; i < 2; i++)
            {
                IStFootnote foot     = book.InsertFootnoteAt(i, jamesBldr, iFootIch);
                IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                    foot, ScrStyleNames.NormalFootnoteParagraph);
                footPara.Contents = strfact.MakeString("This is footnote text for footnote " + i.ToString(), Cache.DefaultVernWs);
                iFootIch         += 20;
            }
            para2.Contents = jamesBldr.GetString();

            //Jude
            m_Jude = AddBookToMockedScripture(65, "Jude");
            AddTitleToMockedBook(m_Jude, "Jude");

            //Jude intro section
            IScrSection judeSection = AddSectionToMockedBook(m_Jude);

            AddSectionHeadParaToSection(judeSection, "Introduction", "Intro Section Head");
            IStTxtPara judePara = AddParaToMockedSectionContent(judeSection, "Intro Paragraph");

            AddRunToMockedPara(judePara, "The Letter from Jude was written to warn against" +
                               " false teachers who claimed to be believers. In this brief letter, which is similar in" +
                               " content to 2 Peter the writer encourages his readers \u201Cto fight on for the faith which" +
                               " once and for all God has given to his people.", null);
            // Insert BT (in two different writing systems) of intro paragraph
            ICmTranslation transEn = AddBtToMockedParagraph(judePara, m_wsEn);
            ICmTranslation transDe = AddBtToMockedParagraph(judePara, m_wsDe);

            // Jude Scripture section
            IScrSection judeSection2 = AddSectionToMockedBook(m_Jude);

            AddSectionHeadParaToSection(judeSection2, "First section", "Section Head");
            IStTxtPara judePara2 = AddParaToMockedSectionContent(judeSection2, "Paragraph");

            AddRunToMockedPara(judePara2, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(judePara2, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(judePara2, "This is the first verse", null);
            AddRunToMockedPara(judePara2, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(judePara2, "This is the second verse", null);
            AddRunToMockedPara(judePara2, "3", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(judePara2, "This is the third verse", null);
            AddRunToMockedPara(judePara2, "4", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(judePara2, "This is the fourth verse", null);

            // Insert footnotes into para 1 of Jude
            ITsStrBldr bldr = judePara.Contents.GetBldr();

            iFootIch = 10;
            for (int i = 0; i < 4; i++)
            {
                IStFootnote foot     = m_Jude.InsertFootnoteAt(i, bldr, iFootIch);
                IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                    foot, ScrStyleNames.NormalFootnoteParagraph);
                footPara.Contents = strfact.MakeString("This is text for footnote " + i.ToString(), Cache.DefaultVernWs);
                iFootIch         += 30;
                // Insert ORC for footnote into BT (in both writing systems)
                AddBtFootnote(transEn, i, m_wsEn, foot);
                AddBtFootnote(transDe, i, m_wsDe, foot);
            }
            judePara.Contents = bldr.GetString();

            // Insert footnotes into para 2 of Jude
            bldr     = judePara2.Contents.GetBldr();
            iFootIch = 10;
            for (int i = 0; i < 4; i++)
            {
                IStFootnote foot     = m_Jude.InsertFootnoteAt(i + 4, bldr, iFootIch);
                IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                    foot, ScrStyleNames.NormalFootnoteParagraph);
                footPara.Contents = strfact.MakeString("This is text for footnote " + (i + 4).ToString(), Cache.DefaultVernWs);
                iFootIch         += 20;
            }
            judePara2.Contents = bldr.GetString();
        }
        public void GotoVerse_ExactWhenOverlappingRanges()
        {
            // section1: 1, 3
            // section2: 6, 7, 8
            // section3: 2, 4, 10
            // ip at beginning of section1

            // goto verse 4

            IScrSection section = AddSectionToMockedBook(m_exodus);

            AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead);
            IStTxtPara para =
                AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse one", null);
            AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse three", null);

            section = AddSectionToMockedBook(m_exodus);
            AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead);
            para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph);
            AddRunToMockedPara(para, "6", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse six", null);
            AddRunToMockedPara(para, "7", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse seven", null);
            AddRunToMockedPara(para, "8", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse eight", null);

            section = AddSectionToMockedBook(m_exodus);
            AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead);
            para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph);
            AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse two", null);
            AddRunToMockedPara(para, "4", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse four", null);
            AddRunToMockedPara(para, "10", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse ten", null);

            m_draftView.RootBox.Reconstruct();             // update the view

            // Set the selection to the start of the section
            m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false);

            // Attempt to go to Exodus 1:4 (should exist)
            Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 4, m_scr.Versification)));

            // Make sure selection is at verse 4 in third section
            IVwSelection vwsel = m_draftView.RootBox.Selection;
            int          ich, hvo, textTag, enc;
            bool         fAssocPrev;
            ITsString    tss2;

            vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag,
                              out enc);
            Assert.AreEqual(StTxtParaTags.kflidContents, textTag);
            Assert.AreEqual("4", tss2.Text.Substring(ich - 1, 1));
            Assert.IsFalse(fAssocPrev);
        }
        public void BtOnlyFootnotes()
        {
            // Set up Scripture to correspond with the back translation to be imported.
            IScrBook    exodus  = AddBookToMockedScripture(2, "Exodus");
            IScrSection section = AddSectionToMockedBook(exodus);
            IStTxtPara  para    = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse one text", null);
            AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse two text", null);
            IStFootnote noteOne = AddFootnote(exodus, para, 11,
                                              "vernacular text for footnote one"); // footnote after "one" in verse 1
            IStFootnote noteTwo = AddFootnote(exodus, para, 27,
                                              "vernacular text for footnote two"); // footnote after "two" in verse 2
            ICmTranslation noteOneTrans = ((IStTxtPara)noteOne.ParagraphsOS[0]).GetOrCreateBT();
            ICmTranslation noteTwoTrans = ((IStTxtPara)noteTwo.ParagraphsOS[0]).GetOrCreateBT();

            m_importer.Settings.ImportTranslation     = false;
            m_importer.Settings.ImportBackTranslation = true;
            m_importer.CurrentImportDomain            = ImportDomain.BackTrans;

            // ************** process a \id segment, test MakeBook() method *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");             // no text provided in segment, just the refs
            Assert.AreEqual(2, m_importer.BookNumber);
            // verify that a new book was added to the DB
            IScrBook book = m_importer.ScrBook;

            Assert.AreEqual("EXO", book.BookId);

            // ************** process a main title *********************
            m_importer.ProcessSegment(string.Empty, @"\mt");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 0);
            m_importer.ProcessSegment("", @"\c");

            // ****** process a new BT paragraph with footnotes **********
            m_importer.ProcessSegment("", @"\p");
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\v");
            m_importer.ProcessSegment("verse one BT text", @"\vt");
            m_importer.ProcessSegment("+", @"\f");
            m_importer.ProcessSegment("BT text for footnote one.", @"\ft");
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 2);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 2);
            m_importer.ProcessSegment("", @"\v");
            m_importer.ProcessSegment("verse two BT text", @"\vt");
            m_importer.ProcessSegment("+", @"\f");
            m_importer.ProcessSegment("BT text for footnote two.", @"\ft");

            // ************** finalize **************
            m_importer.FinalizeImport();

            // Check the BT of these two paragraphs
            Assert.AreEqual(1, para.TranslationsOC.Count);
            ICmTranslation trans1 = para.GetBT();

            Assert.IsNotNull(trans1);
            ITsString tss1 = trans1.Translation.AnalysisDefaultWritingSystem;

            //Assert.AreEqual(7, tss1.RunCount);
            AssertEx.RunIsCorrect(tss1, 0, "1", ScrStyleNames.ChapterNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tss1, 1, "1", ScrStyleNames.VerseNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tss1, 2, "verse one BT text", null, m_wsAnal);

            Guid        guid1    = TsStringUtils.GetGuidFromRun(tss1, 3);
            IStFootnote footnote = Cache.ServiceLocator.GetInstance <IStFootnoteRepository>().GetObject(guid1);

            Assert.AreEqual(noteOneTrans.Owner, footnote.ParagraphsOS[0],
                            "The first imported BT footnote should be owned by paragraph in the first footnote but isn't");

            VerifyFootnoteWithTranslation(0, "vernacular text for footnote one",
                                          "BT text for footnote one.", "a", ScrStyleNames.NormalFootnoteParagraph);
            AssertEx.RunIsCorrect(tss1, 4, "2", ScrStyleNames.VerseNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tss1, 5, "verse two BT text", null, m_wsAnal);
            VerifyFootnoteWithTranslation(1, "vernacular text for footnote two",
                                          "BT text for footnote two.", "b", ScrStyleNames.NormalFootnoteParagraph);
        }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="para"></param>
		/// <param name="iPara"></param>
		/// <param name="section"></param>
		/// <param name="iSec"></param>
		/// <param name="book"></param>
		/// <param name="iBook"></param>
		/// <param name="setupForHeading"></param>
		/// ------------------------------------------------------------------------------------
		public void SetupSelectionInPara(IStTxtPara para, int iPara, IScrSection section,
			int iSec, IScrBook book, int iBook, int ich, bool setupForHeading)
		{
			CheckDisposed();

			SetupRangeSelection(book, iBook, section, iSec, para, iPara, ich, setupForHeading,
				book, iBook, section, iSec, para, iPara, ich, setupForHeading);
		}
        public void SkipInitialStanzaBreak()
        {
            // Set up Scripture to correspond with the back translation to be imported.
            IScrBook    exodus   = AddBookToMockedScripture(2, "Exodus");
            IScrSection section1 = AddSectionToMockedBook(exodus);
            IStTxtPara  paraH1   = AddSectionHeadParaToSection(section1, "Seccion Uno",
                                                               ScrStyleNames.SectionHead);
            IStTxtPara paraC1 = AddParaToMockedSectionContent(section1, ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(paraC1, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(paraC1, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(paraC1, "verse one text", null);

            IScrSection section2 = AddSectionToMockedBook(exodus);
            IStTxtPara  paraH2   = AddSectionHeadParaToSection(section2, "Seccion Dos",
                                                               ScrStyleNames.SectionHead);
            IStTxtPara paraC2 = AddParaToMockedSectionContent(section2, ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(paraC2, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(paraC2, "verse two text", null);

            m_importer.Settings.ImportBackTranslation = true;
            m_importer.CurrentImportDomain            = ImportDomain.BackTrans;

            // ************** process a \id segment, test MakeBook() method *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");             // no text provided in segment, just the refs

            // ************** process a main title *********************
            m_importer.ProcessSegment(string.Empty, @"\mt");

            // ************** process a bogus stanza break *********************
            m_importer.ProcessSegment(string.Empty, @"\b");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 0);
            m_importer.ProcessSegment("", @"\c");

            // ************** process first section head *********************
            m_importer.ProcessSegment("Section One", @"\s");

            // ************** process section contents *********************
            m_importer.ProcessSegment("", @"\p");
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("BT text for verse one", @"\v");

            // ************** process second section head *********************
            m_importer.ProcessSegment("Section Two", @"\s");

            // ************** process section contents *********************
            m_importer.ProcessSegment("", @"\p");
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 2);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 2);
            m_importer.ProcessSegment("BT for text at start of verse 2", @"\v");

            // ************** finalize **************
            m_importer.FinalizeImport();

            // Check the BT
            Assert.AreEqual(1, paraH1.TranslationsOC.Count);
            Assert.AreEqual(1, paraC1.TranslationsOC.Count);
            Assert.AreEqual(1, paraH2.TranslationsOC.Count);
            Assert.AreEqual(1, paraC2.TranslationsOC.Count);

            ICmTranslation transH1 = paraH1.GetBT();
            ITsString      tssH1   = transH1.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual(1, tssH1.RunCount);
            AssertEx.RunIsCorrect(tssH1, 0, "Section One", null, m_wsAnal);

            ICmTranslation transC1 = paraC1.GetBT();
            ITsString      tssC1   = transC1.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual(3, tssC1.RunCount);
            AssertEx.RunIsCorrect(tssC1, 0, "1", ScrStyleNames.ChapterNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tssC1, 1, "1", ScrStyleNames.VerseNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tssC1, 2, "BT text for verse one", null, m_wsAnal);

            ICmTranslation transH2 = paraH2.GetBT();
            ITsString      tssH2   = transH2.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual(1, tssH2.RunCount);
            AssertEx.RunIsCorrect(tssH2, 0, "Section Two", null, m_wsAnal);

            ICmTranslation transC2 = paraC2.GetBT();
            ITsString      tssC2   = transC2.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual(2, tssC2.RunCount);
            AssertEx.RunIsCorrect(tssC2, 0, "2", ScrStyleNames.VerseNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tssC2, 1, "BT for text at start of verse 2", null, m_wsAnal);
        }
Esempio n. 28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a paragraph from a format string, and append it to the given section's
		/// content.
		/// </summary>
		/// <param name="testBase">in-memory test base</param>
		/// <param name="book">book to use</param>
		/// <param name="section">section to append to</param>
		/// <param name="format">(See CreateText for the definition of the format string)</param>
		/// <param name="ws">writing system to use</param>
		/// <param name="paraStyle">paragraph style name</param>
		/// <returns>the new paragraph</returns>
		/// ------------------------------------------------------------------------------------
		internal static IScrTxtPara AppendParagraph(ScrInMemoryFdoTestBase testBase, IScrBook book,
			IScrSection section, string format, int ws, string paraStyle)
		{
			// insert a new para in the section content
			IScrTxtPara para = testBase.Cache.ServiceLocator.GetInstance<IScrTxtParaFactory>().CreateWithStyle(
				section.ContentOA, paraStyle);

			// set the para's fields
			testBase.AddFormatTextToMockedPara(book, para, format, ws);

			return para;
		}
Esempio n. 29
0
		/// <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, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_ParaBldr != null)
					m_ParaBldr.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;
		}
Esempio n. 30
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void CreateTestData()
        {
            ITsStrFactory strfact = TsStrFactoryClass.Create();

            //James
            IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(59, "James");

            m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "James");

            // James first section
            IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);

            m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Paul tells people", "Section Head");
            StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, "Paragraph");

            m_scrInMemoryCache.AddRunToMockedPara(para, "1", "Chapter Number");
            m_scrInMemoryCache.AddRunToMockedPara(para, "1", "Verse Number");
            m_scrInMemoryCache.AddRunToMockedPara(para, "and the earth was without form and void and darkness covered the face of the deep", null);
            section.AdjustReferences();

            // James section2
            IScrSection section2 = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);

            m_scrInMemoryCache.AddSectionHeadParaToSection(section2.Hvo, "Paul tells people more", "Section Head");
            StTxtPara para2 = m_scrInMemoryCache.AddParaToMockedSectionContent(section2.Hvo, "Paragraph");

            m_scrInMemoryCache.AddRunToMockedPara(para2, "2", "Chapter Number");
            m_scrInMemoryCache.AddRunToMockedPara(para2, "1", "Verse Number");
            m_scrInMemoryCache.AddRunToMockedPara(para2, "paul expounds on the nature of reality", null);
            StTxtPara para3 = m_scrInMemoryCache.AddParaToMockedSectionContent(section2.Hvo, "Paragraph");

            m_scrInMemoryCache.AddRunToMockedPara(para3, "2", "Verse Number");
            m_scrInMemoryCache.AddRunToMockedPara(para3, "the existentialists are all wrong", null);

            // insert footnotes into para 2 of James
            ITsTextProps normalFootnoteParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph);
            ITsStrBldr   jamesBldr = para2.Contents.UnderlyingTsString.GetBldr();
            int          iFootIch  = 10;

            for (int i = 0; i < 2; i++)
            {
                StFootnote foot     = ScrFootnote.InsertFootnoteAt(book, i, jamesBldr, iFootIch, "a");
                StTxtPara  footPara = new StTxtPara();
                foot.ParagraphsOS.Append(footPara);
                footPara.StyleRules = normalFootnoteParaProps;
                footPara.Contents.UnderlyingTsString = strfact.MakeString("This is footnote text for footnote " + i.ToString(), Cache.DefaultVernWs);
                iFootIch += 20;
            }
            para2.Contents.UnderlyingTsString = jamesBldr.GetString();
            section2.AdjustReferences();

            //Jude
            m_Jude = m_scrInMemoryCache.AddBookToMockedScripture(65, "Jude");
            m_scrInMemoryCache.AddTitleToMockedBook(m_Jude.Hvo, "Jude");

            //Jude intro section
            IScrSection judeSection = m_scrInMemoryCache.AddSectionToMockedBook(m_Jude.Hvo);

            m_scrInMemoryCache.AddSectionHeadParaToSection(judeSection.Hvo, "Introduction", "Intro Section Head");
            StTxtPara judePara = m_scrInMemoryCache.AddParaToMockedSectionContent(judeSection.Hvo, "Intro Paragraph");

            m_scrInMemoryCache.AddRunToMockedPara(judePara, "The Letter from Jude was written to warn against" +
                                                  " false teachers who claimed to be believers. In this brief letter, which is similar in" +
                                                  " content to 2 Peter the writer encourages his readers “to fight on for the faith which" +
                                                  " once and for all God has given to his people.", null);
            judeSection.AdjustReferences();
            // Insert BT (in two different writing systems) of intro paragraph
            ICmTranslation transEn = m_inMemoryCache.AddBtToMockedParagraph(judePara, InMemoryFdoCache.s_wsHvos.En);
            ICmTranslation transDe = m_inMemoryCache.AddBtToMockedParagraph(judePara, InMemoryFdoCache.s_wsHvos.De);

            // Jude Scripture section
            IScrSection judeSection2 = m_scrInMemoryCache.AddSectionToMockedBook(m_Jude.Hvo);

            m_scrInMemoryCache.AddSectionHeadParaToSection(judeSection2.Hvo, "First section", "Section Head");
            StTxtPara judePara2 = m_scrInMemoryCache.AddParaToMockedSectionContent(judeSection2.Hvo, "Paragraph");

            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "1", ScrStyleNames.ChapterNumber);
            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "1", ScrStyleNames.VerseNumber);
            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "This is the first verse", null);
            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "2", ScrStyleNames.VerseNumber);
            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "This is the second verse", null);
            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "3", ScrStyleNames.VerseNumber);
            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "This is the third verse", null);
            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "4", ScrStyleNames.VerseNumber);
            m_scrInMemoryCache.AddRunToMockedPara(judePara2, "This is the fourth verse", null);

            // Insert footnotes into para 1 of Jude
            ITsStrBldr bldr = judePara.Contents.UnderlyingTsString.GetBldr();

            iFootIch = 10;
            for (int i = 0; i < 4; i++)
            {
                StFootnote foot     = ScrFootnote.InsertFootnoteAt(m_Jude, i, bldr, iFootIch, "a");
                StTxtPara  footPara = new StTxtPara();
                foot.ParagraphsOS.Append(footPara);
                footPara.StyleRules = normalFootnoteParaProps;
                footPara.Contents.UnderlyingTsString = strfact.MakeString("This is text for footnote " + i.ToString(), Cache.DefaultVernWs);
                iFootIch += 30;
                // Insert ORC for footnote into BT (in both writing systems)
                m_scrInMemoryCache.AddFootnoteORCtoTrans(transEn, i, InMemoryFdoCache.s_wsHvos.En, foot);
                m_scrInMemoryCache.AddFootnoteORCtoTrans(transDe, i, InMemoryFdoCache.s_wsHvos.De, foot);
            }
            judePara.Contents.UnderlyingTsString = bldr.GetString();

            // Insert footnotes into para 2 of Jude
            bldr     = judePara2.Contents.UnderlyingTsString.GetBldr();
            iFootIch = 10;
            for (int i = 0; i < 4; i++)
            {
                StFootnote foot     = ScrFootnote.InsertFootnoteAt(m_Jude, i + 4, bldr, iFootIch, "a");
                StTxtPara  footPara = new StTxtPara();
                foot.ParagraphsOS.Append(footPara);
                footPara.StyleRules = normalFootnoteParaProps;
                footPara.Contents.UnderlyingTsString = strfact.MakeString("This is text for footnote " + (i + 4).ToString(), Cache.DefaultVernWs);
                iFootIch += 20;
            }
            judePara2.Contents.UnderlyingTsString = bldr.GetString();
            judeSection2.AdjustReferences();
        }
Esempio n. 31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get full reference (BCV-CV) of section.
		/// </summary>
		/// <param name="section"></param>
		/// <param name="ws">writing system of the book</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public ITsString BookChapterVerseBridgeAsTss(IScrSection section, int ws)
		{
			ITsString tssBookName = ((IScrBook)section.Owner).Name.get_String(ws);
			if (tssBookName.Length > 0)
			{
				ITsStrBldr bldr = tssBookName.GetBldr();
				int cch = bldr.Length;
				bldr.Replace(cch, cch, " " + ChapterVerseBridgeAsString(section), null);
				return bldr.GetString();
			}
			return null;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set up the mocked selection helper with needed level info for a translation.
		/// </summary>
		/// <param name="para">The para.</param>
		/// <param name="trans">The trans.</param>
		/// <param name="wsTrans">The ws trans.</param>
		/// <param name="section">The section.</param>
		/// <param name="book">The book.</param>
		/// ------------------------------------------------------------------------------------
		private void SetupSelHelperLevelInfo(IStTxtPara para, ICmTranslation trans, int wsTrans,
			IScrSection section, IScrBook book)
		{
			SelLevInfo[] selLevInfo = new SelLevInfo[5];
			selLevInfo[4].tag = m_btView.BookFilter.Tag;
			selLevInfo[4].ihvo = 0;
			selLevInfo[4].hvo = book.Hvo;
			selLevInfo[3].tag = ScrBookTags.kflidSections;
			selLevInfo[3].ihvo = 0;
			selLevInfo[3].hvo = section.Hvo;
			selLevInfo[2].ihvo = 0;
			selLevInfo[2].tag = ScrSectionTags.kflidContent;
			selLevInfo[1].ihvo = 0;
			selLevInfo[1].hvo = para.Hvo;
			selLevInfo[1].tag = StTextTags.kflidParagraphs;
			selLevInfo[0].ihvo = 0;
			selLevInfo[0].hvo = trans.Hvo;
			selLevInfo[0].ws = 0; //not useful, but that's what actual selLevelInfo[0] has
			selLevInfo[0].tag = -1; //not useful, but that's what actual selLevelInfo[0] has
			m_selHelper.SetupResult("LevelInfo", selLevInfo);
			m_selHelper.SetupResult("GetLevelInfo", selLevInfo,
				new Type[] { typeof(SelectionHelper.SelLimitType) });
			m_selHelper.SetupResult("NumberOfLevels", 5);
		}
        public void ImplicitParaStart()
        {
            // Set up Scripture to correspond with the back translation to be imported.
            IScrBook    exodus   = AddBookToMockedScripture(2, "Exodus");
            IScrSection section1 = AddSectionToMockedBook(exodus);
            IStTxtPara  para1    = AddParaToMockedSectionContent(section1, ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para1, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(para1, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para1, "verse one text", null);
            AddRunToMockedPara(para1, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para1, "verse two text", null);
            IStTxtPara para2 = AddParaToMockedSectionContent(section1, "List Item1");

            AddRunToMockedPara(para2, "more verse two text", null);

            m_importer.Settings.ImportBackTranslation = true;
            m_importer.CurrentImportDomain            = ImportDomain.BackTrans;

            // ************** process a \id segment, test MakeBook() method *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");             // no text provided in segment, just the refs
            Assert.AreEqual(2, m_importer.BookNumber);
            IScrBook book = m_importer.ScrBook;

            Assert.AreEqual("EXO", book.BookId);

            // ************** process a main title *********************
            m_importer.ProcessSegment(string.Empty, @"\mt");
            //Assert.AreEqual(string.Empty, m_importer.ScrBook.Name.get_String(
            //    m_wsAnal));

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 0);
            m_importer.ProcessSegment("", @"\c");

            // ************** process two new paragraphs *********************
            m_importer.ProcessSegment("", @"\p");
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\v");
            m_importer.ProcessSegment("BT text for verse one", @"\vt");
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 2);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 2);
            m_importer.ProcessSegment("", @"\v");
            m_importer.ProcessSegment("BT for text at start of verse 2", @"\vt");
            m_importer.ProcessSegment("", @"\li1");
            m_importer.ProcessSegment("BT of continued text", @"\vt");

            // ************** finalize **************
            m_importer.FinalizeImport();

            // Check the BT of these two paragraphs
            Assert.AreEqual(1, para1.TranslationsOC.Count);
            ICmTranslation trans1 = para1.GetBT();
            ITsString      tss1   = trans1.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual(5, tss1.RunCount);
            AssertEx.RunIsCorrect(tss1, 0, "1", ScrStyleNames.ChapterNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tss1, 1, "1", ScrStyleNames.VerseNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tss1, 2, "BT text for verse one", null, m_wsAnal);
            AssertEx.RunIsCorrect(tss1, 3, "2", ScrStyleNames.VerseNumber, m_wsAnal);
            AssertEx.RunIsCorrect(tss1, 4, "BT for text at start of verse 2", null, m_wsAnal);

            Assert.AreEqual(1, para2.TranslationsOC.Count);
            ICmTranslation trans2 = para2.GetBT();
            ITsString      tss2   = trans2.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual(1, tss2.RunCount);
        }
Esempio n. 34
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Merges the content of the current section with the previous section if in the
		/// sections have the same context.
		/// </summary>
		/// <param name="helper">The selection helper.</param>
		/// <param name="book">The current book.</param>
		/// <param name="section">The current section.</param>
		/// <param name="iSection">The index of the current section.</param>
		/// <param name="fPositionAtEnd">If true position of Selection is placed at end of
		/// paragraph, else at the beginning.</param>
		/// <returns><c>true</c> if we merged the sections, otherwise <c>false</c>.</returns>
		/// ------------------------------------------------------------------------------------
		private bool MergeWithPreviousSectionIfInSameContext(SelectionHelper helper, ScrBook book,
			IScrSection section, int iSection, bool fPositionAtEnd)
		{
			IScrSection prevSection = book.SectionsOS[iSection - 1];
			if (SectionsHaveSameContext(prevSection, section))
			{
				MergeContentWithPreviousSection(helper, book, section, iSection,
					fPositionAtEnd);
				return true;
			}
			return false;
		}
Esempio n. 35
0
		/// ------------------------------------------------------------------------------------
		/// <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)
		{
			CheckDisposed();

			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.TranslationsOC.HvoArray[0];
				iLev++;
			}
			topInfo[iLev].tag = (int)StText.StTextTags.kflidParagraphs;
			topInfo[iLev].ihvo = iParaStart;
			topInfo[iLev].hvo = paraStart.Hvo;
			topInfo[++iLev].tag = setupForHeadingStart ? (int)ScrSection.ScrSectionTags.kflidHeading :
				(int)ScrSection.ScrSectionTags.kflidContent;
			topInfo[iLev].ihvo = 0;
			topInfo[iLev].hvo = setupForHeadingStart ? sectionStart.HeadingOA.Hvo :
				sectionStart.ContentOA.Hvo;
			topInfo[++iLev].tag = (int)ScrBook.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.TranslationsOC.HvoArray[0];
				iLev++;
			}
			bottomInfo[iLev].tag = (int)StText.StTextTags.kflidParagraphs;
			bottomInfo[iLev].ihvo = iParaEnd;
			bottomInfo[iLev].hvo = paraEnd.Hvo;
			bottomInfo[++iLev].tag = setupForHeadingEnd ? (int)ScrSection.ScrSectionTags.kflidHeading :
				(int)ScrSection.ScrSectionTags.kflidContent;
			bottomInfo[iLev].ihvo = 0;
			bottomInfo[iLev].hvo = setupForHeadingEnd ? sectionEnd.HeadingOA.Hvo :
				sectionEnd.ContentOA.Hvo;
			bottomInfo[++iLev].tag = (int)ScrBook.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("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 ?
				(int)CmTranslation.CmTranslationTags.kflidTranslation :
				(int)StTxtPara.StTxtParaTags.kflidContents,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetTextPropId", wsStart > 0 ?
				(int)CmTranslation.CmTranslationTags.kflidTranslation :
				(int)StTxtPara.StTxtParaTags.kflidContents,
				SelectionHelper.SelLimitType.Anchor);
			fakeSelHelper.SetupResultForParams("GetTextPropId", wsEnd > 0 ?
				(int)CmTranslation.CmTranslationTags.kflidTranslation :
				(int)StTxtPara.StTxtParaTags.kflidContents,
				SelectionHelper.SelLimitType.Bottom);
			fakeSelHelper.SetupResultForParams("GetTextPropId", wsEnd > 0 ?
				(int)CmTranslation.CmTranslationTags.kflidTranslation :
				(int)StTxtPara.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_viewSelection = (SelectionHelper)fakeSelHelper.MockInstance;
		}
Esempio n. 36
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Merges content of given section into the content of the previous section and then
		/// deletes the given section.
		/// </summary>
		/// <param name="helper"> </param>
		/// <param name="book"></param>
		/// <param name="section"></param>
		/// <param name="ihvoSection"></param>
		/// <param name="fPositionAtEnd">If true position of Selection is placed at end of
		/// paragraph, else at the beginning.</param>
		/// ------------------------------------------------------------------------------------
		private void MergeContentWithPreviousSection(SelectionHelper helper, ScrBook book,
			IScrSection section, int ihvoSection, bool fPositionAtEnd)
		{
			//REVIEW: Can the methods that call this be refactored
			//to use (a refactored?) ScrSection.MergeWithPreviousSection?
			//
			// Get the previous section and move the paragraphs.
			IScrSection sectionPrev = book.SectionsOS[ihvoSection - 1];
			IStText textPrev = sectionPrev.ContentOA;
			ILocationTracker tracker = ((ITeView)Control).LocationTracker;
			int iBook = tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Top);
			int cparaPrev = 0;
			if (textPrev == null)
			{
				// Prevent crash when dealing with corrupt database (TE-4869)
				// Since the previous section doesn't have a text, we simply move the entire text
				// object from the current section to the previous section.
				m_cache.ChangeOwner(section.ContentOAHvo, sectionPrev.Hvo,
					(int)ScrSection.ScrSectionTags.kflidContent);
			}
			else
			{
				cparaPrev = textPrev.ParagraphsOS.Count;
				IStText textOldContents = section.ContentOA;
				m_cache.MoveOwningSequence(textOldContents.Hvo, (int)StText.StTextTags.kflidParagraphs,
					0, textOldContents.ParagraphsOS.Count - 1,
					textPrev.Hvo, (int)StText.StTextTags.kflidParagraphs, cparaPrev);
			}
			// protected for some reason...textPrev.ParagraphsOS.Append(text.ParagraphsOS.HvoArray);
			book.SectionsOS.RemoveAt(ihvoSection);
			// Now we have to re-establish a selection. Whatever happens, it will be in the
			// same book as before, and the previous section, and in the body.
			if (InSectionHead || !fPositionAtEnd)
			{
				tracker.SetBookAndSection(helper, SelectionHelper.SelLimitType.Top, iBook,
					ihvoSection - 1);
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[1].tag =
					(int)ScrSection.ScrSectionTags.kflidContent;
			}
			Debug.Assert(helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[1].tag ==
				(int)ScrSection.ScrSectionTags.kflidContent);

			if (fPositionAtEnd)
			{
				// we want selection at end of last paragraph of old previous section.
				// (That is, at the end of paragraph cparaPrev - 1.)
				Debug.Assert(cparaPrev > 0);
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].ihvo = cparaPrev - 1;
				StTxtPara paraPrev = (StTxtPara)(textPrev.ParagraphsOS[cparaPrev - 1]);

				int cchParaPrev = paraPrev.Contents.Length;
				helper.IchAnchor = cchParaPrev;
				helper.IchEnd = cchParaPrev;
				helper.AssocPrev = true;
			}
			else
			{
				// want selection at start of old first paragraph of deleted section.
				// (That is, at the start of paragraph cparaPrev.)
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].ihvo = cparaPrev;
				helper.IchAnchor = 0;
				helper.IchEnd = 0;
				helper.AssocPrev = false;
			}
			helper.SetLevelInfo(SelectionHelper.SelLimitType.Bottom,
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top));
			helper.SetSelection(true);
		}
        public void TwoBts()
        {
            m_importer.Settings.ImportBackTranslation = true;

            // initialize - process a \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("EXO Vernacular ID Text", @"\id");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("verse text", @"\v");

            // verify state of NormalParaStrBldr
            Assert.AreEqual(3, m_importer.NormalParaStrBldr.RunCount);
            VerifyBldrRun(0, "1", ScrStyleNames.ChapterNumber);
            VerifyBldrRun(1, "1", ScrStyleNames.VerseNumber);
            VerifyBldrRun(2, "verse text", null);

            // ************** End of Scripture file *********************

            // ******* Back translation in default Analysis WS **********
            m_importer.CurrentImportDomain        = ImportDomain.BackTrans;
            m_importer.DummySoWrapper.m_CurrentWs = m_wsAnal;

            // process an \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("EXO Ignore this", @"\id");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("back trans", @"\v");

            // ******* Back translation in Spanish WS **********
            int wsSpanish = Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("es");

            m_importer.DummySoWrapper.m_CurrentWs = wsSpanish;

            // process an \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("EXO Ignora esto tambien", @"\id");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("retrotraduccion", @"\v");

            // ************** finalize **************
            m_importer.FinalizeImport();

            IScrBook book = m_importer.ScrBook;

            Assert.AreEqual("Vernacular ID Text", book.IdText);
            Assert.AreEqual(1, book.SectionsOS.Count);
            IScrSection section = book.SectionsOS[0];

            Assert.AreEqual(1, section.ContentOA.ParagraphsOS.Count);
            Assert.AreEqual(02001001, section.VerseRefMin);
            Assert.AreEqual(02001001, section.VerseRefMax);
            IStTxtPara para = (IStTxtPara)section.ContentOA.ParagraphsOS[0];

            Assert.AreEqual("11verse text", para.Contents.Text);
            Assert.AreEqual(1, para.TranslationsOC.Count);
            ICmTranslation trans = para.GetBT();
            // Check default analysis BT
            ITsString btTss = trans.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual("11back trans", btTss.Text);
            Assert.AreEqual(3, btTss.RunCount);
            Assert.AreEqual("back trans", btTss.get_RunText(2));
            ITsTextProps ttpRun3 = btTss.get_Properties(2);

            Assert.AreEqual(null, ttpRun3.GetStrPropValue((int)FwTextPropType.ktptNamedStyle));
            int nVar;

            Assert.AreEqual(m_wsAnal, ttpRun3.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar));

            // Check Spanish BT
            btTss = trans.Translation.get_String(wsSpanish);
            Assert.AreEqual("11retrotraduccion", btTss.Text);
            Assert.AreEqual(3, btTss.RunCount);
            Assert.AreEqual("retrotraduccion", btTss.get_RunText(2));
            ttpRun3 = btTss.get_Properties(2);
            Assert.AreEqual(null, ttpRun3.GetStrPropValue((int)FwTextPropType.ktptNamedStyle));
            Assert.AreEqual(wsSpanish, ttpRun3.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar));
        }
Esempio n. 38
0
		/// ------------------------------------------------------------------------------------------
		/// <summary>
		/// Determines if the beginning and the end of the selection are within the same type
		/// of paragraph (e.g. all in intro material or all in scripture paragraphs).
		/// </summary>
		/// <param name="section1">The section1.</param>
		/// <param name="section2">The section2.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------------
		private bool SectionsHaveSameContext(IScrSection section1, IScrSection section2)
		{
			// Must both be true or both be false: negated exclusive OR.
			return !(section1.IsIntro ^ section2.IsIntro);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="bookStart"></param>
		/// <param name="iBookStart"></param>
		/// <param name="sectionStart"></param>
		/// <param name="iSecStart"></param>
		/// <param name="paraStart"></param>
		/// <param name="iParaStart"></param>
		/// <param name="ichStart"></param>
		/// <param name="setupForHeadingStart"></param>
		/// <param name="bookEnd"></param>
		/// <param name="iBookEnd"></param>
		/// <param name="sectionEnd"></param>
		/// <param name="iSecEnd"></param>
		/// <param name="paraEnd"></param>
		/// <param name="iParaEnd"></param>
		/// <param name="ichEnd"></param>
		/// <param name="setupForHeadingEnd"></param>
		/// ------------------------------------------------------------------------------------
		public void SetupRangeSelection(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)
		{
			CheckDisposed();

			DynamicMock fakeSelHelper = new DynamicMock(typeof(SelectionHelper));
			fakeSelHelper.SetupResult("NumberOfLevels", 4);
			// Setup the anchor
			SelLevInfo[] topInfo = new SelLevInfo[4];
			topInfo[0].tag = StTextTags.kflidParagraphs;
			topInfo[0].ihvo = iParaStart;
			topInfo[0].hvo = paraStart.Hvo;
			topInfo[1].tag = setupForHeadingStart ? ScrSectionTags.kflidHeading :
				ScrSectionTags.kflidContent;
			topInfo[1].ihvo = 0;
			topInfo[1].hvo = setupForHeadingStart ? sectionStart.HeadingOA.Hvo :
				sectionStart.ContentOA.Hvo;
			topInfo[2].tag = ScrBookTags.kflidSections;
			topInfo[2].ihvo = iSecStart;
			topInfo[2].hvo = sectionStart.Hvo;
			topInfo[3].tag = ScriptureTags.kflidScriptureBooks;
			topInfo[3].ihvo = iBookStart;
			topInfo[3].hvo = bookStart.Hvo;

			// Setup the end
			SelLevInfo[] bottomInfo = new SelLevInfo[4];
			bottomInfo[0].tag = StTextTags.kflidParagraphs;
			bottomInfo[0].ihvo = iParaEnd;
			bottomInfo[0].hvo = paraEnd.Hvo;
			bottomInfo[1].tag = setupForHeadingEnd ? ScrSectionTags.kflidHeading :
				ScrSectionTags.kflidContent;
			bottomInfo[1].ihvo = 0;
			bottomInfo[1].hvo = setupForHeadingEnd ? sectionEnd.HeadingOA.Hvo :
				sectionEnd.ContentOA.Hvo;
			bottomInfo[2].tag = ScrBookTags.kflidSections;
			bottomInfo[2].ihvo = iSecEnd;
			bottomInfo[2].hvo = sectionEnd.Hvo;
			bottomInfo[3].tag = ScriptureTags.kflidScriptureBooks;
			bottomInfo[3].ihvo = iBookEnd;
			bottomInfo[3].hvo = bookEnd.Hvo;

			fakeSelHelper.SetupResult("LevelInfo", topInfo);
			fakeSelHelper.SetupResult("IchAnchor", ichStart);
			fakeSelHelper.SetupResult("IchEnd", ichEnd);
			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("GetIch", ichStart,
				SelectionHelper.SelLimitType.Top);
			fakeSelHelper.SetupResultForParams("GetIch", ichEnd,
				SelectionHelper.SelLimitType.Bottom);
			m_currentSelection = (SelectionHelper)fakeSelHelper.MockInstance;
		}
Esempio n. 40
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add a section, with empty heading and contents.
		/// Sets the following members: m_currSection, m_hvoSectionHeading, m_hvoSectionContent
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void MakeSection()
		{
			// Finalize the previous section, if there is one.
			FinalizePrevSection();

			m_currSection = new ScrSection();

			m_iCurrSection++;
			CurrentBook.SectionsOS.InsertAt(m_currSection, m_iCurrSection);
			m_currSection.ContentOA = new StText();
			m_currSection.HeadingOA = new StText();
			m_hvoSectionHeading = m_currSection.HeadingOA.Hvo;
			m_hvoSectionContent = m_currSection.ContentOA.Hvo;
			// REVIEW TomB: what should we do if we don't get a valid HVO?
			Debug.Assert(m_hvoSectionContent > 0);

			// Default new section refs to current segment's ref (or range)
			// in case the new section lacks verse number and verse text segments.
			m_currSection.VerseRefEnd = m_currentRef;
			m_currSection.AdjustReferences();
		}
        public void GotoVerse_MultipleHitsInMultipleSections()
        {
            IScrSection section = AddSectionToMockedBook(m_exodus);

            AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead);
            IStTxtPara para =
                AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse text", null);
            AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse text", null);
            AddRunToMockedPara(para, "3a", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse text", null);
            AddRunToMockedPara(para, "4", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse text", null);

            section = AddSectionToMockedBook(m_exodus);
            AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead);
            para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph);
            AddRunToMockedPara(para, "5", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse text", null);
            AddRunToMockedPara(para, "3b", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse text", null);
            AddRunToMockedPara(para, "6", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "verse text", null);

            m_draftView.RootBox.Reconstruct();             // update the view

            // Set the selection to the start of the section
            m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false);

            // Attempt to go to the first instance of Exodus 1:3 (should exist)
            Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 3, m_scr.Versification)));

            // Make sure selection is immediately following the 3 that marks the beginning
            // of the first verse 3.
            IVwSelection vwsel = m_draftView.RootBox.Selection;
            int          ich, hvo, textTag, enc;
            bool         fAssocPrev;
            ITsString    tss2;

            vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag,
                              out enc);
            Assert.IsFalse(fAssocPrev);
            Assert.AreEqual(StTxtParaTags.kflidContents, textTag);
            Assert.AreEqual("3a", tss2.Text.Substring(ich - 2, 2));

            // Attempt to go to the second instance of Exodus 1:3 (should exist)
            Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 3, m_scr.Versification)));

            // Make sure selection is immediately following the 3 that marks the beginning
            // of the first verse 3.
            vwsel = m_draftView.RootBox.Selection;
            vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag,
                              out enc);
            Assert.IsFalse(fAssocPrev);
            Assert.AreEqual(StTxtParaTags.kflidContents, textTag);
            Assert.AreEqual("3b", tss2.Text.Substring(ich - 2, 2));

            // Attempt to go to the first instance of Exodus 1:3 again (should exist)
            // which will test looping around.
            Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 3, m_scr.Versification)));

            // Make sure selection is immediately following the 3 that marks the beginning
            // of the first verse 3.
            vwsel = m_draftView.RootBox.Selection;
            vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag,
                              out enc);
            Assert.IsFalse(fAssocPrev);
            Assert.AreEqual(StTxtParaTags.kflidContents, textTag);
            Assert.AreEqual("3a", tss2.Text.Substring(ich - 2, 2));
        }
Esempio n. 42
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates test data
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			m_stylesheet = new FwStyleSheet();

			m_scrInMemoryCache.AddScrStyle("User added title style", ContextValues.Title, StructureValues.Undefined, FunctionValues.Prose, false);
			m_scrInMemoryCache.AddScrStyle("Poetry", ContextValues.Text, StructureValues.Body, FunctionValues.Prose, false);
			m_scrInMemoryCache.AddScrStyle("Parallel Passage", ContextValues.Text, StructureValues.Heading, FunctionValues.Prose, false);
			m_scrInMemoryCache.AddScrStyle("Line 1", ContextValues.Text, StructureValues.Body, FunctionValues.Prose, false);

			m_stylesheet.Init(Cache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles);

			m_scrInMemoryCache.AddBookWithTwoSections(40, "Matthew");
			m_philemon = m_scrInMemoryCache.AddBookWithTwoSections(57, "Philemon");
			m_scrInMemoryCache.AddBookWithTwoSections(66, "Revelation");

			m_section1 = (ScrSection)m_philemon.SectionsOS[0];
			m_scrInMemoryCache.AddSectionHeadParaToSection(m_section1.Hvo, "Matt. 4:5-9; Luke 2:6-10", "Parallel Passage");
			StTxtPara para = (StTxtPara)m_section1.ContentOA.ParagraphsOS[0];
			m_scrInMemoryCache.AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " One is the best verse. ", null);
			m_scrInMemoryCache.AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " I like two better. ", null);
			m_scrInMemoryCache.AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " No, three rocks! ", null);
			m_scrInMemoryCache.AddRunToMockedPara(para, "4-8", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " Nobody can touch four through eight. ", null);
			m_section1.AdjustReferences();

			m_section2 = (ScrSection)m_philemon.SectionsOS[1];
			para = (StTxtPara)m_section2.ContentOA.ParagraphsOS[0];
			m_scrInMemoryCache.AddRunToMockedPara(para, "10", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " Ten is the best verse. ", null);
			m_scrInMemoryCache.AddRunToMockedPara(para, "11", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " I like eleven better. ", null);
			m_scrInMemoryCache.AddRunToMockedPara(para, "12", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " No, twelve rocks! ", null);
			m_scrInMemoryCache.AddRunToMockedPara(para, "13", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " Nobody can touch thirteen. ", null);
			para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_section2.Hvo, "Line 1");
			m_scrInMemoryCache.AddRunToMockedPara(para, "Second Stanza.", null);
			m_section2.AdjustReferences();

			m_section3 = m_scrInMemoryCache.AddSectionToMockedBook(m_philemon.Hvo);
			m_scrInMemoryCache.AddSectionHeadParaToSection(m_section3.Hvo, "Heading for section 3",
				ScrStyleNames.SectionHead);
			para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_section3.Hvo, "Poetry");
			m_scrInMemoryCache.AddRunToMockedPara(para, "24", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " Hi, I'm verse 24.", null);
			para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_section3.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para, "25", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " Welcome to the twenty-fifth verse. ", null);
			m_scrInMemoryCache.AddRunToMockedPara(para, "26", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " Welcome to the twenty-sixth verse.", null);
			para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_section3.Hvo, "Line 1");
			m_scrInMemoryCache.AddRunToMockedPara(para, "27", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(para, " This is the end.", null);
			m_section3.AdjustReferences();
		}
Esempio n. 43
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets up a range selection
		/// </summary>
		/// <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(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)
		{
			CheckDisposed();

			SetupRangeSelection(-1, -1, bookStart, iBookStart, sectionStart, iSecStart,
				paraStart, iParaStart, ichStart, setupForHeadingStart, bookEnd, iBookEnd,
				sectionEnd, iSecEnd, paraEnd, iParaEnd, ichEnd, setupForHeadingEnd);
		}
Esempio n. 44
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get the chapter verse bridge for a given section, formatted appropriately for the UI
		/// writing system
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public string ChapterVerseBridgeAsString(IScrSection section)
		{
			if (section.IsIntro)
			{
				return String.Format(Strings.ksScriptureSectionIntroduction, section.OwnOrd);
			}
			ScrReference startRef = new ScrReference(section.VerseRefStart, Versification);
			ScrReference endRef = new ScrReference(section.VerseRefEnd, Versification);
			if (startRef.Chapter != endRef.Chapter)
			{
				return MakeBridgeAsString(ChapterVerseRefAsString(startRef, m_cache.DefaultUserWs),
					ChapterVerseRefAsString(endRef, m_cache.DefaultUserWs), m_cache.DefaultUserWs);
			}
			return ChapterVerseBridgeAsString(startRef, endRef, m_cache.DefaultUserWs);
		}
Esempio n. 45
0
        /// <summary>
        /// This is invoked when TE (or some other program) invokes a link, typically to a Scripture Section text not in our filter.
        /// If possible, add it to the filter and return true. Also add any other sections in the same chapter.
        /// Also when jumping from Notebook to a text that is excluded.
        /// Todo JohnT: get it called from TE and test it; not currently used by TE (ported from parts of old InterlinearTextsVirtualHandler)
        /// </summary>
        public bool AddChapterToInterestingTexts(IStText newText)
        {
            int oldCount       = m_scriptureTexts.Count;
            int targetPosition = TextPosition(newText);

            if (targetPosition < 0)
            {
                var excludedCoreTextIdList = ExcludedCoreTextIdList();
                if (newText.Owner is IText && excludedCoreTextIdList.Contains(newText.Guid))
                {
                    CoreTexts.Add(newText);
                    if (m_interestingTests != null)
                    {
                        m_interestingTests.Add(newText);
                    }
                    excludedCoreTextIdList.Remove(newText.Guid);
                    UpdateExcludedCoreTexts(excludedCoreTextIdList);
                    RaiseInterestingTextsChanged(CoreTexts.Count - 1, 1, 0);
                    return(true);             // added sucessfully
                }
                return(false);                // not a text in current Scripture.
            }
            int index;

            for (index = 0; index < m_scriptureTexts.Count; index++)
            {
                if (TextPosition(m_scriptureTexts[index]) > targetPosition)
                {
                    break;
                }
            }
            m_scriptureTexts.Insert(index, newText);
            // Also insert the other text in the same section
            var sec = newText.Owner as IScrSection;

            if (sec != null)             // not a book title
            {
                if (newText == sec.ContentOA && sec.HeadingOA != null)
                {
                    if (index == 0 || m_scriptureTexts[index - 1] != sec.HeadingOA)
                    {
                        m_scriptureTexts.Insert(index, sec.HeadingOA);
                    }
                    else
                    {
                        index--;                         // move index to point at heading
                    }
                }
                else if (sec.ContentOA != null)
                {
                    if (index >= m_scriptureTexts.Count - 1 || m_scriptureTexts[index + 1] != sec.ContentOA)
                    {
                        m_scriptureTexts.Insert(index + 1, sec.ContentOA);
                    }
                }
                // At this point the heading and contents of the section for the inserted text
                // are at index. We look for adjacent sections in the same chapter and if necessary
                // add them too.
                int indexAfter = index + 1;
                if (sec.ContentOA != null && sec.HeadingOA != null)
                {
                    indexAfter++;
                }
                // It would be nicer to use ScrReference, but not worth adding a whole project reference.
                int chapMax = sec.VerseRefMax / 1000;
                int chapMin = sec.VerseRefMin / 1000;
                var book    = (IScrBook)sec.Owner;
                int csec    = book.SectionsOS.Count;
                int isecCur = sec.IndexInOwner;
                for (int isec = isecCur + 1; isec < csec; isec++)
                {
                    IScrSection secNext = book.SectionsOS[isec];
                    if (secNext.VerseRefMin / 1000 != chapMax)
                    {
                        break;                         // different chapter.
                    }
                    indexAfter = AddAfter(indexAfter, secNext.HeadingOA);
                    indexAfter = AddAfter(indexAfter, secNext.ContentOA);
                }
                for (int isec = isecCur - 1; isec >= 0; isec--)
                {
                    IScrSection secPrev = book.SectionsOS[isec];
                    if (secPrev.VerseRefMax / 1000 != chapMin)
                    {
                        break;
                    }
                    index = AddBefore(index, secPrev.ContentOA);
                    index = AddBefore(index, secPrev.HeadingOA);
                }
            }
            // We could get fancy and try to figure the exact range that changed, but this is close enough.
            RaiseInterestingTextsChanged(CoreTexts.Count, m_scriptureTexts.Count, oldCount);
            return(true);
        }