SIL.FieldWorks.IText.InterlinVc.DisplayLexGlossWithInflType C# (CSharp) Method

DisplayLexGlossWithInflType() private method

NOTE: this routine is ignorant of calling context, so caller must provide NoteDependency to the possibleVariant and the sense (e.g. vwenv.NoteDependency(new[] { wfiMorphBundle.Hvo }, new[] { WfiMorphBundleTags.kflidSense }, 1); vwenv.NoteDependency(new[] { wfiMorphBundle.Hvo }, new[] { WfiMorphBundleTags.kflidInflType }, 1);
private DisplayLexGlossWithInflType ( IVwEnv vwenv, ILexEntry possibleVariant, ILexSense sense, InterlinLineSpec spec, ILexEntryInflType inflType ) : bool
vwenv IVwEnv
possibleVariant ILexEntry
sense ILexSense
spec InterlinLineSpec
inflType ILexEntryInflType
return bool
		internal bool DisplayLexGlossWithInflType(IVwEnv vwenv, ILexEntry possibleVariant, ILexSense sense, InterlinLineSpec spec,
			ILexEntryInflType inflType)
		{
			int iLineChoice = m_lineChoices.IndexOf(spec);
			ILexEntryRef ler;
			if (possibleVariant.IsVariantOfSenseOrOwnerEntry(sense, out ler))
			{
				var wsPreferred = GetRealWsOrBestWsForContext(sense.Hvo, spec);
				var wsGloss = Cache.ServiceLocator.WritingSystemManager.Get(wsPreferred);
				var wsUser = Cache.ServiceLocator.WritingSystemManager.UserWritingSystem;
				var testGloss = sense.Gloss.get_String(wsPreferred);
				// don't bother adding anything for an empty gloss.
				if (testGloss.Text != null && testGloss.Text.Length >= 0)
				{
					vwenv.OpenParagraph();
					// see if we have an irregularly inflected form type reference
					var leitFirst =
						ler.VariantEntryTypesRS.Where(
							let => let.ClassID == LexEntryInflTypeTags.kClassId).FirstOrDefault();

					// add any GlossPrepend info
					if (leitFirst != null)
					{
						vwenv.OpenInnerPile();
						// TODO: add dependency to VariantType GlossPrepend/Append names
						vwenv.NoteDependency(new[] { ler.Hvo },
											 new[] { LexEntryRefTags.kflidVariantEntryTypes }, 1);
						vwenv.OpenParagraph();
						ITsString tssPrepend = null;
						if (inflType != null)
						{
							tssPrepend = MorphServices.AddTssGlossAffix(null, inflType.GlossPrepend, wsGloss, wsUser);
						}
						else
						{
							ITsIncStrBldr sbPrepend;
							ITsIncStrBldr sbAppend;
							JoinGlossAffixesOfInflVariantTypes(ler, wsPreferred, out sbPrepend,
															   out sbAppend);
							if (sbPrepend.Text != null)
								tssPrepend = sbPrepend.GetString();
						}
						if (tssPrepend != null)
							vwenv.AddString(tssPrepend);
						vwenv.CloseParagraph();
						vwenv.CloseInnerPile();
					}
					// add gloss of main entry or sense
					{
						vwenv.OpenInnerPile();
						// NOTE: remember to NoteDependency from OuterObject
						vwenv.AddObj(sense.Hvo, this, kfragLineChoices + iLineChoice);
						vwenv.CloseInnerPile();
					}
					// now add variant type info
					if (leitFirst != null)
					{
						vwenv.OpenInnerPile();
						// TODO: add dependency to VariantType GlossPrepend/Append names
						vwenv.NoteDependency(new[] { ler.Hvo },
											 new[] { LexEntryRefTags.kflidVariantEntryTypes }, 1);
						vwenv.OpenParagraph();
						 ITsString tssAppend = null;
						 if (inflType != null)
						 {
							 tssAppend = MorphServices.AddTssGlossAffix(null, inflType.GlossAppend, wsGloss, wsUser);
						 }
						 else
						 {
							 ITsIncStrBldr sbPrepend;
							 ITsIncStrBldr sbAppend;
							 JoinGlossAffixesOfInflVariantTypes(ler, wsPreferred, out sbPrepend,
																out sbAppend);
							 if (sbAppend.Text != null)
								 tssAppend = sbAppend.GetString();
						 }
						{
							// Use AddProp/DisplayVariant to store GlossAppend with m_tssPendingGlossAffix
							// this allows InterlinearExporter to know to export a glsAppend item
							try
							{
								if (tssAppend != null)
									m_tssPendingGlossAffix = tssAppend;
								else
									m_tssPendingGlossAffix = m_tssMissingGlossAppend;

								vwenv.AddProp(ktagGlossAppend, this, 0);
							}
							finally
							{
								m_tssPendingGlossAffix = null;
							}
						}
						vwenv.CloseParagraph();
						vwenv.CloseInnerPile();
					}
					vwenv.CloseParagraph();
					return true;
				}
			}
			return false;
		}

Usage Example

Ejemplo n.º 1
0
		internal static bool TryGetLexGlossWithInflTypeTss(ILexEntry possibleVariant, ILexSense sense, InterlinLineSpec spec, InterlinLineChoices lineChoices, int vernWsContext, ILexEntryInflType inflType, out ITsString result)
		{
			FdoCache cache = possibleVariant.Cache;
			using (var vcLexGlossFrag = new InterlinVc(cache))
			{
				vcLexGlossFrag.LineChoices = lineChoices;
				vcLexGlossFrag.PreferredVernWs = vernWsContext;


				result = null;
				var collector = new TsStringCollectorEnv(null, vcLexGlossFrag.Cache.MainCacheAccessor,
														 possibleVariant.Hvo)
									{
										RequestAppendSpaceForFirstWordInNewParagraph = false
									};
				if (vcLexGlossFrag.DisplayLexGlossWithInflType(collector, possibleVariant, sense, spec, inflType))
				{
					result = collector.Result;
					return true;
				}
				return false;
			}
		}