Example #1
0
		private void MakeUndoAction()
		{
			m_respellUndoaction = new RespellUndoAction(
				m_specialSda,
				m_cache,
				m_vernWs,
				m_srcwfiWordform.Form.get_String(m_vernWs).Text,
				m_cbNewSpelling.Text)
									{
										PreserveCase = m_cbMaintainCase.Checked
									};
			var tagEnabled = m_sourceSentences.BrowseViewer.PreviewEnabledTag;
			foreach (int hvo in m_sourceSentences.BrowseViewer.CheckedItems)
			{
				if (m_specialSda.get_IntProp(hvo, tagEnabled) == 1)
					m_respellUndoaction.AddOccurrence(hvo);
			}
		}
Example #2
0
		private void AddAllOccurrences(RespellUndoAction action, List<int> occurrences)
		{
			foreach (int hvo in occurrences)
				action.AddOccurrence(hvo);
		}
Example #3
0
		private void MakeUndoAction()
		{
			m_respellUndoaction = new RespellUndoAction(m_cache, m_vernWs, m_srcwfiWordform.Form.GetAlternativeTss(m_vernWs).Text,
				m_cbNewSpelling.Text);
			m_respellUndoaction.PreserveCase = m_cbMaintainCase.Checked;
			int tagEnabled = m_sourceSentences.BrowseViewer.PreviewEnabledTag;
			foreach (int hvo in m_sourceSentences.BrowseViewer.CheckedItems)
			{
				if (m_cache.GetIntProperty(hvo, tagEnabled) == 1)
					m_respellUndoaction.AddOccurrence(hvo);
			}
		}
Example #4
0
		public void ApplyTwoAndCopyAnalyses()
		{
			MakeMonoAnalyses();
			MakeMultiAnalyses();
			// Makes one more analysis, which (having no human approval) should NOT get copied.
			m_wfAxx.AnalysesOC.Add(new WfiAnalysis());
			m_cAnalyses++;

			RespellUndoAction action = new RespellUndoAction(Cache, "axx", "ayyy");
			action.AddOccurrence(m_para2Occurrences[1]);
			action.AddOccurrence(m_para2Occurrences[2]);
			action.CopyAnalyses = true;
			action.DoIt();
			VerifyDoneStateApplyTwoAndCopyAnalyses();
			Assert.IsTrue(m_fdoCache.CanUndo, "undo should be possible after respelling");
			UndoResult ures;
			m_fdoCache.Undo(out ures);
			VerifyStartingState();
			m_fdoCache.Redo(out ures);
			VerifyDoneStateApplyTwoAndCopyAnalyses();
		}
Example #5
0
		public void ApplyTwo()
		{
			RespellUndoAction action = new RespellUndoAction(Cache, "axx", "ayyy");
			action.AddOccurrence(m_para2Occurrences[1]);
			action.AddOccurrence(m_para2Occurrences[2]);
			action.DoIt();
			VerifyDoneStateApplyTwo();
			Assert.IsTrue(m_fdoCache.CanUndo, "undo should be possible after respelling");
			UndoResult ures;
			m_fdoCache.Undo(out ures);
			VerifyStartingState();
			m_fdoCache.Redo(out ures);
			VerifyDoneStateApplyTwo();
		}
Example #6
0
		public void PreserveCase()
		{
			Assert.AreEqual(6, m_axxOccurrences.Count);
			int ich2ndOcc = Cache.GetIntProperty(m_para1Occurrences[1], kflidBeginOffset);
			RespellUndoAction action = new RespellUndoAction(Cache, "axx", "ayyy");
			action.AddOccurrence(m_para1Occurrences[0]);
			action.AddOccurrence(m_para1Occurrences[1]);
			action.SetupPreviews(tagPrecedingContext, tagPreview, tagAdjustedBegin, tagAdjustedEnd, tagEnabled, m_axxOccurrences);
			Assert.AreEqual("Axx", Cache.GetTsStringProperty(m_para1Occurrences[0], tagPrecedingContext).Text,
				"Old value at start without preserve case");
			Assert.AreEqual("ayyy simplexx testxx withxx axx", Cache.GetTsStringProperty(m_para1Occurrences[1], tagPrecedingContext).Text,
				"Preceding context without preserve case has LC");
			action.PreserveCase = true;
			action.UpdatePreviews();
			Assert.AreEqual("Axx", Cache.GetTsStringProperty(m_para1Occurrences[0], tagPrecedingContext).Text,
				"Old value at start with preserver case");
			Assert.AreEqual("Ayyy simplexx testxx withxx axx", Cache.GetTsStringProperty(m_para1Occurrences[1], tagPrecedingContext).Text,
				"Preceding context with preserve case has UC");
		}
Example #7
0
		public void Previews()
		{
			Assert.AreEqual(6, m_axxOccurrences.Count);
			int ich2ndOcc = Cache.GetIntProperty(m_para2Occurrences[1], kflidBeginOffset);
			int ich3rdOcc = Cache.GetIntProperty(m_para2Occurrences[2], kflidBeginOffset);
			RespellUndoAction action = new RespellUndoAction(Cache, "axx", "ayyy");
			action.AddOccurrence(m_para2Occurrences[1]);
			action.AddOccurrence(m_para2Occurrences[2]);
			action.SetupPreviews(tagPrecedingContext, tagPreview, tagAdjustedBegin, tagAdjustedEnd, tagEnabled, m_axxOccurrences);
			Assert.AreEqual(m_para1.Contents.Text, Cache.GetTsStringProperty(m_para1Occurrences[1], tagPrecedingContext).Text,
				"Unselected occurrences should have unchanged previews");
			Assert.AreEqual(0, Cache.GetIntProperty(m_para1Occurrences[0], tagAdjustedBegin),
				"Unselected occurrences should still have adjustedBegin set");
			Assert.AreEqual(3, Cache.GetIntProperty(m_para1Occurrences[0], tagAdjustedEnd),
				"Unselected occurrences should still have adjustedEnd set");
			AssertTextProp(m_para1Occurrences[0], tagPrecedingContext, 0, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on unchanged occurrence");

			Assert.AreEqual("axx sentencexx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPrecedingContext).Text,
				"First occurrence should have only part of para 2");
			Assert.AreEqual(ich2ndOcc, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedBegin),
				"First occurrence in para has no begin adjustment");
			Assert.AreEqual(ich2ndOcc + 3, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedEnd),
				"First occurrence in para has no end adjustment");
			Assert.AreEqual("ayyy havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPreview).Text,
				"First occurrence should have correct following context");
			AssertTextProp(m_para2Occurrences[1], tagPrecedingContext, 0, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on unchanged occurrence- 2");
			AssertTextProp(m_para2Occurrences[1], tagPrecedingContext, 5, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on other words");
			AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length, RespellUndoAction.SecondaryTextProp,
				RespellUndoAction.SecondaryTextVal, "prop should be set on changed occurrence in Preview");
			AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length - 1, RespellUndoAction.SecondaryTextProp,
				-1, "prop should not be set on other text in Preview");
			AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length + 4, RespellUndoAction.SecondaryTextProp,
				-1, "prop should not be set on other text in Preview");
			AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ayyy lotxx ofxx a".Length, RespellUndoAction.SecondaryTextProp,
				-1, "prop should not be set on unchanged occurrence in Preview");
			AssertTextProp(m_para2Occurrences[1], tagPreview, 0, (int)FwTextPropType.ktptBold,
				(int)FwTextToggleVal.kttvForceOn, "bold should be set at start of preview");
			AssertTextProp(m_para2Occurrences[1], tagPreview, 4, (int)FwTextPropType.ktptBold,
				-1, "bold should not be set except on changed word");
			// no longer action responsibility. Assert.IsTrue(Cache.GetIntProperty(m_para2Occurrences[1], tagEnabled) != 0);

			Assert.AreEqual("axx sentencexx ayyy havingxx axx", Cache.GetTsStringProperty(m_para2Occurrences[2], tagPrecedingContext).Text,
				"Second occurrence should have more of para 2 with first occurrence corrected");
			Assert.AreEqual(ich3rdOcc + 1, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedBegin),
				"Second occurrence in para has begin adjustment");
			Assert.AreEqual(ich3rdOcc + 1 + 3, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedEnd),
				"Second occurrence in para has end adjustment");
			Assert.AreEqual("ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[2], tagPreview).Text,
				"Second occurrence should have correct following context");
			AssertTextProp(m_para2Occurrences[2], tagPrecedingContext, 0, RespellUndoAction.SecondaryTextProp, -1, "prop should not be set on unchanged occurrence- 3");
			AssertTextProp(m_para2Occurrences[2], tagPrecedingContext, "axx sentencexx a".Length, RespellUndoAction.SecondaryTextProp,
				RespellUndoAction.SecondaryTextVal, "prop should be set on changed occurrence in preceding context");
			AssertTextProp(m_para2Occurrences[2], tagPrecedingContext, "axx sentencexx".Length, RespellUndoAction.SecondaryTextProp,
				-1, "prop should not be set on other text in preceding context");
			AssertTextProp(m_para2Occurrences[2], tagPrecedingContext, "axx sentencexx ayyy".Length, RespellUndoAction.SecondaryTextProp,
				-1, "prop should not be set on other text in preceding context - 2");
			AssertTextProp(m_para2Occurrences[2], tagPreview, 0, (int)FwTextPropType.ktptBold,
				(int)FwTextToggleVal.kttvForceOn, "bold should be set at start of preview - 2");
			AssertTextProp(m_para2Occurrences[2], tagPreview, 4, (int)FwTextPropType.ktptBold,
				-1, "bold should not be set except on changed word - 2");

			Assert.AreEqual("axx sentencexx ayyy havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[3], tagPrecedingContext).Text,
				"Unselected occurrences should have full-length preview");
			Assert.AreEqual("axx sentencexx axx havingxx axx lotxx ofxx ".Length + 2, Cache.GetIntProperty(m_para2Occurrences[3], tagAdjustedBegin),
				"Unselected occurrences after changed ones should have adjusted begin");
			Assert.AreEqual("axx sentencexx axx havingxx axx lotxx ofxx ".Length + 2 + 3, Cache.GetIntProperty(m_para2Occurrences[3], tagAdjustedEnd),
				"Unselected occurrences after changed ones should have adjustedEnd set");

			//-----------------------------------------------------------------------------------
			// This is rather a 'greedy' test, but tests on the real database are expensive.
			// Now we want to try changing the status of an occurrence to see whether it updates correctly.
			action.UpdatePreview(m_para2Occurrences[0], true);
			Assert.AreEqual("axx", Cache.GetTsStringProperty(m_para2Occurrences[0], tagPrecedingContext).Text,
				"Newly selected item at start of sentence has null preceding context");
			Assert.AreEqual("ayyy sentencexx ayyy havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[0], tagPreview).Text,
				"After select at start occ(0) should have correct preview");
			AssertTextProp(m_para2Occurrences[0], tagPreview, 0, (int)FwTextPropType.ktptBold,
				(int)FwTextToggleVal.kttvForceOn, "After select at start occ(0) bold should be set at start of preview");
			AssertTextProp(m_para2Occurrences[0], tagPreview, 4, (int)FwTextPropType.ktptBold,
				-1, "After select at start occ(0) bold should not be set except on changed word");

			Assert.AreEqual("ayyy sentencexx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPrecedingContext).Text,
				"After select at start occ(1) should have new preceding context.");
			Assert.AreEqual(ich2ndOcc + 1, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedBegin),
				"After select at start occ(1) should have changed begin adjustment");
			Assert.AreEqual(ich2ndOcc + 4, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedEnd),
				"After select at start occ(1) should have changed end adjustment");
			Assert.AreEqual("ayyy havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPreview).Text,
				"After select at start occ(1) should have correct following context");
			AssertTextProp(m_para2Occurrences[1], tagPrecedingContext, 0, RespellUndoAction.SecondaryTextProp,
				RespellUndoAction.SecondaryTextVal, "after select at start prop should be set on initial (new) occurrence");
			AssertTextProp(m_para2Occurrences[1], tagPrecedingContext, 5, RespellUndoAction.SecondaryTextProp, -1,
				"after select at start prop should not be set on other words");
			AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length, RespellUndoAction.SecondaryTextProp,
				RespellUndoAction.SecondaryTextVal, "after select at start prop should be set on changed occurrence in Preview");
			AssertTextProp(m_para2Occurrences[1], tagPreview, "ayyy havingxx ".Length - 1, RespellUndoAction.SecondaryTextProp,
				-1, "after select at start prop should not be set on other text in Preview");
			// no longer action responsibilty. Assert.IsTrue(Cache.GetIntProperty(m_para2Occurrences[1], tagEnabled) != 0);
			Assert.AreEqual(ich3rdOcc + 2, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedBegin),
				"After one change occ(2) should have appropriate begin adjustment");
			Assert.AreEqual(ich3rdOcc + 2 + 3, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedEnd),
				"After one change occ(2) should have appropriate end adjustment");

			//------------------------------------------------------------------------
			// And now try turning one off.
			action.UpdatePreview(m_para2Occurrences[1], false);
			Assert.AreEqual("ayyy sentencexx axx havingxx ayyy lotxx ofxx axx", Cache.GetTsStringProperty(m_para2Occurrences[1], tagPrecedingContext).Text,
				"Turned-off occurrence should have full-length preview");
			Assert.AreEqual("ayyy sentencexx ".Length, Cache.GetIntProperty(m_para2Occurrences[1], tagAdjustedBegin),
				"Turned-off occurrence should still have adjusted begin");
			Assert.AreEqual("ayyy sentencexx axx havingxx axx", Cache.GetTsStringProperty(m_para2Occurrences[2], tagPrecedingContext).Text,
				"After two changes occ(2) should have appropriate preceding context");
			Assert.AreEqual(ich3rdOcc + 1, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedBegin),
				"After two changes occ(2) should have appropriate begin adjustment");
			Assert.AreEqual(ich3rdOcc + 1 + 3, Cache.GetIntProperty(m_para2Occurrences[2], tagAdjustedEnd),
				"After two changes occ(2) should have appropriate end adjustment");

		}
Example #8
0
		private RespellUndoAction SetUpParaAndRespellUndoAction_MultiMorphemic(string sParaText,
			string sWordToReplace, string sNewWord, string[] morphsToCreate, int clidPara,
			out IStTxtPara para)
		{
			List<IParaFragment> paraFrags = new List<IParaFragment>();
			IStTxtPara paraT = null;
			IStText stText = null;
			UndoableUnitOfWorkHelper.Do("Undo create book", "Redo create book", m_actionHandler, () =>
			{
				var lp = Cache.LanguageProject;
				if (clidPara == ScrTxtParaTags.kClassId)
				{
					IScrBook book = Cache.ServiceLocator.GetInstance<IScrBookFactory>().Create(1, out stText);
					paraT = Cache.ServiceLocator.GetInstance<IScrTxtParaFactory>().CreateWithStyle(stText, "Monkey");
					paraT.Contents = TsStringUtils.MakeTss(sParaText, Cache.DefaultVernWs);
					object owner = ReflectionHelper.CreateObject("FDO.dll", "SIL.FieldWorks.FDO.Infrastructure.Impl.CmObjectId", BindingFlags.NonPublic,
						new object[] { book.Guid });
					ReflectionHelper.SetField(stText, "m_owner", owner);
				}
				else
				{
					var proj = Cache.LangProject;
					var text = Cache.ServiceLocator.GetInstance<ITextFactory>().Create();
					stText = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create();
					text.ContentsOA = stText;
					paraT = Cache.ServiceLocator.GetInstance<IStTxtParaFactory>().Create();
					stText.ParagraphsOS.Add(paraT);
					paraT.Contents = TsStringUtils.MakeTss(sParaText, Cache.DefaultVernWs);
				}
				foreach (ISegment seg in paraT.SegmentsOS)
				{
					FdoTestHelper.CreateAnalyses(seg, paraT.Contents, seg.BeginOffset, seg.EndOffset, true);
					var thisSegParaFrags = GetParaFragmentsInSegmentForWord(seg, sWordToReplace);
					SetMultimorphemicAnalyses(thisSegParaFrags, morphsToCreate);
					paraFrags.AddRange(thisSegParaFrags);
				}
			});

			var rsda = new RespellingSda((ISilDataAccessManaged)Cache.MainCacheAccessor, null, Cache.ServiceLocator);
			InterestingTextList dummyTextList = MockRepository.GenerateStub<InterestingTextList>(null, Cache.ServiceLocator.GetInstance<ITextRepository>(),
			Cache.ServiceLocator.GetInstance<IStTextRepository>());
			if (clidPara == ScrTxtParaTags.kClassId)
				dummyTextList.Stub(tl => tl.InterestingTexts).Return(new IStText[0]);
			else
				dummyTextList.Stub(t1 => t1.InterestingTexts).Return(new IStText[1] { stText });
			ReflectionHelper.SetField(rsda, "m_interestingTexts", dummyTextList);
			rsda.SetCache(Cache);
			rsda.SetOccurrences(0, paraFrags);
			ObjectListPublisher publisher = new ObjectListPublisher(rsda, kObjectListFlid);
			XMLViewsDataCache xmlCache = MockRepository.GenerateStub<XMLViewsDataCache>(publisher, true, new Dictionary<int, int>());

			xmlCache.Stub(c => c.get_IntProp(paraT.Hvo, CmObjectTags.kflidClass)).Return(ScrTxtParaTags.kClassId);
			xmlCache.Stub(c => c.VecProp(Arg<int>.Is.Anything, Arg<int>.Is.Anything)).Do(new Func<int, int, int[]>(publisher.VecProp));
			xmlCache.MetaDataCache = new RespellingMdc((IFwMetaDataCacheManaged)Cache.MetaDataCacheAccessor);
			xmlCache.Stub(c => c.get_ObjectProp(Arg<int>.Is.Anything, Arg<int>.Is.Anything)).Do(new Func<int, int, int>(publisher.get_ObjectProp));
			xmlCache.Stub(c => c.get_IntProp(Arg<int>.Is.Anything, Arg<int>.Is.Anything)).Do(new Func<int, int, int>(publisher.get_IntProp));

			var respellUndoaction = new RespellUndoAction(xmlCache, Cache, Cache.DefaultVernWs, sWordToReplace, sNewWord);
			foreach (int hvoFake in rsda.VecProp(0, ConcDecorator.kflidConcOccurrences))
				respellUndoaction.AddOccurrence(hvoFake);

			para = paraT;
			return respellUndoaction;
		}