int m_wsUr; // Urdu writing system (used for Foreign style) #endregion #region Test setup /// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_inMemoryCache.InitializeWritingSystemEncodings(); // create footnote m_footnote = new StFootnote(); m_book = (ScrBook)m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_book.FootnotesOS.Append(m_footnote); m_footnote.FootnoteMarker.Text = "o"; m_footnote.DisplayFootnoteMarker = true; m_footnote.DisplayFootnoteReference = false; // create one empty footnote para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); m_strFact = TsStrFactoryClass.Create(); m_vernWs = Cache.LangProject.DefaultVernacularWritingSystem; para.Contents.UnderlyingTsString = m_strFact.MakeString(string.Empty, m_vernWs); m_footnotePara = (StTxtPara)m_footnote.ParagraphsOS[0]; m_wsUr = InMemoryFdoCache.s_wsHvos.Ur; // used with 'foreign' character style m_wsDe = InMemoryFdoCache.s_wsHvos.De; // used for back translations m_wsEs = InMemoryFdoCache.s_wsHvos.Es; }
/// <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> /// Creates a blank dummy footnote. Used when a footnote object is missing. /// Note: This does not insert an ORC into the paragraph. The caller is fixing the ORC /// with a missing object. /// </summary> /// <param name="owner">The owner to which we will add a footnote.</param> /// <param name="iFootnote">The 0-based index where the footnote will be inserted in the /// owner.</param> /// <param name="paraContents">The paragraph string where the ORC is being fixed.</param> /// <param name="iRun">The 0-based index of the run from which we will get the writing /// system used in the footnote.</param> /// <returns>a blank general footnote</returns> /// ------------------------------------------------------------------------------------ protected override StFootnote CreateBlankDummyFootnoteNoRecursion(ICmObject owner, int iFootnote, ITsString paraContents, int iRun) { if (!(owner is IScrBook)) { return(base.CreateBlankDummyFootnoteNoRecursion(owner, iFootnote, paraContents, iRun)); } // get the writing system of the existing ORC run int nDummy; int ws = paraContents.get_Properties(iRun).GetIntPropValues( (int)FwTextPropType.ktptWs, out nDummy); // Make a dummy blank footnote IScripture scr = m_cache.LangProject.TranslatedScriptureOA; string sMarker = scr.GeneralFootnoteMarker; StFootnote newFootnote = ScrFootnote.CreateFootnoteInScrBook((IScrBook)owner, iFootnote, ref sMarker, m_cache, ws); // Create an empty footnote paragraph with properties with default style and writing system. StTxtPara footnotePara = new StTxtPara(); newFootnote.ParagraphsOS.Append(footnotePara); footnotePara.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); // Insert an empty run into the footnote paragraph in order to set the // default writing system. ITsStrFactory strFactory = TsStrFactoryClass.Create(); footnotePara.Contents.UnderlyingTsString = strFactory.MakeString(string.Empty, m_cache.DefaultVernWs); return(newFootnote); }
public void CreateTwoParagraphs() { // Build First IStTxtPara IParaStylePropsProxy proxy = new DummyProxy("MyParaStyle"); m_bldr.ParaStylePropsProxy = proxy; ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, m_wsArbitrary); m_bldr.AppendRun("Para 1", textProps); int iPara = m_text.ParagraphsOS.Count; IStTxtPara para1 = m_bldr.CreateParagraph(m_text, iPara); // verify paragraph 1 AssertEx.RunIsCorrect(para1.Contents, 0, "Para 1", null, m_wsArbitrary); // Build Second IStTxtPara -- Builder should have been cleared textProps = StyleUtils.CharStyleTextProps("BringBrangBrung", m_wsArbitrary); m_bldr.AppendRun("Para 2", textProps); IStTxtPara para2 = m_bldr.CreateParagraph(m_text, iPara + 1); Assert.AreEqual(m_text.ParagraphsOS[iPara], para1); Assert.AreEqual(m_text.ParagraphsOS[iPara + 1], para2); // Re-verify paragraph 1 AssertEx.RunIsCorrect(para1.Contents, 0, "Para 1", null, m_wsArbitrary); // verify paragraph 2 AssertEx.RunIsCorrect(para2.Contents, 0, "Para 2", "BringBrangBrung", m_wsArbitrary); }
public void CreateFromStringRep_twoParas() { ITsStrBldr bldr = m_footnotePara.Contents.GetBldr(); bldr.Replace(0, 0, "Paragraph One", null); m_footnotePara.Contents = bldr.GetString(); ReflectionHelper.SetField(typeof(ScrFootnote), "s_maxAllowedParagraphs", 2); // create second para IStTxtPara para = m_footnote.AddNewTextPara("Note Exegesis Paragraph"); bldr = TsStringUtils.MakeStrBldr(); bldr.Replace(0, 0, "Paragraph Two", StyleUtils.CharStyleTextProps("Foreign", m_wsUr)); para.Contents = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Paragraph One</RUN></P><P><PS>Note Exegesis Paragraph</PS>" + @"<RUN WS='ur' CS='Foreign'>Paragraph Two</RUN></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Helper function to add an empty noraml paragraph to the given section. /// </summary> /// <param name="section">The section where the empty paragraph will be added.</param> /// <param name="style">The style for the added paragraph.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected StTxtPara AddEmptyPara(IScrSection section, string style) { StTxtParaBldr paraBldr = new StTxtParaBldr(Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(style); return(paraBldr.CreateParagraph(section.ContentOA.Hvo)); }
public void Equals_FollowsGuidelines() { var sectionCur = Cache.ServiceLocator.GetInstance <IScrSectionFactory>().CreateScrSection( m_genesis, 0, "Verse One. ", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs), false); var stPara = (IScrTxtPara)sectionCur.ContentOA.ParagraphsOS[0]; using (var verseSet1 = new ScrVerseSet(stPara)) { using (var verseSet2 = new ScrVerseSet(stPara)) { using (var verseSet3 = new ScrVerseSet(stPara)) { // Iterate through the verses in the paragraph Assert.IsTrue(verseSet1.MoveNext()); Assert.IsTrue(verseSet2.MoveNext()); Assert.IsTrue(verseSet3.MoveNext()); var x = verseSet1.Current; var y = verseSet2.Current; var z = verseSet3.Current; Assert.IsTrue(x.Equals(x)); Assert.AreEqual(x.Equals(y), y.Equals(x)); Assert.AreEqual(x.Equals(z), x.Equals(y) && y.Equals(z)); Assert.AreEqual(x.Equals(y), x.Equals(y)); Assert.IsFalse(x.Equals(null)); } } } }
public void CreateTwoParagraphs() { CheckDisposed(); // Build First StTxtPara StTxtParaBldr bldr = new StTxtParaBldr(Cache); IParaStylePropsProxy proxy = new DummyProxy("MyParaStyle"); bldr.ParaStylePropsProxy = proxy; ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, m_wsArbitrary); bldr.AppendRun("Para 1", textProps); StText text = new StText(Cache, m_text.Hvo); int iPara = text.ParagraphsOS.Count; StTxtPara para1 = bldr.CreateParagraph(text.Hvo, iPara); // verify paragraph 1 AssertEx.RunIsCorrect(para1.Contents.UnderlyingTsString, 0, "Para 1", null, m_wsArbitrary); // Build Second StTxtPara -- Builder should have been cleared textProps = StyleUtils.CharStyleTextProps("BringBrangBrung", m_wsArbitrary); bldr.AppendRun("Para 2", textProps); StTxtPara para2 = bldr.CreateParagraph(text.Hvo, iPara + 1); Assert.AreEqual(text.ParagraphsOS[iPara].Hvo, para1.Hvo); Assert.AreEqual(text.ParagraphsOS[iPara + 1].Hvo, para2.Hvo); // Re-verify paragraph 1 AssertEx.RunIsCorrect(para1.Contents.UnderlyingTsString, 0, "Para 1", null, m_wsArbitrary); // verify paragraph 2 AssertEx.RunIsCorrect(para2.Contents.UnderlyingTsString, 0, "Para 2", "BringBrangBrung", m_wsArbitrary); }
public void AppendParagraph() { CheckDisposed(); // Build an StTxtPara StTxtParaBldr bldr = new StTxtParaBldr(Cache); IParaStylePropsProxy proxy = new DummyProxy("Para Meister"); bldr.ParaStylePropsProxy = proxy; ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, Cache.LanguageEncodings.Item(0).Hvo); bldr.AppendRun("Run 1", textProps); StText text = new StText(Cache, m_text.Hvo); int iPara = text.ParagraphsOS.Count; StTxtPara para = bldr.CreateParagraph(text.Hvo); // verify paragraph's state Assert.IsNotNull(para); Assert.AreEqual(proxy.Props, para.StyleRules); AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 0, "Run 1", null, m_wsArbitrary); Assert.AreEqual(para.Hvo, text.ParagraphsOS[iPara].Hvo); // Builder should now be cleared Assert.AreEqual(0, bldr.Length); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Save the object match criteria in this cell's Contents field as an ITsString. /// </summary> /// ------------------------------------------------------------------------------------ private void SaveObjectMatchCriteria() { ITsStrBldr bldr = TsStrBldrClass.Create(); string sCriteria = string.Empty; if (m_comparisonType == ComparisionTypes.kMatches) { sCriteria = (m_matchEmpty ? "Empty or Matches " : "Matches "); } else if (m_matchEmpty) { sCriteria = "Empty"; } ITsTextProps ttp = StyleUtils.CharStyleTextProps(null, m_cache.DefaultUserWs); bldr.Replace(0, 0, sCriteria, ttp); if (m_matchValue > 0) { StringUtils.InsertOrcIntoPara(m_cache.GetGuidFromId(m_matchValue), FwObjDataTypes.kodtNameGuidHot, bldr, bldr.Length, bldr.Length, m_cache.DefaultUserWs); } if (m_matchSubitems) { sCriteria = (m_matchValue > 0) ? " +subitems" : "+subitems"; bldr.Replace(bldr.Length, bldr.Length, sCriteria, ttp); } Contents.UnderlyingTsString = bldr.GetString(); }
public void AppendTwoRuns_WithAndWithoutNamedCharStyles() { CheckDisposed(); // Build an StTxtPara StTxtParaBldr bldr = new StTxtParaBldr(Cache); IParaStylePropsProxy proxy = new DummyProxy("Para Meister"); bldr.ParaStylePropsProxy = proxy; ITsTextProps textProps = StyleUtils.CharStyleTextProps(null, m_wsArbitrary); bldr.AppendRun("Run 1 ", textProps); textProps = StyleUtils.CharStyleTextProps("Italic Run", m_wsArbitrary); // verify its length Assert.AreEqual(6, bldr.Length); // add another run bldr.AppendRun("Run 2", textProps); StTxtPara para = bldr.CreateParagraph(m_text.Hvo, 1); // verify paragraph's state Assert.IsNotNull(para); Assert.AreEqual(proxy.Props, para.StyleRules); AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 0, "Run 1 ", null, m_wsArbitrary); AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 1, "Run 2", "Italic Run", m_wsArbitrary); // Builder should now be cleared Assert.AreEqual(0, bldr.Length); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verify misc. stuff about the specified section, just inserted into a book. We expect /// a section with 1) section head with one empty para, 2) contents with one para with /// one run, having the specified details. /// </summary> /// <param name="section">Section to verify</param> /// <param name="isIntro">true if an intro paragraph, false if a scripture para</param> /// <param name="contentRunText"></param> /// <param name="contentRunStyle"></param> /// <param name="contentRunWS"></param> /// <param name="verseRef"></param> /// ------------------------------------------------------------------------------------ public static void VerifyInsertedBookSection(IScrSection section, bool isIntro, string contentRunText, string contentRunStyle, int contentRunWS, int verseRef) { // Verify the new section heading paragraph count and the first para's style. Assert.AreEqual(1, section.HeadingOA.ParagraphsOS.Count, "Incorrect number of paras in section heading."); IStTxtPara para = (IStTxtPara)section.HeadingOA.ParagraphsOS[0]; Assert.AreEqual(StyleUtils.ParaStyleTextProps( isIntro ? ScrStyleNames.IntroSectionHead : ScrStyleNames.SectionHead), para.StyleRules); // Verify there's one content paragraph in new section, and its para style. Assert.AreEqual(1, section.ContentOA.ParagraphsOS.Count); para = (StTxtPara)section.ContentOA.ParagraphsOS[0]; //first para Assert.AreEqual(StyleUtils.ParaStyleTextProps( isIntro ? ScrStyleNames.IntroParagraph : ScrStyleNames.NormalParagraph), para.StyleRules); // Verify the paragraph has one run, with specified text, style, & ws. Assert.AreEqual(1, para.Contents.UnderlyingTsString.RunCount); AssertEx.RunIsCorrect(para.Contents.UnderlyingTsString, 0, contentRunText, contentRunStyle, contentRunWS); // Check the section verse refs VerifySectionRefs(section, verseRef, verseRef, verseRef, verseRef); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create test data in a right-to-left script. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { // Set the default writing system to a right-to-left writing system (Urdu) m_wsUrdu = InMemoryFdoCache.s_wsHvos.Ur; m_scrInMemoryCache.ChangeDefaultVernWs(m_wsUrdu); LgWritingSystem defWs = new LgWritingSystem(Cache, Cache.DefaultVernWs); // Add basic data for Genesis m_genesis = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_scrInMemoryCache.AddTitleToMockedBook(1, m_StartText); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, null); m_scrInMemoryCache.AddFormatTextToMockedPara(m_genesis, para, @"\c12\v13-14\*" + m_WordsText, m_wsUrdu); section.AdjustReferences(); // Add footnote ITsTextProps normalFootnoteParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); StFootnote footnote = m_scrInMemoryCache.AddFootnote(m_genesis, para, 10); StTxtPara footPara = new StTxtPara(); footnote.ParagraphsOS.Append(footPara); footPara.StyleRules = normalFootnoteParaProps; ITsStrFactory strfact = TsStrFactoryClass.Create(); footPara.Contents.UnderlyingTsString = strfact.MakeString(m_WordsText, m_wsUrdu); }
public void CreateFromStringRep_twoParas() { CheckDisposed(); ITsStrBldr bldr = m_footnotePara.Contents.UnderlyingTsString.GetBldr(); bldr.Replace(0, 0, "Paragraph One", null); m_footnotePara.Contents.UnderlyingTsString = bldr.GetString(); // create second para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps("Note Exegesis Paragraph"); bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Paragraph Two", StyleUtils.CharStyleTextProps("Foreign", m_wsUr)); para.Contents.UnderlyingTsString = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Paragraph One</RUN></P><P><PS>Note Exegesis Paragraph</PS>" + @"<RUN WS='ur' CS='Foreign'>Paragraph Two</RUN></P></FN>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Helper method to set up the test paragraph in m_archivedText, including footnotes /// and back translations, plus any other fields deemed necessary. /// </summary> /// ------------------------------------------------------------------------------------ private StTxtPara SetUpParagraphInArchiveWithFootnotesAndBT() { // Prepare the Revision paragraph in m_archivedText // note: CreateTestData has already placed "11This is the previous version of the text." // in paragraph in m_archivedText. StTxtPara paraRev = (StTxtPara)m_archivedText.ParagraphsOS[0]; paraRev.StyleRules = StyleUtils.ParaStyleTextProps("Line 1"); // add footnotes to existing paragraph. StFootnote footnote1 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, paraRev, 6, "Footnote1"); StFootnote footnote2 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, paraRev, 10, "Footnote2"); Assert.AreEqual(2, m_archivedFootnotesOS.Count); // Add two back translations of the para and footnotes int[] wsBt = new int[] { InMemoryFdoCache.s_wsHvos.En, InMemoryFdoCache.s_wsHvos.De }; foreach (int ws in wsBt) { // add back translation of the para, and status ICmTranslation paraTrans = m_inMemoryCache.AddBtToMockedParagraph(paraRev, ws); m_inMemoryCache.AddRunToMockedTrans(paraTrans, ws, "BT of test paragraph" + ws.ToString(), null); paraTrans.Status.SetAlternative(BackTranslationStatus.Finished.ToString(), ws); // add BT footnotes, and status ICmTranslation footnoteTrans = m_inMemoryCache.AddFootnoteORCtoTrans(paraTrans, 2, ws, footnote1, "BT of footnote1 " + ws.ToString()); footnoteTrans.Status.SetAlternative(BackTranslationStatus.Checked.ToString(), ws); footnoteTrans = m_inMemoryCache.AddFootnoteORCtoTrans(paraTrans, 6, ws, footnote2, "BT of footnote2 " + ws.ToString()); footnoteTrans.Status.SetAlternative(BackTranslationStatus.Finished.ToString(), ws); } return(paraRev); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { ITsStrFactory strfact = TsStrFactoryClass.Create(); //Jude IScrBook jude = m_scrInMemoryCache.AddBookToMockedScripture(65, "Jude"); m_scrInMemoryCache.AddTitleToMockedBook(jude.Hvo, "Jude"); // Jude Scripture section IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(jude.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "First section", "Section Head"); StTxtPara judePara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, "Paragraph"); m_scrInMemoryCache.AddRunToMockedPara(judePara, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(judePara, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(judePara, "This is the first verse", null); // Insert footnote into para 1 of Jude ITsStrBldr bldr = judePara.Contents.UnderlyingTsString.GetBldr(); StFootnote foot = ScrFootnote.InsertFootnoteAt(jude, 0, bldr, 10, "#"); StTxtPara footPara = new StTxtPara(); foot.ParagraphsOS.Append(footPara); footPara.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); footPara.Contents.UnderlyingTsString = strfact.MakeString("This is text for the footnote.", Cache.DefaultVernWs); judePara.Contents.UnderlyingTsString = bldr.GetString(); section.AdjustReferences(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create and Check an Annotation /// </summary> /// <param name="hvoParaStart">The hvo para start.</param> /// <param name="hvoParaEnd">The hvo para end.</param> /// <param name="startRef">The start ref.</param> /// <param name="endRef">The end ref.</param> /// <param name="startOffset">The start offset.</param> /// <param name="endOffset">The end offset.</param> /// <param name="tssQuote">The text in the quote.</param> /// <param name="sel">selection in main window</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private IScrScriptureNote CreateAndCheckAnnotation(ICmObject topObj, ICmObject bottomObj, int startRef, int endRef, int startOffset, int endOffset, string strQuote) { ILangProject lp = Cache.LangProject; ICmAnnotationDefn transNoteAnnDefn = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().TranslatorAnnotationDefn; // Get information from the selection about the location of the annotation. ITsStrBldr tssBldrQuote = TsStrBldrClass.Create(); tssBldrQuote.Replace(0, 0, strQuote, StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrScriptureNote ann = m_notesEditingHelper.InsertNote(transNoteAnnDefn, startRef, endRef, topObj, bottomObj, startOffset, endOffset, tssBldrQuote.GetString()); Assert.IsNotNull(ann); Assert.AreEqual(transNoteAnnDefn, ann.AnnotationTypeRA, "Wrong type of note created"); Assert.AreEqual(topObj, ann.BeginObjectRA, "Wrong paragraph annotated"); Assert.AreEqual(bottomObj, ann.EndObjectRA, "Wrong paragraph annotated"); Assert.AreEqual(startRef, ann.BeginRef, "Should have the correct start para reference"); Assert.AreEqual(endRef, ann.EndRef, "Should have the correct end para reference"); Assert.AreEqual(startOffset, ann.BeginOffset, "Should have the correct starting char offset"); Assert.AreEqual(endOffset, ann.EndOffset, "Should have the correct ending char offset"); Assert.AreEqual(lp.DefaultUserAgent, ann.SourceRA, "Wrong agent"); VerifyInitializedText(ann.DiscussionOA, "Discussion"); Assert.AreEqual(tssBldrQuote.Text, ((IStTxtPara)ann.QuoteOA.ParagraphsOS[0]).Contents.Text); VerifyInitializedText(ann.RecommendationOA, "Recommendation"); VerifyInitializedText(ann.ResolutionOA, "Resolution"); return(ann); }
/// <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> /// Saves the paragraphs contained in this paragraph collection to the specified text /// </summary> /// <param name="text">The journal text (i.e., quote, discussion, suggestion, /// resolution, etc.) to write the paragraphs to</param> /// ------------------------------------------------------------------------------------ internal void WriteToCache(IStJournalText text) { Debug.Assert(text != null); if (text == null) { return; } if (text.ParagraphsOS.Count == 0 && Count == 0) { // Create one empty paragraph even if there's no data. IStPara para = text.ParagraphsOS.Append(new StTxtPara()); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark); return; } foreach (IStTxtPara para in text.ParagraphsOS) { if (para == null) { continue; } ParaMatchType type; int iPara = FindMatchingParagraph(para, out type); switch (type) { case ParaMatchType.Exact: // new is same as old, just discard the imported paragraph. RemoveAt(iPara); break; case ParaMatchType.Contains: // no new information, just discard the imported paragraph. // REVIEW: this may indicate a deletion. RemoveAt(iPara); break; case ParaMatchType.IsContained: // we have new information added to an existing paragraph. // (or could it be a deletion?) // replace the current paragraph. para.Contents.UnderlyingTsString = this[iPara].StringBuilder.GetString(); para.StyleRules = this[iPara].ParaStylePropsProxy.Props; RemoveAt(iPara); break; case ParaMatchType.None: // Existing paragraph was not found in the list of imported paras. // REVIEW: this may indicate a deletion. break; } } // Append any new paragraphs to the list of paragraphs in the text. foreach (StTxtParaBldr paraBldr in this) { paraBldr.CreateParagraph(text.Hvo); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create and Check an Annotation /// </summary> /// <param name="hvoParaStart">The hvo para start.</param> /// <param name="hvoParaEnd">The hvo para end.</param> /// <param name="startRef">The start ref.</param> /// <param name="endRef">The end ref.</param> /// <param name="startOffset">The start offset.</param> /// <param name="endOffset">The end offset.</param> /// <param name="tssQuote">The text in the quote.</param> /// <param name="sel">selection in main window</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private IScrScriptureNote CreateAndCheckAnnotation(int hvoObjStart, int hvoObjEnd, int startRef, int endRef, int startOffset, int endOffset, string strQuote) { ILangProject lp = Cache.LangProject; CmAnnotationDefn transNoteAnnDefn = new CmAnnotationDefn(Cache, LangProject.kguidAnnTranslatorNote); // Get information from the selection about the location of the annotation. CmObject topObj = (CmObject)CmObject.CreateFromDBObject(m_inMemoryCache.Cache, hvoObjStart); CmObject bottomObj = (CmObject)CmObject.CreateFromDBObject(m_inMemoryCache.Cache, hvoObjEnd); int wsSelector = -1; ITsStrBldr tssBldrQuote = TsStrBldrClass.Create(); tssBldrQuote.Replace(0, 0, strQuote, StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark)); IScrScriptureNote ann = m_notesEditingHelper.InsertNote(transNoteAnnDefn, startRef, endRef, topObj, bottomObj, wsSelector, startOffset, endOffset, tssBldrQuote.GetString()); Assert.IsNotNull(ann); Assert.AreEqual(transNoteAnnDefn.Hvo, ann.AnnotationTypeRAHvo, "Wrong type of note created"); Assert.AreEqual(hvoObjStart, ann.BeginObjectRAHvo, "Wrong paragraph annotated"); Assert.AreEqual(hvoObjEnd, ann.EndObjectRAHvo, "Wrong paragraph annotated"); Assert.AreEqual(startRef, ann.BeginRef, "Should have the correct start para reference"); Assert.AreEqual(endRef, ann.EndRef, "Should have the correct end para reference"); Assert.AreEqual(startOffset, ann.BeginOffset, "Should have the correct starting char offset"); Assert.AreEqual(endOffset, ann.EndOffset, "Should have the correct ending char offset"); Assert.AreEqual(lp.DefaultUserAgent.Hvo, ann.SourceRAHvo, "Wrong agent"); VerifyInitializedText(ann.DiscussionOA, "Discussion"); Assert.AreEqual(tssBldrQuote.Text, ((StTxtPara)ann.QuoteOA.ParagraphsOS[0]).Contents.Text); VerifyInitializedText(ann.RecommendationOA, "Recommendation"); VerifyInitializedText(ann.ResolutionOA, "Resolution"); return(ann); }
public void InsertVerseNumber_Verse2NoVerse1() { CheckDisposed(); // Remove the formatting on the verse number so it doesn't interfere with the test. m_draftView.SelectRangeOfChars(1, 11, 0, 1, 2); m_draftView.EditingHelper.RemoveCharFormattingWithUndo(); // Set the IP in the middle of verse James 4:1 when there is no verse number 1 m_draftView.SetInsertionPoint(1, 11, 0, 8, true); // insert verse num 2 at the IP m_draftView.InsertVerseNumber(); ScrBook book = (ScrBook)m_cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS[1]; StTxtPara para = (StTxtPara)((ScrSection)book.SectionsOS[11]).ContentOA.ParagraphsOS[0]; ITsString tss = para.Contents.UnderlyingTsString; AssertEx.RunIsCorrect(tss, 0, "4", "Chapter Number", m_cache.DefaultVernWs); Assert.AreEqual("1Where ", para.Contents.UnderlyingTsString.get_RunText(1).Substring(0, 7)); Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs), para.Contents.UnderlyingTsString.get_Properties(1)); AssertEx.RunIsCorrect(tss, 2, "2", "Verse Number", m_cache.DefaultVernWs); Assert.AreEqual("do all the fights", para.Contents.UnderlyingTsString.get_RunText(3).Substring(0, 17)); Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs), para.Contents.UnderlyingTsString.get_Properties(3)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Insert a book /// </summary> /// <returns>The new book</returns> /// ------------------------------------------------------------------------------------ public IScrBook Do() { IScripture scr = m_cache.LangProject.TranslatedScriptureOA; int hvoTitle; IScrBook newBook = ScrBook.CreateNewScrBook(m_bookID, scr, out hvoTitle); m_bookHvo = newBook.Hvo; // Insert the new book title and set the book names newBook.InitTitlePara(); newBook.Name.CopyAlternatives(newBook.BookIdRA.BookName); newBook.Abbrev.CopyAlternatives(newBook.BookIdRA.BookAbbrev); // Now insert the first section for the new book. ITsTextProps textProps = StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, m_cache.DefaultVernWs); ScrSection.CreateScrSection(newBook, 0, scr.ConvertToString(1), textProps, false); // Do synchronize stuff if (FwApp.App != null) { FwApp.App.Synchronize(new SyncInfo(SyncMsg.ksyncReloadScriptureControl, 0, 0), m_cache); } // Use Redo for rest of sync'ing and updating book filter Redo(false); return(newBook); }
public void OnAddWordGlossesToFreeTrans_ORCs() { ISegment seg = m_para0_0.SegmentsOS[0]; ITsStrBldr strBldr = m_para0_0.Contents.GetBldr(); Guid footnoteGuid = Guid.NewGuid(); TsStringUtils.InsertOrcIntoPara(footnoteGuid, FwObjDataTypes.kodtOwnNameGuidHot, strBldr, 7, 7, Cache.DefaultVernWs); UndoableUnitOfWorkHelper.Do("undo Add ORC", "redo Add ORC", Cache.ActionHandlerAccessor, () => { m_para0_0.Contents = strBldr.GetString(); }); SetUpMocksForOnAddWordGlossesToFreeTransTest(seg); SetUpGlosses(seg, "hope", null, "this", "works"); m_interlinDoc.OnAddWordGlossesToFreeTrans(null); strBldr.Clear(); strBldr.Replace(0, 0, "hope this works.", StyleUtils.CharStyleTextProps(null, Cache.DefaultAnalWs)); TsStringUtils.InsertOrcIntoPara(footnoteGuid, FwObjDataTypes.kodtNameGuidHot, strBldr, 4, 4, Cache.DefaultAnalWs); AssertEx.AreTsStringsEqual(strBldr.GetString(), seg.FreeTranslation.AnalysisDefaultWritingSystem); }
public void ExportNotationParagraphs_WritingSystems() { IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_book.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); IScrScriptureNote note = m_scrInMemoryCache.AddAnnotation(para, new BCVRef(01001001), NoteType.Translator, "This is some text with espa\u00F1ol."); TsStringAccessor tssaDisc = ((StTxtPara)note.DiscussionOA.ParagraphsOS[0]).Contents; ITsStrBldr bldr = tssaDisc.UnderlyingTsString.GetBldr(); bldr.SetProperties(bldr.Length - 8, bldr.Length - 1, StyleUtils.CharStyleTextProps(null, InMemoryFdoCache.s_wsHvos.Es)); tssaDisc.UnderlyingTsString = bldr.GetString(); StringWriter stream = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(stream); m_exporter = new ExportXml(null, Cache, null, ExportWhat.AllBooks, 0, 0, 0, "ExportNotationParagraphs_WritingSystems"); ReflectionHelper.SetField(m_exporter, "m_writer", writer); ReflectionHelper.CallMethod(m_exporter, "ExportNotationParagraphs", note.DiscussionOA, "notationDiscussion"); Assert.AreEqual("<notationDiscussion><para xml:lang=\"en\">" + "<span>This is some text with </span>" + "<span xml:lang=\"es\">espa\u00F1ol</span>" + "<span>.</span>" + "</para></notationDiscussion>", stream.ToString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Performs a bunch of verifications in a draft view after a scripture book has been /// inserted. /// </summary> /// <param name="selHelper">The selection helper represnting the selection that is /// made when the book is inserted.</param> /// ------------------------------------------------------------------------------------ private void VerifyInsertedBookInDraftView(SelectionHelper selHelper) { bool fAssocPrev; int ich, hvoObj, tag, enc; ITsString tss; // Make sure that IP has been given appropriate properties for typing regular // vernacular text (not continuing to enter text using "Chapter Number" style). Assert.AreEqual(4, selHelper.NumberOfLevels); // This better be the first book in the view. Assert.AreEqual(0, selHelper.LevelInfo[3].ihvo); // Since this book was just inserted, we should be in the first section. Assert.AreEqual(0, selHelper.LevelInfo[2].ihvo); // The InsertBook command should leave our insertion point in the Content of // this section (as opposed to the section Heading). Assert.AreEqual(ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); // We should be in the first paragraph of that section's content. Assert.AreEqual(0, selHelper.LevelInfo[0].ihvo); // We should have a simple IP, not a range selection Assert.IsFalse(selHelper.IsRange); Assert.AreEqual(1, selHelper.IchAnchor, "IP should follow chapter number"); #if WANTTESTPORT // (TE) This is probably unnecessary. If needed at all, we can probably change the selection props whenever a selection is created next to a chapter number. // If the user starts typing, they should be entering regular vernacular text Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_wsVern), selHelper.SelProps); #endif }
/// ------------------------------------------------------------------------------------ /// <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="scrInMemoryCache">in-memory cache to use for testing</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. Can be a simple string /// or a format string. (See CreateText for the definition of the format string)</param> /// <param name="paraStyleName">paragraph style to apply to the section head</param> /// <returns>The newly created section</returns> /// ------------------------------------------------------------------------------------ internal static ScrSection CreateSection(ScrInMemoryFdoCache scrInMemoryCache, IScrBook book, string sSectionHead, string paraStyleName) { // Create a section ScrSection section = new ScrSection(); book.SectionsOS.Append(section); // Create a section head for this section section.HeadingOA = new StText(); if (sSectionHead.Length == 0 || sSectionHead[0] != '\\') { // create a simple section head with no character style StTxtParaBldr paraBldr = new StTxtParaBldr(scrInMemoryCache.Cache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(paraStyleName); paraBldr.AppendRun(sSectionHead, StyleUtils.CharStyleTextProps(null, scrInMemoryCache.Cache.DefaultVernWs)); paraBldr.CreateParagraph(section.HeadingOAHvo); } else { // Create a more complex section head from the given format string // insert a new para in the title StTxtPara para = new StTxtPara(); section.HeadingOA.ParagraphsOS.Append(para); // set the para's fields scrInMemoryCache.AddFormatTextToMockedPara(book, para, sSectionHead, scrInMemoryCache.Cache.DefaultVernWs); para.StyleRules = StyleUtils.ParaStyleTextProps(paraStyleName); } section.ContentOA = new StText(); section.AdjustReferences(); return(section); }
public void UserPromptForBookTitleWithEmptyPara() { CheckDisposed(); // Set up title with an empty paragraph StText title = m_inMemoryCache.AddTitleToMockedBook(m_book.Hvo, m_emptyTsString, StyleUtils.ParaStyleTextProps(ScrStyleNames.MainBookTitle)); Options.ShowEmptyParagraphPromptsSetting = true; DummyTeStVc stVc = new DummyTeStVc(m_inMemoryCache.Cache, m_inMemoryCache.Cache.DefaultVernWs); CreateExpectedUserPrompt(stVc, title.ParagraphsOS.FirstItem.Hvo, (int)ScrBook.ScrBookTags.kflidTitle, (int)StTxtPara.StTxtParaTags.kflidContents); m_vwenvMock.ExpectAndReturn("CurrentObject", title.ParagraphsOS.FirstItem.Hvo); IVwEnv vwEnv = (IVwEnv)m_vwenvMock.MockInstance; bool fTextAdded = stVc.CallInsertUserPrompt(vwEnv, title.ParagraphsOS.FirstItem.Hvo); Assert.IsTrue(fTextAdded, "User prompt not added"); ITsString text = stVc.DisplayVariant(vwEnv, SimpleRootSite.kTagUserPrompt, null, (int)ScrBook.ScrBookTags.kflidTitle); string difference; bool fEqual = TsStringHelper.TsStringsAreEqual( ExpectedUserPrompt("Type book title for Philemon here", m_inMemoryCache.Cache.DefaultVernWs), text, out difference); Assert.IsTrue(fEqual, difference); m_vwenvMock.Verify(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Save the object match criteria in this cell's Contents field as an ITsString. /// </summary> /// <param name="matchVal">The match value.</param> /// ------------------------------------------------------------------------------------ private void SaveObjectMatchCriteria(ICmPossibility matchVal) { ITsStrBldr bldr = TsStringUtils.MakeStrBldr(); string sCriteria = string.Empty; if (m_comparisonType == ComparisonTypes.kMatches) { sCriteria = (m_matchEmpty ? "Empty or Matches " : "Matches "); } else if (m_matchEmpty) { sCriteria = "Empty"; } ITsTextProps ttp = StyleUtils.CharStyleTextProps(null, m_cache.DefaultUserWs); bldr.Replace(0, 0, sCriteria, ttp); if (matchVal != null) { bldr.AppendOrc(matchVal.Guid, FwObjDataTypes.kodtNameGuidHot, m_cache.DefaultUserWs); } if (m_matchSubitems) { sCriteria = (matchVal != null ? " " : string.Empty) + "+subitems"; bldr.Replace(bldr.Length, bldr.Length, sCriteria, ttp); } Contents = bldr.GetString(); InitializeMatchValuesArray(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Used by constructor. /// Sets the text property vars for this proxy, from the name, type, and ws /// </summary> /// ------------------------------------------------------------------------------------ private void SetTextProps() { if (m_Context == ContextValues.EndMarker || m_sStyleName == null || m_sStyleName == string.Empty) { // props are not relevant for end markers or markers with no style name m_ttpRunProps = m_ws == 0 ? null : StyleUtils.CharStyleTextProps(null, m_ws); m_rgbParaProps = null; return; } Debug.Assert(m_StyleType == StyleType.kstCharacter || m_StyleType == StyleType.kstParagraph); Debug.Assert(m_ws != 0); // For char style, the run props contain writing system & char style name; for para // style, they contain only the writing system. m_ttpRunProps = StyleUtils.CharStyleTextProps( (m_StyleType == StyleType.kstCharacter) ? m_sStyleName : null, m_ws); // For char style, the paragraph props are empty; for para style, they contain the // para style name. if (m_StyleType == StyleType.kstParagraph) { ITsTextProps props = StyleUtils.ParaStyleTextProps(m_sStyleName); using (ArrayPtr rgbFmtBufPtr = MarshalEx.ArrayToNative <byte>(kcbFmtBufMax)) { int nBytes = props.SerializeRgb(rgbFmtBufPtr, kcbFmtBufMax); m_rgbParaProps = MarshalEx.NativeToArray <byte>(rgbFmtBufPtr, nBytes); } } else { m_rgbParaProps = null; } }
public void GetTextRepresentation_twoParas() { CheckDisposed(); m_footnotePara.Contents.UnderlyingTsString = m_strFact.MakeString("Paragraph One", m_vernWs); // create second para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); // Set the paragraph style para.StyleRules = StyleUtils.ParaStyleTextProps("Note Exegesis Paragraph"); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Paragraph Two", StyleUtils.CharStyleTextProps( "Foreign", m_wsUr)); para.Contents.UnderlyingTsString = bldr.GetString(); string result = m_footnote.GetTextRepresentation(); Assert.AreEqual(@"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Paragraph One</RUN></P><P><PS>Note Exegesis Paragraph</PS>" + @"<RUN WS='ur' CS='Foreign'>Paragraph Two</RUN></P></FN>", result); }