public void CreateOwnedObjects_AtEnd() { CheckDisposed(); StTxtPara para = (StTxtPara)m_currentText.ParagraphsOS[0]; // We use m_archivedText with para from m_currentText to create a footnote. // This simulates a "paragraph with footnote" just copied from m_archivedText. // The important thing here is that we have a footnote that links to a // different owner. m_archivedFootnotesOS = m_inMemoryCache.CreateArbitraryFootnoteSequence(m_archivedText); m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, para, para.Contents.Length, null); int paraLen = para.Contents.Length; NMock.DynamicMock mockIObjectMetaInfoProvider = new DynamicMock(typeof(IObjectMetaInfoProvider)); mockIObjectMetaInfoProvider.Strict = true; mockIObjectMetaInfoProvider.ExpectAndReturn("NextFootnoteIndex", 0, new object[] { para, paraLen - 1 }); mockIObjectMetaInfoProvider.SetupResult("FootnoteMarkerStyle", "Note Marker"); Assert.AreEqual(0, m_currentFootnotesOS.Count); para.CreateOwnedObjects(paraLen - 1, paraLen, (IObjectMetaInfoProvider)mockIObjectMetaInfoProvider.MockInstance); mockIObjectMetaInfoProvider.Verify(); Assert.AreEqual(1, m_currentFootnotesOS.Count); VerifyFootnote((StFootnote)m_currentFootnotesOS[0], para, paraLen - 1); }
public void GoToNextSection() { FdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS; // Start in the title of the second book. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 1, 0); m_draftView.TeEditingHelper.GoToNextSection(); VerifySelection(4, 1, 0, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); // Start in the last section of the first book. IScrBook book = books[0]; m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, 0, book.SectionsOS.Count - 1); m_draftView.TeEditingHelper.GoToNextSection(); VerifySelection(4, 1, 0, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); // Start in the last para of the contents of the last section of the last book. int iBook = books.Count - 1; book = books[iBook]; int iSection = book.SectionsOS.Count - 1; IScrSection lastSection = book.SectionsOS[iSection]; int iPara = lastSection.ContentOA.ParagraphsOS.Count - 1; m_draftView.TeEditingHelper.SetInsertionPoint(iBook, iSection, iPara, 2, true); // Nothing should move m_draftView.TeEditingHelper.GoToNextSection(); VerifySelection(4, iBook, iSection, (int)ScrSection.ScrSectionTags.kflidContent, 2, 2); // Check the para SelectionHelper selHelper = SelectionHelper.Create(m_draftView); Assert.AreEqual(iPara, selHelper.LevelInfo[0].ihvo); // Start with a multi-text range selection IScrBook startBook = books[0]; m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, 0, startBook.SectionsOS.Count - 2); IVwSelection vwsel1 = m_draftView.RootBox.Selection; m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, 0, startBook.SectionsOS.Count - 3); IVwSelection vwsel2 = m_draftView.RootBox.Selection; m_draftView.RootBox.MakeRangeSelection(vwsel1, vwsel2, true); m_draftView.TeEditingHelper.GoToNextSection(); VerifySelection(4, 0, startBook.SectionsOS.Count - 1, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determine where in the annotation list to insert a new annotation having the /// specified startRef, beginning object and beginning offset. /// </summary> /// <param name="startRef">The start ref.</param> /// <param name="beginObject">The begin object.</param> /// <param name="begOffset">The beg offset.</param> /// ------------------------------------------------------------------------------------ private int GetNewNotesInsertIndex(BCVRef startRef, ICmObject beginObject, int begOffset) { // Get the index within the book of the section containing the paragraph // containing the reference to which the new annotation corresponds. int iNewNoteSection; int iNewNotePara; GetLocationInfoForObj(beginObject, out iNewNoteSection, out iNewNotePara); FdoOwningSequence <IScrScriptureNote> notes = NotesOS; int insertIndex = notes.Count; // Go backward through the list of existing annotations. for (int i = notes.Count - 1; i >= 0; i--) { IScrScriptureNote note = notes[i]; int iSect, iPara; GetLocationInfoForObj(note.BeginObjectRA, out iSect, out iPara); // If the annotation is for text that follows the text associated // with the new annotation we're adding, then decrement the index // of where to insert the new annotation. if (note.BeginRef > startRef || iSect > iNewNoteSection || (iSect == iNewNoteSection && iPara > iNewNotePara) || (iSect == iNewNoteSection && iPara == iNewNotePara && note.BeginOffset > begOffset)) { insertIndex--; } } return(insertIndex); }
public void MergeOwningCollection() { CheckDisposed(); // 25 LexEntry.MorphoSyntaxAnalyses ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); FdoOwningSequence<ICmPossibility> posSeq = Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS; posSeq.Append(new PartOfSpeech()); posSeq.Append(new PartOfSpeech()); // Merge content into null. IMoStemMsa msaSrc = (IMoStemMsa)lmeSrc.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); msaSrc.PartOfSpeechRA = (IPartOfSpeech)posSeq[0]; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(1, lmeKeeper.MorphoSyntaxAnalysesOC.Count); Assert.AreEqual(msaSrc.Hvo, lmeKeeper.MorphoSyntaxAnalysesOC.HvoArray[0]); // Merge content into content. lmeSrc = m_entriesCol.Add(new LexEntry()); IMoStemMsa msaSrc2 = (IMoStemMsa)lmeSrc.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); msaSrc2.PartOfSpeechRA = (IPartOfSpeech)posSeq[1]; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(2, lmeKeeper.MorphoSyntaxAnalysesOC.Count); }
public void GoToNextBook() { FdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS; // Set up to start in the the second to last book. IScrBook book = books[0]; m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 0, 0); for (int i = 1; i < books.Count - 1; i++) { // Goto next book and verify we moved. m_draftView.TeEditingHelper.GoToNextBook(); VerifySelection(3, i, 0, (int)ScrBook.ScrBookTags.kflidTitle, 0, 0); } // The difference between the two loops is that this one starts at the first section // of the content of the book for (int i = 0; i < books.Count - 2; i++) { // Goto the first section's contents. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, i, 0); // Goto next book and verify we moved m_draftView.TeEditingHelper.GoToNextBook(); VerifySelection(3, i + 1, 0, (int)ScrBook.ScrBookTags.kflidTitle, 0, 0); } // Goto the last section's contents in the first book. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, books.Count - 1, 0); // Goto previous book and verify we didn't move m_draftView.TeEditingHelper.GoToNextBook(); VerifySelection(4, books.Count - 1, 0, (int)ScrSection.ScrSectionTags.kflidContent, 0, 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Loads the footnotes. /// </summary> /// <param name="footnoteHvo">The footnote hvo.</param> /// ------------------------------------------------------------------------------------ private void LoadFootnotes(int footnoteHvo) { Debug.Assert(m_cache.GetClassOfObject(footnoteHvo) == StFootnote.kClassId); StFootnote foot = new StFootnote(m_cache, footnoteHvo); IScrBook book = new ScrBook(m_cache, foot.OwnerHVO); int footnoteCount = GetBookFootnoteCount(book.Hvo); FdoOwningSequence <IStFootnote> footnotes = book.FootnotesOS; // If the information we want is already in the cache, then do nothing if (footnotes.Count == footnoteCount && m_htFootnoteIndex.ContainsKey(footnoteHvo)) { return; } ScrFootnote footnote = null; int index = 0; for (int i = 0; i < footnotes.Count; i++) { footnote = new ScrFootnote(m_cache, footnotes.HvoArray[i]); if (footnote.FootnoteType == FootnoteMarkerTypes.AutoFootnoteMarker) { int oldIndex = GetFootnoteIndex(footnote.Hvo); if (oldIndex != index) { m_htFootnoteIndex[footnote.Hvo] = new FootnoteIndexCacheInfo(index, true); } index++; } } m_htBookFootnoteCount[book.Hvo] = footnotes.Count; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new (empty) StFootnote and add it to the owner's collection. /// This method provides a way to create a new footnote object in the db for any generic /// CmObject owner. /// </summary> /// <param name="owner">The owner CmObject.</param> /// <param name="flid">The flid of the owner's footnote collection.</param> /// <param name="footnoteIndex">Index to insert the footnote at in the collection.</param> /// <returns>the new footnote object</returns> /// ------------------------------------------------------------------------------------ public StFootnote(ICmObject owner, int flid, int footnoteIndex) : this() { // add this new (empty) footnote to the owner's collection FdoOwningSequence<IStFootnote> footnotes = new FdoOwningSequence<IStFootnote>(owner.Cache, owner.Hvo, flid); footnotes.InsertAt(this, footnoteIndex); }
public void ExistingAnnotation_WithResponses() { IScrScriptureNote existingAnn = m_scrInMemoryCache.AddAnnotation(null, 02002008, NoteType.Translator, "This is my discussion"); existingAnn.ResolutionStatus = NoteStatus.Open; IStJournalText exisingResponse1 = existingAnn.ResponsesOS.Append(new StJournalText()); AddParasTo(exisingResponse1, "This is my first response"); IStJournalText exisingResponse2 = existingAnn.ResponsesOS.Append(new StJournalText()); AddParasTo(exisingResponse2, "This is my second response"); DateTime now = DateTime.Now; DateTime utcNow = now.ToUniversalTime(); XmlScrNote ann = CreateNote(); ann.BeginScrRef = "EXO 2:8"; ann.ResolutionStatus = NoteStatus.Open; ann.AnnotationTypeGuid = LangProject.kguidAnnTranslatorNote.ToString(); ann.DateTimeCreated = utcNow.ToString(); ann.DateTimeModified = utcNow.AddDays(1).ToString(); AddParasTo(ann.Discussion, "This is my discussion"); XmlNoteResponse firstResponse = new XmlNoteResponse(); AddParasTo(firstResponse.Paragraphs, "This is my first response"); ann.Responses.Add(firstResponse); XmlNoteResponse secondResponse = new XmlNoteResponse(); AddParasTo(secondResponse.Paragraphs, "This is my second response"); ann.Responses.Add(secondResponse); DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList(); list.Annotations.Add(ann); list.CallWriteToCache(Cache, m_stylesheet); IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[1]; Assert.AreEqual(1, annotations.NotesOS.Count); IScrScriptureNote note = annotations.NotesOS[0]; Assert.AreEqual(NoteType.Translator, note.AnnotationType); Assert.IsTrue(AreDateTimesClose(now, note.DateCreated)); Assert.IsTrue(AreDateTimesClose(now.AddDays(1), note.DateModified)); Assert.AreEqual(DateTime.MinValue, note.DateResolved); FdoOwningSequence <IStJournalText> responses = note.ResponsesOS; Assert.AreEqual(2, responses.Count); TestAnnotationField(responses[0], "This is my first response"); TestAnnotationField(responses[1], "This is my second response"); }
public void FdoOwningCollection_AddToOCFromOS() { CheckDisposed(); // Now test to see if something can actually be moved. // We will use subrecords in a RN object for this. // The source flid is a sequence, while the destination is a collection. m_inMemoryCache.InitializeDataNotebook(); IRnResearchNbk rn = Cache.LangProject.ResearchNotebookOA; IRnEvent ev = (IRnEvent)rn.RecordsOC.Add(new RnEvent()); ev.SubRecordsOS.Append(new RnEvent()); ev.SubRecordsOS.Append(new RnEvent()); ev.SubRecordsOS.Append(new RnEvent()); FdoOwningSequence <IRnGenericRec> os = ev.SubRecordsOS; int[] ahvoSrcBefore = (int[])os.HvoArray.Clone(); FdoOwningCollection <IRnGenericRec> oc = Cache.LangProject.ResearchNotebookOA.RecordsOC; int[] ahvoDstBefore = (int[])oc.HvoArray.Clone(); oc.Add(os.HvoArray); // Check data. Assert.AreEqual(0, os.HvoArray.Length); // Not empty, so they didn't all get moved. Assert.AreEqual((ahvoSrcBefore.Length + ahvoDstBefore.Length), oc.HvoArray.Length); // Not the same size, so they didn't get moved. // Make sure everything in ahvoDstBefore is still in cv.HvoArray. // If not, then the test failed. foreach (int i in ahvoDstBefore) { bool fFailed = true; foreach (int j in oc.HvoArray) { if (i == j) { fFailed = false; break; } } Assert.IsFalse(fFailed); } // Make sure everything in ahvoSrcBefore made it into cv.HvoArray. // If not, then the test failed. foreach (int i in ahvoSrcBefore) { bool fFailed = true; foreach (int j in oc.HvoArray) { if (i == j) { fFailed = false; break; } } Assert.IsFalse(fFailed); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new (empty) StFootnote and add it to the owner's collection. /// This method provides a way to create a new footnote object in the db for any generic /// CmObject owner. /// </summary> /// <param name="owner">The owner CmObject.</param> /// <param name="flid">The flid of the owner's footnote collection.</param> /// <param name="footnoteIndex">Index to insert the footnote at in the collection.</param> /// <returns>the new footnote object</returns> /// ------------------------------------------------------------------------------------ public StFootnote(ICmObject owner, int flid, int footnoteIndex) : this() { // add this new (empty) footnote to the owner's collection FdoOwningSequence <IStFootnote> footnotes = new FdoOwningSequence <IStFootnote>(owner.Cache, owner.Hvo, flid); footnotes.InsertAt(this, footnoteIndex); }
private void AddPossibilities(TreeNodeCollection tnc, FdoOwningSequence <ICmPossibility> possibilities) { foreach (ICmPossibility poss in possibilities) { TreeNode tn = new TreeNode(poss.Name.BestAnalysisVernacularAlternative.Text); tn.Tag = poss; tnc.Add(tn); AddPossibilities(tn.Nodes, poss.SubPossibilitiesOS); } }
public void SignatureOfCmObject_VectorAccessor() //jdh 9Oct2002 { CheckDisposed(); IText itext = m_inMemoryCache.AddInterlinearTextToLangProj("My Interlinear Text"); IStTxtPara para = m_inMemoryCache.AddParaToInterlinearTextContents(itext, "Once upon a time..."); FdoOwningSequence <ICmObject> os = para.AnalyzedTextObjectsOS; //that's it. This will fail if the code generator generated a bogus fully qualified signature. }
public void GoToPrevSection() { FdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS; // Start in the title of the third book. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 1, 0); int iTargBook = 0; IScrBook targetBook = books[iTargBook]; m_draftView.TeEditingHelper.GoToPrevSection(); VerifySelection(4, iTargBook, targetBook.SectionsOS.Count - 1, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); // Start in the last section head of the first book. IScrBook startBook = books[0]; m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, books.Count - 1, startBook.SectionsOS.Count - 1); m_draftView.TeEditingHelper.GoToPrevSection(); VerifySelection(4, 0, startBook.SectionsOS.Count - 2, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); // Start in the last para of the contents of the first section of the first book. startBook = books[0]; IScrSection firstSection = startBook.SectionsOS[0]; m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, firstSection.ContentOA.ParagraphsOS.Count - 1, 2, true); // Nothing should move m_draftView.TeEditingHelper.GoToPrevSection(); VerifySelection(4, 0, 0, (int)ScrSection.ScrSectionTags.kflidContent, 2, 2); // Start with a multi-text range selection startBook = ((ScrBook)books[0]); m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, 0, startBook.SectionsOS.Count - 1); IVwSelection vwsel1 = m_draftView.RootBox.Selection; m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, 0, startBook.SectionsOS.Count - 2); IVwSelection vwsel2 = m_draftView.RootBox.Selection; m_draftView.RootBox.MakeRangeSelection(vwsel1, vwsel2, true); m_draftView.TeEditingHelper.GoToPrevSection(); VerifySelection(4, 0, startBook.SectionsOS.Count - 3, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); }
public void GoToLastBook() { FdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS; int lastBook = books.Count - 1; // Set up to start in the the second to last book. int iBook = (books.Count > 1 ? books.Count - 2 : 0); IScrBook book = books[iBook]; // Set up to start in the last section of the the second to last book. int iSection = (book.SectionsOS.Count > 0 ? book.SectionsOS.Count - 1 : 0); // Start in the title of the second to last book and goto the last book. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, iBook, 0); m_draftView.TeEditingHelper.GoToLastBook(); VerifySelection(3, lastBook, 0, (int)ScrBook.ScrBookTags.kflidTitle, 0, 0); // Start in the last section's heading of the second to last book and // goto the last book. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, iBook, iSection); m_draftView.TeEditingHelper.GoToLastBook(); VerifySelection(3, lastBook, 0, (int)ScrBook.ScrBookTags.kflidTitle, 0, 0); // Start in the last section's contents of the second to last book and // goto the last book. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, iBook, iSection); m_draftView.TeEditingHelper.GoToLastBook(); VerifySelection(3, lastBook, 0, (int)ScrBook.ScrBookTags.kflidTitle, 0, 0); // Start in the last section's contents of the first book and goto the last book. book = books[0]; iSection = (book.SectionsOS.Count > 0 ? book.SectionsOS.Count - 1 : 0); m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, 0, iSection); m_draftView.TeEditingHelper.GoToLastBook(); VerifySelection(3, lastBook, 0, (int)ScrBook.ScrBookTags.kflidTitle, 0, 0); // At this point, we should already be in the last book. Goto the contents of // the last section in the book and verify the IP moves to the book's title. book = books[lastBook]; iSection = (book.SectionsOS.Count > 0 ? book.SectionsOS.Count - 1 : 0); m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, lastBook, iSection); m_draftView.TeEditingHelper.GoToLastBook(); VerifySelection(3, lastBook, 0, (int)ScrBook.ScrBookTags.kflidTitle, 0, 0); // We should already be in the last books title. Goto the last book and verify // we didn't move. m_draftView.TeEditingHelper.GoToLastBook(); VerifySelection(3, lastBook, 0, (int)ScrBook.ScrBookTags.kflidTitle, 0, 0); }
public void CreateOwnedObjects_MultipleFootnotesStartInMiddle() { CheckDisposed(); StTxtPara para = m_inMemoryCache.AddParaToMockedText(m_currentText.Hvo, "Normal"); m_inMemoryCache.AddRunToMockedPara(para, "This is the paragraph of the second section " + "of the first chapter of Genesis. This is here so that we have enough characters " + "to insert footnotes into it.", null); m_inMemoryCache.AddFootnote(m_currentFootnotesOS, para, 0, null); m_inMemoryCache.AddFootnote(m_currentFootnotesOS, para, 20, null); StFootnote footnotePrev = (StFootnote)m_currentFootnotesOS[0]; StFootnote footnoteAfter = (StFootnote)m_currentFootnotesOS[1]; para = (StTxtPara)m_currentText.ParagraphsOS[0]; m_archivedFootnotesOS = m_inMemoryCache.CreateArbitraryFootnoteSequence(m_archivedText); StFootnote footnote1 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, para, 4, null); footnote1.DisplayFootnoteMarker = true; footnote1.DisplayFootnoteReference = false; StFootnote footnote2 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, para, 7, null); footnote2.DisplayFootnoteMarker = false; footnote2.DisplayFootnoteReference = true; Cache.ChangeOwner(para.Hvo, m_currentText.Hvo, (int)StText.StTextTags.kflidParagraphs, 0); NMock.DynamicMock mockIObjectMetaInfoProvider = new DynamicMock(typeof(IObjectMetaInfoProvider)); mockIObjectMetaInfoProvider.Strict = true; mockIObjectMetaInfoProvider.ExpectAndReturn("NextFootnoteIndex", 1, new object[] { para, 0 }); mockIObjectMetaInfoProvider.SetupResult("FootnoteMarkerStyle", "Note Marker"); para.CreateOwnedObjects(0, 10, (IObjectMetaInfoProvider)mockIObjectMetaInfoProvider.MockInstance); mockIObjectMetaInfoProvider.Verify(); Assert.AreEqual(4, m_currentFootnotesOS.Count); IStFootnote testFootnote = m_currentFootnotesOS[0]; Assert.AreEqual(footnotePrev.Hvo, testFootnote.Hvo, "Previous footnote shouldn't have moved"); testFootnote = m_currentFootnotesOS[1]; VerifyFootnote(testFootnote, para, 4); Assert.IsTrue(testFootnote.DisplayFootnoteMarker); Assert.IsFalse(testFootnote.DisplayFootnoteReference); testFootnote = m_currentFootnotesOS[2]; VerifyFootnote(testFootnote, para, 7); Assert.IsFalse(testFootnote.DisplayFootnoteMarker); Assert.IsTrue(testFootnote.DisplayFootnoteReference); testFootnote = m_currentFootnotesOS[3]; Assert.AreEqual(footnoteAfter.Hvo, testFootnote.Hvo, "Following footnote should have gotten bumped two places"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verify misc. stuff about the inserted book's main title. /// </summary> /// <param name="title">title</param> /// <param name="sText">Expected book title.</param> /// ------------------------------------------------------------------------------------ private void VerifyInsertedBookMainTitle(IStText title, string sText) { FdoOwningSequence <IStPara> titleParas = title.ParagraphsOS; Assert.AreEqual(1, titleParas.Count, "The title should consist of 1 para"); // Verify the main title's text and paragraph style is correct. Assert.IsNull(((StTxtPara)titleParas[0]).Contents.Text, "Incorrect book title"); Assert.AreEqual(StyleUtils.ParaStyleTextProps(ScrStyleNames.MainBookTitle), ((StTxtPara)titleParas[0]).StyleRules); }
public void SavingDeserializedAnnotationsToCache_WithResponses() { DateTime now = DateTime.Now; DateTime utcNow = now.ToUniversalTime(); XmlScrNote ann = CreateNote(); ann.BeginScrRef = "EXO 2:8"; ann.ResolutionStatus = NoteStatus.Open; ann.AnnotationTypeGuid = LangProject.kguidAnnTranslatorNote.ToString(); ann.DateTimeCreated = utcNow.ToString(); ann.DateTimeModified = utcNow.AddDays(1).ToString(); AddParasTo(ann.Discussion, "This is my discussion"); AddParasTo(ann.Resolution, "This is my resolution for the note"); AddParasTo(ann.Quote, "This is the quoted text"); AddParasTo(ann.Suggestion, "This is my suggestion"); XmlNoteResponse firstResponse = new XmlNoteResponse(); AddParasTo(firstResponse.Paragraphs, "This is", "my", "first", "response"); ann.Responses.Add(firstResponse); XmlNoteResponse secondResponse = new XmlNoteResponse(); AddParasTo(secondResponse.Paragraphs, "This is", "my second response"); ann.Responses.Add(secondResponse); DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList(); list.Annotations.Add(ann); list.CallWriteToCache(Cache, m_stylesheet); IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[1]; Assert.AreEqual(1, annotations.NotesOS.Count); IScrScriptureNote note = annotations.NotesOS[0]; Assert.AreEqual(NoteType.Translator, note.AnnotationType); Assert.IsTrue(AreDateTimesClose(now, note.DateCreated)); Assert.IsTrue(AreDateTimesClose(now.AddDays(1), note.DateModified)); Assert.AreEqual(DateTime.MinValue, note.DateResolved); TestAnnotationField(note.QuoteOA, "This is the quoted text"); TestAnnotationField(note.DiscussionOA, "This is my discussion"); TestAnnotationField(note.ResolutionOA, "This is my resolution for the note"); TestAnnotationField(note.RecommendationOA, "This is my suggestion"); FdoOwningSequence <IStJournalText> responses = note.ResponsesOS; Assert.AreEqual(2, responses.Count); TestAnnotationField(responses[0], "This is", "my", "first", "response"); TestAnnotationField(responses[1], "This is", "my second response"); }
public void GetLastRunInfoForCheck_AllBooksChecked() { IScrBook book1 = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); IScrBook book2 = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus"); IScrBook book3 = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus"); m_bookFilter.Add(new int[] { book1.Hvo, book2.Hvo, book3.Hvo }); FdoOwningSequence <IScrBookAnnotations> booksAnnotations = m_inMemoryCache.Cache.LangProject.TranslatedScriptureOA.BookAnnotationsOS; Guid checkId = Guid.NewGuid(); DateTime date1 = new DateTime(2008, 3, 5, 14, 20, 30); DateTime date2 = new DateTime(2007, 3, 5, 14, 20, 30); DateTime date3 = new DateTime(2009, 3, 5, 14, 20, 30); // Add a check history record for Genesis. ScrCheckRun checkRun = new ScrCheckRun(); booksAnnotations[0].ChkHistRecsOC.Add(checkRun); checkRun.CheckId = checkId; checkRun.RunDate = date1; // Add a check history record for Exodus. checkRun = new ScrCheckRun(); booksAnnotations[1].ChkHistRecsOC.Add(checkRun); checkRun.CheckId = checkId; checkRun.RunDate = date2; // Add a check history record for Leviticus. checkRun = new ScrCheckRun(); booksAnnotations[2].ChkHistRecsOC.Add(checkRun); checkRun.CheckId = checkId; checkRun.RunDate = date3; // Call the method we're testing. Send the arguments in an object // array because the second argument is an out parameter. object[] args = new object[] { checkId, new string[] { } }; DateTime lastRun = ReflectionHelper.GetDateTimeResult(m_editChecksControl, "GetLastRunInfoForCheck", args); string[] bookChkInfo = args[1] as string[]; Assert.AreEqual(date2, lastRun); Assert.AreEqual(3, bookChkInfo.Length); Assert.IsTrue(bookChkInfo[0].Contains(date1.ToString())); Assert.IsTrue(bookChkInfo[1].Contains(date2.ToString())); Assert.IsTrue(bookChkInfo[2].Contains(date3.ToString())); Assert.IsTrue(bookChkInfo[0].Contains("Genesis")); Assert.IsTrue(bookChkInfo[1].Contains("Exodus")); Assert.IsTrue(bookChkInfo[2].Contains("Leviticus")); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the insert index where a new annotation is inserted when the annotation's /// reference is that specified. The index will be at the end of those for the /// specified reference. /// </summary> /// ------------------------------------------------------------------------------------ private int GetInsertIndexForRef(BCVRef startRef) { FdoOwningSequence <IScrScriptureNote> notes = NotesOS; for (int i = notes.Count - 1; i >= 0; i--) { IScrScriptureNote note = notes[i]; if (note.BeginRef <= startRef) { return(i + 1); } } return(0); }
public void MergeCollectionPropertyBackReferences() { CheckDisposed(); ILexEntry lme = m_entriesCol.Add(new LexEntry()); FdoOwningSequence<IPhEnvironment> envsSeq = Cache.LangProject.PhonologicalDataOA.EnvironmentsOS; IPhEnvironment envKeeper = envsSeq.Append(new PhEnvironment()); IPhEnvironment envSrc = envsSeq.Append(new PhEnvironment()); // Shift back references from reference sequence property. IMoAffixAllomorph referrer = (IMoAffixAllomorph)lme.AlternateFormsOS.Append(new MoAffixAllomorph()); referrer.PhoneEnvRC.Add(envSrc); envKeeper.MergeObject(envSrc); Assert.AreEqual(envKeeper.Hvo, referrer.PhoneEnvRC.HvoArray[0]); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find a text that matches the paragraph strings in rgtss, if any. /// </summary> /// <param name="paragraphs">The paragraphs for the response.</param> /// <param name="texts">The sequence of journal texts to search.</param> /// <param name="type">The type of match found (or not).</param> /// <returns>The index of the existing text found to be a match; or -1 if no match is /// found</returns> /// ------------------------------------------------------------------------------------ private static int FindMatchingResponse(ParagraphCollection paragraphs, FdoOwningSequence <IStJournalText> texts, out ParagraphCollection.ParaMatchType type) { for (int i = 0; i < texts.Count; ++i) { if (paragraphs.Equals(texts[i])) { type = ParagraphCollection.ParaMatchType.Exact; return(i); } } type = ParagraphCollection.ParaMatchType.None; return(-1); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_inMemoryCache.InitializeWritingSystemEncodings(); m_currentText = m_inMemoryCache.CreateArbitraryStText(); StTxtPara para = m_inMemoryCache.AddParaToMockedText(m_currentText.Hvo, "Normal"); m_inMemoryCache.AddRunToMockedPara(para, "1", "CharacterStyle1"); m_inMemoryCache.AddRunToMockedPara(para, "1", "CharacterStyle2"); m_inMemoryCache.AddRunToMockedPara(para, "This text has no char style.", null); m_currentFootnotesOS = m_inMemoryCache.CreateArbitraryFootnoteSequence(m_currentText); m_archivedText = m_inMemoryCache.CreateArbitraryStText(); para = m_inMemoryCache.AddParaToMockedText(m_archivedText.Hvo, "Normal"); m_inMemoryCache.AddRunToMockedPara(para, "1", "CharacterStyle1"); m_inMemoryCache.AddRunToMockedPara(para, "1", "CharacterStyle2"); m_inMemoryCache.AddRunToMockedPara(para, "This is the previous version of the text.", null); m_archivedFootnotesOS = m_inMemoryCache.CreateArbitraryFootnoteSequence(m_archivedText); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Tests that a footnote has been created in the DB with a single default run having /// the specified text and the given translation. /// </summary> /// <param name="iFootnoteIndex">zero-based footnote index</param> /// <param name="sFootnoteSegment">Expected footnote contents</param> /// <param name="sFootnoteTransSegment">Expected footnote translation contents</param> /// <param name="sMarker">One of: <c>"a"</c>, for automatic alpha sequence; <c>"*"</c>, /// for a literal marker (we always use "*" in these tests); or <c>string.Empty</c>, /// for no marker</param> /// <param name="sParaStyleName">Name of the paragraph style</param> /// ------------------------------------------------------------------------------------ public void VerifyFootnoteWithTranslation(int iFootnoteIndex, string sFootnoteSegment, string sFootnoteTransSegment, string sMarker, string sParaStyleName) { // Force reload of book IStFootnote footnote = m_importer.GetFootnote(iFootnoteIndex); if (sMarker == "a") { sMarker = new string((char)((int)'a' + (iFootnoteIndex % 26)), 1); } if (sMarker != null) { AssertEx.RunIsCorrect(footnote.FootnoteMarker.UnderlyingTsString, 0, sMarker, ScrStyleNames.FootnoteMarker, m_wsVern); } else { Assert.IsNull(footnote.FootnoteMarker.Text); } FdoOwningSequence <IStPara> footnoteParas = footnote.ParagraphsOS; Assert.AreEqual(1, footnoteParas.Count); StTxtPara para = (StTxtPara)footnoteParas[0]; Assert.AreEqual(StyleUtils.ParaStyleTextProps(sParaStyleName), para.StyleRules); ITsString tss = para.Contents.UnderlyingTsString; Assert.AreEqual(1, tss.RunCount); AssertEx.RunIsCorrect(tss, 0, sFootnoteSegment, null, m_wsVern); // Check Translation if (sFootnoteTransSegment != null) { Assert.AreEqual(1, para.TranslationsOC.Count); ICmTranslation trans = para.GetBT(); tss = trans.Translation.AnalysisDefaultWritingSystem.UnderlyingTsString; Assert.AreEqual(1, tss.RunCount); AssertEx.RunIsCorrect(tss, 0, sFootnoteTransSegment, null, m_wsAnal); } else { Assert.AreEqual(0, para.TranslationsOC.Count); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); if (DialogResult == DialogResult.Cancel) { return; } FdoOwningSequence <IStPara> oldParas = m_error.ResolutionOA.ParagraphsOS; ITsString[] newParas = m_text.Paragraphs; // If there are fewer paragraphs in the new comment, then remove from the end // of the old comment the number paragraphs that is the difference between // the number of old and new paragraphs. if (newParas.Length < oldParas.Count) { for (int i = oldParas.Count - 1; i >= newParas.Length; i--) { oldParas.RemoveAt(i); } } for (int i = 0; i < newParas.Length; i++) { if (i < oldParas.Count) { // Reuse the old paragraph. ((StTxtPara)oldParas[i]).Contents.UnderlyingTsString = newParas[i]; } else { // Create a new paragraph StTxtPara newStPara = new StTxtPara(); oldParas.Append(newStPara); newStPara.Contents.UnderlyingTsString = newParas[i]; ITsPropsFactory tspf = TsPropsFactoryClass.Create(); newStPara.StyleRules = tspf.MakeProps(ScrStyleNames.Remark, m_text.CurrentWs, 0); } } }
public void MergeReferenceSequence() { CheckDisposed(); // 28 MoAffixAllomorph.Position(refers to PhEnvironment) ILexEntry lme = m_entriesCol.Add(new LexEntry()); IMoAffixAllomorph aKeeper = (IMoAffixAllomorph)lme.AlternateFormsOS.Append(new MoAffixAllomorph()); IMoAffixAllomorph aSrc = (IMoAffixAllomorph)lme.AlternateFormsOS.Append(new MoAffixAllomorph()); FdoOwningSequence<IPhEnvironment> envsSeq = Cache.LangProject.PhonologicalDataOA.EnvironmentsOS; envsSeq.Append(new PhEnvironment()); envsSeq.Append(new PhEnvironment()); envsSeq.Append(new PhEnvironment()); // Merge content into null. aSrc.PositionRS.Append(envsSeq[0].Hvo); aSrc.PositionRS.Append(envsSeq[1].Hvo); aKeeper.MergeObject(aSrc); Assert.AreEqual(2, aKeeper.PositionRS.Count); // Merge duplicate content into content. aSrc = (IMoAffixAllomorph)lme.AlternateFormsOS.Append(new MoAffixAllomorph()); aSrc.PositionRS.Append(envsSeq[0].Hvo); aSrc.PositionRS.Append(envsSeq[1].Hvo); aKeeper.MergeObject(aSrc); Assert.AreEqual(4, aKeeper.PositionRS.Count); // Merge content into content. aSrc = (IMoAffixAllomorph)lme.AlternateFormsOS.Append(new MoAffixAllomorph()); aSrc.PositionRS.Append(envsSeq[0].Hvo); aSrc.PositionRS.Append(envsSeq[1].Hvo); aSrc.PositionRS.Append(envsSeq[2].Hvo); aKeeper.MergeObject(aSrc); Assert.AreEqual(7, aKeeper.PositionRS.Count); // Merge null into content. aSrc = (IMoAffixAllomorph)lme.AlternateFormsOS.Append(new MoAffixAllomorph()); Assert.AreEqual(0, aSrc.PositionRS.Count); aKeeper.MergeObject(aSrc); Assert.AreEqual(7, aKeeper.PositionRS.Count); }
public void CreateScrBookAnnotations() { CheckDisposed(); // Remove annotations for books that have already been created to test // CreateScrBookAnnotations. foreach (IScrBookAnnotations annotations in m_scr.BookAnnotationsOS) { m_scr.BookAnnotationsOS.Remove(annotations.Hvo); } m_scrInitializer.CallCreateScrBookAnnotations(m_scr); FdoOwningSequence <IScrBookAnnotations> bookNotes = m_scr.BookAnnotationsOS; // Make sure the right number of books was generated. Assert.AreEqual(66, bookNotes.Count); Assert.AreEqual(1, bookNotes[0].OwnOrd); Assert.AreEqual(66, bookNotes[BCVRef.LastBook - 1].OwnOrd); }
public void MergeReferenceCollection() { CheckDisposed(); // 26 LexSense.UsageTypes(refers to CmPossibility) ILexEntry lme = m_entriesCol.Add(new LexEntry()); ILexSense lsKeeper = lme.SensesOS.Append(new LexSense()); ILexSense lsSrc = lme.SensesOS.Append(new LexSense()); FdoOwningSequence<ICmPossibility> usageSeq = m_ldb.UsageTypesOA.PossibilitiesOS; usageSeq.Append(new CmPossibility()); usageSeq.Append(new CmPossibility()); usageSeq.Append(new CmPossibility()); int[] srcTypes = new int[2]; // Merge content into null. srcTypes[0] = usageSeq[0].Hvo; srcTypes[1] = usageSeq[1].Hvo; lsSrc.UsageTypesRC.Add(srcTypes); lsKeeper.MergeObject(lsSrc); Assert.AreEqual(2, lsKeeper.UsageTypesRC.Count); // Merge content into content. lsSrc = lme.SensesOS.Append(new LexSense()); lsSrc.UsageTypesRC.Add(usageSeq[2].Hvo); lsKeeper.MergeObject(lsSrc); Assert.AreEqual(3, lsKeeper.UsageTypesRC.Count); // Merge duplicate content into content. lsSrc = lme.SensesOS.Append(new LexSense()); lsSrc.UsageTypesRC.Add(usageSeq[2].Hvo); Assert.AreEqual(1, lsSrc.UsageTypesRC.Count); lsKeeper.MergeObject(lsSrc); Assert.AreEqual(3, lsKeeper.UsageTypesRC.Count); // Merge null into content. lsSrc = lme.SensesOS.Append(new LexSense()); Assert.AreEqual(0, lsSrc.UsageTypesRC.Count); lsKeeper.MergeObject(lsSrc); Assert.AreEqual(3, lsKeeper.UsageTypesRC.Count); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adjusts the references of the section and creates any needed BT's /// </summary> /// <param name="hvoText">The StText that was changed</param> /// <param name="ivMin">the starting index where the change occurred</param> /// <param name="cvIns">the number of paragraphs inserted</param> /// <param name="cvDel">the number of paragraphs deleted</param> /// ------------------------------------------------------------------------------------ protected override void DoEffectsOfPropChange(int hvoText, int ivMin, int cvIns, int cvDel) { if (cvIns == 0 && cvDel == 0) { return; // Nothing actually changed } int flid = m_cache.GetOwningFlidOfObject(hvoText); StText text = new StText(m_cache, hvoText, false, false); FdoOwningSequence <IStPara> paras = text.ParagraphsOS; // Create back translations for any new paragraphs if (flid == (int)ScrSection.ScrSectionTags.kflidContent || flid == (int)ScrSection.ScrSectionTags.kflidHeading || flid == (int)ScrBook.ScrBookTags.kflidTitle) { for (int iPara = ivMin; iPara < ivMin + cvIns; iPara++) { ScrTxtPara para = new ScrTxtPara(m_cache, paras.HvoArray[iPara]); para.GetOrCreateBT(); } } // Adjust section references for section contents if we have some paragraphs left if (flid == (int)ScrSection.ScrSectionTags.kflidContent && paras.Count > 0) { ScrTxtPara.AdjustSectionRefsForStTextParaChg(text, ivMin); } // If we show boundary markers and we insert or delete a paragraph, we have to // update the marker of the previous paragraph as well, as that might // now be no longer the last paragraph (and thus needs to show the paragraph // marker instead of the section marker). if (((cvIns > 0 && cvDel == 0) || (cvIns == 0 && cvDel > 0)) && ivMin > 0 && Options.ShowFormatMarksSetting) { text.Cache.PropChanged(null, PropChangeType.kpctNotifyAll, hvoText, (int)StText.StTextTags.kflidParagraphs, ivMin - 1, 1, 1); } }
public void GoToLastSection() { FdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS; // Start in the title of the second book. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 1, 0); IScrBook book = books[1]; m_draftView.TeEditingHelper.GoToLastSection(); VerifySelection(4, 1, book.SectionsOS.Count - 1, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); // Start in the last section head of the last book. book = books[books.Count - 1]; m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, books.Count - 1, book.SectionsOS.Count - 1); m_draftView.TeEditingHelper.GoToLastSection(); VerifySelection(4, books.Count - 1, book.SectionsOS.Count - 1, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); // Start in the last para of the contents of the second section of the first book. int iTargBook = 0; book = books[iTargBook]; int iStartsection = 1; IScrSection secondSection = book.SectionsOS[iStartsection]; m_draftView.TeEditingHelper.SetInsertionPoint(iTargBook, iStartsection, secondSection.ContentOA.ParagraphsOS.Count - 1, 2, true); m_draftView.TeEditingHelper.GoToLastSection(); VerifySelection(4, iTargBook, book.SectionsOS.Count - 1, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); }
public void VectorRemove_ReferenceCollection() { CheckDisposed(); ILexDb ldb = Cache.LangProject.LexDbOA; ILexEntry lme = ldb.EntriesOC.Add(new LexEntry()); ILexSense ls = lme.SensesOS.Append(new LexSense()); FdoOwningSequence <ICmPossibility> usageSeq = ldb.UsageTypesOA.PossibilitiesOS; usageSeq.Append(new CmPossibility()); usageSeq.Append(new CmPossibility()); usageSeq.Append(new CmPossibility()); int[] usageTypes = new int[3]; usageTypes[0] = usageSeq[0].Hvo; usageTypes[1] = usageSeq[1].Hvo; usageTypes[2] = usageSeq[2].Hvo; ls.UsageTypesRC.Add(usageTypes); ls.UsageTypesRC.Remove(usageSeq[1].Hvo); Assert.AreEqual(2, ls.UsageTypesRC.Count); }
public void GoToFirstSection() { FdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS; // Start in the title of the second book. m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 1, 0); m_draftView.TeEditingHelper.GoToFirstSection(); VerifySelection(4, 1, 0, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); // Start in the last section head of the last book. IScrBook book = books[books.Count - 1]; m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, books.Count - 1, book.SectionsOS.Count - 1); m_draftView.TeEditingHelper.GoToFirstSection(); VerifySelection(4, books.Count - 1, 0, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0); // Start in the last para of the contents of the first section of the first book. book = books[0]; IScrSection firstSection = book.SectionsOS[0]; m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, firstSection.ContentOA.ParagraphsOS.Count - 1, 2, true); m_draftView.TeEditingHelper.GoToFirstSection(); int targetTag = firstSection.HeadingOA.ParagraphsOS.Count > 0 ? (int)ScrSection.ScrSectionTags.kflidHeading : (int)ScrSection.ScrSectionTags.kflidContent; VerifySelection(4, 0, 0, targetTag, 0, 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the book in the given sequence which follows the given book (identified by its /// canonical number). /// </summary> /// <param name="booksOs">The sequence of books in which to look.</param> /// <param name="nCanonicalBookNum">The n canonical book num.</param> /// <returns>The HVO of the following book; or -1 if no following book is found</returns> /// ------------------------------------------------------------------------------------ private int GetBookFollowing(FdoOwningSequence<IScrBook> booksOs, int nCanonicalBookNum) { foreach (IScrBook existingBook in booksOs) { if (existingBook.CanonicalNum > nCanonicalBookNum) { return existingBook.Hvo; } } return -1; }
internal ParagraphBuilder(FdoOwningSequence<IStPara> owner, XmlNode paraDefn) : this(owner) { m_paraDefn = paraDefn; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares the revision and current paragraphs (can be heading or content paragraphs). /// </summary> /// <param name="fIsHeading">if set to <c>true</c> comparing heading paragraphs; /// if set to <c>false</c> comparing content paragraphs.</param> /// <param name="iSection">index of the section</param> /// <param name="revParas">The rev paras.</param> /// <param name="curParas">The cur paras.</param> /// ------------------------------------------------------------------------------------ private void CompareParas(bool fIsHeading, int iSection, FdoOwningSequence<IStPara> revParas, FdoOwningSequence<IStPara> curParas) { for (int iPara = 0; iPara < revParas.Count; iPara++) { AssertEx.AreTsStringsEqual(((StTxtPara)revParas[iPara]).Contents.UnderlyingTsString, ((StTxtPara)curParas[iPara]).Contents.UnderlyingTsString, ((fIsHeading) ? "Headings" : "Contents") + " are different in para " + iPara + " of section " + iSection); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle section nesting for a "Speech Speaker" style paragraph. /// </summary> /// <param name="paras">sequence of paragraphs</param> /// <param name="iPara">index to the current paragraph</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private bool HandleSpeechSpeaker(FdoOwningSequence<IStPara> paras, int iPara) { if (iPara == paras.Count - 1) { FlushSectionElementStack(SectionLevel.Series); m_writer.WriteStartElement("section"); m_stackSectionLevels.Push(SectionLevel.Series); } else if (iPara == 0) { // we need to pump out a <section> element, but not another one from // the following header! (this is probably bad data, but...) bool fSkip = false; bool fUnknown; string styleNext = paras[1].StyleName; bool fSectionFromNext = WriteSectionHead(paras, 1, styleNext, ScrStyleNames.SpeechSpeaker, ref fSkip, out fUnknown); if (!fSectionFromNext) { // Start a new section at the same level. StartNewSection(); } return fSectionFromNext; } else { // REVIEW: what to do? Debug.Assert(iPara == 0 || iPara == paras.Count - 1, "SpeechSpeaker style is out of place!"); } return false; }
protected bool RemoveContextsFrom(bool forward, SelectionHelper sel, FdoOwningSequence<IPhSimpleContext> seq, bool deleteUnderlyingObject, out int index) { index = -1; bool reconstruct = true; int[] hvos = seq.HvoArray; // if the selection is a range remove all items in the selection if (sel.IsRange) { int[] indices = GetIndicesToRemove(hvos, sel); // return index of the item before the removed items if (indices.Length > 0) index = indices[0] - 1; foreach (int idx in indices) { // Sometimes when deleting a range, DeleteUnderlyingObject() takes out // parts of the rule before this loop gets to it. [LT-9775] if (m_cache.IsValidObject(hvos[idx])) ProcessIndicesSimpleContext(seq, hvos, deleteUnderlyingObject, idx); } } else { int idx = GetIndexToRemove(hvos, sel, forward); if (idx > -1) { // return index of the item before the removed items index = idx - 1; ProcessIndicesSimpleContext(seq, hvos, deleteUnderlyingObject, idx); } else { // if the backspace button is pressed at the beginning of a cell or the delete // button is pressed at the end of a cell, don't do anything reconstruct = false; } } return reconstruct; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Searches section backwards for last footnote reference in a section range. /// </summary> /// <param name="sectionRange">The section range.</param> /// <param name="ihvoSectionStart">The index of the starting section in the section hvo array</param> /// <param name="ihvoSectionEnd">The index of the ending section in the section hvo array</param> /// <returns>last footnote in a range of sections or null if not found</returns> /// ------------------------------------------------------------------------------------ public static ScrFootnote FindLastFootnoteInSectionRange( FdoOwningSequence<IScrSection> sectionRange, int ihvoSectionStart, int ihvoSectionEnd) { ScrFootnote footnote; int iPara; int ich; int tag; for (int iSection = ihvoSectionEnd; iSection >= ihvoSectionStart; iSection--) { ScrSection section = (ScrSection)sectionRange[iSection]; footnote = FindLastFootnoteInSection(section, out iPara, out ich, out tag); if (footnote != null) return footnote; } return null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find a text that matches the paragraph strings in rgtss, if any. /// </summary> /// <param name="paragraphs">The paragraphs for the response.</param> /// <param name="texts">The sequence of journal texts to search.</param> /// <param name="type">The type of match found (or not).</param> /// <returns>The index of the existing text found to be a match; or -1 if no match is /// found</returns> /// ------------------------------------------------------------------------------------ private static int FindMatchingResponse(ParagraphCollection paragraphs, FdoOwningSequence<IStJournalText> texts, out ParagraphCollection.ParaMatchType type) { for (int i = 0; i < texts.Count; ++i) { if (paragraphs.Equals(texts[i])) { type = ParagraphCollection.ParaMatchType.Exact; return i; } } type = ParagraphCollection.ParaMatchType.None; return -1; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Close and open <section> elements as indicated by the paragraph style. This /// is where the linear list of sections in FieldWorks is transformed into a hierarchy /// of nested sections in OXES. /// </summary> /// <param name="paras">the vector of header paragraphs</param> /// <param name="i">current index into paras</param> /// <param name="style">the style of the current paragraph</param> /// <param name="stylePrev"></param> /// <param name="fSectionFromNext">flag whether this paragraph has already been handled</param> /// <param name="fUnknownStyle"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private bool WriteSectionHead(FdoOwningSequence<IStPara> paras, int i, string style, string stylePrev, ref bool fSectionFromNext, out bool fUnknownStyle) { fUnknownStyle = false; if (fSectionFromNext) { fSectionFromNext = false; return true; } switch (style) { case ScrStyleNames.SectionHeadMajor: FinishAndStartSection(SectionLevel.Major, "major", i == 0); return true; case ScrStyleNames.SectionHead: case ScrStyleNames.ChapterHead: FinishAndStartSection(SectionLevel.Normal, null, i == 0); return true; case ScrStyleNames.SectionHeadMinor: FinishAndStartSection(SectionLevel.Minor, "minor", i == 0); return true; case ScrStyleNames.SectionHeadSeries: FinishAndStartSection(SectionLevel.Series, "series", i == 0); return true; case ScrStyleNames.IntroSectionHead: FinishAndStartSection(SectionLevel.Normal, null, i == 0); return true; case ScrStyleNames.VariantSectionHead: case ScrStyleNames.VariantSectionTail: // I don't think this is a heading style! FinishAndStartSection(SectionLevel.Normal, "variant", i == 0); return true; // the remaining styles are more complicated, and may need to look ahead one // paragraph to close/open <section> elements properly. case ScrStyleNames.SpeechSpeaker: fSectionFromNext = HandleSpeechSpeaker(paras, i); return false; case ScrStyleNames.ParallelPassageReference: fSectionFromNext = HandleSecondaryTitle(paras, i, style, stylePrev); return false; case ScrStyleNames.HebrewTitle: fSectionFromNext = HandleSecondaryTitle(paras, i, style, stylePrev); return true; case ScrStyleNames.SectionRangeParagraph: fSectionFromNext = HandleSecondaryTitle(paras, i, style, stylePrev); return true; default: FinishAndStartSection(SectionLevel.Normal, null, i == 0); fUnknownStyle = true; return true; } }
private void AddPossibilities(TreeNodeCollection tnc, FdoOwningSequence<ICmPossibility> possibilities) { foreach (ICmPossibility poss in possibilities) { TreeNode tn = new TreeNode(poss.Name.BestAnalysisVernacularAlternative.Text); tn.Tag = poss; tnc.Add(tn); AddPossibilities(tn.Nodes, poss.SubPossibilitiesOS); } }
private string GetFirstGlossOfMSAThatMatches(FdoOwningSequence<ILexSense> os) { string sGloss = null; foreach (ILexSense sense in os) { // get the gloss of the first sense that refers to this MSA if (sense.MorphoSyntaxAnalysisRAHvo == Hvo) { sGloss = sense.Gloss.AnalysisDefaultWritingSystem; break; // found first gloss; quit } else { sGloss = GetFirstGlossOfMSAThatMatches(sense.SensesOS); if (sGloss != null) break; // first gloss was in a subsense; quit } } return sGloss; }
protected int InsertContextInto(IPhSimpleContext ctxt, int fsFlid, int fsHvo, SelectionHelper sel, FdoOwningSequence<IPhSimpleContext> seq) { int[] hvos = seq.HvoArray; int index = GetInsertionIndex(hvos, sel); // if the current selection is a range remove the items we are overwriting if (sel.IsRange) { int[] indices = GetIndicesToRemove(hvos, sel); foreach (int idx in indices) { if (seq.Contains(hvos[idx])) { IPhSimpleContext removeCtxt = PhSimpleContext.CreateFromDBObject(m_cache, hvos[idx]); removeCtxt.DeleteUnderlyingObject(); } } } seq.InsertAt(ctxt, index); m_cache.SetObjProperty(ctxt.Hvo, fsFlid, fsHvo); ctxt.NotifyNew(); return index; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a mindless footnote (i.e., it's marker, paragraph style, etc. won't be set) /// to a paragraph. /// </summary> /// <param name="footnoteSequence">Sequence of footnotes into which to insert</param> /// <param name="para">the paragraph into which to insert the footnote ORC</param> /// <param name="ichPos">the zero-based character offset at which to insert the footnote /// ORC into the paragraph</param> /// <param name="footnoteText">text for the footnote (no footnote paragraph created if /// null)</param> /// <returns>the new footnote</returns> /// ------------------------------------------------------------------------------------ public StFootnote AddFootnote(FdoOwningSequence<IStFootnote> footnoteSequence, IStTxtPara para, int ichPos, string footnoteText) { CheckDisposed(); // Create the footnote StFootnote footnote = new StFootnote(); footnoteSequence.Append(footnote); // Update the paragraph contents to include the footnote marker ORC ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr(); footnote.InsertOwningORCIntoPara(tsStrBldr, ichPos, m_fdoCache.DefaultVernWs); para.Contents.UnderlyingTsString = tsStrBldr.GetString(); if (footnoteText != null) { // Create the footnote paragraph with the given footnoteText StTxtParaBldr paraBldr = new StTxtParaBldr(m_fdoCache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps("Note General Paragraph"); paraBldr.AppendRun(footnoteText, StyleUtils.CharStyleTextProps(null, m_fdoCache.DefaultVernWs)); paraBldr.CreateParagraph(footnote.Hvo); } return footnote; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle section nesting for a "Hebrew Title" or "Parallel Passage Reference" style /// paragraph. /// </summary> /// <param name="paras">the vector of header paragraphs</param> /// <param name="iPara">current index into paras</param> /// <param name="style">the style of the current paragraph</param> /// <param name="stylePrev">The style of the previous paragraph</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private bool HandleSecondaryTitle(FdoOwningSequence<IStPara> paras, int iPara, string style, string stylePrev) { if (iPara == 0) { if (paras.Count == 1) { // Start a new section at the same level. StartNewSection(); } else { // we need to pump out a <section> element, but not another one from // the following header! (this is probably bad data, but...) bool fSkip = false; bool fUnknown; string styleNext = paras[1].StyleName; bool fSectionFromNext = WriteSectionHead(paras, 1, styleNext, style, ref fSkip, out fUnknown); if (!fSectionFromNext) { // Start a new section at the same level. StartNewSection(); } return fSectionFromNext; } } else { // If we follow a normal section heading, then we're okay. if (stylePrev == ScrStyleNames.SectionHead || stylePrev == ScrStyleNames.ChapterHead || stylePrev == ScrStyleNames.SectionHeadMajor || stylePrev == ScrStyleNames.SectionHeadMinor || stylePrev == ScrStyleNames.SectionHeadSeries) { return false; // don't need to do anything. } else { // TODO (TE-7289): It's okay for Parallel Passage to be the only para in a section head Debug.Assert(iPara == 0, String.Format("{0} style is out of place!", style)); } } return false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finds the name of the possibility by name only. /// </summary> /// ------------------------------------------------------------------------------------ private int FindPossibilityByName(FdoOwningSequence<ICmPossibility> possList, string possibilityPath, int ws) { foreach (CmPossibility poss in possList) { int dummyWs; if (possibilityPath.Equals(poss.Name.GetAlternativeOrBestTss(ws, out dummyWs).Text) || possibilityPath.Equals(poss.Abbreviation.GetAlternativeOrBestTss(ws, out dummyWs).Text)) { return poss.Hvo; } // Search any subpossibilities of this possibility. int hvo = FindPossibilityByName(poss.SubPossibilitiesOS, possibilityPath, ws); if (hvo != -1) return hvo; } return -1; }
private void ProcessIndicesSimpleContext(FdoOwningSequence<IPhSimpleContext> seq, int[] hvos, bool deleteUnderlyingObject, int idx) { if (hvos == null || idx > hvos.Length - 1 || idx < 0) return; if (deleteUnderlyingObject) { IPhSimpleContext ctxt = PhSimpleContext.CreateFromDBObject(m_cache, hvos[idx]); ctxt.DeleteUnderlyingObject(); } else { seq.Remove(hvos[idx]); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Fill the possibility map from name to HVO for looking up possibilities. /// </summary> /// ----------------------------------------------------------------------------------- private void CacheNoteCategories(FdoOwningSequence<ICmPossibility> possibilityList, int ws) { if (!m_possibilityMap.ContainsKey(ws)) m_possibilityMap[ws] = new Dictionary<string, int>(); string s; foreach (ICmPossibility poss in possibilityList) { string sNotFound = poss.Abbreviation.NotFoundTss.Text; s = poss.AbbrevHierarchyString; if (!string.IsNullOrEmpty(s) && s != sNotFound) m_possibilityMap[ws][s] = poss.Hvo; s = poss.NameHierarchyString; if (!string.IsNullOrEmpty(s) && s != sNotFound) m_possibilityMap[ws][s] = poss.Hvo; CacheNoteCategories(poss.SubPossibilitiesOS, ws); } }
//bool m_fNeedToRebuildParagraphContentFromStrings = false; internal ParagraphBuilder(FdoOwningSequence<IStPara> owner) { m_owner = owner; m_cache = owner.Cache; }