/// ------------------------------------------------------------------------------------ /// <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 ParagraphFollowTest_EnterAtSectionHeadEnd_EmptyPara() { 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.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(ScrStyleNames.NormalParagraph); styleHead.NextRA = stylePara; // send an Enter key m_draftView.TeEditingHelper.OnKeyPress(new KeyPressEventArgs('\r'), Keys.None, null); // Make sure that the book still has one section with the same 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(1, sectionCur.ContentOA.ParagraphsOS.Count); selHelper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(4, selHelper.NumberOfLevels); Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); }
/// ------------------------------------------------------------------------------------ /// <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> /// Finalizes section references and checks if the current section has any heading text /// and content. If not, a single blank paragraph is written for whatever is missing. /// </summary> /// ------------------------------------------------------------------------------------ protected void FinalizePrevSection() { if (m_currSection == null || !m_currSection.IsValidObject()) return; m_currSection.AdjustReferences(!m_fInScriptureText); int bcvRef = (m_firstImportedRef.IsEmpty) ? m_currSection.VerseRefMin : Math.Min(m_firstImportedRef, m_currSection.VerseRefMin); m_firstImportedRef = new ScrReference(bcvRef, m_scr.Versification); if (InMainImportDomain) return; // First, check if there is heading content. If not, add a blank paragraph. if (m_currSection.HeadingOA.ParagraphsOS.Count == 0) { StTxtParaBldr paraBldr = new StTxtParaBldr(m_cache); paraBldr.ParaStylePropsProxy = (m_fInScriptureText ? m_ScrSectionHeadParaProxy : m_DefaultIntroSectionHeadParaProxy); paraBldr.StringBuilder.SetIntPropValues(0, 0, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_wsVern); paraBldr.CreateParagraph(m_hvoSectionHeading); } // Now, check if there is content. If not, add a blank paragraph. if (m_currSection.ContentOA.ParagraphsOS.Count == 0) { StTxtParaBldr paraBldr = new StTxtParaBldr(m_cache); paraBldr.ParaStylePropsProxy = (m_fInScriptureText ? m_DefaultScrParaProxy : m_DefaultIntroParaProxy); paraBldr.StringBuilder.SetIntPropValues(0, 0, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_wsVern); paraBldr.CreateParagraph(m_hvoSectionContent); } m_fInScriptureText = !m_fCurrentSectionIsIntro; }
/// <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> /// 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 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); }
/// ------------------------------------------------------------------------------------ /// <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 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 BkspAtStartOfHeadingIntoEmptyContentPara() { CheckDisposed(); // Prepare test by adding new empty paragraph to first section of book 0 IScrBook book = m_scr.ScriptureBooksOS[0]; int cSectionsOrig = book.SectionsOS.Count; Assert.IsTrue(cSectionsOrig > 1); // Add an empty paragraph to the end of the first section content IScrSection section = book.SectionsOS[1]; int cOrigParas = section.ContentOA.ParagraphsOS.Count; StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.CreateParagraph(section.ContentOAHvo); m_draftView.RefreshDisplay(); Assert.AreEqual(cOrigParas + 1, section.ContentOA.ParagraphsOS.Count); // Set insertion point to beginning of first paragraph section 2 heading m_draftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, 0, 2); IVwSelection sel = m_draftView.RootBox.Selection; Assert.IsNotNull(sel); // Now do the real thing m_draftView.OnProblemDeletion(sel, VwDelProbType.kdptBsAtStartPara); Assert.AreEqual(cSectionsOrig, book.SectionsOS.Count); Assert.AreEqual(cOrigParas, section.ContentOA.ParagraphsOS.Count); // Verify that insertion point is still at beginning of first heading paragraph SelectionHelper helper = SelectionHelper.Create(m_draftView); SelLevInfo[] selInfo = helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor); Assert.AreEqual(4, selInfo.Length); Assert.AreEqual(0, selInfo[3].ihvo); // Book Assert.AreEqual(2, selInfo[2].ihvo); // Section Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidHeading, selInfo[1].tag); // In Content Assert.AreEqual(0, selInfo[0].ihvo); // Paragraph Assert.AreEqual(0, helper.GetIch(SelectionHelper.SelLimitType.Anchor)); }
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); }
/// ------------------------------------------------------------------------------------ /// <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 ParagraphFollowTest_EnterWithRangeSelection() { 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.CreateParagraph(sectionCur.ContentOAHvo); // finish the section info sectionCur.AdjustReferences(); m_draftView.RefreshDisplay(); m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, (int)ScrSection.ScrSectionTags.kflidHeading, 0, sectionHead.Length - 3, sectionHead.Length, true, true, false); // 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 book still has one section with the same paragraphs and // that the IP is in the first body paragraph. Also, the text of the section head // should be missing the last three letters that were selected. Assert.AreEqual(1, m_genesis.SectionsOS.Count); Assert.AreEqual(1, sectionCur.HeadingOA.ParagraphsOS.Count); Assert.AreEqual(1, sectionCur.ContentOA.ParagraphsOS.Count); SelectionHelper selHelper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(4, selHelper.NumberOfLevels); Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); Assert.AreEqual(sectionHead.Substring(0, sectionHead.Length - 3), ((StTxtPara)sectionCur.HeadingOA.ParagraphsOS[0]).Contents.Text); }
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_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 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 DelAtEndOfContentBeforeEmptyHeadingPara() { CheckDisposed(); // Prepare test by adding new empty paragraph to first section of book 0 IScrBook book = m_scr.ScriptureBooksOS[0]; int cSectionsOrig = book.SectionsOS.Count; Assert.IsTrue(cSectionsOrig > 1); IScrSection section1 = book.SectionsOS[1]; StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph); paraBldr.CreateParagraph(section1.HeadingOAHvo, 0); Assert.AreEqual(2, section1.HeadingOA.ParagraphsOS.Count); m_draftView.RefreshDisplay(); // Set insertion point to end of last paragraph of section 0 content IScrSection section0 = book.SectionsOS[0]; int cParas = section0.ContentOA.ParagraphsOS.Count; StTxtPara para = (StTxtPara) section0.ContentOA.ParagraphsOS[cParas - 1]; int paraLen = para.Contents.Length; m_draftView.SetInsertionPoint(0, 0, cParas - 1, paraLen, false); IVwSelection sel = m_draftView.RootBox.Selection; Assert.IsNotNull(sel); // Now do the real thing m_draftView.OnProblemDeletion(sel, VwDelProbType.kdptDelAtEndPara); Assert.AreEqual(cSectionsOrig, book.SectionsOS.Count); Assert.AreEqual(1, section1.HeadingOA.ParagraphsOS.Count); // Verify that insertion point is still at end of last content paragraph SelectionHelper helper = SelectionHelper.Create(m_draftView); SelLevInfo[] selInfo = helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor); Assert.AreEqual(4, selInfo.Length); Assert.AreEqual(0, selInfo[3].ihvo); // Book Assert.AreEqual(0, selInfo[2].ihvo); // Section Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent, selInfo[1].tag); // In Content Assert.AreEqual(cParas - 1, selInfo[0].ihvo); // Paragraph Assert.AreEqual(paraLen, helper.GetIch(SelectionHelper.SelLimitType.Anchor)); }
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 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); }
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 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> /// 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> /// 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> /// Initialize the text for the paragraph with the specified builder, or create an /// empty paragraph if the builder is null. /// </summary> /// <param name="bldr">paragraph builder</param> /// <param name="text">StText</param> /// ------------------------------------------------------------------------------------ private void InitializeText(StTxtParaBldr bldr, IStText text) { if (bldr == null) { IStTxtPara para = (StTxtPara)text.ParagraphsOS.Append(new StTxtPara()); para.Contents.UnderlyingTsString = StringUtils.MakeTss(String.Empty, Cache.DefaultAnalWs); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark); } else { bldr.CreateParagraph(text.Hvo); } }
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); }
/// ------------------------------------------------------------------------------------ /// <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; }
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()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finalizes the title. If is empty, a single blank paragraph is written for /// whatever is missing. /// </summary> /// ------------------------------------------------------------------------------------ protected void FinalizePrevTitle() { if (m_cache == null || m_hvoTitle == 0) return; StText title = new StText(m_cache, m_hvoTitle); // First, check if there is content. If not, add a blank paragraph. if (title.ParagraphsOS.Count == 0) { StTxtParaBldr titleParaBldr = new StTxtParaBldr(m_cache); titleParaBldr.ParaStylePropsProxy = m_BookTitleParaProxy; titleParaBldr.CreateParagraph(m_hvoTitle); } m_fInBookTitle = false; }
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); }
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 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); }