/// ------------------------------------------------------------------------------------ /// <summary> /// Creates an empty paragraph with the given paragraph style and writing system. /// </summary> /// <param name="cache"></param> /// <param name="ownerHvo"></param> /// <param name="paraStyle"></param> /// <param name="ws"></param> /// ------------------------------------------------------------------------------------ public static void CreateEmptyPara(FdoCache cache, int ownerHvo, string paraStyle, int ws) { using (StTxtParaBldr bldr = new StTxtParaBldr(cache)) { bldr.ParaProps = StyleUtils.ParaStyleTextProps(paraStyle); bldr.AppendRun(String.Empty, StyleUtils.CharStyleTextProps(null, ws)); bldr.CreateParagraph(ownerHvo); } // Dispose() frees ICU resources. }
/// ------------------------------------------------------------------------------------ /// <summary> /// Use this method to move the adjacent part of one StText to the adjacent position /// in another. /// </summary> /// <param name="fromText">StText from which the contents is moved</param> /// <param name="toText">StText to which the contents is moved</param> /// <param name="divIndex">Index of last partial paragraph to be moved or the first /// whole paragraph not moved</param> /// <param name="ichDiv">character offset of last character to be moved or zero if /// none are to be moved</param> /// <param name="toIsPreceding">Should equal true if the toText preceeds the fromText. /// If true, the moved text will be appended to the toText. /// If false, they will be placed at the beginning of the toText.</param> /// ------------------------------------------------------------------------------------ public static void MovePartialContents(IStText fromText, IStText toText, int divIndex, int ichDiv, bool toIsPreceding) { int iLastFromPara = fromText.ParagraphsOS.Count - 1; Debug.Assert((divIndex >= 0) && (divIndex <= iLastFromPara)); // Set up parameters for whole paragraph movement based on direction of movement int iStartAt, iEndAt, iInsertAt, iReferenceEdge; if (toIsPreceding) { //From beginning to para preceding IP, appended iStartAt = 0; iEndAt = divIndex - 1; iInsertAt = toText.ParagraphsOS.Count; iReferenceEdge = 0; } else { //From para following IP to the end, pre-pended iStartAt = (ichDiv > 0) ? divIndex + 1 : divIndex; iEndAt = iLastFromPara; iInsertAt = 0; iReferenceEdge = iLastFromPara; } // Move the whole paragraphs of fromText to empty toText if (divIndex != iReferenceEdge || (ichDiv == 0 && !toIsPreceding)) { MoveWholeParas(fromText, iStartAt, iEndAt, toText, iInsertAt); } // Move partial paragraph (now in the edge paragraph of the fromText) // to a new paragraph in the toText if (ichDiv > 0 || toIsPreceding) { DivideParaContents(fromText, ichDiv, toText, toIsPreceding); } if (fromText.ParagraphsOS.Count == 0) { // We moved all of the paragraphs out of the existing section so we need to // create a new paragraph so the user can enter text StTxtPara newSectionFirstPara = (StTxtPara)toText.ParagraphsOS[0]; using (StTxtParaBldr bldr = new StTxtParaBldr(fromText.Cache)) { bldr.ParaProps = newSectionFirstPara.StyleRules; bldr.AppendRun(string.Empty, StyleUtils.CharStyleTextProps(null, fromText.Cache.DefaultVernWs)); bldr.CreateParagraph(fromText.Hvo); } } }
public void GoToScrScriptureNoteRef_OrigParaEmpty() { CheckDisposed(); ScrBook exodus = (ScrBook)ScrBook.FindBookByID(m_scr, 2); StTxtPara para = (StTxtPara)exodus[1].ContentOA.ParagraphsOS[1]; int ichStartExpected = para.Contents.Text.IndexOf("three"); Assert.IsTrue(ichStartExpected > 0, "Unexpected data in paragraph"); StTxtParaBldr bldrQuote = new StTxtParaBldr(Cache); ITsPropsFactory fact = TsPropsFactoryClass.Create(); bldrQuote.ParaProps = fact.MakeProps(ScrStyleNames.Remark, 0, 0); bldrQuote.AppendRun("three", fact.MakeProps(null, Cache.DefaultVernWs, 0)); ScrScriptureNote note = new ScrScriptureNote(); m_scr.BookAnnotationsOS[0].NotesOS.Append(note); note.InitializeNote(LangProject.kguidAnnConsultantNote, 2001003, 2001003, para, para, -1, 0 ,0, bldrQuote, null, null, null); note.BeginOffset = ichStartExpected; note.EndOffset = ichStartExpected + 5; ITsStrBldr bldr = para.Contents.UnderlyingTsString.GetBldr(); bldr.ReplaceRgch(0, para.Contents.Length, string.Empty, 0, null); // We want to prevent data validation so that we can set up an empty paragraph. Cache.PropChangedHandling = PropChangedHandling.SuppressChangeWatcher; para.Contents.UnderlyingTsString = bldr.GetString(); Assert.AreEqual(0, para.Contents.Length, "Contents of paragraph 3 should have been deleted."); // Initial offsets are irrelevant since the original paragraph is empty. note.BeginOffset = 7; note.EndOffset = 12; TeEditingHelper helper = m_draftView.TeEditingHelper; helper.GoToScrScriptureNoteRef(note); // Confirm that a selection is made close to the empty paragraph with the deleted verse. Assert.IsFalse(helper.EditedRootBox.Selection.IsRange); Assert.AreEqual(2001002, helper.CurrentStartRef.BBCCCVVV); }
public void AdjustAnnotationReferences_WithQuote() { IScrBook genesis = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_scrInMemoryCache.AddTitleToMockedBook(genesis.Hvo, "Genesis"); // Introduction section IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(genesis.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Introduction head", ScrStyleNames.IntroSectionHead); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.IntroParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "An intro to Genesis", null); para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.IntroParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "Contains quoted text - the quote", null); section.AdjustReferences(true); ScrBookAnnotations annotations = (ScrBookAnnotations)m_scr.BookAnnotationsOS[0]; BCVRef ref1 = new BCVRef(1, 1, 0); int iPos; StTxtParaBldr quoteBldr = new StTxtParaBldr(m_scrInMemoryCache.Cache); quoteBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark); quoteBldr.AppendRun("the quote", StyleUtils.CharStyleTextProps(null, m_scrInMemoryCache.Cache.DefaultVernWs)); IScrScriptureNote note = annotations.InsertNote(ref1, ref1, null, null, LangProject.kguidAnnConsultantNote, -1, 0, 0, quoteBldr, null, null, null, out iPos); Assert.IsNotNull(note); m_scr.AdjustAnnotationReferences(); Assert.AreEqual(para.Hvo, note.BeginObjectRA.Hvo); Assert.AreEqual(23, note.BeginOffset); Assert.AreEqual(32, note.EndOffset); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Use this method to move the adjacent part of one StText to the adjacent position /// in another. /// </summary> /// <param name="fromText">StText from which the contents is moved</param> /// <param name="toText">StText to which the contents is moved</param> /// <param name="divIndex">Index of last partial paragraph to be moved or the first /// whole paragraph not moved</param> /// <param name="ichDiv">character offset of last character to be moved or zero if /// none are to be moved</param> /// <param name="toIsPreceding">Should equal true if the toText preceeds the fromText. /// If true, the moved text will be appended to the toText. /// If false, they will be placed at the beginning of the toText.</param> /// ------------------------------------------------------------------------------------ public static void MovePartialContents(IStText fromText, IStText toText, int divIndex, int ichDiv, bool toIsPreceding) { int iLastFromPara = fromText.ParagraphsOS.Count - 1; Debug.Assert((divIndex >= 0) && (divIndex <= iLastFromPara)); // Set up parameters for whole paragraph movement based on direction of movement int iStartAt, iEndAt, iInsertAt, iReferenceEdge; if (toIsPreceding) { //From beginning to para preceding IP, appended iStartAt = 0; iEndAt = divIndex - 1; iInsertAt = toText.ParagraphsOS.Count; iReferenceEdge = 0; } else { //From para following IP to the end, pre-pended iStartAt = (ichDiv > 0) ? divIndex + 1 : divIndex; iEndAt = iLastFromPara; iInsertAt = 0; iReferenceEdge = iLastFromPara; } // Move the whole paragraphs of fromText to empty toText if (divIndex != iReferenceEdge || (ichDiv == 0 && !toIsPreceding)) MoveWholeParas(fromText, iStartAt, iEndAt, toText, iInsertAt); // Move partial paragraph (now in the edge paragraph of the fromText) // to a new paragraph in the toText if (ichDiv > 0 || toIsPreceding) DivideParaContents(fromText, ichDiv, toText, toIsPreceding); if (fromText.ParagraphsOS.Count == 0) { // We moved all of the paragraphs out of the existing section so we need to // create a new paragraph so the user can enter text StTxtPara newSectionFirstPara = (StTxtPara)toText.ParagraphsOS[0]; using (StTxtParaBldr bldr = new StTxtParaBldr(fromText.Cache)) { bldr.ParaProps = newSectionFirstPara.StyleRules; bldr.AppendRun(string.Empty, StyleUtils.CharStyleTextProps(null, fromText.Cache.DefaultVernWs)); bldr.CreateParagraph(fromText.Hvo); } } }
/// ----------------------------------------------------------------------------------- /// <summary> /// If user presses Enter and a new style is applied to the following paragraph, we /// need to mark that style as being in use. If in a section Head, we might need to fix /// the structure. /// </summary> /// <param name="fCalledFromKeyDown">True if this method gets called from OnKeyDown</param> /// <param name="stuInput">input string</param> /// <param name="cchBackspace">number of backspace characters in stuInput</param> /// <param name="cchDelForward">number of delete characters in stuInput</param> /// <param name="ss">Status of Shift/Control/Alt key</param> /// <param name="graphics">graphics for processing input</param> /// <param name="modifiers">key modifiers - shift status, etc.</param> /// <remarks>I (EberhardB) added the parameter <paramref name="fCalledFromKeyDown"/> /// to be able to distinguish between Ctrl-Delete and Ctrl-Backspace.</remarks> /// ----------------------------------------------------------------------------------- protected void HandleEnterKey(bool fCalledFromKeyDown, string stuInput, int cchBackspace, int cchDelForward, VwShiftStatus ss, IVwGraphics graphics, Keys modifiers) { if (IsPictureSelected) // Enter should do nothing if a picture or caption is selected. return; SelLevInfo[] levInfo; // If we are at the end of a heading paragraph, we need to check the "next" style to // see if it is a body type. If it is not, then allow processing to proceed as normal. // If it is a body type, then don't create a new paragraph, just move down to the start // of the first body paragraph in the section. if (InSectionHead) { // if the selection is a range selection then try to delete the selected text first. if (CurrentSelection.Selection.IsRange) { ITsStrFactory factory = TsStrFactoryClass.Create(); CurrentSelection.Selection.ReplaceWithTsString( factory.MakeString("", m_cache.DefaultVernWs)); // If selection is still a range selection, the deletion failed and we don't // need to do anything else. if (CurrentSelection.Selection.IsRange || !InSectionHead) return; } // If the heading style has a following style that is a body style and we are at the // end of the paragraph then move the IP to the beginning of the body paragraph. levInfo = CurrentSelection.GetLevelInfo(SelectionHelper.SelLimitType.Anchor); // This is the paragraph that was originally selected ScrTxtPara headPara = new ScrTxtPara(m_cache, levInfo[0].hvo); IStStyle headParaStyle = m_scr.FindStyle(headPara.StyleName); IStStyle followStyle = headParaStyle != null ? headParaStyle.NextRA : null; if (followStyle != null && followStyle.Structure == StructureValues.Body && SelectionAtEndParagraph()) { // if there is another section head paragraph, then the section needs to be split ScrSection section = new ScrSection(m_cache, ((ITeView)Control).LocationTracker.GetSectionHvo(CurrentSelection, SelectionHelper.SelLimitType.Anchor)); if (CurrentSelection.LevelInfo[0].ihvo < section.HeadingOA.ParagraphsOS.Count - 1) { // Setting the style rules destroys the selection, so we have to remember // the current location before we change the style rules. int iBook = BookIndex; int iSection = SectionIndex; // break the section // create a new empty paragraph in the first section // set the IP to the start of the new paragraph CreateSection(BCVRef.GetVerseFromBcv(section.VerseRefMin) == 0); Debug.Assert(CurrentSelection != null && CurrentSelection.IsValid, "Creating the section didn't set a selection"); StTxtPara contentPara = new StTxtPara(m_cache, CurrentSelection.LevelInfo[0].hvo); contentPara.StyleRules = StyleUtils.ParaStyleTextProps(followStyle.Name); SetInsertionPoint(iBook, iSection, 0, 0, false); } else { SetInsertionPoint(BookIndex, SectionIndex, 0, 0, false); // If the first paragraph is not empty, then insert a new paragraph with the // follow-on style of the section head. StTxtPara contentPara = new StTxtPara(m_cache, CurrentSelection.LevelInfo[0].hvo); if (contentPara.Contents.Length > 0) { StTxtParaBldr bldr = new StTxtParaBldr(m_cache); bldr.ParaProps = StyleUtils.ParaStyleTextProps(followStyle.Name); bldr.AppendRun(String.Empty, StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs)); bldr.CreateParagraph(contentPara.OwnerHVO, 0); SetInsertionPoint(BookIndex, SectionIndex, 0, 0, false); } } return; } } // Call the base to handle the key base.OnCharAux('\r', fCalledFromKeyDown, stuInput, cchBackspace, cchDelForward, ss, graphics, modifiers); try { levInfo = CurrentSelection.GetLevelInfo(SelectionHelper.SelLimitType.Anchor); ScrTxtPara para = new ScrTxtPara(m_cache, levInfo[0].hvo); IStStyle style = m_scr.FindStyle(para.StyleName); if (style != null) style.InUse = true; } catch { // Oh, well. We tried. } }
public void ContentMultipleParasToSectionHead() { CheckDisposed(); // create a book IScrBook book = CreateGenesis(); // Create a section IScrSection sectionCur = CreateSection(book, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("In the beginning, God created the heavens and the earth. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // create paragraph that will be changed to a section heading paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("My other aching head!", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // create paragraph that will be changed to a section heading paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("My third aching head!", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // create paragraph three holding chapter 2 paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Thus the heavens and the earth were completed in all their vast array. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); Assert.AreEqual(4, sectionCur.ContentOA.ParagraphsOS.Count); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); // Create a range selection from paragraph 1 to paragraph 2. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 0; //section with 1:1 to 2:1 int iParaIP = 1; int ichIP = 0; m_draftView.SetInsertionPoint(iBook, iSectionIP, iParaIP, ichIP, true); IVwSelection sel0 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel0); m_draftView.SetInsertionPoint(iBook, iSectionIP, iParaIP + 1, ichIP, true); IVwSelection sel1 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel1); IVwSelection sel = m_draftView.RootBox.MakeRangeSelection(sel0, sel1, true); Assert.IsNotNull(sel); // InsertSection should add a scripture section m_draftView.ApplyStyle(ScrStyleNames.SectionHead); Assert.AreEqual(2, book.SectionsOS.Count, "Should add a section"); // setup variables for testing IScrSection existingSection = book.SectionsOS[iSectionIP]; int iSectionIns = iSectionIP + 1; IScrSection createdSection = book.SectionsOS[iSectionIns]; // Verify verse start and end refs Assert.AreEqual(1001001, existingSection.VerseRefMin, "Existing section should have same verse start ref"); Assert.AreEqual(1001001, existingSection.VerseRefMax, "Existing section should have new verse end ref"); Assert.AreEqual(1002001, createdSection.VerseRefMin, "New section should have correct verse start ref"); Assert.AreEqual(1002001, createdSection.VerseRefMax, "New section should have correct verse end ref"); // Verify section head Assert.AreEqual(2, createdSection.HeadingOA.ParagraphsOS.Count); Assert.AreEqual("My other aching head!", ((StTxtPara)createdSection.HeadingOA.ParagraphsOS[0]).Contents.Text); Assert.AreEqual("My third aching head!", ((StTxtPara)createdSection.HeadingOA.ParagraphsOS[1]).Contents.Text); Assert.AreEqual(1, createdSection.ContentOA.ParagraphsOS.Count); // Verify that selection is in heading of the new section Assert.IsTrue(m_draftView.TeEditingHelper.InSectionHead, "Should be in section heading"); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(iSectionIns, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); // Check that end is in second paragraph of heading SelectionHelper helper = SelectionHelper.Create(m_draftView); SelLevInfo[] endInfo = helper.GetLevelInfo(SelectionHelper.SelLimitType.End); Assert.AreEqual(4, endInfo.Length); Assert.AreEqual(iSectionIns, endInfo[2].ihvo); Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidHeading, endInfo[1].tag); Assert.AreEqual(1, endInfo[0].ihvo); }
public void SectionHeadFirstParaToParagraph() { CheckDisposed(); // create a book IScrBook book = CreateGenesis(); // Create section 1 IScrSection sectionCur = CreateSection(book, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("In the beginning, God created the heavens and the earth. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); sectionCur.AdjustReferences(); // create section 2 sectionCur = CreateSection(book, "My other aching head!", "Second paragraph of heading"); // create paragraph holding chapter 2 paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Thus the heavens and the earth were completed in all their vast array. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); // Set the IP in the 2nd section. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 1; //section with 2:1 // Make a range selection that covers both paragraphs of section heading m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, iBook, iSectionIP); // ApplyStyle should move paragraph from heading, but not change number // of sections. Assert.AreEqual(2, book.SectionsOS.Count, "Two sections before ApplyStyle"); m_draftView.ApplyStyle(ScrStyleNames.NormalParagraph); Assert.AreEqual(2, book.SectionsOS.Count, "Two sections after ApplyStyle"); // setup variables for testing IScrSection section1 = book.SectionsOS[0]; IScrSection section2 = book.SectionsOS[1]; // Verify section paragraphs Assert.AreEqual(1, section1.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(2, section1.ContentOA.ParagraphsOS.Count); StTxtPara para = (StTxtPara)section1.ContentOA.ParagraphsOS[1]; Assert.AreEqual("My other aching head!", para.Contents.Text); Assert.AreEqual(ScrStyleNames.NormalParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section2.HeadingOA.ParagraphsOS[0]; Assert.AreEqual("Second paragraph of heading", para.Contents.Text); Assert.AreEqual(ScrStyleNames.SectionHead, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); Assert.AreEqual(1, section2.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(1, section2.ContentOA.ParagraphsOS.Count); // Verify that selection is in paragraph that was the heading of the // second section Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(0, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(1, m_draftView.ParagraphIndex); }
public void ParagraphFollowTest_EnterWithBigRangeSelection() { CheckDisposed(); // Create a section string sectionHead = "Apples and Oranges"; IScrSection sectionCur = CreateSection(m_genesis, sectionHead); // create a paragraph StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); string bodyText = "A complex dissertation on the sections of fruit."; paraBldr.AppendRun(bodyText, StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); // make a selection that goes from the beginning of the section head into the text // of the first paragraph. m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); IVwSelection sel1 = m_draftView.TeEditingHelper.CurrentSelection.Selection; m_draftView.SetInsertionPoint(m_genesis.OwnOrd, 0, 0, 5, true); IVwSelection sel2 = m_draftView.TeEditingHelper.CurrentSelection.Selection; IVwSelection sel = m_draftView.RootBox.MakeRangeSelection(sel1, sel2, true); // Set the style follow property to a paragraph style. IStStyle styleHead = m_scr.FindStyle(ScrStyleNames.SectionHead); IStStyle stylePara = m_scr.FindStyle(ScrStyleNames.NormalParagraph); styleHead.NextRA = stylePara; // send an Enter key m_draftView.TeEditingHelper.OnKeyPress(new KeyPressEventArgs('\r'), Keys.None, null); // Make sure that the nothing changed. Assert.AreEqual(1, m_genesis.SectionsOS.Count); Assert.AreEqual(1, sectionCur.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(1, sectionCur.ContentOA.ParagraphsOS.Count); sel = m_draftView.TeEditingHelper.CurrentSelection.Selection; Assert.IsTrue(sel.IsRange); }
public void ParagraphFollowTest_EnterBetweenSectionHeadParas() { CheckDisposed(); // Create a section string sectionHead = "Apples and Oranges"; IScrSection sectionCur = CreateSection(m_genesis, sectionHead); // Add a second paragraph to the section head StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead); paraBldr.AppendRun("Peaches and Bananas", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.HeadingOAHvo); // create a paragraph paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); string bodyText = "A complex dissertation on the sections of fruit."; paraBldr.AppendRun(bodyText, StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); SelectionHelper selHelper = m_draftView.EditingHelper.CurrentSelection; selHelper.IchAnchor = sectionHead.Length; selHelper.IchEnd = sectionHead.Length; Assert.IsTrue(selHelper.SetSelection(true) != null); // Set the style follow property to a paragraph style. IStStyle styleHead = m_scr.FindStyle(ScrStyleNames.SectionHead); IStStyle stylePara = m_scr.FindStyle("Line1"); styleHead.NextRA = stylePara; // send an Enter key m_draftView.TeEditingHelper.OnKeyPress(new KeyPressEventArgs('\r'), Keys.None, null); // Make sure that the book has two sections each with one paragraph. The first section // will have a new empty paragraph and the second section will have the old paragraph // contents. The IP is in the first body paragraph of the first section. Assert.AreEqual(2, m_genesis.SectionsOS.Count); IScrSection section1 = m_genesis.SectionsOS[0]; Assert.AreEqual(1, section1.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(1, section1.ContentOA.ParagraphsOS.Count); // Make sure the first paragraph is empty and that it has the correct follow on style IStTxtPara firstPara = (IStTxtPara)section1.ContentOA.ParagraphsOS[0]; Assert.AreEqual(0, firstPara.Contents.Length); Assert.AreEqual(stylePara.Name, firstPara.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); // get the second section and check that it has one paragraph and that it has the same content IScrSection section2 = m_genesis.SectionsOS[1]; Assert.AreEqual(1, section2.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(1, section2.ContentOA.ParagraphsOS.Count); // Make sure the first paragraph is empty and that it has the correct follow on style IStTxtPara firstPara2 = (IStTxtPara)section2.ContentOA.ParagraphsOS[0]; Assert.AreEqual(bodyText, firstPara2.Contents.Text); // Verify that selection is in first content paragraph of first section selHelper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(4, selHelper.NumberOfLevels); Assert.AreEqual(0, selHelper.LevelInfo[2].ihvo); Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); Assert.AreEqual(0, selHelper.LevelInfo[0].ihvo); }
public void InsertSection_InMidSectionAtBeginningOfChapter() { CheckDisposed(); // Create a section IScrSection sectionCur = CreateSection(m_genesis, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("In the beginning, God created the heavens and the earth. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // create paragraph two holding chapter 2 paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Thus the heavens and the earth were completed in all their vast array. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); int iBook = 0; // assume that iBook 0 is Genesis // Set the IP at the beginning of the 2nd paragraph in the 1st section. int iSectionIP = 0; //section with 1:1 to 2:1 int iParaIP = 1; IStText text = m_genesis.SectionsOS[iSectionIP].ContentOA; IStTxtPara paraBeforeSectBreak = (IStTxtPara)text.ParagraphsOS[iParaIP - 1]; int ichIP = 0; int cExpectedParagraphsInNewSection = text.ParagraphsOS.Count - iParaIP; // Set the para props to something funky, to provide a better test paraBeforeSectBreak.StyleRules = StyleUtils.ParaStyleTextProps("Line1"); // Save details we will test against ITsTextProps paraRulesOrig = paraBeforeSectBreak.StyleRules; ITsString tssParaOrig = paraBeforeSectBreak.Contents.UnderlyingTsString; ITsTextProps paraRulesFirstNew = ((StTxtPara)text.ParagraphsOS[iParaIP]).StyleRules; ITsString tssFirstNewPara = ((StTxtPara)text.ParagraphsOS[iParaIP]).Contents.UnderlyingTsString; // Put the IP in place m_draftView.SetInsertionPoint(iBook, iSectionIP, iParaIP, ichIP, true); // InsertSection should add a scripture section int nSectionsExpected = m_genesis.SectionsOS.Count + 1; m_draftView.TeEditingHelper.CreateSection(false); Assert.AreEqual(nSectionsExpected, m_genesis.SectionsOS.Count, "Should add a section"); // setup variables for testing IScrSection existingSection = m_genesis.SectionsOS[iSectionIP]; int iSectionIns = iSectionIP + 1; IScrSection createdSection = m_genesis.SectionsOS[iSectionIns]; // Verify verse start and end refs Assert.AreEqual(1001001, existingSection.VerseRefMin, "Existing section should have same verse start ref"); Assert.AreEqual(1001001, existingSection.VerseRefMax, "Existing section should have new verse end ref"); Assert.AreEqual(1002001, createdSection.VerseRefMin, "New section should have correct verse start ref"); Assert.AreEqual(1002001, createdSection.VerseRefMax, "New section should have correct verse end ref"); // Verify number of paragraphs in each section Assert.AreEqual(iParaIP, existingSection.ContentOA.ParagraphsOS.Count); Assert.AreEqual(cExpectedParagraphsInNewSection, createdSection.ContentOA.ParagraphsOS.Count); }
public void ParagraphFollowTest_EnterAtSectionHeadEnd_NonEmptyPara() { CheckDisposed(); // Create a section string sectionHead = "Apples and Oranges"; IScrSection sectionCur = CreateSection(m_genesis, sectionHead); // create an empty paragraph StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("A dissertation on the sections of fruit.", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); SelectionHelper selHelper = m_draftView.EditingHelper.CurrentSelection; selHelper.IchAnchor = sectionHead.Length; selHelper.SetSelection(true); // Set the style follow property to a paragraph style. IStStyle styleHead = m_scr.FindStyle(ScrStyleNames.SectionHead); IStStyle stylePara = m_scr.FindStyle("Line1"); styleHead.NextRA = stylePara; // send an Enter key m_draftView.TeEditingHelper.OnKeyPress(new KeyPressEventArgs('\r'), Keys.None, null); // Make sure that the book has one section with two body paragraphs and // that the IP is in the first body paragraph Assert.AreEqual(1, m_genesis.SectionsOS.Count); Assert.AreEqual(1, sectionCur.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(2, sectionCur.ContentOA.ParagraphsOS.Count); selHelper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(4, selHelper.NumberOfLevels); Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); Assert.AreEqual(0, selHelper.LevelInfo[0].ihvo); // Make sure the first paragraph is empty and that it has the correct follow on style IStTxtPara firstPara = (IStTxtPara)sectionCur.ContentOA.ParagraphsOS[0]; Assert.AreEqual(0, firstPara.Contents.Length); Assert.AreEqual(stylePara.Name, firstPara.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); }
public void MoveNext_SpacesInVerses() { CheckDisposed(); ScrSection sectionCur = new ScrSection(); m_genesis.SectionsOS.Append(sectionCur); // Create a section head for this section sectionCur.HeadingOA = new StText(); StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead); paraBldr.AppendRun("My aching head!", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.HeadingOAHvo); sectionCur.ContentOA = new StText(); paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(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)); StTxtPara para = paraBldr.CreateParagraph(sectionCur.ContentOA.Hvo); sectionCur.AdjustReferences(); ScrTxtPara stPara = new ScrTxtPara(Cache, para.Hvo); ScrVerseSet verseSet = new ScrVerseSet(stPara); // Iterate through the verses in the paragraph ScrVerse verse; Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("1", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("Verse One. ", verse.Text.Text); Assert.AreEqual(01001001, verse.StartRef); Assert.AreEqual(01001001, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)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 = (ScrVerse)verseSet.Current; Assert.AreEqual("3Verse Three.", verse.Text.Text); Assert.AreEqual(01001003, verse.StartRef); Assert.AreEqual(01001003, verse.EndRef); Assert.IsTrue(verseSet.MoveNext()); verse = (ScrVerse)verseSet.Current; Assert.AreEqual("4 ", verse.Text.Text); Assert.AreEqual(01001004, verse.StartRef); Assert.AreEqual(01001004, verse.EndRef); Assert.IsFalse(verseSet.MoveNext()); }
public void GoToScrScriptureNoteRef_VerseDeleted() { CheckDisposed(); IScrBook exodus = ScrBook.FindBookByID(m_scr, 2); StTxtPara para = (StTxtPara)exodus.SectionsOS[1].ContentOA.ParagraphsOS[0]; int ichStartOrig = para.Contents.Text.IndexOf("two"); StTxtParaBldr bldrQuote = new StTxtParaBldr(Cache); ITsPropsFactory fact = TsPropsFactoryClass.Create(); bldrQuote.ParaProps = fact.MakeProps(ScrStyleNames.Remark, 0, 0); bldrQuote.AppendRun("two", fact.MakeProps(null, Cache.DefaultVernWs, 0)); ScrScriptureNote note = new ScrScriptureNote(); m_scr.BookAnnotationsOS[0].NotesOS.Append(note); note.InitializeNote(LangProject.kguidAnnConsultantNote, 2001002, 2001002, para, para, -1, 0 ,0, bldrQuote, null, null, null); note.BeginOffset = ichStartOrig; note.EndOffset = ichStartOrig + 3; // Now we delete verse two from that paragraph. int ichStartOfVerse2 = para.Contents.Text.IndexOf("2"); ITsStrBldr bldr = para.Contents.UnderlyingTsString.GetBldr(); bldr.Replace(ichStartOfVerse2, para.Contents.Length, string.Empty, null); para.Contents.UnderlyingTsString = bldr.GetString(); TeEditingHelper helper = m_draftView.TeEditingHelper; helper.GoToScrScriptureNoteRef(note); // Confirm that the selection is at the start of the verse 3. Assert.IsFalse(helper.EditedRootBox.Selection.IsRange); ITsString tss; int ichStart; bool assocPrev; int hvoSel, tag, ws; helper.EditedRootBox.Selection.TextSelInfo(false, out tss, out ichStart, out assocPrev, out hvoSel, out tag, out ws); Assert.AreEqual(2, ichStart, "IP should be after verse number one and chapter number one."); Assert.AreEqual(2001001, helper.CurrentStartRef.BBCCCVVV); }
public void GoToScrScriptureNoteRef_TextExistethNot() { CheckDisposed(); IScrBook exodus = ScrBook.FindBookByID(m_scr, 2); StTxtPara para = (StTxtPara)exodus.SectionsOS[1].ContentOA.ParagraphsOS[0]; Assert.IsFalse(para.Contents.Text.Contains("sixty-three"), "Unexpected data in paragraph"); StTxtParaBldr bldrQuote = new StTxtParaBldr(Cache); ITsPropsFactory fact = TsPropsFactoryClass.Create(); bldrQuote.ParaProps = fact.MakeProps(ScrStyleNames.Remark, 0, 0); // Set text to something that does not exist in the verse to simiulate subsequent deletion. bldrQuote.AppendRun("sixty-three", fact.MakeProps(null, Cache.DefaultVernWs, 0)); ScrScriptureNote note = new ScrScriptureNote(); m_scr.BookAnnotationsOS[0].NotesOS.Append(note); note.InitializeNote(LangProject.kguidAnnConsultantNote, 2001001, 2001001, para, para, -1, 0 ,0, bldrQuote, null, null, null); note.BeginOffset = 100; note.EndOffset = 111; TeEditingHelper helper = m_draftView.TeEditingHelper; helper.GoToScrScriptureNoteRef(note); // Confirm that the selection is at the start of the verse. Assert.IsFalse(helper.EditedRootBox.Selection.IsRange); ITsString tss; int ichStart; bool assocPrev; int hvoSel, tag, ws; helper.EditedRootBox.Selection.TextSelInfo(false, out tss, out ichStart, out assocPrev, out hvoSel, out tag, out ws); Assert.AreEqual(2, ichStart, "IP should be at start of verse, following chapter number and verse number."); Assert.AreEqual(2001001, helper.CurrentStartRef.BBCCCVVV); }
public void ContentAllParasOfLastSectionToSectionHead() { CheckDisposed(); ITsTextProps textRunProps = StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs); ITsTextProps chapterRunProps = StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs); // create a book IScrBook book = CreateGenesis(); // Create section one IScrSection section1 = CreateSection(book, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("1", chapterRunProps); paraBldr.AppendRun("In the beginning", textRunProps); paraBldr.CreateParagraph(section1.ContentOAHvo); // create paragraph two holding text that really belongs in the section head paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("Ouch!", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section1.ContentOAHvo); Assert.AreEqual(2, section1.ContentOA.ParagraphsOS.Count); // finish the section info section1.AdjustReferences(); // Create section two IScrSection section2 = CreateSection(book, "My other aching head!"); // create paragraph three holding chapter 2 paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("Thus the heavens", textRunProps); paraBldr.CreateParagraph(section2.ContentOAHvo); paraBldr.AppendRun("were completed", textRunProps); paraBldr.CreateParagraph(section2.ContentOAHvo); Assert.AreEqual(2, section2.ContentOA.ParagraphsOS.Count); // finish the section info section2.AdjustReferences(); m_draftView.RefreshDisplay(); // Set the IP at the beginning of the 2nd paragraph in the 1st section. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 1; //section with 2:1 to 2:1 int iParaIP = 0; int ichIP = 0; // Put the IP in place m_draftView.SetInsertionPoint(iBook, iSectionIP, iParaIP, ichIP, true); IVwSelection sel0 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel0); m_draftView.SetInsertionPoint(iBook, iSectionIP, iParaIP + 1, ichIP, true); IVwSelection sel1 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel1); IVwSelection sel = m_draftView.RootBox.MakeRangeSelection(sel0, sel1, true); Assert.IsNotNull(sel); // ApplyStyle should not create a new section, but should move paragraph // from content of section one to heading of section two m_draftView.ApplyStyle(ScrStyleNames.SectionHead); Assert.AreEqual(2, book.SectionsOS.Count, "Should not be combined sections"); // Verify verse start and end refs Assert.AreEqual(1001001, section2.VerseRefMin, "Remaining section should have same verse start ref"); Assert.AreEqual(1001001, section2.VerseRefMax, "Remaining section should have correct verse end ref"); // Verify paragraph counts of section 1 Assert.AreEqual(1, section1.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(2, section1.ContentOA.ParagraphsOS.Count); // Verify section head of section 2 Assert.AreEqual(3, section2.HeadingOA.ParagraphsOS.Count); Assert.AreEqual("My other aching head!", ((StTxtPara)section2.HeadingOA.ParagraphsOS[0]).Contents.Text); ITsTextProps ttp = ((StTxtPara)section2.HeadingOA.ParagraphsOS[0]).StyleRules; Assert.AreEqual(ScrStyleNames.SectionHead, ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); Assert.AreEqual("Thus the heavens", ((StTxtPara)section2.HeadingOA.ParagraphsOS[1]).Contents.Text); ttp = ((StTxtPara)section2.HeadingOA.ParagraphsOS[1]).StyleRules; Assert.AreEqual(ScrStyleNames.SectionHead, ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); Assert.AreEqual("were completed", ((StTxtPara)section2.HeadingOA.ParagraphsOS[2]).Contents.Text); Assert.AreEqual(1, section2.ContentOA.ParagraphsOS.Count); StTxtPara para = (StTxtPara)section2.ContentOA.ParagraphsOS[0]; Assert.AreEqual(0, para.Contents.Length); // Verify that selection is in second paragraph of remaining section Assert.IsTrue(m_draftView.TeEditingHelper.InSectionHead, "Should be in section heading"); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(1, m_draftView.ParagraphIndex); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Append a new section to the given book, having the specified text as the section /// head. The new section will have an empty content text created also. /// </summary> /// <param name="styleName">Style name for section</param> /// <param name="book">The book to which the section is to be appended</param> /// <param name="sSectionHead">The text of the new section head</param> /// <returns>The newly created section</returns> /// ------------------------------------------------------------------------------------ private IScrSection CreateSection(string styleName, IScrBook book, params string[] sSectionHead) { // Create a section IScrSection section = new ScrSection(); book.SectionsOS.Append(section); // Create a section head for this section section.HeadingOA = new StText(); StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); for (int i = 0; i < sSectionHead.Length; i++) { paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(styleName); paraBldr.AppendRun(sSectionHead[i], StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section.HeadingOAHvo); } section.ContentOA = new StText(); return section; }
public void ContentMidParaToSectionHead() { CheckDisposed(); // create a book IScrBook book = CreateGenesis(); // Create a section IScrSection sectionCur = CreateSection(book, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("In the beginning, God created the heavens and the earth. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // create paragraph that will be changed to a section heading paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("My other aching head!", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // create paragraph three holding chapter 2 paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Thus the heavens and the earth were completed in all their vast array. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); Assert.AreEqual(3, sectionCur.ContentOA.ParagraphsOS.Count); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); // Set the IP at the beginning of the 2nd paragraph in the 1st section. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 0; //section with 1:1 to 2:1 int iParaIP = 1; int ichIP = 0; // Put the IP in place m_draftView.SetInsertionPoint(iBook, iSectionIP, iParaIP, ichIP, true); // InsertSection should add a scripture section m_draftView.ApplyStyle(ScrStyleNames.SectionHead); Assert.AreEqual(2, book.SectionsOS.Count, "Should add a section"); // setup variables for testing IScrSection existingSection = book.SectionsOS[iSectionIP]; int iSectionIns = iSectionIP + 1; IScrSection createdSection = book.SectionsOS[iSectionIns]; // Verify verse start and end refs Assert.AreEqual(1001001, existingSection.VerseRefMin, "Existing section should have same verse start ref"); Assert.AreEqual(1001001, existingSection.VerseRefMax, "Existing section should have new verse end ref"); Assert.AreEqual(1002001, createdSection.VerseRefMin, "New section should have correct verse start ref"); Assert.AreEqual(1002001, createdSection.VerseRefMax, "New section should have correct verse end ref"); // Verify section head Assert.AreEqual("My other aching head!", ((StTxtPara)createdSection.HeadingOA.ParagraphsOS.FirstItem).Contents.Text); Assert.AreEqual(1, createdSection.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(1, createdSection.ContentOA.ParagraphsOS.Count); // Verify that selection is in heading of the new section Assert.IsTrue(m_draftView.TeEditingHelper.InSectionHead, "Should be in section heading"); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(iSectionIns, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); }
public void InsertSection_EndFirstHeadingPara() { CheckDisposed(); int nSectionsExpected = m_exodus.SectionsOS.Count; // Create second heading paragraph int iSectionIns = 1; IScrSection section = m_exodus.SectionsOS[iSectionIns]; StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead); paraBldr.AppendRun("Second Paragraph", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section.HeadingOAHvo); Assert.AreEqual(2, section.HeadingOA.ParagraphsOS.Count); // Put the IP into the heading of section 2 at end of first heading paragraph SelectionHelper selHelper = new SelectionHelper(); selHelper.NumberOfLevels = 4; selHelper.LevelInfo[0].tag = (int)StText.StTextTags.kflidParagraphs; selHelper.LevelInfo[0].ihvo = 0; selHelper.LevelInfo[1].tag = (int)ScrSection.ScrSectionTags.kflidHeading; selHelper.LevelInfo[1].ihvo = 0; selHelper.LevelInfo[2].tag = (int)ScrBook.ScrBookTags.kflidSections; selHelper.LevelInfo[2].ihvo = iSectionIns; selHelper.LevelInfo[3].tag = m_draftView.BookFilter.Tag; selHelper.LevelInfo[3].ihvo = m_exodus.OwnOrd; selHelper.IchAnchor = 9; // end of "Heading 2" int cContentParas = section.ContentOA.ParagraphsOS.Count; // Now that all the preparation to set the IP is done, set it. IVwSelection vwsel = selHelper.SetSelection(m_draftView, true, true); // InsertSection should add a section m_draftView.TeEditingHelper.CreateSection(false); nSectionsExpected++; Assert.AreEqual(nSectionsExpected, m_exodus.SectionsOS.Count, "Should add a section"); IScrSection newSection = m_exodus.SectionsOS[iSectionIns]; IScrSection oldSection = m_exodus.SectionsOS[iSectionIns + 1]; Assert.AreEqual(02001001, newSection.VerseRefMin, "Wrong start reference for new section"); Assert.AreEqual(02001001, newSection.VerseRefMax, "Wrong end reference for new section"); Assert.AreEqual(02001001, oldSection.VerseRefMin, "Wrong start reference for existing section"); Assert.AreEqual(02001005, oldSection.VerseRefMax, "Wrong end reference for existing section"); Assert.AreEqual(1, newSection.HeadingOA.ParagraphsOS.Count); Assert.AreEqual("Heading 2", ((StTxtPara)newSection.HeadingOA.ParagraphsOS.FirstItem).Contents.Text, "Wrong heading in new section"); Assert.IsNull(((StTxtPara)newSection.ContentOA.ParagraphsOS.FirstItem).Contents.Text, "Content of new section is not empty"); Assert.AreEqual(1, oldSection.HeadingOA.ParagraphsOS.Count, "Wrong number of paragraphs in old section"); Assert.AreEqual("Second Paragraph", ((StTxtPara)oldSection.HeadingOA.ParagraphsOS.FirstItem).Contents.Text, "Wrong heading in old section"); Assert.AreEqual(cContentParas, oldSection.ContentOA.ParagraphsOS.Count, "Wrong number of paragraphs in old content"); }
public void SectionHeadAllParasToParagraph() { CheckDisposed(); // create a book IScrBook book = CreateGenesis(); // Create section 1 IScrSection sectionCur = CreateSection(book, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("In the beginning, God created the heavens and the earth. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); sectionCur.AdjustReferences(); // create section 2 sectionCur = CreateSection(book, "My other aching head!", "Second paragraph of heading"); // create paragraph holding chapter 2 paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Thus the heavens and the earth were completed in all their vast array. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); // Set the IP in the 2nd section. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 1; //section with 2:1 // Make a range selection that covers both paragraphs of section heading m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, iBook, iSectionIP); SelectionHelper helper = SelectionHelper.Create(m_draftView); // adjust end point level info to point to second paragraph SelLevInfo[] levInfo = helper.GetLevelInfo(SelectionHelper.SelLimitType.End); levInfo[0].ihvo = 1; helper.SetLevelInfo(SelectionHelper.SelLimitType.End, levInfo); helper.IchEnd = 0; // needed to make selection a range selection helper.SetSelection(true); // InsertSection should add a scripture section Assert.AreEqual(2, book.SectionsOS.Count, "Two sections before ApplyStyle"); m_draftView.ApplyStyle(ScrStyleNames.NormalParagraph); Assert.AreEqual(1, book.SectionsOS.Count, "Should remove a section"); // setup variables for testing IScrSection section = book.SectionsOS[0]; // Verify verse start and end refs Assert.AreEqual(1001001, section.VerseRefMin, "Existing section should have same verse start ref"); Assert.AreEqual(1002001, section.VerseRefMax, "New section should have correct verse end ref"); // Verify section paragraphs Assert.AreEqual(1, section.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(4, section.ContentOA.ParagraphsOS.Count); StTxtPara para = (StTxtPara)section.ContentOA.ParagraphsOS[1]; Assert.AreEqual("My other aching head!", para.Contents.Text); Assert.AreEqual(ScrStyleNames.NormalParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section.ContentOA.ParagraphsOS[2]; Assert.AreEqual("Second paragraph of heading", para.Contents.Text); Assert.AreEqual(ScrStyleNames.NormalParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); // Verify that selection is in paragraph that was the heading of the // removed section Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(0, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(1, m_draftView.ParagraphIndex); }
public void SectionHeadAllIntroParasToParagraph() { CheckDisposed(); // create a book IScrBook book = CreateGenesis(); // Create section 1 IScrSection sectionCur = CreateSection(ScrStyleNames.IntroSectionHead, book, "My aching head!", "Second paragraph of heading"); // create paragraph in section content StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.IntroParagraph); paraBldr.AppendRun("This is Genesis.", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); sectionCur.AdjustReferences(); // create section 2 sectionCur = CreateSection(book, "My other aching head!"); // create paragraph in content paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Thus the heavens and the earth were completed in all their vast array. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); // Set the IP in the 2nd section. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 0; // intro section // Make a range selection in for all paragraphs of the intro section heading m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, iBook, iSectionIP); IVwSelection sel0 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel0); m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, iBook, iSectionIP, 1); IVwSelection sel1 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel1); IVwSelection sel = m_draftView.RootBox.MakeRangeSelection(sel0, sel1, true); Assert.IsNotNull(sel); // ApplyStyle should move paragraphs from heading, but not change number // of sections. Assert.AreEqual(2, book.SectionsOS.Count, "Should be two sections before ApplyStyle"); m_draftView.ApplyStyle(ScrStyleNames.IntroParagraph); Assert.AreEqual(2, book.SectionsOS.Count, "Should be two sections after ApplyStyle"); // setup variables for testing IScrSection section1 = book.SectionsOS[0]; // Verify section paragraphs Assert.AreEqual(1, section1.HeadingOA.ParagraphsOS.Count, "Should be one heading para"); Assert.AreEqual(3, section1.ContentOA.ParagraphsOS.Count, "Should be three body paras"); StTxtPara para = (StTxtPara)section1.HeadingOA.ParagraphsOS[0]; Assert.IsNull(para.Contents.Text); Assert.AreEqual(ScrStyleNames.IntroSectionHead, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section1.ContentOA.ParagraphsOS[0]; Assert.AreEqual("My aching head!", para.Contents.Text); Assert.AreEqual(ScrStyleNames.IntroParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section1.ContentOA.ParagraphsOS[1]; Assert.AreEqual("Second paragraph of heading", para.Contents.Text); Assert.AreEqual(ScrStyleNames.IntroParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section1.ContentOA.ParagraphsOS[2]; Assert.AreEqual("This is Genesis.", para.Contents.Text); Assert.AreEqual(ScrStyleNames.IntroParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); // Verify that selection is in paragraph that was the heading of the // second section Assert.IsFalse(m_draftView.TeEditingHelper.InSectionHead, "Should be in body"); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(0, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new section, to be owned by the given book. The section will be an intro /// section if the isIntro flag is set to <code>true</code> /// The contents of the first content paragraph are filled with a single run as /// requested. The start and end references for the section are set based on where it's /// being inserted in the book. /// </summary> /// <param name="book">The book where the new section will be created</param> /// <param name="iSection">The zero-based index of the new section</param> /// <param name="contentText">The text to be used as the first para in the new section /// content</param> /// <param name="contentTextProps">The character properties to be applied to the first /// para in the new section content</param> /// <param name="isIntro">True to create an intro section, false to create a /// normal scripture section</param> /// <returns>Created section</returns> /// ------------------------------------------------------------------------------------ public static IScrSection CreateScrSection(IScrBook book, int iSection, string contentText, ITsTextProps contentTextProps, bool isIntro) { Debug.Assert(book != null); IScrSection section = CreateSectionWithHeadingPara(book, iSection, isIntro); // Insert the section contents. using (StTxtParaBldr bldr = new StTxtParaBldr(book.Cache)) { bldr.ParaProps = StyleUtils.ParaStyleTextProps( isIntro ? ScrStyleNames.IntroParagraph : ScrStyleNames.NormalParagraph); bldr.AppendRun(contentText, contentTextProps); bldr.CreateParagraph(section.ContentOAHvo); } // Dispose() frees ICU resources. return section; }
public void SectionHeadMidParaToParagraph() { CheckDisposed(); // create a book IScrBook book = CreateGenesis(); // Create section 1 IScrSection sectionCur = CreateSection(book, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("In the beginning, God created the heavens and the earth. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("And the earth was void.", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); sectionCur.AdjustReferences(); // create section 2 // section head will have four paragraphs sectionCur = CreateSection(book, "My other aching head!", "Paragraph A", "Paragraph B", "Last para of section head"); // create content paragraph holding chapter 2 paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Thus the heavens and the earth were completed in all their vast array. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); // Set the IP in the 2nd section. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 1; //section with 2:1 // Make a selection in the second paragraph of the heading m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, iBook, iSectionIP, 1); SelectionHelper helper = SelectionHelper.Create(m_draftView); // adjust end point level info to point to third paragraph SelLevInfo[] levInfo = helper.GetLevelInfo(SelectionHelper.SelLimitType.End); levInfo[0].ihvo = 2; helper.SetLevelInfo(SelectionHelper.SelLimitType.End, levInfo); helper.IchEnd = 0; // needed to make selection a range selection helper.SetSelection(true); // ApplyStyle should move paragraph from heading, but not change number // of sections. Assert.AreEqual(2, book.SectionsOS.Count, "Not two sections before ApplyStyle"); m_draftView.ApplyStyle(ScrStyleNames.NormalParagraph); Assert.AreEqual(3, book.SectionsOS.Count, "Not three sections after ApplyStyle"); // setup variables for testing IScrSection section1 = book.SectionsOS[0]; IScrSection section2 = book.SectionsOS[1]; IScrSection section3 = book.SectionsOS[2]; // Verify section paragraphs Assert.AreEqual(1, section1.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(1, section1.ContentOA.ParagraphsOS.Count); Assert.AreEqual(1, section2.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(2, section2.ContentOA.ParagraphsOS.Count); Assert.AreEqual(1, section3.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(1, section3.ContentOA.ParagraphsOS.Count); Assert.AreEqual(01001002, section1.VerseRefMax); Assert.AreEqual(01001002, section2.VerseRefMin); Assert.AreEqual(01001002, section2.VerseRefMax); Assert.AreEqual(01002001, section3.VerseRefMin); Assert.AreEqual(01002001, section3.VerseRefMax); StTxtPara para = (StTxtPara)section2.HeadingOA.ParagraphsOS[0]; Assert.AreEqual("My other aching head!", para.Contents.Text); Assert.AreEqual(ScrStyleNames.SectionHead, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section2.ContentOA.ParagraphsOS[0]; Assert.AreEqual("Paragraph A", para.Contents.Text); Assert.AreEqual(ScrStyleNames.NormalParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section2.ContentOA.ParagraphsOS[1]; Assert.AreEqual("Paragraph B", para.Contents.Text); Assert.AreEqual(ScrStyleNames.NormalParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section3.HeadingOA.ParagraphsOS[0]; Assert.AreEqual("Last para of section head", para.Contents.Text); Assert.AreEqual(ScrStyleNames.SectionHead, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); para = (StTxtPara)section3.ContentOA.ParagraphsOS[0]; Assert.AreEqual("2Thus the heavens and the earth were completed in all their vast array. ", para.Contents.Text); // chapter num and words Assert.AreEqual(ScrStyleNames.NormalParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); // Verify that selection is in paragraphs that have become the contents of the // second section Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); }
/// <summary> /// attach an annotation describing this failure to the object. *Does Not* remove previous annotations! /// </summary> /// <remarks> I say it does not remove previous annotations because I haven't thought about how much smarts /// it would take to only remove once associated with this particular failure. So I am stipulating for now that /// the caller should first remove all of the kinds of indications which it might create.</remarks> /// <returns></returns> protected ICmBaseAnnotation MakeAnnotation() { // callar should do something like this:CmBaseAnnotation.RemoveAnnotationsForObject(m_object.Cache, m_object.Hvo); ICmBaseAnnotation annotation = (ICmBaseAnnotation)m_cache.LangProject.AnnotationsOC.Add(new CmBaseAnnotation()); annotation.CompDetails = m_xmlDescription; annotation.TextOA = new StText(); using (StTxtParaBldr paraBldr = new StTxtParaBldr(m_cache)) { //review: I have no idea what this is as to be paraBldr.ParaProps = StyleUtils.ParaStyleTextProps("Paragraph"); //todo: this pretends that the default analysis writing system is also the user // interface 1. but I don't really know what's the right thing to do. paraBldr.AppendRun(m_explanation, StyleUtils.CharStyleTextProps(null, m_cache.DefaultAnalWs)); paraBldr.CreateParagraph(annotation.TextOAHvo); } // Dispose() frees ICU resources. annotation.BeginObjectRA = m_object; annotation.Flid = m_flid; annotation.CompDetails = m_xmlDescription; annotation.SourceRA = m_cache.LangProject.ConstraintCheckerAgent; // Although we generated a PropChanged when we actually created the annotation, we need another // one now that all its properties have been set, as there may be a filter that excludes it // until those properties. Simulate removing and re-adding the new annotation (presumed to be // at the end of the collection). int chvo = m_cache.LangProject.AnnotationsOC.Count; m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_cache.LangProject.Hvo, (int) LangProject.LangProjectTags.kflidAnnotations, chvo - 1, 1, 1); return annotation; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Append a new section to the given book, having the specified text as the section /// head. The new section will have an empty content text created also. /// </summary> /// <param name="styleName">Style name for section</param> /// <param name="book">The book to which the section is to be appended</param> /// <param name="sSectionHead">The text of the new section head</param> /// <returns>The newly created section</returns> /// ------------------------------------------------------------------------------------ private IScrSection CreateSection(string styleName, IScrBook book, params string[] sSectionHead) { // Create a section IScrSection section = new ScrSection(); book.SectionsOS.Append(section); // Create a section head for this section section.HeadingOA = new StText(); StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); for (int i = 0; i < sSectionHead.Length; i++) { paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(styleName); paraBldr.AppendRun(sSectionHead[i], StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section.HeadingOAHvo); } int verse = (styleName == ScrStyleNames.SectionHead) ? 1 : 0; section.ContentOA = new StText(); section.VerseRefEnd = section.VerseRefStart = new ScrReference(book.CanonicalNum, 1, verse, m_scr.Versification); return section; }
/// ------------------------------------------------------------------------------------ /// <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; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a mindless footnote (i.e., it's marker, paragraph style, etc. won't be set) /// to a paragraph. /// </summary> /// <param name="footnoteSequence">Sequence of footnotes into which to insert</param> /// <param name="para">the paragraph into which to insert the footnote ORC</param> /// <param name="ichPos">the zero-based character offset at which to insert the footnote /// ORC into the paragraph</param> /// <param name="footnoteText">text for the footnote (no footnote paragraph created if /// null)</param> /// <returns>the new footnote</returns> /// ------------------------------------------------------------------------------------ public StFootnote AddFootnote(FdoOwningSequence<IStFootnote> footnoteSequence, IStTxtPara para, int ichPos, string footnoteText) { CheckDisposed(); // Create the footnote StFootnote footnote = new StFootnote(); footnoteSequence.Append(footnote); // Update the paragraph contents to include the footnote marker ORC ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr(); footnote.InsertOwningORCIntoPara(tsStrBldr, ichPos, m_fdoCache.DefaultVernWs); para.Contents.UnderlyingTsString = tsStrBldr.GetString(); if (footnoteText != null) { // Create the footnote paragraph with the given footnoteText StTxtParaBldr paraBldr = new StTxtParaBldr(m_fdoCache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps("Note General Paragraph"); paraBldr.AppendRun(footnoteText, StyleUtils.CharStyleTextProps(null, m_fdoCache.DefaultVernWs)); paraBldr.CreateParagraph(footnote.Hvo); } return footnote; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a new annotation to the pending list /// </summary> /// ------------------------------------------------------------------------------------ private void AddNewAnnotation(ImportStyleProxy paraProxy, ITsTextProps runProps) { StTxtParaBldr paraBldr = new StTxtParaBldr(m_cache); paraBldr.ParaStylePropsProxy = paraProxy; paraBldr.AppendRun(m_sSegmentText, runProps); Guid guidAnnotationType = Guid.Empty; try { if (paraProxy.NoteType != null) guidAnnotationType = paraProxy.NoteType.Guid; else if (m_SOWrapper.CurrentAnnotationType > 0) guidAnnotationType = m_cache.GetGuidFromId(m_SOWrapper.CurrentAnnotationType); } catch { } finally { if (guidAnnotationType == Guid.Empty) guidAnnotationType = m_scrTranslatorAnnotationDef.Guid; } BCVRef lastRef = SOWrapper.SegmentLastRef; // If we haven't come across any scripture text (still in title or intro), then make // sure that the chapter number is set right. if (lastRef.Chapter == 0) lastRef.Chapter = 1; m_PendingAnnotations.Add(new ScrAnnotationInfo(guidAnnotationType, paraBldr, (m_ParaBldr.Length > 0 ? m_ParaBldr.Length - 1 : 0), m_currentRef.BBCCCVVV, lastRef.BBCCCVVV)); }
public void ContentLastIntroParaToIntroSectionHead() { CheckDisposed(); // create a book IScrBook book = CreateGenesis(); // Create section one - an introduction section IScrSection section1 = CreateSection(ScrStyleNames.IntroSectionHead, book, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.IntroParagraph); paraBldr.AppendRun("This is the first book of the Bible", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section1.ContentOAHvo); // create paragraph two holding text that really belongs in the section head paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.IntroParagraph); paraBldr.AppendRun("Ouch!", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section1.ContentOAHvo); Assert.AreEqual(2, section1.ContentOA.ParagraphsOS.Count); // finish the section info section1.AdjustReferences(); // Create section two IScrSection section2 = CreateSection(book, "My other aching head!"); // create paragraph three holding chapter 2 paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Thus the heavens and the earth were completed in all their vast array. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section2.ContentOAHvo); Assert.AreEqual(1, section2.ContentOA.ParagraphsOS.Count); // finish the section info section2.AdjustReferences(); m_draftView.RefreshDisplay(); // Set the IP at the beginning of the 2nd paragraph in the 1st section. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 0; //intro section int iParaIP = 1; // last intro para int ichIP = 0; // Put the IP in place m_draftView.SetInsertionPoint(iBook, iSectionIP, iParaIP, ichIP, true); // ApplyStyle should create a new section with the intro paragraph as the // section head and an empty body. m_draftView.ApplyStyle(ScrStyleNames.IntroSectionHead); Assert.AreEqual(3, book.SectionsOS.Count, "Should add a section"); // Verify verse start and end refs Assert.AreEqual(1001000, section1.VerseRefMin, "Existing section should have same verse start ref"); Assert.AreEqual(1001000, section1.VerseRefMax, "New section should have correct verse end ref"); section2 = (ScrSection) book.SectionsOS[1]; Assert.AreEqual(1001000, section2.VerseRefMin, "Existing section should have same verse start ref"); Assert.AreEqual(1001000, section2.VerseRefMax, "New section should have correct verse end ref"); // Verify Contents of section 1 Assert.AreEqual(1, section1.ContentOA.ParagraphsOS.Count); // Verify section head of section 2 Assert.AreEqual(1, section2.HeadingOA.ParagraphsOS.Count); Assert.AreEqual("Ouch!", ((StTxtPara)section2.HeadingOA.ParagraphsOS.FirstItem).Contents.Text); ITsTextProps ttp = ((StTxtPara)section2.HeadingOA.ParagraphsOS.FirstItem).StyleRules; Assert.AreEqual(ScrStyleNames.IntroSectionHead, ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); Assert.AreEqual(1, section2.ContentOA.ParagraphsOS.Count); Assert.IsNull(((StTxtPara)section2.ContentOA.ParagraphsOS.FirstItem).Contents.Text); ttp = ((StTxtPara)section2.ContentOA.ParagraphsOS.FirstItem).StyleRules; Assert.AreEqual(ScrStyleNames.IntroParagraph, ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); // Verify that selection is in first paragraph of section two heading Assert.IsTrue(m_draftView.TeEditingHelper.InSectionHead, "Should be in section heading"); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); }
public void ContentOnlyParaToSectionHead() { CheckDisposed(); // create a book IScrBook book = CreateGenesis(); // Create a section IScrSection sectionCur = CreateSection(book, "My aching head!"); // create paragraph one holding text that really belongs in the section head StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.AppendRun("Ouch!", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOAHvo); Assert.AreEqual(1, sectionCur.ContentOA.ParagraphsOS.Count); m_draftView.RefreshDisplay(); // Set the IP at the beginning of the paragraph in the section. int iBook = 0; // assume that iBook 0 is Genesis int iSectionIP = 0; //section with content to become section head int iParaIP = 0; int ichIP = 0; // Put the IP in place m_draftView.SetInsertionPoint(iBook, iSectionIP, iParaIP, ichIP, true); // ApplyStyle should not add a scripture section m_draftView.ApplyStyle(ScrStyleNames.SectionHead); Assert.AreEqual(1, book.SectionsOS.Count, "Should not add a section"); // setup variables for testing IScrSection section = book.SectionsOS[iSectionIP]; // Verify verse start and end refs Assert.AreEqual(1001001, section.VerseRefMin, "Existing section should have same verse start ref"); Assert.AreEqual(1001001, section.VerseRefMax, "New section should have correct verse end ref"); // Verify section head Assert.AreEqual(2, section.HeadingOA.ParagraphsOS.Count, "Should have 2 heading paragraphs"); Assert.AreEqual("My aching head!", ((StTxtPara)section.HeadingOA.ParagraphsOS.FirstItem).Contents.Text); Assert.AreEqual("Ouch!", ((StTxtPara)section.HeadingOA.ParagraphsOS[1]).Contents.Text); ITsTextProps ttp = ((StTxtPara)section.HeadingOA.ParagraphsOS[1]).StyleRules; Assert.AreEqual(ScrStyleNames.SectionHead, ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); // Verify Contents - should now be an empty paragraph Assert.AreEqual(1, section.ContentOA.ParagraphsOS.Count, "Should have one content paragraph"); StTxtPara para = (StTxtPara) section.ContentOA.ParagraphsOS.FirstItem; Assert.AreEqual(0, para.Contents.Length); Assert.AreEqual(ScrStyleNames.NormalParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); // Verify that selection is in second para of the section head Assert.IsTrue(m_draftView.TeEditingHelper.InSectionHead, "Should be in section heading"); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(0, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(1, m_draftView.ParagraphIndex); }
public void GoToScrScriptureNoteRef_OrigParaGone() { CheckDisposed(); IScrBook exodus = ScrBook.FindBookByID(m_scr, 2); StTxtPara para = (StTxtPara)exodus.SectionsOS[1].ContentOA.ParagraphsOS[0]; int ichStartExpected = para.Contents.Text.IndexOf("one"); Assert.IsTrue(ichStartExpected > 0, "Unexpected data in paragraph"); StTxtParaBldr bldrQuote = new StTxtParaBldr(Cache); ITsPropsFactory fact = TsPropsFactoryClass.Create(); bldrQuote.ParaProps = fact.MakeProps(ScrStyleNames.Remark, 0, 0); bldrQuote.AppendRun("one", fact.MakeProps(null, Cache.DefaultVernWs, 0)); ScrScriptureNote note = new ScrScriptureNote(); m_scr.BookAnnotationsOS[0].NotesOS.Append(note); StTxtPara para2 = (StTxtPara)exodus.SectionsOS[1].ContentOA.ParagraphsOS[1]; note.InitializeNote(LangProject.kguidAnnConsultantNote, 2001001, 2001001, para2, para2, -1, 0 ,0, bldrQuote, null, null, null); // Now delete the paragraph the note refers to. exodus.SectionsOS[1].ContentOA.ParagraphsOS.RemoveAt(1); // Initial offsets are irrelevant since the original paragraph is deleted. note.BeginOffset = 10; note.EndOffset = 13; TeEditingHelper helper = m_draftView.TeEditingHelper; helper.GoToScrScriptureNoteRef(note); // Confirm that the text referenced in the ScrScriptureNote is selected. Assert.IsTrue(helper.EditedRootBox.Selection.IsRange); ITsString tss; int ichStart, ichEnd; bool assocPrev; int hvoSel, tag, ws; helper.EditedRootBox.Selection.TextSelInfo(false, out tss, out ichStart, out assocPrev, out hvoSel, out tag, out ws); helper.EditedRootBox.Selection.TextSelInfo(true, out tss, out ichEnd, out assocPrev, out hvoSel, out tag, out ws); helper.EditedRootBox.Selection.GetSelectionString(out tss, "#"); Assert.AreEqual("one", tss.Text); Assert.AreEqual(ichStartExpected, ichStart); Assert.AreEqual(ichStartExpected + 3, ichEnd); Assert.AreEqual(2001001, helper.CurrentStartRef.BBCCCVVV); }