The interesting texts list is responsible for maintaining a list of the texts that should be displayed in the Interlinear Texts tool and searched in the various concordance tools. Currently this is all the StTexts owned by Texts (that is, the main collection of interlinear texts in the language project), and selected sections of Scripture. The list is persisted in the mediator's property table, being thus specific to one user, and possibly a particular window. It implements IVwNotifyChange and updates the list when various relevant properties change.
Inheritance: IVwNotifyChange
Example #1
0
 public void SetMediator(Mediator mediator, PropertyTable propertyTable)
 {
     Mediator           = mediator;
     PropTable          = propertyTable;
     m_interestingTexts = InterestingTextsDecorator.GetInterestingTextList(mediator, PropTable, m_services);
     m_interestingTexts.InterestingTextsChanged += m_interestingTexts_InterestingTextsChanged;
 }
        private MockText AddMockText(MockTextRepository mockTextRep, InterestingTextList testObj)
        {
            var newText = new MockText();

            mockTextRep.m_texts.Add(newText);
            testObj.PropChanged(newText.Hvo, TextTags.kflidContents, 0, 1, 0);
            return(newText);
        }
        private void RemoveText(MockTextRepository mockTextRep, InterestingTextList testObj, int index)
        {
            var oldTextHvo = mockTextRep.m_texts[index].Hvo;

            ((MockText)mockTextRep.m_texts[index]).IsValidObject = false;
            ((MockStText)mockTextRep.m_texts[index].ContentsOA).IsValidObject = false;
            mockTextRep.m_texts.RemoveAt(index);
            testObj.PropChanged(oldTextHvo, TextTags.kflidContents, 0, 0, 1);
        }
        public void GetCoreTexts()
        {
            MockTextRepository mockTextRep = MakeMockTextRepoWithTwoMockTexts();
            var testObj = new InterestingTextList(m_propertyTable, mockTextRep, m_mockStTextRepo);

            VerifyList(CurrentTexts(mockTextRep),
                       testObj.InterestingTexts, "texts from initial list of two");
            // Make sure it works if there are none.
            Assert.AreEqual(0, new InterestingTextList(m_propertyTable, new MockTextRepository(), m_mockStTextRepo).InterestingTexts.Count());
            Assert.IsTrue(testObj.IsInterestingText(mockTextRep.m_texts[0].ContentsOA));
            Assert.IsFalse(testObj.IsInterestingText(new MockStText()));
        }
        public void PropertyTableHasInvalidObjects()
        {
            MockTextRepository mockTextRep = MakeMockTextRepoWithTwoMockTexts();

            MakeMockScriptureSection();
            m_propertyTable.SetProperty(InterestingTextList.PersistPropertyName, InterestingTextList.MakeIdList(
                                            new ICmObject[] { m_sections[0].ContentOA, m_sections[0].HeadingOA }) + "," + Convert.ToBase64String(Guid.NewGuid().ToByteArray()) + ",$%^#@+");
            var testObj = new InterestingTextList(m_propertyTable, mockTextRep, m_mockStTextRepo, true);

            testObj.InterestingTextsChanged += TextsChangedHandler;
            var expectedScripture = new List <IStText>();

            expectedScripture.Add(m_sections[0].ContentOA);
            expectedScripture.Add(m_sections[0].HeadingOA);
            VerifyList(expectedScripture, testObj.ScriptureTexts, "Just two valid Guids");
        }
		static public InterestingTextList GetInterestingTextList(Mediator mediator, IFdoServiceLocator services)
		{
			var interestingTextList = mediator.PropertyTable.GetValue(InterestingTextKey, null) as InterestingTextList;
			if (interestingTextList == null)
			{
				interestingTextList = new InterestingTextList(mediator.PropertyTable, services.GetInstance<ITextRepository>(),
					services.GetInstance<IStTextRepository>(), FwUtils.IsOkToDisplayScriptureIfPresent);
				// Make this list available for other tools in this window, but don't try to persist it.
				mediator.PropertyTable.SetProperty(InterestingTextKey, interestingTextList, false);
				mediator.PropertyTable.SetPropertyPersistence(InterestingTextKey, false);
				// Since the list hangs around indefinitely, it indefinitely monitors prop changes.
				// I can't find any way to make sure it eventually gets removed from the notification list.
				services.GetInstance<ISilDataAccessManaged>().AddNotification(interestingTextList);
			}
			return interestingTextList;
		}
        public void ReplaceCoreText()
        {
            MockTextRepository mockTextRepo = MakeMockTextRepoWithTwoMockTexts();
            var      testObj     = new InterestingTextList(m_propertyTable, mockTextRepo, m_mockStTextRepo);
            var      firstStText = testObj.InterestingTexts.First();
            MockText firstText   = firstStText.Owner as MockText;
            var      replacement = new MockStText();

            testObj.InterestingTextsChanged += TextsChangedHandler;
            firstText.ContentsOA             = replacement;
            testObj.PropChanged(firstText.Hvo, TextTags.kflidContents, 0, 1, 1);

            VerifyList(CurrentTexts(mockTextRepo),
                       testObj.InterestingTexts, "texts after replace");
            // Various possibilities could be valid for the arguments...for now just verify we got something.
            Assert.That(m_lastTextsChangedArgs, Is.Not.Null);
        }
Example #8
0
        static public InterestingTextList GetInterestingTextList(Mediator mediator, IFdoServiceLocator services)
        {
            var interestingTextList = mediator.PropertyTable.GetValue(InterestingTextKey, null) as InterestingTextList;

            if (interestingTextList == null)
            {
                interestingTextList = new InterestingTextList(mediator.PropertyTable, services.GetInstance <ITextRepository>(),
                                                              services.GetInstance <IStTextRepository>(), FwUtils.IsTEInstalled);
                // Make this list available for other tools in this window, but don't try to persist it.
                mediator.PropertyTable.SetProperty(InterestingTextKey, interestingTextList, false);
                mediator.PropertyTable.SetPropertyPersistence(InterestingTextKey, false);
                // Since the list hangs around indefinitely, it indefinitely monitors prop changes.
                // I can't find any way to make sure it eventually gets removed from the notification list.
                services.GetInstance <ISilDataAccessManaged>().AddNotification(interestingTextList);
            }
            return(interestingTextList);
        }
        public void AddAndRemoveCoreTexts()
        {
            MockTextRepository mockTextRep = MakeMockTextRepoWithTwoMockTexts();
            var testObj = new InterestingTextList(m_propertyTable, mockTextRep, m_mockStTextRepo);

            Assert.AreEqual(0, testObj.ScriptureTexts.Count());
            testObj.InterestingTextsChanged += TextsChangedHandler;
            MockText newText = AddMockText(mockTextRep, testObj);

            VerifyList(CurrentTexts(mockTextRep),
                       testObj.InterestingTexts, "texts from initial list of two");
            VerifyTextsChangedArgs(2, 1, 0);
            var removed = mockTextRep.m_texts[1].ContentsOA;

            RemoveText(mockTextRep, testObj, 1);
            VerifyList(CurrentTexts(mockTextRep),
                       testObj.InterestingTexts, "texts from initial list of two");
            VerifyTextsChangedArgs(1, 0, 1);
            Assert.IsTrue(testObj.IsInterestingText(mockTextRep.m_texts[1].ContentsOA), "text not removed still interesting");
            Assert.IsFalse(testObj.IsInterestingText(removed), "removed text no longer interesting");
        }
        private InterestingTextList SetupTwoMockTextsAndOneScriptureSection(bool fIncludeScripture, out List <IStText> expectedScripture,
                                                                            out List <IStText> expected)
        {
            MockTextRepository mockTextRep = MakeMockTextRepoWithTwoMockTexts();

            MakeMockScriptureSection();
            m_propertyTable.SetProperty(InterestingTextList.PersistPropertyName, InterestingTextList.MakeIdList(
                                            new ICmObject[] { m_sections[0].ContentOA, m_sections[0].HeadingOA }));
            var testObj = new InterestingTextList(m_propertyTable, mockTextRep, m_mockStTextRepo, fIncludeScripture);

            testObj.InterestingTextsChanged += TextsChangedHandler;
            expectedScripture = new List <IStText>();
            expectedScripture.Add(m_sections[0].ContentOA);
            expectedScripture.Add(m_sections[0].HeadingOA);
            VerifyScriptureList(testObj, expectedScripture, "Initially two Scripture texts");

            expected = new List <IStText>(CurrentTexts(mockTextRep));
            if (fIncludeScripture)
            {
                expected.AddRange(expectedScripture);
            }
            VerifyList(expected, testObj.InterestingTexts, "two ordinary and two Scripture texts");
            return(testObj);
        }
Example #11
0
 public void SetMediator(Mediator mediator)
 {
     m_interestingTexts = GetInterestingTextList(mediator, m_services);
     m_interestingTexts.InterestingTextsChanged += m_interestingTexts_InterestingTextsChanged;
 }
Example #12
0
 public void SetMediator(Mediator mediator, PropertyTable propertyTable)
 {
     m_interestingTexts = GetInterestingTextList(mediator, propertyTable, m_services);
     m_interestingTexts.InterestingTextsChanged += m_interestingTexts_InterestingTextsChanged;
 }
        public void AddAndRemoveScripture()
        {
            List <IStText>      expectedScripture;
            List <IStText>      expected;
            InterestingTextList testObj = SetupTwoMockTextsAndOneScriptureSection(true, out expectedScripture, out expected);

            MakeMockScriptureSection();
            testObj.PropChanged(m_sections[1].Hvo, ScrSectionTags.kflidContent, 0, 1, 0);
            testObj.PropChanged(m_sections[1].Hvo, ScrSectionTags.kflidHeading, 0, 1, 0);
            VerifyList(expected, testObj.InterestingTexts, "new Scripture objects are not added automatically");
            VerifyScriptureList(testObj, expectedScripture, "new Scripture objects are not added automatically to ScriptureTexts");
            Assert.IsTrue(testObj.IsInterestingText(expectedScripture[0]));
            Assert.IsTrue(testObj.IsInterestingText(expectedScripture[1]));

            var remove = ((MockStText)m_sections[0].ContentOA);

            remove.IsValidObject = false;
            expected.Remove(m_sections[0].ContentOA);   // before we clear ContentsOA!
            expectedScripture.Remove(m_sections[0].ContentOA);
            m_sections[0].ContentOA = null;             // not normally valid, but makes things somewhat more consistent for test.
            testObj.PropChanged(m_sections[0].Hvo, ScrSectionTags.kflidContent, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (ContentsOA)");
            VerifyScriptureList(testObj, expectedScripture, "deleted Scripture texts are removed from ScriptureTexts (ContentsOA");
            VerifyTextsChangedArgs(2, 0, 1);
            Assert.IsFalse(testObj.IsInterestingText(remove));
            Assert.IsTrue(testObj.IsInterestingText(expectedScripture[0]));

            ((MockStText)m_sections[0].HeadingOA).IsValidObject = false;
            expected.Remove(m_sections[0].HeadingOA);   // before we clear ContentsOA!
            m_sections[0].HeadingOA = null;             // not normally valid, but makes things somewhat more consistent for test.
            testObj.PropChanged(m_sections[0].Hvo, ScrSectionTags.kflidHeading, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (HeadingOA)");

            m_sections[0].ContentOA = new MockStText();
            var newTexts = new IStText[] { expected[0], expected[1], m_sections[0].ContentOA, m_sections[1].ContentOA, m_sections[1].HeadingOA };

            testObj.SetInterestingTexts(newTexts);
            VerifyTextsChangedArgs(2, 3, 0);
            expected.AddRange(new[] { m_sections[0].ContentOA, m_sections[1].ContentOA, m_sections[1].HeadingOA });
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (HeadingOA)");
            // Unfortunately, I don't think we actually get PropChanged on the direct owning property,
            // if the owning object (Text or ScrSection) gets deleted. We need to detect deleted objects
            // if things are deleted from any of the possible owning properties.
            // This is also a chance to verify that being owned by an ScrDraft does not count as valid.
            // It's not a very realistic test, as we aren't trying to make everything about the test data consistent.
            ((MockStText)m_sections[0].ContentOA).m_mockOwnerOfClass = new MockScrDraft();              // not allowed in list.
            testObj.PropChanged(m_sections[0].Hvo, ScrBookTags.kflidSections, 0, 0, 1);
            expected.RemoveAt(2);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (ScrBook.SectionsOS)");
            VerifyTextsChangedArgs(2, 0, 1);

            ((MockStText)expected[3]).IsValidObject = false;
            expected.RemoveAt(3);
            testObj.PropChanged(m_sections[0].Hvo, ScriptureTags.kflidScriptureBooks, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (Scripture.ScriptureBooks)");
            VerifyTextsChangedArgs(3, 0, 1);

            ((MockStText)expected[2]).IsValidObject = false;
            expected.RemoveAt(2);
            testObj.PropChanged(m_sections[0].Hvo, ScrBookTags.kflidTitle, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted Scripture texts are removed (ScrBookTags.Title)");
            VerifyTextsChangedArgs(2, 0, 1);
            Assert.AreEqual(0, testObj.ScriptureTexts.Count(), "by now we've removed all ScriptureTexts");

            ((MockStText)expected[1]).IsValidObject = false;
            expected.RemoveAt(1);
            //testObj.PropChanged(1, LangProjectTags.kflidTexts, 0, 0, 1);
            VerifyList(expected, testObj.InterestingTexts, "deleted texts are removed (LangProject.Texts)");
            VerifyTextsChangedArgs(1, 0, 1);
        }
Example #14
0
 public void SetMediator(Mediator mediator)
 {
     Mediator           = mediator;
     m_interestingTexts = InterestingTextsDecorator.GetInterestingTextList(mediator, m_services);
     m_interestingTexts.InterestingTextsChanged += m_interestingTexts_InterestingTextsChanged;
 }
		public void SetMediator(Mediator mediator)
		{
			m_interestingTexts = GetInterestingTextList(mediator, m_services);
			m_interestingTexts.InterestingTextsChanged += m_interestingTexts_InterestingTextsChanged;
		}
Example #16
0
		public void SetMediator(Mediator mediator)
		{
			Mediator = mediator;
			m_interestingTexts = InterestingTextsDecorator.GetInterestingTextList(mediator, m_services);
			m_interestingTexts.InterestingTextsChanged += m_interestingTexts_InterestingTextsChanged;
		}
 private void VerifyScriptureList(InterestingTextList testObj, List <IStText> expectedScripture, string comment)
 {
     VerifyList(expectedScripture, testObj.ScriptureTexts, comment);
     Assert.AreEqual(InterestingTextList.MakeIdList(expectedScripture.Cast <ICmObject>()),
                     m_propertyTable.GetStringProperty(InterestingTextList.PersistPropertyName, null));
 }