Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Insert end of paragraph or section marks, if needed. Highlight the markers if
        /// they are part of a diff range in a paragraph split, merge or structure change.
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="paraHvo"></param>
        /// ------------------------------------------------------------------------------------
        protected override void InsertEndOfParaMarks(IVwEnv vwenv, int paraHvo)
        {
            IStTxtPara para     = m_cache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraHvo);
            Difference rootDiff = m_Differences.CurrentDifference;
            bool       fParaNeedsBoundaryHighlight = NeedsBoundaryHighlight(rootDiff, para);

            if (m_target == LayoutViewTarget.targetDraft && fParaNeedsBoundaryHighlight)
            {
                // Set up for an end mark.

                // If this is the last paragraph of a section then insert an
                // end of section mark, otherwise insert a paragraph mark.
                VwBoundaryMark boundaryMark;
                IFdoOwningSequence <IStPara> paraArray = ((IStText)para.Owner).ParagraphsOS;
                if (para == paraArray[paraArray.Count - 1])
                {
                    boundaryMark = VwBoundaryMark.endofSectionHighlighted;                     // "§"
                }
                else
                {
                    boundaryMark = VwBoundaryMark.endOfParagraphHighlighted;                     // "¶"
                }
                vwenv.SetParagraphMark(boundaryMark);
            }
        }
        public void GoToNextBook()
        {
            IFdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS;

            // Set up to start in the the second to last book.
            m_draftView.TeEditingHelper.SetInsertionPoint(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, 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(ScrSectionTags.kflidContent,
                                                              i, 0);
                // Goto next book and verify we moved
                m_draftView.TeEditingHelper.GoToNextBook();
                VerifySelection(3, i + 1, 0, ScrBookTags.kflidTitle, 0, 0);
            }

            // Goto the last section's contents in the first book.
            m_draftView.TeEditingHelper.SetInsertionPoint(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,
                            ScrSectionTags.kflidContent, 0, 0);
        }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Recursively populate the nodes of the tree with the key terms
        /// </summary>
        /// <param name="nodes">collection of nodes to be populated</param>
        /// <param name="keyTerm">The ChkTerm which is part of the keyterm hierarchy</param>
        /// ------------------------------------------------------------------------------------
        private void PopulateTreeNode(TreeNodeCollection nodes, ICmPossibility keyTerm)
        {
            // ENHANCE (TE-9407): Support displaying list in two writing systems (primary and secondary)
            int    ws;
            string nodeName = keyTerm.Name.GetBestAlternative(out ws, m_wsDefault,
                                                              WritingSystemServices.kwsFirstAnal, m_cache.WritingSystemFactory.GetWsFromStr("grk"),
                                                              m_cache.WritingSystemFactory.GetWsFromStr("hbo")).Text;

            TreeNode tn = new TreeNode(nodeName);

            if (ws != m_wsDefault)
            {
                tn.NodeFont = GetFontForWs(ws);
            }
            tn.Tag = keyTerm;
            IFdoOwningSequence <ICmPossibility> subKeyTerms = keyTerm.SubPossibilitiesOS;
            bool fAddKeyTermWithOccurrences = ShouldAddLeafNode(keyTerm, subKeyTerms);

            foreach (ICmPossibility subKeyTerm in subKeyTerms)
            {
                PopulateTreeNode(tn.Nodes, subKeyTerm);
            }
            // if we added children to the node, then add the node to the parent tree collection.
            if (fAddKeyTermWithOccurrences || tn.Nodes.Count > 0)
            {
                nodes.Add(tn);
                if (fAddKeyTermWithOccurrences)
                {
                    m_chkTermsWithRefs.Add((IChkTerm)keyTerm);
                }
            }
        }
Esempio n. 4
0
        public void CreateScrBookRefs()
        {
            ReflectionHelper.CallMethod(typeof(TeScrBookRefsInit), "SetNamesAndAbbreviations",
                                        new DummyProgressDlg(), Cache);

            IFdoOwningSequence <IScrBookRef> books =
                Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().Singleton.BooksOS;

            // Make sure the right number of books was generated.
            Assert.AreEqual(66, books.Count);

            ILgWritingSystemFactory wsf = Cache.WritingSystemFactory;
            int wsEnglish = wsf.GetWsFromStr("en");
            int wsSpanish = wsf.GetWsFromStr("es");

            // Check English Genesis
            IScrBookRef genesis = books[0];

            Assert.AreEqual("Genesis",
                            genesis.BookName.get_String(wsEnglish).Text);
            Assert.AreEqual("Gen",
                            genesis.BookAbbrev.get_String(wsEnglish).Text);
            Assert.IsNull(genesis.BookNameAlt.get_String(wsEnglish).Text);

            // Check Spanish Matthew
            IScrBookRef mateo = books[39];

            Assert.AreEqual("Mateo",
                            mateo.BookName.get_String(wsSpanish).Text);
            Assert.AreEqual("Mt",
                            mateo.BookAbbrev.get_String(wsSpanish).Text);
            Assert.IsNull(mateo.BookNameAlt.get_String(wsSpanish).Text);

            // Check English 2 Corinthians
            IScrBookRef iiCor = books[46];

            Assert.AreEqual("2 Corinthians",
                            iiCor.BookName.get_String(wsEnglish).Text);
            Assert.AreEqual("2Cor",
                            iiCor.BookAbbrev.get_String(wsEnglish).Text);
            Assert.AreEqual("II Corinthians",
                            iiCor.BookNameAlt.get_String(wsEnglish).Text);

            // Check Spanish Revelation
            IScrBookRef apocalipsis = books[65];

            Assert.AreEqual("Apocalipsis",
                            apocalipsis.BookName.get_String(wsSpanish).Text);
            Assert.AreEqual("Ap",
                            apocalipsis.BookAbbrev.get_String(wsSpanish).Text);
            Assert.IsNull(apocalipsis.BookNameAlt.get_String(wsSpanish).Text);

            MultilingScrBooks mlsb = new MultilingScrBooks(m_scr.ScrProjMetaDataProvider);

            foreach (IScrBookRef brf in books)
            {
                Assert.IsTrue(!String.IsNullOrEmpty(brf.BookName.get_String(wsEnglish).Text));
                Assert.IsTrue(!String.IsNullOrEmpty(brf.BookAbbrev.get_String(wsEnglish).Text));
            }
        }
Esempio n. 5
0
 private bool ShouldAddLeafNode(ICmPossibility keyTerm, IFdoOwningSequence <ICmPossibility> subKeyTerms)
 {
     // if we have a book filter and the keyterm doesn't have subpossibilities (ie. it's a leaf node)
     // make sure this key term has an occurrence in the books specified by the book filter.
     if (subKeyTerms.Count == 0)
     {
         if (HasBookFilter)
         {
             IChkTerm chkTerm = (IChkTerm)keyTerm;
             foreach (IChkRef chkRef in chkTerm.OccurrencesOS)
             {
                 int bookIdOfOccurrence = ScrReference.GetBookFromBcv(chkRef.Ref);
                 if (FilteredBookIds.Contains(bookIdOfOccurrence))
                 {
                     // the reference is in one of our filtered books
                     // so add its key term to our tree.
                     return(true);
                 }
             }
         }
         else
         {
             // no book filter to apply, so add all the key terms.
             return(true);
         }
     }
     else
     {
         // return false. not a leaf-node.
     }
     return(false);
 }
        public void ExistingAnnotation_WithResponses()
        {
            IScrScriptureNote existingAnn =
                AddAnnotation(null, 02002008, NoteType.Translator, "This is my discussion");

            existingAnn.ResolutionStatus = NoteStatus.Open;

            IStJournalText exisingResponse1 = Cache.ServiceLocator.GetInstance <IStJournalTextFactory>().Create();

            existingAnn.ResponsesOS.Add(exisingResponse1);
            AddParasTo(exisingResponse1, "This is my first response");

            IStJournalText exisingResponse2 = Cache.ServiceLocator.GetInstance <IStJournalTextFactory>().Create();

            existingAnn.ResponsesOS.Add(exisingResponse2);
            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 = CmAnnotationDefnTags.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(AreDatesClose(now.AddDays(1), note.DateModified));
            Assert.AreEqual(DateTime.MinValue, note.DateResolved);

            IFdoOwningSequence <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");
        }
 private void FillInMapForPossibilities(Dictionary <string, ICmPossibility> mapNameToItem,
                                        IFdoOwningSequence <ICmPossibility> possibilities)
 {
     if (possibilities == null)
     {
         return;
     }
     foreach (var item in possibilities)
     {
         ITsString tss = item.Name.get_String(m_wsEn);
         if (tss == null)
         {
             continue;
         }
         string name = tss.Text;
         if (String.IsNullOrEmpty(name))
         {
             continue;
         }
         if (mapNameToItem.ContainsKey(name))
         {
             continue;
         }
         mapNameToItem.Add(name, item);
         FillInMapForPossibilities(mapNameToItem, item.SubPossibilitiesOS);
     }
 }
        public void GoToNextSection()
        {
            IFdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS;

            // Start in the title of the second book.
            m_draftView.TeEditingHelper.SetInsertionPoint(ScrBookTags.kflidTitle, 1, 0);

            m_draftView.TeEditingHelper.GoToNextSection();

            VerifySelection(4, 1, 0, ScrSectionTags.kflidHeading, 0, 0);

            // Start in the last section of the first book.
            IScrBook book = books[0];

            m_draftView.TeEditingHelper.SetInsertionPoint(ScrSectionTags.kflidContent,
                                                          0, book.SectionsOS.Count - 1);

            m_draftView.TeEditingHelper.GoToNextSection();

            VerifySelection(4, 1, 0, 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, 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(ScrSectionTags.kflidHeading,
                                                          0, startBook.SectionsOS.Count - 2);
            IVwSelection vwsel1 = m_draftView.RootBox.Selection;

            m_draftView.TeEditingHelper.SetInsertionPoint(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,
                            ScrSectionTags.kflidHeading, 0, 0);
        }
Esempio n. 9
0
 private void RegisterAllSubrecordIndexTSSChanged(IFdoOwningSequence <IRnGenericRec> subs, int flid, ITsString dummy)
 {
     foreach (IRnGenericRec rec in subs)
     {
         ((IServiceLocatorInternal)m_cache.ServiceLocator).UnitOfWorkService.RegisterVirtualAsModified(
             rec, flid, null, dummy);
         RegisterAllSubrecordIndexTSSChanged(rec.SubRecordsOS, flid, dummy);
     }
 }
        public void GoToLastBook()
        {
            IFdoOwningSequence <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(ScrBookTags.kflidTitle, iBook, 0);
            m_draftView.TeEditingHelper.GoToLastBook();
            VerifySelection(3, lastBook, 0, 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(ScrSectionTags.kflidHeading,
                                                          iBook, iSection);
            m_draftView.TeEditingHelper.GoToLastBook();
            VerifySelection(3, lastBook, 0, 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(ScrSectionTags.kflidContent,
                                                          iBook, iSection);
            m_draftView.TeEditingHelper.GoToLastBook();
            VerifySelection(3, lastBook, 0, 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(ScrSectionTags.kflidContent,
                                                          0, iSection);
            m_draftView.TeEditingHelper.GoToLastBook();
            VerifySelection(3, lastBook, 0, 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(ScrSectionTags.kflidContent,
                                                          lastBook, iSection);
            m_draftView.TeEditingHelper.GoToLastBook();
            VerifySelection(3, lastBook, 0, 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, ScrBookTags.kflidTitle, 0, 0);
        }
        public void GoToPrevSection()
        {
            IFdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS;

            // Start in the title of the third book.
            m_draftView.TeEditingHelper.SetInsertionPoint(ScrBookTags.kflidTitle, 1, 0);
            int      iTargBook  = 0;
            IScrBook targetBook = books[iTargBook];

            m_draftView.TeEditingHelper.GoToPrevSection();

            VerifySelection(4, iTargBook, targetBook.SectionsOS.Count - 1,
                            ScrSectionTags.kflidHeading, 0, 0);

            // Start in the last section head of the first book.
            IScrBook startBook = books[0];

            m_draftView.TeEditingHelper.SetInsertionPoint(ScrSectionTags.kflidHeading,
                                                          books.Count - 1, startBook.SectionsOS.Count - 1);

            m_draftView.TeEditingHelper.GoToPrevSection();

            VerifySelection(4, 0, startBook.SectionsOS.Count - 2,
                            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, ScrSectionTags.kflidContent, 2, 2);

            // Start with a multi-text range selection
            startBook = ((IScrBook)books[0]);
            m_draftView.TeEditingHelper.SetInsertionPoint(ScrSectionTags.kflidHeading,
                                                          0, startBook.SectionsOS.Count - 1);
            IVwSelection vwsel1 = m_draftView.RootBox.Selection;

            m_draftView.TeEditingHelper.SetInsertionPoint(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,
                            ScrSectionTags.kflidHeading, 0, 0);
        }
Esempio n. 12
0
		private void ProcessIndicesSimpleContext(IFdoOwningSequence<IPhSimpleContext> seq, ICmObject[] ctxts, bool preRemovalSideEffects,
			int idx)
		{
			if (ctxts == null || idx > ctxts.Length - 1 || idx < 0)
				return;

			var c = (IPhSimpleContext) ctxts[idx];
			if (preRemovalSideEffects)
				c.PreRemovalSideEffects();
			seq.Remove(c);
		}
        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 = CmAnnotationDefnTags.kguidAnnTranslatorNote.ToString();
            // (The created and modified dates are now set as side effects when the note is
            // created and when the fields in the note are modified.)
            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, 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");

            IFdoOwningSequence <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 = AddBookToMockedScripture(1, "Genesis");
            IScrBook book2 = AddBookToMockedScripture(2, "Exodus");
            IScrBook book3 = AddBookToMockedScripture(3, "Leviticus");

            m_bookFilter.Add(new IScrBook[] { book1, book2, book3 });

            IFdoOwningSequence <IScrBookAnnotations> booksAnnotations =
                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.
            IScrCheckRunFactory checkRunFactory = Cache.ServiceLocator.GetInstance <IScrCheckRunFactory>();
            IScrCheckRun        checkRun        = checkRunFactory.Create();

            booksAnnotations[0].ChkHistRecsOC.Add(checkRun);
            checkRun.CheckId = checkId;
            checkRun.RunDate = date1;

            // Add a check history record for Exodus.
            checkRun = checkRunFactory.Create();
            booksAnnotations[1].ChkHistRecsOC.Add(checkRun);
            checkRun.CheckId = checkId;
            checkRun.RunDate = date2;

            // Add a check history record for Leviticus.
            checkRun = checkRunFactory.Create();
            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"));
        }
Esempio n. 15
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Matches the old check refs to the new check refs and copies over any renderings,
 /// then adds the ids of the old ChkTerms and ChkRefs to the set of IDs to be deleted.
 /// </summary>
 /// <param name="newKeyTerms">The CmPossibility whose SubPossiblities are the new key
 /// terms.</param>
 /// <param name="oldTerms">The old (top-level) key terms.</param>
 /// <param name="dlg">Progress dialog box (can be null)</param>
 /// ------------------------------------------------------------------------------------
 private void CopyRenderingsFromOldCheckRefs(ICmPossibility newKeyTerms,
                                             IFdoOwningSequence <ICmPossibility> oldTerms, IProgress dlg)
 {
     foreach (ICmPossibility poss in oldTerms)
     {
         // TE-7697, oldTerms contained something that wasn't a IChkTerm, so changed
         // using IChkTerm as loop variable to explicit cast and check for failure
         IChkTerm term = poss as IChkTerm;
         if (term != null)
         {
             foreach (IChkRef oldChkRef in term.OccurrencesOS)
             {
                 if (oldChkRef.Status != KeyTermRenderingStatus.Unassigned)
                 {
                     foreach (IChkRef newChkRef in ChkRefMatcher.FindCorrespondingChkRefs(
                                  newKeyTerms, oldChkRef))
                     {
                         newChkRef.Status      = oldChkRef.Status;
                         newChkRef.RenderingRA = oldChkRef.RenderingRA;
                         if (newChkRef.RenderingRA != null)
                         {
                             IChkTerm owningTerm = (IChkTerm)newChkRef.Owner;
                             bool     fRenderingAlreadyInCollection = false;
                             foreach (IChkRendering rendering in owningTerm.RenderingsOC)
                             {
                                 if (rendering.SurfaceFormRA == newChkRef.RenderingRA)
                                 {
                                     fRenderingAlreadyInCollection = true;
                                     break;
                                 }
                             }
                             if (!fRenderingAlreadyInCollection)
                             {
                                 IChkRendering rendering = m_servLoc.GetInstance <IChkRenderingFactory>().Create();
                                 owningTerm.RenderingsOC.Add(rendering);
                                 rendering.SurfaceFormRA = newChkRef.RenderingRA;
                             }
                         }
                     }
                 }
             }
             if (dlg != null)
             {
                 dlg.Step(1);
             }
         }
         CopyRenderingsFromOldCheckRefs(newKeyTerms, poss.SubPossibilitiesOS, null);
     }
 }
Esempio n. 16
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,
                                                IFdoOwningSequence <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);
        }
Esempio n. 17
0
        /// ------------------------------------------------------------------------------------
        /// <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)
        {
            IFdoOwningSequence <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);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Recursively adds XML terms for any terms in the list that have occurrences with
        /// renderings or explicit non-renderings (i.e., "ignored").
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void AddTerms(IFdoOwningSequence <ICmPossibility> possibilities)
        {
            foreach (ICmPossibility poss in possibilities)
            {
                IChkTerm term = poss as IChkTerm;
                if (term != null && term.OccurrencesOS.Any(o =>
                                                           o.Status != KeyTermRenderingStatus.AutoAssigned && o.Status != KeyTermRenderingStatus.Unassigned))
                {
                    Terms.Add(new XmlTerm(term));
                }

                if (poss.SubPossibilitiesOS.Any())
                {
                    AddTerms(poss.SubPossibilitiesOS);
                }
            }
        }
Esempio n. 19
0
		protected int InsertContextInto(IPhSimpleContext ctxt, SelectionHelper sel, IFdoOwningSequence<IPhSimpleContext> seq)
		{
			ICmObject[] ctxts = seq.Cast<ICmObject>().ToArray();
			int index = GetInsertionIndex(ctxts, sel);
			// if the current selection is a range remove the items we are overwriting
			if (sel.IsRange)
			{
				var indices = GetIndicesToRemove(ctxts, sel);
				foreach (int idx in indices)
				{
					var c = (IPhSimpleContext) ctxts[idx];
					c.PreRemovalSideEffects();
					seq.Remove(c);
				}
			}
			seq.Insert(index, ctxt);
			return index;
		}
        /// ------------------------------------------------------------------------------------
        /// <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, 0,
                                      sMarker, ScrStyleNames.FootnoteMarker, m_wsVern);
            }
            else
            {
                Assert.IsNull(footnote.FootnoteMarker.Text);
            }
            IFdoOwningSequence <IStPara> footnoteParas = footnote.ParagraphsOS;

            Assert.AreEqual(1, footnoteParas.Count);
            IStTxtPara para = (IStTxtPara)footnoteParas[0];

            Assert.AreEqual(StyleUtils.ParaStyleTextProps(sParaStyleName), para.StyleRules);
            ITsString tss = para.Contents;

            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;
                Assert.AreEqual(1, tss.RunCount);
                AssertEx.RunIsCorrect(tss, 0, sFootnoteTransSegment, null, m_wsAnal);
            }
            else
            {
                Assert.AreEqual(1, para.TranslationsOC.Count);
                Assert.IsNull(para.GetBT().Translation.AnalysisDefaultWritingSystem.Text);
            }
        }
Esempio n. 21
0
		protected bool RemoveContextsFrom(bool forward, SelectionHelper sel, IFdoOwningSequence<IPhSimpleContext> seq,
			bool preRemovalSideEffects, out int index)
		{
			index = -1;
			bool reconstruct = true;
			ICmObject[] ctxts = seq.Cast<ICmObject>().ToArray();
			// if the selection is a range remove all items in the selection
			if (sel.IsRange)
			{
				int[] indices = GetIndicesToRemove(ctxts, 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 (ctxts[idx].IsValidObject)
						ProcessIndicesSimpleContext(seq, ctxts, preRemovalSideEffects, idx);
				}
			}
			else
			{
				int idx = GetIndexToRemove(ctxts, sel, forward);
				if (idx > -1)
				{
					// return index of the item before the removed items
					index = idx - 1;
					ProcessIndicesSimpleContext(seq, ctxts, preRemovalSideEffects, 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>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (DialogResult == DialogResult.Cancel)
            {
                return;
            }

            IFdoOwningSequence <IStPara> oldParas = m_error.MyNote.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.
                    ((IStTxtPara)oldParas[i]).Contents = newParas[i];
                }
                else
                {
                    // Create a new paragraph
                    IStTxtPara newStPara = m_error.MyNote.ResolutionOA.AddNewTextPara(ScrStyleNames.Remark);
                    newStPara.Contents = newParas[i];
                }
            }
        }
Esempio n. 23
0
 /// <summary>
 /// Fills the in map of English name to CmPossibility object.
 /// </summary>
 /// <remarks>
 /// Allow access to tests.
 /// </remarks>
 internal void FillInMapForPossibilities(Dictionary <string, ICmPossibility> mapNameToItem,
                                         IFdoOwningSequence <ICmPossibility> possibilities)
 {
     if (possibilities == null)
     {
         return;
     }
     foreach (var item in possibilities)
     {
         var key = GetKeyForPossibility(item);
         if (String.IsNullOrEmpty(key))
         {
             continue;
         }
         if (mapNameToItem.ContainsKey(key))
         {
             continue;
         }
         mapNameToItem.Add(key, item);
         FillInMapForPossibilities(mapNameToItem, item.SubPossibilitiesOS);
     }
 }
        public void GoToLastSection()
        {
            IFdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS;

            // Start in the title of the second book.
            m_draftView.TeEditingHelper.SetInsertionPoint(ScrBookTags.kflidTitle, 1, 0);
            IScrBook book = books[1];

            m_draftView.TeEditingHelper.GoToLastSection();

            VerifySelection(4, 1, book.SectionsOS.Count - 1,
                            ScrSectionTags.kflidHeading, 0, 0);

            // Start in the last section head of the last book.
            book = books[books.Count - 1];
            m_draftView.TeEditingHelper.SetInsertionPoint(ScrSectionTags.kflidHeading,
                                                          books.Count - 1, book.SectionsOS.Count - 1);

            m_draftView.TeEditingHelper.GoToLastSection();

            VerifySelection(4, books.Count - 1, book.SectionsOS.Count - 1,
                            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,
                            ScrSectionTags.kflidHeading, 0, 0);
        }
        public void GoToFirstSection()
        {
            IFdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS;

            // Start in the title of the second book.
            m_draftView.TeEditingHelper.SetInsertionPoint(ScrBookTags.kflidTitle, 1, 0);

            m_draftView.TeEditingHelper.GoToFirstSection();

            VerifySelection(4, 1, 0, ScrSectionTags.kflidHeading, 0, 0);

            // Start in the last section head of the last book.
            IScrBook book = books[books.Count - 1];

            m_draftView.TeEditingHelper.SetInsertionPoint(ScrSectionTags.kflidHeading,
                                                          books.Count - 1, book.SectionsOS.Count - 1);

            m_draftView.TeEditingHelper.GoToFirstSection();

            VerifySelection(4, books.Count - 1, 0,
                            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 ?
                            ScrSectionTags.kflidHeading :
                            ScrSectionTags.kflidContent;

            VerifySelection(4, 0, 0, targetTag, 0, 0);
        }
Esempio n. 26
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);

            IFdoOwningSequence <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--;
                }
                else
                {
                    break;                     // found first spot for note
                }
            }

            return(insertIndex);
        }
Esempio n. 27
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="IScrBook"/> class and adds it to
		/// the given sequence.
		/// </summary>
		/// <param name="booksOS">Owning sequence of books to add the new book to</param>
		/// <param name="bookNumber">Canonical book number to be inserted</param>
		/// <returns>A ScrBook object representing the newly inserted book</returns>
		/// <exception cref="InvalidOperationException">If this method is called with a
		/// canonical book number which is already represented in the given sequence</exception>
		/// ------------------------------------------------------------------------------------
		public IScrBook Create(IFdoOwningSequence<IScrBook> booksOS, int bookNumber)
		{
			int iBook = 0;
			foreach (var existingBook in booksOS)
			{
				if (existingBook.CanonicalNum == bookNumber)
					throw new InvalidOperationException("Attempting to create a Scripture book that already exists.");

				if (existingBook.CanonicalNum > bookNumber)
					break;
				iBook++;
			}

			IScrBook book = new ScrBook();
			booksOS.Insert(iBook, book);
			book.CanonicalNum = bookNumber;
			book.BookIdRA = m_cache.ServiceLocator.GetInstance<IScrRefSystemRepository>().Singleton.BooksOS[bookNumber - 1];
			book.Name.CopyAlternatives(book.BookIdRA.BookName);
			book.Abbrev.CopyAlternatives(book.BookIdRA.BookAbbrev);
			return book;
		}
Esempio n. 28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="IScrBook"/> class and adds it to
		/// the given sequence. Also creates a new StText for the ScrBook's Title
		/// property.
		/// </summary>
		/// <param name="booksOS">Owning sequence of books to add the new book to</param>
		/// <param name="bookNumber">Canonical book number to be inserted</param>
		/// <param name="title">The title StText created for the new book</param>
		/// <returns>A ScrBook object representing the newly inserted book</returns>
		/// <exception cref="InvalidOperationException">If this method is called with a
		/// canonical book number which is already represented in the given sequence</exception>
		/// ------------------------------------------------------------------------------------
		public IScrBook Create(IFdoOwningSequence<IScrBook> booksOS, int bookNumber,
			out IStText title)
		{
			IScrBook book = Create(booksOS, bookNumber);
			book.TitleOA = title = m_cache.ServiceLocator.GetInstance<IStTextFactory>().Create();
			return book;
		}
Esempio n. 29
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Close and open &lt;section&gt; 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(IFdoOwningSequence<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;
			}
		}
Esempio n. 30
0
        public void RdeMerge_GlossAndCf()
        {
            if (Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Count < 5)
            {
                ICmSemanticDomainFactory factSemDom = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>();
                while (Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Count < 5)
                {
                    ICmSemanticDomain sem = factSemDom.Create();
                    Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(sem);
                }
            }
            IFdoOwningSequence <ICmPossibility> seqSemDom = Cache.LangProject.SemanticDomainListOA.PossibilitiesOS;
            ICmSemanticDomain semDom1 = seqSemDom[0] as ICmSemanticDomain;
            ICmSemanticDomain semDom2 = seqSemDom[1] as ICmSemanticDomain;
            ICmSemanticDomain semDom3 = seqSemDom[2] as ICmSemanticDomain;
            ICmSemanticDomain semDom4 = seqSemDom[4] as ICmSemanticDomain;

            // Create a LexEntry LE1 (cf "red" gloss "rot" in D1).
            // Attempt to merge it and verify that it survives.

            ILexEntry red      = MakeLexEntry("red", "", "rot", "", semDom1);
            Set <int> newItems = new Set <int>();
            ILexSense sense1   = red.SensesOS[0];

            newItems.Add(sense1.Hvo);
            List <XmlNode> columns       = new List <XmlNode>();
            bool           fSenseDeleted = RunMergeSense(columns, red);

            Assert.IsFalse(fSenseDeleted, "Merging red when there is no similar item should not delete sense");
            Assert.IsTrue(IsRealLexEntry(red), "Merging with no similar entry should not delete entry");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove semantic domain");

            // After creating similar entry in another domain with same info, should merge.
            var red2 = MakeLexEntry("red", "", "rot", "", semDom2);

            fSenseDeleted = RunMergeSense(columns, red2);
            Assert.IsTrue(fSenseDeleted, "Merging red/rot with matching lf/gloss should merge and delete new sense");
            Assert.IsFalse(IsRealLexEntry(red2), "Merging with red/rot with matching lf/gloss should delete entry");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should add new semantic domain");

            // Another similar entry should merge, adding definition.
            var red3 = MakeLexEntry("red", "", "rot", "rot2", semDom3);

            fSenseDeleted = RunMergeSense(columns, red3);
            Assert.IsTrue(fSenseDeleted, "Merging red/rot with matching lf/gloss and new defn should merge and delete new sense");
            Assert.IsFalse(IsRealLexEntry(red3), "Merging with red/rot with matching lf/gloss and new defn should delete entry");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.IsTrue(red.SensesOS[0].SemanticDomainsRC.Contains(semDom3), "Merging should add new semantic domain");
            Assert.That(red.SensesOS[0].Definition.AnalysisDefaultWritingSystem.Text, Is.EqualTo("rot2"));

            // Similarly we should be able to start with a matching definition, and add a gloss.
            var blue  = MakeLexEntry("blue", "", "", "blau", semDom1);
            var blue2 = MakeLexEntry("blue", "", "blauG", "blau", semDom2);

            fSenseDeleted = RunMergeSense(columns, blue2);
            Assert.IsTrue(fSenseDeleted, "Merging blue/blau with matching lf/defn and new gloss should merge and delete new sense");
            Assert.IsFalse(IsRealLexEntry(blue2), "Merging blue/blau with matching lf/defn and new gloss should delete entry");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should add new semantic domain");
            Assert.That(blue.SensesOS[0].Gloss.AnalysisDefaultWritingSystem.Text, Is.EqualTo("blauG"));

            // Conflicts in another writing system should prevent merging
            var blue3 = MakeLexEntry("blue", "", "blauG", "blau", semDom3);
            var wsEs  = Cache.WritingSystemFactory.GetWsFromStr("es");

            blue.SensesOS[0].Gloss.set_String(wsEs, "blueS");
            blue3.SensesOS[0].Gloss.set_String(wsEs, "blueS3");
            fSenseDeleted = RunMergeSense(columns, blue3);
            Assert.IsFalse(fSenseDeleted, "Merging blue/blau with matching lf/defn/gloss but different gloss in spanish should not delete sense");
            Assert.IsFalse(IsRealLexEntry(blue3), "Merging blue/blau with matching lf/defn/gloss but different gloss in spanish should delete entry");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue.SensesOS[1].SemanticDomainsRC.Contains(semDom3), "Merging should not remove old semantic domain");

            // A conflicting lex entry, even though a homograph in the current relevant writing system, should prevent merging,
            // even though the sense data all matches
            blue.CitationForm.set_String(Cache.DefaultVernWs, "blueCf");
            var blue4 = MakeLexEntry("blueForm2", "blueCf", "blauG", "blau", semDom4);

            fSenseDeleted = RunMergeSense(columns, blue4);
            Assert.IsFalse(fSenseDeleted, "Merging blueCf/blau with matching lf/defn/gloss but different lexeme form should not delete sense");
            Assert.IsTrue(IsRealLexEntry(blue4), "Merging blueCf/blau with matching lf/defn/gloss but different lexeme form should not delete entry");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.IsTrue(blue4.SensesOS[0].SemanticDomainsRC.Contains(semDom4), "Merging should not remove old semantic domain");

            // This case demonstrates that we can merge when the existing entry has no lexeme form, filling in the one we have.
            // We can also fill in other WS alternatives.
            var green  = MakeLexEntry("", "greenF", "grun", "color grun", semDom1);
            var green2 = MakeLexEntry("green", "greenF", "grun", "color grun", semDom2);

            green2.CitationForm.set_String(wsEs, "grunCfS");
            green2.LexemeFormOA.Form.set_String(wsEs, "grunS");
            fSenseDeleted = RunMergeSense(columns, green2);
            Assert.IsTrue(fSenseDeleted, "Merging green/grun with matching cf/defn/gloss and one missing LF should delete sense");
            Assert.IsFalse(IsRealLexEntry(green2), "Merging blueCf/blau with matching lf/defn/gloss but different lexeme form should not delete entry");
            Assert.IsTrue(green.SensesOS[0].SemanticDomainsRC.Contains(semDom1), "Merging should not remove old semantic domain");
            Assert.IsTrue(green.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should not remove old semantic domain");
            Assert.That(green.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text, Is.EqualTo("green"), "merge should fill in missing LF");
            Assert.That(green.LexemeFormOA.Form.get_String(wsEs).Text, Is.EqualTo("grunS"), "merge should fill in missing spanish LF");
            Assert.That(green.CitationForm.get_String(wsEs).Text, Is.EqualTo("grunCfS"), "merge should fill in missing spanish CF");

            // We should not merge when NO non-empty string matches.
            var brown  = MakeLexEntry("brown", "", "braun", "", semDom1);
            var brown2 = MakeLexEntry("brown", "", "", "braun color", semDom2);

            fSenseDeleted = RunMergeSense(columns, brown2);
            Assert.IsFalse(fSenseDeleted, "Merging two forms of brown with no overlap between gloss and defn should not delete sense");

            // But as a special case we can merge if definition of one matches gloss of other.
            var brown3 = MakeLexEntry("brown", "", "", "braun", semDom2);

            fSenseDeleted = RunMergeSense(columns, brown3);
            Assert.IsTrue(fSenseDeleted, "Merging two forms of brown with no gloss of one equal to defn of other should delete sense");
            Assert.IsTrue(brown.SensesOS[0].SemanticDomainsRC.Contains(semDom2), "Merging should combine semantic domains");
            Assert.That(brown.SensesOS[0].Definition.AnalysisDefaultWritingSystem.Text, Is.EqualTo("braun"), "Merging should copy definition");

            // We want to match entries that have the same LexemeForm even if they are not homographs.
            // This is possible if one of them has an empty CF in the homograph writing system.
            var orange  = MakeLexEntry("orange", "orangeCf", "orang", "", semDom1);
            var orange2 = MakeLexEntry("orange", "", "orang", "", semDom2);

            fSenseDeleted = RunMergeSense(columns, orange2);
            Assert.IsTrue(fSenseDeleted, "Merging two forms of orange with matching LF and new blank Cf should delete sense");

            var pink  = MakeLexEntry("pink", "", "rose", "", semDom1);
            var pink2 = MakeLexEntry("pink", "pinkCf", "rose", "", semDom2);

            fSenseDeleted = RunMergeSense(columns, pink2);
            Assert.IsTrue(fSenseDeleted, "Merging two forms of pink with matching LF and old blank Cf should delete sense");
            Assert.That(pink.CitationForm.VernacularDefaultWritingSystem.Text, Is.EqualTo("pinkCf"), "merge should fill in missing CF");

            // An inexact match that moves a sense should still fill in missing info on the chosen entry.
            var yellow  = MakeLexEntry("yellow", "", "flower", "", semDom1);
            var yellow2 = MakeLexEntry("yellow", "yellowCf", "floral", "", semDom2);

            fSenseDeleted = RunMergeSense(columns, yellow2);
            Assert.IsFalse(fSenseDeleted, "Merging two forms of yellow with matching LF and old blank Cf should delete sense");
            Assert.That(yellow.CitationForm.VernacularDefaultWritingSystem.Text, Is.EqualTo("yellowCf"), "merge should fill in missing CF");
        }
Esempio n. 31
0
		/// ------------------------------------------------------------------------------------
		/// <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="sequence">The sequence 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 virtual IStFootnote CreateBlankDummyFootnote(IFdoOwningSequence<IStFootnote> sequence,
			int iFootnote, ITsString paraContents, int iRun)
		{
			// Make a dummy blank footnote is handled in ScrTextPara subclass. Since this isn't
			// a regular subclass but hopefully has been mapped, we use a hack: If StTxtPara is
			// mapped, CreateFromDBObject will return a ScrTextPara on which we can call
			// CreateBlankDummyFootnoteNoRecursion. Otherwise we call our implementation
			// (which currently just throws an exception).
			// If "this" is already a ScrTxtPara, we override CreateBlankDummyFootnote and
			// don't come here.
			return CreateBlankDummyFootnoteNoRecursion(sequence, iFootnote, paraContents, iRun);
		}
		/// <summary>
		/// Get the default analysis gloss of the first sense of the specified sense container
		/// (typically our owning entry, but we may recurse through its nested senses)
		/// that uses this MSA.
		/// </summary>
		/// <param name="os"></param>
		/// <returns></returns>
		private ITsString GetFirstGlossOfMSAThatMatchesTss(IFdoOwningSequence<ILexSense> os)
		{
			foreach (var sense in os)
			{
				// Get the gloss of the first sense that refers to this MSA.
				if (sense.MorphoSyntaxAnalysisRA == this)
				{
					return sense.Gloss.AnalysisDefaultWritingSystem;
				}
				else
				{
					var sGloss = GetFirstGlossOfMSAThatMatchesTss(sense.SensesOS);
					if (sGloss != null)
						return sGloss; // first gloss was in a subsense; quit
				}
			}
			return null;
		}
Esempio n. 33
0
		private bool ShouldAddLeafNode(ICmPossibility keyTerm, IFdoOwningSequence<ICmPossibility> subKeyTerms)
		{
			// if we have a book filter and the keyterm doesn't have subpossibilities (ie. it's a leaf node)
			// make sure this key term has an occurrence in the books specified by the book filter.
			if (subKeyTerms.Count == 0)
			{
				if (HasBookFilter)
				{
					IChkTerm chkTerm = (IChkTerm)keyTerm;
					foreach (IChkRef chkRef in chkTerm.OccurrencesOS)
					{
						int bookIdOfOccurrence = ScrReference.GetBookFromBcv(chkRef.Ref);
						if (FilteredBookIds.Contains(bookIdOfOccurrence))
						{
							// the reference is in one of our filtered books
							// so add its key term to our tree.
							return true;
						}
					}
				}
				else
				{
					// no book filter to apply, so add all the key terms.
					return true;
				}
			}
			else
			{
				// return false. not a leaf-node.
			}
			return false;
		}
Esempio n. 34
0
		public void CreateOwnedObjects_MultipleFootnotesStartInMiddle()
		{
			// Set up the current book with a second paragraph
			IStTxtPara para1 = m_currentText[0];
			IStTxtPara para2 = AddParaToMockedText(m_currentText, "Normal");
			AddRunToMockedPara(para2, "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);

			// add a typical footnote near the start of para1
			IScrFootnote footnotePrev = AddFootnote(m_book, para1, 0, null);
			// add a typical footnote in the middle of para2
			IScrFootnote footnoteAfter = AddFootnote(m_book, para2, 20, null);

			// Add two footnotes to the archived book.
			// The ORCs are placed near the start of para2 in the current book.
			// This may seem wierd, but it simulates text that has just been copied from the archive book
			//  to para2, but the owned objects need to created for the current book with para2
			m_archivedFootnotesOS = m_arcBook.FootnotesOS;
			AddFootnote(m_arcBook, para2, 4, "footnote para2 ich 4");
			AddFootnote(m_arcBook, para2, 7, "footnote para2 ich 7");

			// call the code under test
			ReflectionHelper.CallMethod((IScrTxtPara)para2, "CreateOwnedObjects", 0, 10);

			Assert.AreEqual(4, m_currentFootnotesOS.Count);
			// Verify that the original footnotes are in the current book in the correct sequence.
			Assert.AreEqual(footnotePrev, m_currentFootnotesOS[0], "Previous footnote shouldn't have moved");
			Assert.AreEqual(footnoteAfter, m_currentFootnotesOS[3],
				"Following footnote should have gotten bumped two places");

			// Verify that the copied footnotes were created.
			VerifyFootnote(m_currentFootnotesOS[1], para2, 4);
			Assert.AreEqual("footnote para2 ich 4", ((IScrTxtPara)m_currentFootnotesOS[1].ParagraphsOS[0]).Contents.Text);
			VerifyFootnote(m_currentFootnotesOS[2], para2, 7);
			Assert.AreEqual("footnote para2 ich 7", ((IScrTxtPara)m_currentFootnotesOS[2].ParagraphsOS[0]).Contents.Text);
		}
Esempio n. 35
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Recursively adds XML terms for any terms in the list that have occurrences with
		/// renderings or explicit non-renderings (i.e., "ignored").
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void AddTerms(IFdoOwningSequence<ICmPossibility> possibilities)
		{
			foreach (ICmPossibility poss in possibilities)
			{
				IChkTerm term = poss as IChkTerm;
				if (term != null && term.OccurrencesOS.Any(o =>
					o.Status != KeyTermRenderingStatus.AutoAssigned && o.Status != KeyTermRenderingStatus.Unassigned))
				{
					Terms.Add(new XmlTerm(term));
				}

				if (poss.SubPossibilitiesOS.Any())
					AddTerms(poss.SubPossibilitiesOS);
			}
		}
Esempio n. 36
0
		public void CreateOwnedObjects_AtEnd()
		{
			IStTxtPara para = m_currentText[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_arcBook.FootnotesOS;
			AddFootnote(m_arcBook, para, para.Contents.Length, null);
			int paraLen = para.Contents.Length;
			Assert.AreEqual(0, m_currentFootnotesOS.Count);

			ReflectionHelper.CallMethod((IScrTxtPara)para, "CreateOwnedObjects", paraLen - 1, paraLen);

			Assert.AreEqual(1, m_currentFootnotesOS.Count);

			VerifyFootnote(m_currentFootnotesOS[0], para, paraLen - 1);
		}
Esempio n. 37
0
        /// <summary>
        /// Creates a TreeNode tree along genres populated by the texts that claim them.
        /// The list of textsWithNoGenre is also populated.
        /// Recursively descend the genre tree and duplicate parts that have corresponding texts.
        /// </summary>
        /// <param name="parent">The parent to attach the genres to. If null, nothing is done.</param>
        /// <param name="genreList">The owning sequence of genres - its a tree.</param>
        /// <param name="allTexts">The flat list of all texts in the project.</param>
        private void LoadTextsFromGenres(TreeNode parent, IFdoOwningSequence <ICmPossibility> genreList, IEnumerable <FDO.IText> allTexts)
        {
            if (parent == null)
            {
                return;
            }
            var sortedGenreList = new List <ICmPossibility>();

            foreach (var gen in genreList)
            {
                sortedGenreList.Add(gen);
            }
            var sorter = new CmPossibilitySorter();

            sortedGenreList.Sort(sorter);
            foreach (var gen in sortedGenreList)
            {
                // This tree node is added to genreTreeNodes if there are texts or children
                var genItem = new TreeNode(gen.ChooserNameTS.Text);

                // LT-12179: Create a List for collecting selected tree nodes which we will later sort
                // before actually adding them to the tree:
                var sortedNodes    = new List <TreeNode>();
                var foundFirstText = false;
                // Create a collator ready for sorting:
                var collator = LgIcuCollatorClass.Create();

                foreach (IText tex in allTexts)
                {                   // This tex may not have a genre or it may claim to be in more than one
                    foreach (var tgen in tex.GenresRC)
                    {
                        if (tgen.Equals(gen))
                        {
                            // The current tex is valid, so create a TreeNode with its details:
                            var texItem = new TreeNode(tex.ChooserNameTS.Text);
                            texItem.Tag  = tex.ContentsOA;
                            texItem.Name = "Text";

                            // LT-12179: Add the new TreeNode to the (not-yet-)sorted list:
                            sortedNodes.Add(texItem);

                            // LT-12179: If this is the first tex we've added, establish the collator's details
                            // according to the writing system at the start of the tex:
                            if (!foundFirstText)
                            {
                                foundFirstText = true;
                                var ws1      = tex.ChooserNameTS.get_WritingSystemAt(0);
                                var wsEngine = gen.Cache.WritingSystemFactory.get_EngineOrNull(ws1);
                                collator.Open(wsEngine.Id);
                            }
                            break;
                        }
                    }
                }

                // LT-12179:
                if (foundFirstText)
                {
                    // Order the TreeNodes alphabetically:
                    sortedNodes.Sort((x, y) => collator.Compare(x.Text, y.Text, LgCollatingOptions.fcoIgnoreCase));
                    // Add the TreeNodes to the tree:
                    genItem.Nodes.AddRange(sortedNodes.ToArray());
                }

                if (gen.SubPossibilitiesOS.Count > 0)
                {                   // Descend to the child genres regardless if there were texts assigned to this genre
                    LoadTextsFromGenres(genItem, gen.SubPossibilitiesOS, allTexts);
                }

                //Add the node even if there are no texts that point to this genre.
                genItem.Tag  = gen;                 // ICmPossibility
                genItem.Name = "Genre";
                parent.Nodes.Add(genItem);
            }
        }
Esempio n. 38
0
		IPartOfSpeech CreatePartOfSpeech(IFdoOwningSequence<ICmPossibility> owningSeq,
			string sName, bool fCreateAffixTemplate)
		{
			IPartOfSpeech pos = Cache.ServiceLocator.GetInstance<IPartOfSpeechFactory>().Create();
			owningSeq.Add(pos);
			pos.Name.set_String(Cache.DefaultAnalWs, sName);
			if (fCreateAffixTemplate)
			{
				IMoInflAffixTemplate t = Cache.ServiceLocator.GetInstance<IMoInflAffixTemplateFactory>().Create();
				pos.AffixTemplatesOS.Add(t);
			}
			return pos;
		}
Esempio n. 39
0
        public void RdeMerge()
        {
            if (Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Count < 5)
            {
                ICmSemanticDomainFactory factSemDom = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>();
                while (Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Count < 5)
                {
                    ICmSemanticDomain sem = factSemDom.Create();
                    Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(sem);
                }
            }
            IFdoOwningSequence <ICmPossibility> seqSemDom = Cache.LangProject.SemanticDomainListOA.PossibilitiesOS;
            ICmSemanticDomain semDom1 = seqSemDom[0] as ICmSemanticDomain;
            ICmSemanticDomain semDom2 = seqSemDom[1] as ICmSemanticDomain;
            ICmSemanticDomain semDom3 = seqSemDom[2] as ICmSemanticDomain;
            ICmSemanticDomain semDom4 = seqSemDom[4] as ICmSemanticDomain;

            // Create a LexEntry LE1 ("xyzTest1" defined as "xyzDefn1.1" in D1).
            // Attempt to merge it and verify that it survives.

            ILexEntry le1      = MakeLexEntry("xyzTest1", "xyzDefn1.1", semDom1);
            Set <int> newItems = new Set <int>();
            ILexSense sense1   = le1.SensesOS[0];

            newItems.Add(sense1.Hvo);
            // get an id for the 'list of senses' property (which isn't in the model)
            int fakeFlid = (int)CmObjectFields.kflidStartDummyFlids + 1;

            List <XmlNode> columns       = new List <XmlNode>();
            bool           fSenseDeleted = sense1.RDEMergeSense(semDom1.Hvo, columns, Cache, newItems);

            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 1: sense should not be deleted");
            Assert.IsTrue(IsRealLexEntry(le1));
            Assert.IsTrue(le1.SensesOS[0].SemanticDomainsRC.Contains(semDom1));

            // Attempt to merge them both.
            // Verify that LE3 survives.
            // Verify that old LE1 survives and now has two senses; new sense has xyzDefn1.2.
            // Verify that LE2 is deleted and LE3 survives.
            ILexEntry le2       = MakeLexEntry("xyzTest1", "xyzDefn1.2", semDom2);
            Set <int> newItems2 = new Set <int>();
            ILexSense sense2    = le2.SensesOS[0];

            newItems2.Add(sense2.Hvo);

            ILexEntry le3    = MakeLexEntry("xyzTest3", "xyzDefn3.1", semDom2);
            ILexSense sense3 = le3.SensesOS[0];

            newItems2.Add(sense3.Hvo);

            fSenseDeleted = sense2.RDEMergeSense(semDom2.Hvo, columns, Cache, newItems2);
            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 2: sense should not be deleted");
            fSenseDeleted = sense3.RDEMergeSense(semDom2.Hvo, columns, Cache, newItems2);
            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 3: sense should not be deleted");
            Assert.IsTrue(IsRealLexEntry(le3));
            Assert.IsFalse(IsRealLexEntry(le2), "entry should be deleted");
            Assert.IsTrue(IsRealLexEntry(le1));
            Assert.AreEqual(2, le1.SensesOS.Count, "sense added to entry by merge");
            Assert.AreEqual(1, le3.SensesOS.Count, "should still be one sense");
            Assert.AreEqual("xyzDefn1.2", le1.SensesOS[1].Definition.AnalysisDefaultWritingSystem.Text);
            Assert.IsTrue(le1.SensesOS[1].SemanticDomainsRC.Contains(semDom2));
            Assert.IsTrue(le3.SensesOS[0].SemanticDomainsRC.Contains(semDom2));

            // Create two more entries LE4("xyzTest1/xyzDefn1.2/D3" and LE5 ("xyzTest1/xyzDefn1.3/D3").
            // Verify that the second sense of LE1 gains a domain;
            // It also gains exactly one new sense;
            // And LE4 and LE5 are both deleted.
            ILexEntry le4       = MakeLexEntry("xyzTest1", "xyzDefn1.2", semDom3);
            Set <int> newItems3 = new Set <int>();
            ILexSense sense4    = le4.SensesOS[0];

            newItems3.Add(sense4.Hvo);

            ILexEntry le5    = MakeLexEntry("xyzTest1", "xyzDefn1.3", semDom3);
            ILexSense sense5 = le5.SensesOS[0];

            newItems3.Add(sense5.Hvo);

            fSenseDeleted = sense4.RDEMergeSense(semDom3.Hvo, columns, Cache, newItems3);
            Assert.IsTrue(fSenseDeleted, "RDEMergeSense 4: sense should be deleted");
            fSenseDeleted = sense5.RDEMergeSense(semDom3.Hvo, columns, Cache, newItems3);
            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 5: sense should not be deleted");
            Assert.IsTrue(IsRealLexEntry(le3));
            Assert.IsFalse(IsRealLexEntry(le4));
            Assert.IsFalse(IsRealLexEntry(le5));
            Assert.IsTrue(IsRealLexEntry(le1));
            Assert.AreEqual(3, le1.SensesOS.Count, "one sense added to entry by merge");
            Assert.AreEqual("xyzDefn1.3", le1.SensesOS[2].Definition.AnalysisDefaultWritingSystem.Text);
            Assert.IsTrue(le1.SensesOS[2].SemanticDomainsRC.Contains(semDom3));
            int[] sense2Domains = le1.SensesOS[1].SemanticDomainsRC.ToHvoArray();
            Assert.AreEqual(2, sense2Domains.Length, "got 2 semantic domains on sense 2");
            int minDom    = Math.Min(semDom2.Hvo, semDom3.Hvo);           // smaller of expected domains.
            int maxDom    = Math.Max(semDom2.Hvo, semDom3.Hvo);
            int minActual = Math.Min(sense2Domains[0], sense2Domains[1]);
            int maxActual = Math.Max(sense2Domains[0], sense2Domains[1]);

            Assert.AreEqual(minDom, minActual, "expected domains on merged sense");
            Assert.AreEqual(maxDom, maxActual, "expected domains on merged sense");

            // Try adding four senses, three for the same CF, but which doesn't pre-exist.
            // Also, the three are exact duplicates.
            ILexEntry le6       = MakeLexEntry("xyzTest6", "xyzDefn6.1", semDom4);
            Set <int> newItems4 = new Set <int>();
            ILexSense sense6    = le6.SensesOS[0];

            newItems4.Add(sense6.Hvo);

            ILexEntry le7    = MakeLexEntry("xyzTest6", "xyzDefn6.1", semDom4);
            ILexSense sense7 = le7.SensesOS[0];

            newItems4.Add(sense7.Hvo);

            ILexEntry le8    = MakeLexEntry("xyzTest6", "xyzDefn6.1", semDom4);
            ILexSense sense8 = le8.SensesOS[0];

            newItems4.Add(sense8.Hvo);

            fSenseDeleted = sense6.RDEMergeSense(semDom4.Hvo, columns, Cache, newItems4);
            Assert.IsFalse(fSenseDeleted, "RDEMergeSense 6: sense should not be deleted");
            fSenseDeleted = sense7.RDEMergeSense(semDom4.Hvo, columns, Cache, newItems4);
            Assert.IsTrue(fSenseDeleted, "RDEMergeSense 7: sense should be deleted");
            fSenseDeleted = sense8.RDEMergeSense(semDom4.Hvo, columns, Cache, newItems4);
            Assert.IsTrue(fSenseDeleted, "RDEMergeSense 8: sense should be deleted");

            Assert.IsTrue(IsRealLexEntry(le6));
            Assert.IsFalse(IsRealLexEntry(le7));
            Assert.IsFalse(IsRealLexEntry(le8));
            Assert.AreEqual(1, le6.SensesOS.Count, "one sense survives merge");
        }
Esempio n. 40
0
			//bool m_fNeedToRebuildParagraphContentFromStrings = false;

			internal ParagraphBuilder(FdoCache cache, IFdoOwningSequence<IStPara> owner)
			{
				m_owner = owner;
				m_cache = cache;
			}
Esempio n. 41
0
		private void RegisterAllSubrecordIndexTSSChanged(IFdoOwningSequence<IRnGenericRec> subs, int flid, ITsString dummy)
		{
			foreach (IRnGenericRec rec in subs)
			{
				((IServiceLocatorInternal)m_cache.ServiceLocator).UnitOfWorkService.RegisterVirtualAsModified(
					rec, flid, null, dummy);
				RegisterAllSubrecordIndexTSSChanged(rec.SubRecordsOS, flid, dummy);
			}
		}
Esempio n. 42
0
			internal ParagraphBuilder(FdoCache cache, IFdoOwningSequence<IStPara> owner, XmlNode paraDefn)
				: this(cache, owner)
			{
				m_paraDefn = paraDefn;
			}
Esempio n. 43
0
		/// <summary>
		/// Find an environment in allProjectEnvs of string representation
		/// environmentPattern. Prefer to find a match that is in preferredHvos
		/// (such as hvos used before recent editing) and not in alreadyUsedHvos
		/// (hvos already used in slice).
		/// Preferring matching a hvo used before recent editing helps the
		/// Environments dialog behave more sensibly in the case of multiple
		/// items with the same string representation. (eg FWNX-822)
		/// </summary>
		private static IPhEnvironment FindPhoneEnv(
			IFdoOwningSequence<IPhEnvironment> allProjectEnvs,
			string environmentPattern, int[] alreadyUsedHvos,
			int[] preferredHvos)
		{
			// Try to find a match in the preferred set that isn't already used
			var preferredMatches = preferredHvos.Where(preferredHvo =>
				EqualsIgnoringSpaces(
					GetEnvironmentFromHvo(allProjectEnvs, preferredHvo)
						.StringRepresentation.Text,
					environmentPattern));
			if (preferredMatches.Count() > 0)
			{
				var unusedPreferred = preferredMatches.Except(alreadyUsedHvos);
				if (unusedPreferred.Count() > 0)
					return GetEnvironmentFromHvo(allProjectEnvs,
						unusedPreferred.First());
			}

			// Broaden where we look to all project environments
			var anyMatches = allProjectEnvs.Where(env =>
				EqualsIgnoringSpaces(
					env.StringRepresentation.Text,
					environmentPattern));
			if (anyMatches.Count() == 0)
				return null; // Shouldn't happen if adding envs new to project ahead of time.

			// Try to return a match that isn't already used.
			var unused = anyMatches.Select(env => env.Hvo).Except(alreadyUsedHvos);

			if (unused.Count() > 0)
				return GetEnvironmentFromHvo(allProjectEnvs, unused.First());

			// Just re-use an env
			return anyMatches.First();
		}
		private string GetFirstGlossOfMSAThatMatches(IFdoOwningSequence<ILexSense> os)
		{
			var tss = GetFirstGlossOfMSAThatMatchesTss(os);
			if (tss != null)
				return tss.Text;
			return null;
		}
Esempio n. 45
0
		/// ------------------------------------------------------------------------------------
		/// <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(IFdoOwningSequence<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;
		}
Esempio n. 46
0
		private static void FillPossibilityMap(RnSfMarker rsf, IFdoOwningSequence<ICmPossibility> seq,
			Dictionary<string, ICmPossibility> map)
		{
			if (seq == null || seq.Count == 0)
				return;
			bool fAbbrev = rsf.m_tlo.m_pnt == PossNameType.kpntAbbreviation;
			foreach (ICmPossibility poss in seq)
			{
				string sKey = fAbbrev ?
					poss.Abbreviation.AnalysisDefaultWritingSystem.Text :
					poss.Name.AnalysisDefaultWritingSystem.Text;
				if (String.IsNullOrEmpty(sKey))
					continue;
				sKey = sKey.ToLowerInvariant();
				if (map.ContainsKey(sKey))
					continue;
				map.Add(sKey, poss);
				FillPossibilityMap(rsf, poss.SubPossibilitiesOS, map);
			}
		}
Esempio n. 47
0
		/// ------------------------------------------------------------------------------------
		/// <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(IFdoOwningSequence<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;
		}
Esempio n. 48
0
		/// ------------------------------------------------------------------------------------
		/// <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, IFdoOwningSequence<IStPara> revParas,
			IFdoOwningSequence<IStPara> curParas)
		{
			for (int iPara = 0; iPara < revParas.Count; iPara++)
			{
				AssertEx.AreTsStringsEqual(((IScrTxtPara)revParas[iPara]).Contents,
					((IScrTxtPara)curParas[iPara]).Contents,
					((fIsHeading) ? "Headings" : "Contents") + " are different in para " + iPara +
					" of section " + iSection);
			}
		}
Esempio n. 49
0
		private ICmPossibility CreateNewPossibility(List<string> rgsHier,
			CmPossibilityCreator factory,
			IFdoOwningSequence<ICmPossibility> possList,
			Dictionary<string, ICmPossibility> map,
			List<ICmPossibility> rgNew)
		{
			ICmPossibility possParent = null;
			ICmPossibility poss = null;
			int i;
			for (i = 0; i < rgsHier.Count; ++i)
			{
				if (!map.TryGetValue(rgsHier[i].ToLowerInvariant(), out poss))
					break;
				if (i > 0 && poss.Owner != possParent)
					break;
				possParent = poss;
			}
			if (i == rgsHier.Count)
			{
				// program bug -- shouldn't get here!
				Debug.Assert(i < rgsHier.Count);
				return null;
			}
			if (poss != null && i > 0 && poss.Owner != possParent)
			{
				// we can't create a duplicate name at a lower level in our current alogrithm!
				// Complain and do nothing...
				return null;
			}
			ICmPossibility itemParent = possParent as ICmAnthroItem;
			ICmPossibility item = null;
			for (; i < rgsHier.Count; ++i)
			{
				item = factory.Create();
				if (itemParent == null)
					possList.Add(item);
				else
					itemParent.SubPossibilitiesOS.Add(item);
				ITsString tss = m_cache.TsStrFactory.MakeString(rgsHier[i], m_cache.DefaultAnalWs);
				item.Name.AnalysisDefaultWritingSystem = tss;
				item.Abbreviation.AnalysisDefaultWritingSystem = tss;
				map.Add(rgsHier[i].ToLowerInvariant(), item);
				rgNew.Add(item);
				itemParent = item;
			}
			return item;
		}
Esempio n. 50
0
		/// <summary>
		/// Fills the in map of English name to CmPossibility object.
		/// </summary>
		/// <remarks>
		/// Allow access to tests.
		/// </remarks>
		internal void FillInMapForPossibilities(Dictionary<string, ICmPossibility> mapNameToItem,
			IFdoOwningSequence<ICmPossibility> possibilities)
		{
			if (possibilities == null)
				return;
			foreach (var item in possibilities)
			{
				var key = GetKeyForPossibility(item);
				if (String.IsNullOrEmpty(key))
					continue;
				if (mapNameToItem.ContainsKey(key))
					continue;
				mapNameToItem.Add(key, item);
				FillInMapForPossibilities(mapNameToItem, item.SubPossibilitiesOS);
			}
		}
Esempio n. 51
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			// ScrBooks are only used because, currently, they are the only objects that
			// own footnotes
			m_book = Cache.ServiceLocator.GetInstance<IScrBookFactory>().Create(1, out m_currentText);

			IStTxtPara para = AddParaToMockedText(m_currentText, "Normal");
			AddRunToMockedPara(para, "1", "CharacterStyle1");
			AddRunToMockedPara(para, "1", "CharacterStyle2");
			AddRunToMockedPara(para, "This text has no char style.", null);
			m_currentFootnotesOS = m_book.FootnotesOS;

			// make the archive text
			m_arcBook = Cache.ServiceLocator.GetInstance<IScrBookFactory>().Create(2, out m_archivedText);

			para = AddParaToMockedText(m_archivedText, "Normal");
			AddRunToMockedPara(para, "1", "CharacterStyle1");
			AddRunToMockedPara(para, "1", "CharacterStyle2");
			AddRunToMockedPara(para, "This is the previous version of the text.", null);
			m_archivedFootnotesOS = m_arcBook.FootnotesOS;
		}
Esempio n. 52
0
		/// <returns>
		/// First matching environment from environmentsHaystack or null if none
		/// found.
		/// </returns>
		private static IPhEnvironment GetEnvironmentFromHvo(
			IFdoOwningSequence<IPhEnvironment> environmentsHaystack,
			int hvoPattern)
		{
			return environmentsHaystack.FirstOrDefault(env =>
				env.Hvo == hvoPattern);
		}
Esempio n. 53
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,
			IFdoOwningSequence<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;
		}
Esempio n. 54
0
		private void FillInMapForPossibilities(Dictionary<string, ICmPossibility> mapNameToItem,
			IFdoOwningSequence<ICmPossibility> possibilities)
		{
			if (possibilities == null)
				return;
			foreach (var item in possibilities)
			{
				ITsString tss = item.Name.get_String(m_wsEn);
				if (tss == null)
					continue;
				string name = tss.Text;
				if (String.IsNullOrEmpty(name))
					continue;
				if (mapNameToItem.ContainsKey(name))
					continue;
				mapNameToItem.Add(name, item);
				FillInMapForPossibilities(mapNameToItem, item.SubPossibilitiesOS);
			}
		}
Esempio n. 55
0
		/// ------------------------------------------------------------------------------------
		/// <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="sequence">The sequence 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>
		/// <remarks>NOTE: Don't call this version directly - always call
		/// CreateBlankDummyFootnote!</remarks>
		/// ------------------------------------------------------------------------------------
		protected virtual IStFootnote CreateBlankDummyFootnoteNoRecursion(IFdoOwningSequence<IStFootnote> sequence,
			int iFootnote, ITsString paraContents, int iRun)
		{
			throw new NotImplementedException("Not yet implemented for non-ScrBook owners");
		}