示例#1
0
		internal static ITsString AnnotationTargetString(int hvoTarget, int flid, int ws, RespellingSda sda)
		{
			ITsString tssValue;
			if (IsMultilingual(flid))
				tssValue = sda.get_MultiStringAlt(hvoTarget, flid, ws);
			else
				tssValue = sda.get_StringProp(hvoTarget, flid);
			return tssValue;
		}
示例#2
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;
		}