/// <summary> /// attach an annotation describing this failure to the object. *Does Not* remove previous annotations! Generally call RemoveObsoleteAnnotations first. /// </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> public ICmBaseAnnotation MakeAnnotation() { var annotation = m_cache.ServiceLocator.GetInstance <ICmBaseAnnotationFactory>().Create(); m_cache.LanguageProject.AnnotationsOC.Add(annotation); annotation.CompDetails = m_xmlDescription; annotation.TextOA = m_cache.ServiceLocator.GetInstance <IStTextFactory>().Create(); var paraBldr = new StTxtParaBldr(m_cache); //review: I have no idea what this has to be. paraBldr.ParaStyleName = "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.TextOA); annotation.BeginObjectRA = m_object; annotation.Flid = m_flid; annotation.CompDetails = m_xmlDescription; annotation.SourceRA = m_cache.LanguageProject.ConstraintCheckerAgent; return(annotation); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates an empty paragraph with the given paragraph style and writing system. /// </summary> /// <param name="cache"></param> /// <param name="owner"></param> /// <param name="paraStyle"></param> /// <param name="ws"></param> /// ------------------------------------------------------------------------------------ public static void CreateEmptyPara(FdoCache cache, IStText owner, string paraStyle, int ws) { var bldr = new StTxtParaBldr(cache); bldr.ParaStyleName = paraStyle; bldr.AppendRun(String.Empty, StyleUtils.CharStyleTextProps(null, ws)); bldr.CreateParagraph(owner); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the cited text for checking error annotation. /// </summary> /// <param name="citedText">The cited text.</param> /// <param name="ws">The writing system.</param> /// <returns>Quote for the ScrScriptureNote</returns> /// ------------------------------------------------------------------------------------ private StTxtParaBldr SetCitedText(string citedText, int ws) { StTxtParaBldr quote = new StTxtParaBldr(m_cache); quote.ParaStyleName = ScrStyleNames.Remark; // ENHANCE: Cache the run props using a hash table for each writing system quote.AppendRun(citedText, StyleUtils.CharStyleTextProps(null, ws)); return(quote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the error message. /// </summary> /// <param name="formattedMsg">The localized and formatted message.</param> /// <returns>Discussion for the ScrScriptureNote</returns> /// ------------------------------------------------------------------------------------ private StTxtParaBldr SetErrorMessage(string formattedMsg) { StTxtParaBldr discussion = new StTxtParaBldr(m_cache); discussion.ParaStyleName = ScrStyleNames.Remark; // ENHANCE: Cache the run props for the UI writing system discussion.AppendRun(formattedMsg, StyleUtils.CharStyleTextProps(null, m_cache.DefaultUserWs)); return(discussion); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the error annotation to the database. /// </summary> /// <param name="citedText">The cited text.</param> /// <param name="offset">The offset.</param> /// <param name="length">The length.</param> /// <param name="checkId">The Scripture error checking id.</param> /// <param name="firstToken">The first token.</param> /// <param name="lastToken">The last token.</param> /// <param name="formattedMsg">The formatted error message.</param> /// ------------------------------------------------------------------------------------ private void AddErrorAnnotation(string citedText, int offset, int length, Guid checkId, ScrCheckingToken firstToken, ScrCheckingToken lastToken, string formattedMsg) { IScrBookAnnotations annotations = (IScrBookAnnotations)m_scr.BookAnnotationsOS[firstToken.StartRef.Book - 1]; StTxtParaBldr quote = SetCitedText(citedText, firstToken.Ws); StTxtParaBldr discussion = SetErrorMessage(formattedMsg); IScrScriptureNote note = annotations.InsertErrorAnnotation(firstToken.StartRef, lastToken.EndRef, firstToken.Object, lastToken.Object, checkId, quote, discussion); note.BeginOffset = firstToken.ParaOffset + offset; note.EndOffset = note.BeginOffset + length; note.Flid = firstToken.Flid; }
public void DetectDifferences_Identical() { // Create a section for both the current version of Genesis and the stored revision. IScrSection sectionCur = CreateSection(m_genesis, "My aching head!"); IScrSection sectionRev = CreateSection(m_genesisRevision, "My aching head!"); StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = 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 formless and void... ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("3", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("And God said, 'Let there be light...' ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOA); paraBldr.ParaStyleName = 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 formless and void... ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("3", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("And God said, 'Let there be light...' ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionRev.ContentOA); // Find the diffs for Genesis m_bookMerger.DetectDifferences(null); // MoveFirst should return null because there are no diffs. Assert.IsNull(m_bookMerger.Differences.MoveFirst()); }
public void ParagraphFollowTest_EnterWithBigRangeSelection() { // Create a section string sectionHead = "Apples and Oranges"; IScrSection sectionCur = CreateSection(m_genesis, sectionHead); // create a paragraph StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; string bodyText = "A complex dissertation on the sections of fruit."; paraBldr.AppendRun(bodyText, StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOA); // finish the section info 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(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); // 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); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds to para BLDR. /// </summary> /// ------------------------------------------------------------------------------------ internal override void AddToParaBldr(StTxtParaBldr bldr, int ws, FwStyleSheet styleSheet) { if (string.IsNullOrEmpty(Href)) throw new Exception("OXESA validation found an invalid URL."); bool fSucceeded = FwEditingHelper.AddHyperlink(bldr.StringBuilder, ws, Text, Href, styleSheet); Debug.Assert(fSucceeded); }
/// ------------------------------------------------------------------------------------ /// <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 IScrSection CreateScrSection(IScrBook book, int iSection, string contentText, ITsTextProps contentTextProps, bool isIntro) { if (book == null) throw new ArgumentNullException(); IScrSection section = CreateSection(book, iSection, isIntro, true, false); // Insert the section contents. StTxtParaBldr bldr = new StTxtParaBldr(book.Cache); bldr.ParaStyleName = isIntro ? ScrStyleNames.IntroParagraph : ScrStyleNames.NormalParagraph; bldr.AppendRun(contentText, contentTextProps); bldr.CreateParagraph(section.ContentOA); 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(IScrBook 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++) { string styleName = ttpSrcArray[i].GetStrPropValue((int)FwTextPropType.ktptNamedStyle); IStStyle style = m_scr.FindStyle(styleName); 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) { // Create heading paragraph at end of section heading section.HeadingOA.InsertNewPara(-1, styleName, tssParas[i]); } else { isIntro = (style.Context == ContextValues.Intro); // Create a new section and add the current paragraph to the heading section = m_cache.ServiceLocator.GetInstance<IScrSectionFactory>().CreateEmptySection( book, sectionIndex + cAddedSections++); section.HeadingOA.InsertNewPara(-1, styleName, tssParas[i]); } } else { // Create content paragraph for the current section section.ContentOA.InsertNewPara(-1, styleName, 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.ParaStyleName = styleName; ITsTextProps charProps = StyleUtils.CharStyleTextProps(styleName, m_wsContainer.DefaultVernacularWritingSystem.Handle); bldr.AppendRun(string.Empty, charProps); bldr.CreateParagraph(section.ContentOA); } return true; }
/// ------------------------------------------------------------------------------------ /// <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; 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_sectionHeading); } // 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_sectionContent); } m_fInScriptureText = !m_fCurrentSectionIsIntro; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Convert each of the child paragraphs into an ITsString object, and add that object /// to the given list. If the paragraph's writing system cannot be found, then the /// specified default writing system is used. /// </summary> /// ----------------------------------------------------------------------------------- public StTxtParaBldr BuildParagraph(FwStyleSheet styleSheet, int wsDefault) { StTxtParaBldr bldr; int wsPara = (string.IsNullOrEmpty(IcuLocale) ? wsDefault : ScrNoteImportManager.GetWsForLocale(IcuLocale)); bldr = new StTxtParaBldr(styleSheet.Cache); string stylename = (string.IsNullOrEmpty(StyleName) ? ScrStyleNames.Remark : StyleName); bldr.ParaStylePropsProxy = StyleProxyListManager.GetXmlParaStyleProxy( stylename, ContextValues.Annotation, wsDefault); foreach (XmlTextRun run in Runs) { int ws = -1; try { ws = (string.IsNullOrEmpty(run.IcuLocale) ? wsPara : ScrNoteImportManager.GetWsForLocale(run.IcuLocale)); } catch (UnknownPalasoWsException e) { throw new UnknownPalasoWsRunException(e.IcuLocale + " on a text run is not known", run.Text, e.IcuLocale, e.WsIdentifier); } run.AddToParaBldr(bldr, ws, styleSheet); } // OXES supports mixed text so this is designed to handle text that // is found in the "para" tag but not in any "span" or "a" tag. if (!string.IsNullOrEmpty(m_text)) { XmlTextRun extraText = new XmlTextRun(); extraText.Text = m_text; extraText.AddToParaBldr(bldr, wsPara, styleSheet); } return bldr; }
/// ------------------------------------------------------------------------------------ /// <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_Title == null) return; // First, check if there is content. If not, add a blank paragraph. if (m_Title.ParagraphsOS.Count == 0) { StTxtParaBldr titleParaBldr = new StTxtParaBldr(m_cache); titleParaBldr.ParaStylePropsProxy = m_BookTitleParaProxy; titleParaBldr.CreateParagraph(m_Title); } m_fInBookTitle = false; }
public void InsertSection_EndFirstHeadingPara() { 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.ParaStyleName = ScrStyleNames.SectionHead; paraBldr.AppendRun("Second Paragraph", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section.HeadingOA); 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 = StTextTags.kflidParagraphs; selHelper.LevelInfo[0].ihvo = 0; selHelper.LevelInfo[1].tag = ScrSectionTags.kflidHeading; selHelper.LevelInfo[1].ihvo = 0; selHelper.LevelInfo[2].tag = 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" selHelper.TextPropId = StTxtParaTags.kflidContents; int cContentParas = section.ContentOA.ParagraphsOS.Count; // Now that all the preparation to set the IP is done, set it. 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", newSection.HeadingOA[0].Contents.Text, "Wrong heading in new section"); Assert.IsNull(newSection.ContentOA[0].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", oldSection.HeadingOA[0].Contents.Text, "Wrong heading in old section"); Assert.AreEqual(cContentParas, oldSection.ContentOA.ParagraphsOS.Count, "Wrong number of paragraphs in old content"); }
public void AdjustAnnotationReferences_WithQuote() { IScrBook genesis = AddBookToMockedScripture(1, "Genesis"); AddTitleToMockedBook(genesis, "Genesis"); // Introduction section IScrSection section = AddSectionToMockedBook(genesis, true); AddSectionHeadParaToSection(section, "Introduction head", ScrStyleNames.IntroSectionHead); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.IntroParagraph); AddRunToMockedPara(para, "An intro to Genesis", null); para = AddParaToMockedSectionContent(section, ScrStyleNames.IntroParagraph); AddRunToMockedPara(para, "Contains quoted text - the quote", null); IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[0]; BCVRef ref1 = new BCVRef(1, 1, 0); int iPos; StTxtParaBldr quoteBldr = new StTxtParaBldr(Cache); quoteBldr.ParaStyleName = ScrStyleNames.Remark; quoteBldr.AppendRun("the quote", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrScriptureNote note = annotations.InsertNote(ref1, ref1, null, null, CmAnnotationDefnTags.kguidAnnConsultantNote, 0, 0, quoteBldr, null, null, null, out iPos); Assert.IsNotNull(note); m_scr.AdjustAnnotationReferences(); Assert.AreEqual(para, note.BeginObjectRA); Assert.AreEqual(23, note.BeginOffset); Assert.AreEqual(32, note.EndOffset); }
/// ------------------------------------------------------------------------------------ /// <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 = AddSectionToMockedBook(book); // Create a section head for this section section.HeadingOA = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create(); StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); for (int i = 0; i < sSectionHead.Length; i++) { paraBldr.ParaStyleName = styleName; paraBldr.AppendRun(sSectionHead[i], StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(section.HeadingOA); } section.ContentOA = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create(); return section; }
public void ParagraphFollowTest_EnterBetweenSectionHeadParas() { // 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.ParaStyleName = ScrStyleNames.SectionHead; paraBldr.AppendRun("Peaches and Bananas", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.HeadingOA); // create a paragraph paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; string bodyText = "A complex dissertation on the sections of fruit."; paraBldr.AppendRun(bodyText, StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOA); // finish the section info m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint(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); // 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[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[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(ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); Assert.AreEqual(0, selHelper.LevelInfo[0].ihvo); }
public void ParagraphFollowTest_EnterWithRangeSelection() { // Create a section string sectionHead = "Apples and Oranges"; IScrSection sectionCur = CreateSection(m_genesis, sectionHead); // create an empty paragraph StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; paraBldr.CreateParagraph(sectionCur.ContentOA); // finish the section info m_draftView.RefreshDisplay(); m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, 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); // 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(ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); Assert.AreEqual(sectionHead.Substring(0, sectionHead.Length - 3), sectionCur.HeadingOA[0].Contents.Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the scripture importer /// </summary> /// ------------------------------------------------------------------------------------ protected void Initialize() { m_wsAnal = m_cache.DefaultAnalWs; m_wsVern = m_cache.DefaultVernWs; m_wsPara = m_cache.DefaultVernWs; m_scr = m_cache.LangProject.TranslatedScriptureOA; InitInterpretFootnoteSettings(); // ENHANCE (TomB): Might want to make it possible to end importing in the middle // of a book someday. ScrReference endRef = new ScrReference(m_settings.EndRef, m_scr.Versification); ScrReference startRef = new ScrReference(m_settings.StartRef, m_scr.Versification); m_nBookNumber = m_settings.StartRef.Book; m_settings.EndRef = endRef = endRef.LastReferenceForBook; // Initialize scripture object InitScriptureObject(); // Load the scripture text project & enum LoadScriptureProject(); // Display progress if one was supplied if (m_importCallbacks.IsDisplayingUi) { int cChapters = ScrReference.GetNumberOfChaptersInRange(SOWrapper.BooksPresent, startRef, endRef); int nMax = m_settings.ImportTranslation ? cChapters : 0; if (SOWrapper.HasNonInterleavedBT && m_settings.ImportBackTranslation) nMax += cChapters; if (SOWrapper.HasNonInterleavedNotes && m_settings.ImportAnnotations) nMax += cChapters; m_importCallbacks.Maximum = nMax; } // Init our set of style proxies LoadImportMappingProxies(); // Init member vars special paragraph style proxies, used as fallbacks in case // import data lacks a paragraph style. // For now we always use the default vernacular writing system. This may change // when we are able to import paratext project proxies with multiple // domains (vern, back transl, notes) m_BookTitleParaProxy = new ImportStyleProxy(ScrStyleNames.MainBookTitle, StyleType.kstParagraph, m_wsVern, ContextValues.Title, m_styleSheet); Debug.Assert(m_BookTitleParaProxy.Context == ContextValues.Title); m_ScrSectionHeadParaProxy = new ImportStyleProxy(ScrStyleNames.SectionHead, StyleType.kstParagraph, m_wsVern, ContextValues.Text, m_styleSheet); m_DefaultIntroSectionHeadParaProxy = new ImportStyleProxy(ScrStyleNames.IntroSectionHead, StyleType.kstParagraph, m_wsVern, ContextValues.Intro, m_styleSheet); m_DefaultScrParaProxy = new ImportStyleProxy(ScrStyleNames.NormalParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Text, m_styleSheet); m_DefaultIntroParaProxy = new ImportStyleProxy(ScrStyleNames.IntroParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Intro, m_styleSheet); m_DefaultFootnoteParaProxy = new ImportStyleProxy(ScrStyleNames.NormalFootnoteParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Note, m_styleSheet); m_DefaultAnnotationStyleProxy = new ImportStyleProxy(ScrStyleNames.Remark, StyleType.kstParagraph, m_wsAnal, ContextValues.Annotation, m_styleSheet); // Make a paragraph builder. We will keep re-using this every time we build a paragraph. m_ParaBldr = new StTxtParaBldr(m_cache); // Handle the case where the very first marker (after the \id line) is a // character style. m_ParaBldr.ParaStylePropsProxy = m_DefaultIntroParaProxy; // Build generic character props for use with different runs of text and analysis // character properties ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); // analysis character properties tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_wsAnal); m_analTextProps = tsPropsBldr.GetTextProps(); // vernacular character properties tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_wsVern); m_vernTextProps = tsPropsBldr.GetTextProps(); // Get a reference to the annotation definition of translator notes (to use as default note type) m_scrTranslatorAnnotationDef = m_cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>().GetObject(CmAnnotationDefnTags.kguidAnnTranslatorNote); }
public void VerseIterator_InitialText() { // Create section 1 for Genesis. IScrSection section1 = CreateSection(m_genesis, "My aching head!", 01001001, 01001001); // build paragraph for section 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; paraBldr.AppendRun("Some initial text. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("5-6", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verses 5-6.", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrTxtPara hvoS1Para = (IScrTxtPara)paraBldr.CreateParagraph(section1.ContentOA); // Create an iterator to test m_bookMerger.CreateVerseIteratorForStText(section1.ContentOA); // Verify section 1 content ScrVerse scrVerse = m_bookMerger.NextVerseInStText(); Assert.AreEqual(hvoS1Para, scrVerse.Para); Assert.AreEqual(01001001, scrVerse.StartRef); Assert.AreEqual(01001001, scrVerse.EndRef); Assert.AreEqual("Some initial text. ", scrVerse.Text.Text); Assert.AreEqual(0, scrVerse.VerseStartIndex); scrVerse = m_bookMerger.NextVerseInStText(); Assert.AreEqual(hvoS1Para, scrVerse.Para); Assert.AreEqual(01001005, scrVerse.StartRef); Assert.AreEqual(01001006, scrVerse.EndRef); Assert.AreEqual("5-6Verses 5-6.", scrVerse.Text.Text); Assert.AreEqual(19, scrVerse.VerseStartIndex); Assert.IsNull(m_bookMerger.NextVerseInStText()); }
/// ------------------------------------------------------------------------------------ /// <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.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>().GetObject(m_SOWrapper.CurrentAnnotationType).Guid; } } 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 VerseIterator() { // Create section 1 for Genesis. IScrSection section1 = CreateSection(m_genesis, "My aching head!"); // build paragraph for section 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse 1. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse 2. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.AppendRun("3-4", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse 3-4.", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrTxtPara hvoS1Para = (IScrTxtPara)paraBldr.CreateParagraph(section1.ContentOA); // Create an iterator to test heading m_bookMerger.CreateVerseIteratorForStText(section1.HeadingOA); // Verify section 1 heading ScrVerse scrVerse = m_bookMerger.NextVerseInStText(); Assert.AreEqual(section1.HeadingOA[0], scrVerse.Para); Assert.AreEqual(01002001, scrVerse.StartRef); Assert.AreEqual(01002001, scrVerse.EndRef); Assert.AreEqual("My aching head!", scrVerse.Text.Text); Assert.AreEqual(0, scrVerse.VerseStartIndex); // Verify there are no more scrVerses scrVerse = m_bookMerger.NextVerseInStText(); Assert.IsNull(scrVerse); // Create an iterator to test content m_bookMerger.CreateVerseIteratorForStText(section1.ContentOA); // Verify section 1 content scrVerse = m_bookMerger.NextVerseInStText(); Assert.AreEqual(hvoS1Para, scrVerse.Para); Assert.AreEqual(01002001, scrVerse.StartRef); Assert.AreEqual(01002001, scrVerse.EndRef); Assert.AreEqual("2Verse 1. ", scrVerse.Text.Text); Assert.AreEqual(0, scrVerse.VerseStartIndex); Assert.AreEqual(1, scrVerse.TextStartIndex); scrVerse = m_bookMerger.NextVerseInStText(); Assert.AreEqual(01002002, scrVerse.StartRef); Assert.AreEqual(01002002, scrVerse.EndRef); Assert.AreEqual("2Verse 2. ", scrVerse.Text.Text); Assert.AreEqual(10, scrVerse.VerseStartIndex); scrVerse = m_bookMerger.NextVerseInStText(); Assert.AreEqual(01002003, scrVerse.StartRef); Assert.AreEqual(01002004, scrVerse.EndRef); Assert.AreEqual("3-4Verse 3-4.", scrVerse.Text.Text); Assert.AreEqual(20, scrVerse.VerseStartIndex); // Verify there are no more scrVerses scrVerse = m_bookMerger.NextVerseInStText(); Assert.IsNull(scrVerse); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Begin a footnote: insert the footnote into the ScrBook and insert the footnote /// marker into the paragraph. Subsequent footnote segments will be added to the /// footnote paragraph until <see cref="EndFootnote"/> is called. /// </summary> /// ------------------------------------------------------------------------------------ protected void BeginFootnote() { Debug.Assert(!m_fInFootnote); // Check to see if this footnote is a USFM style footnote or otherwise begins with a // single character that is likely to be a footnote marker. If so, strip the marker // from the data. CheckDataForFootnoteMarker(); // If the footnote marker is the auto marker, then generate a marker for it ImportStyleProxy proxy = (m_styleProxy.StyleType == StyleType.kstParagraph) ? m_styleProxy : m_DefaultFootnoteParaProxy; string sFootnoteMarker = m_scr.GetFootnoteMarker(proxy.StyleId); // If the last character in the paragraph is a separator, then insert the footnote // marker before it. (TE-2431) ITsStrBldr strbldr = m_ParaBldr.StringBuilder; int ichMarker = m_ParaBldr.Length; bool fInsertSpaceAfterCaller = false; if (UnicodeCharProps.get_IsSeparator(m_ParaBldr.FinalCharInPara)) ichMarker--; else if (m_settings.ImportTypeEnum == TypeOfImport.Other) { // Check to see if we are inserting this right after a verse. ITsTextProps propsOfLastRun = strbldr.get_Properties(strbldr.RunCount - 1); string sStyleOfLastRun = propsOfLastRun.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); if (sStyleOfLastRun == ScrStyleNames.VerseNumber) fInsertSpaceAfterCaller = true; } // When importing a whole book, we can call this version of InsertFootnoteAt and save // the time of trying to look for the previous footnote each time and checking to see // if we need to resequence following footnotes. // TODO (TE-920 and/or TE-431): m_CurrFootnote = m_scrBook.InsertFootnoteAt(m_iCurrFootnote, strbldr, ichMarker); if (fInsertSpaceAfterCaller) strbldr.Replace(strbldr.Length, strbldr.Length, " ", m_vernTextProps); // Set up the paragraph builder m_SavedParaBldr = m_ParaBldr; m_ParaBldr = new StTxtParaBldr(m_cache); m_ParaBldr.ParaStylePropsProxy = proxy; m_CurrParaFootnotes.Add(new FootnoteInfo(m_CurrFootnote, proxy.StyleId)); // remember that we are now processing a footnote SetInFootnote(); }
public void ParagraphFollowTest_EnterAtSectionHeadEnd_EmptyPara() { // Create a section string sectionHead = "Apples and Oranges"; IScrSection sectionCur = CreateSection(m_genesis, sectionHead); // create an empty paragraph StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; paraBldr.CreateParagraph(sectionCur.ContentOA); // finish the section info m_draftView.RefreshDisplay(); SelectionHelper selHelper = m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 0); 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); // 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(ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** "); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. var disposable = m_pauseEvent as IDisposable; if (disposable != null) disposable.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_ParaBldr = null; m_cache = null; m_styleSheet = null; m_scr = null; m_undoManager = null; m_importCallbacks = null; m_ScrSectionHeadParaProxy = null; m_DefaultIntroSectionHeadParaProxy = null; m_DefaultScrParaProxy = null; m_DefaultIntroParaProxy = null; m_BTStrBldrs = null; m_SavedParaBldr = null; m_CurrFootnote = null; m_ttpChapterNumber = null; m_sPrevBook = null; m_scrBook = null; m_currSection = null; m_isDisposed = true; }
public void InsertSection_InMidSectionAtBeginningOfChapter() { // Create a section IScrSection sectionCur = CreateSection(m_genesis, "My aching head!"); // create paragraph one holding chapter 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = 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.ContentOA); // create paragraph two holding chapter 2 paraBldr.ParaStyleName = 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.ContentOA); // finish the section info 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[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; ITsTextProps paraRulesFirstNew = text[iParaIP].StyleRules; ITsString tssFirstNewPara = text[iParaIP].Contents; // 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); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Use this method to move a portion of one StText to the same field (i.e. heading or /// content) in another section. /// </summary> /// <param name="field">The field (heading or contents) from and to which contents /// will be moved.</param> /// <param name="destSection">section to which the contents is moved</param> /// <param name="iparaDiv">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> /// ------------------------------------------------------------------------------------ private void MovePartialContentsTo(int field, IScrSection destSection, int iparaDiv, int ichDiv) { IStText srcText = (field == ScrSectionTags.kflidContent) ? ContentOA : HeadingOA; IStText destText = (field == ScrSectionTags.kflidContent) ? destSection.ContentOA : destSection.HeadingOA; int iLastSrcPara = srcText.ParagraphsOS.Count - 1; Debug.Assert((iparaDiv >= 0) && (iparaDiv <= iLastSrcPara)); IStTxtPara divPara = (IStTxtPara)srcText.ParagraphsOS[iparaDiv]; if (ichDiv > 0 && ichDiv < divPara.Contents.Length) { divPara.SplitParaAt(ichDiv); iLastSrcPara++; } // Set up parameters for whole paragraph movement based on direction of movement //From para following IP to the end, pre-pended int iStartAt = (ichDiv > 0) ? iparaDiv + 1 : iparaDiv; int iInsertAt = 0; // Move the whole paragraphs of srcText to empty destText if (iparaDiv != iLastSrcPara || ichDiv == 0) MoveWholeParas(this, field, iStartAt, iLastSrcPara, destSection, field, iInsertAt, null); if (srcText.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 IStTxtPara newSectionFirstPara = destText[0]; StTxtParaBldr bldr = new StTxtParaBldr(m_cache); bldr.ParaStyleName = newSectionFirstPara.StyleName; bldr.AppendRun(string.Empty, StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs)); bldr.CreateParagraph(srcText); } }
public void FindOrCreateAnnotation_GuidNotFound() { StTxtParaBldr bldr = new StTxtParaBldr(Cache); ScrAnnotationInfo annInfo = new ScrAnnotationInfo(CmAnnotationDefnTags.kguidAnnConsultantNote, bldr, 0, 01001001, 01001002); IScrScriptureNote newNote = ScrNoteImportManager.FindOrCreateAnnotation(annInfo, Guid.NewGuid()); Assert.IsNotNull(newNote); Assert.IsNull(newNote.BeginObjectRA); Assert.IsNull(newNote.EndObjectRA); Assert.AreEqual(01001001, newNote.BeginRef); Assert.AreEqual(01001002, newNote.EndRef); }
internal ITsString RebuildParagraphContentFromStrings() { try { m_expectedWordformsAndOccurrences = null; //<Contents16> <Str> <Run ws=""> XmlNodeList runs = m_paraDefn.SelectNodes("Contents16/Str/Run"); if (runs == null) return null; StTxtParaBldr bldr = new StTxtParaBldr(m_cache); bldr.StringBuilder.Clear(); foreach (XmlNode run in runs) { int ws = GetWsFromStringNode(run); bldr.AppendRun(run.InnerText, MakeTextProps(ws)); } SetContents(bldr.StringBuilder.GetString(), false); return m_para.Contents; } finally { //m_fNeedToRebuildParagraphContentFromStrings = false; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds to para BLDR. /// </summary> /// ------------------------------------------------------------------------------------ internal virtual void AddToParaBldr(StTxtParaBldr bldr, int ws, FwStyleSheet styleSheet) { bldr.AppendRun(m_text, StyleUtils.CharStyleTextProps(StyleName, ws)); }
public void VerseIterator_ForSetOfStTexts() { // Create section 1 for Genesis. IScrSection section1 = CreateSection(m_genesis, "My aching head!"); // build paragraph for section 1 StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse 1. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrTxtPara para1 = (IScrTxtPara)paraBldr.CreateParagraph(section1.ContentOA); // Create section 2 for Genesis. IScrSection section2 = CreateSection(m_genesis, "My aching behind!"); // build paragraph for section 2 paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; paraBldr.AppendRun("3", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs)); paraBldr.AppendRun("Verse 1. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrTxtPara para2 = (IScrTxtPara)paraBldr.CreateParagraph(section2.ContentOA); // Create section 3 for Genesis. IScrSection section3 = CreateSection(m_genesis, ""); // build paragraph for section 3 paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; IScrTxtPara para3 = (IScrTxtPara)paraBldr.CreateParagraph(section3.ContentOA); // Create an iterator to test group of StTexts List<IStText> list = new List<IStText>(6); // this is not a typical list for TE, just a bunch of StTexts for this test list.Add(section1.HeadingOA); list.Add(section2.HeadingOA); list.Add(section3.HeadingOA); list.Add(section1.ContentOA); list.Add(section2.ContentOA); list.Add(section3.ContentOA); m_bookMerger.CreateVerseIteratorForSetOfStTexts(list); // Verify section 1 heading ScrVerse scrVerse = m_bookMerger.NextVerseInSet(); DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section1.HeadingOA[0], 01002001, 01002001, "My aching head!", 0, false, true, 0); // Verify section 2 heading scrVerse = m_bookMerger.NextVerseInSet(); DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section2.HeadingOA[0], 01003001, 01003001, "My aching behind!", 0, false, true, 1); // section 3 heading is empty, but returns an empty ScrVerse scrVerse = m_bookMerger.NextVerseInSet(); DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section3.HeadingOA[0], 01003001, 01003001, null, 0, false, true, 2); // Verify section 1 content scrVerse = m_bookMerger.NextVerseInSet(); DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section1.ContentOA[0], 01002001, 01002001, "2Verse 1. ", 0, true, false, 0); // Verify section 2 content scrVerse = m_bookMerger.NextVerseInSet(); DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section2.ContentOA[0], 01003001, 01003001, "3Verse 1. ", 0, true, false, 1); // Verify section 3 content--an empty ScrVerse scrVerse = m_bookMerger.NextVerseInSet(); DiffTestHelper.VerifyScrVerse(scrVerse, (IScrTxtPara)section3.ContentOA[0], 01003001, 01003001, null, 0, false, false, 2); // Verify there are no more scrVerses scrVerse = m_bookMerger.NextVerseInSet(); Assert.IsNull(scrVerse); }
public void ParagraphFollowTest_EnterAtSectionHeadEnd_NonEmptyPara() { // Create a section string sectionHead = "Apples and Oranges"; IScrSection sectionCur = CreateSection(m_genesis, sectionHead); // create an empty paragraph StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaStyleName = ScrStyleNames.NormalParagraph; paraBldr.AppendRun("A dissertation on the sections of fruit.", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); paraBldr.CreateParagraph(sectionCur.ContentOA); // finish the section info m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint(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); // 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(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[0]; Assert.AreEqual(0, firstPara.Contents.Length); Assert.AreEqual(stylePara.Name, firstPara.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public override void TestSetup() { base.TestSetup(); m_bldr = new StTxtParaBldr(Cache); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts a note referencing the currently selected paragraph. /// </summary> /// <param name="noteType">Type of note</param> /// <param name="startRef">reference at beginning of selection</param> /// <param name="endRef">reference at end of selection</param> /// <param name="topObj">The object where quoted text begins.</param> /// <param name="bottomObj">The object where quoted text ends.</param> /// <param name="startOffset">The starting character offset.</param> /// <param name="endOffset">The ending character offset.</param> /// <param name="tssQuote">The text of the quote.</param> /// <returns>The inserted note</returns> /// ------------------------------------------------------------------------------------ public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef, BCVRef endRef, ICmObject topObj, ICmObject bottomObj, int startOffset, int endOffset, ITsString tssQuote) { CheckDisposed(); int iPos; IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[startRef.Book - 1]; StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache); quoteParaBldr.ParaStyleName = ScrStyleNames.Remark; quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote); IScrScriptureNote annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj, noteType.Guid, startOffset, endOffset, quoteParaBldr, null, null, null, out iPos); RegisterScrollCallBack(startRef.Book, iPos); // REVIEW: Do we need to create a synch record? return annotation; }