예제 #1
0
		/// <summary>
		/// Try to find a WfiWordform object corresponding the the focus selection.
		/// If successful return its guid, otherwise, return Guid.Empty.
		/// </summary>
		/// <returns></returns>
		internal static Guid ActiveWordform(FdoCache cache, Mediator mediator)
		{
			IApp app = mediator.PropertyTable.GetValue("App") as IApp;
			if (app == null)
				return Guid.Empty;
			IFwMainWnd window = app.ActiveMainWindow as IFwMainWnd;
			if (window == null)
				return Guid.Empty;
			IRootSite activeView = window.ActiveView;
			if (activeView == null)
				return Guid.Empty;
			List<IVwRootBox> roots = activeView.AllRootBoxes();
			if (roots.Count < 1)
				return Guid.Empty;
			SelectionHelper helper = SelectionHelper.Create(roots[0].Site);
			if (helper == null)
				return Guid.Empty;
			ITsString word = helper.SelectedWord;
			if (word == null || word.Length == 0)
				return Guid.Empty;
#if WANTPORT // FWR-2784
			int hvoWordform = cache.LangProject.WordformInventoryOA.GetWordformId(word);
			if (hvoWordform == 0 || cache.IsDummyObject(hvoWordform))
				return Guid.Empty;
			return cache.GetGuidFromId(hvoWordform);
#else
			return Guid.Empty;
#endif
		}
예제 #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Replaces all references to one paragraph in the footnote cache with another. Used to
		/// update the cache when a paragraph is being merged with another.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="oldParaHvo">id of paragraph being merged into another</param>
		/// <param name="newParaHvo">id of paragraph surviving the merge</param>
		/// ------------------------------------------------------------------------------------
		public static void ReplaceReferencesToParagraph(FdoCache cache, int oldParaHvo, int newParaHvo)
		{
			int bookHvo = cache.GetOwnerOfObjectOfClass(oldParaHvo, (int)ScrBook.kclsidScrBook);
			if (bookHvo <= 0)
			{
				Debug.Fail("Footnotes have to be contained in paragraphs owned by books.");
				return;
			}
			Guid bookGuid = cache.GetGuidFromId(bookHvo);

			Dictionary<int, FootnoteHashEntry> dict;
			// Don't bother on empty cache - it will be created when needed. Need to use HVO to get
			// GUID so we don't create the book and potentially cause the refresh routine to be called.
			if (!cache.TryGetHashtable<int, FootnoteHashEntry>(bookGuid, out dict) || dict.Count == 0)
				return;

			foreach (FootnoteHashEntry entry in dict.Values)
			{
				if (entry.HvoPara == oldParaHvo)
					entry.HvoPara = newParaHvo;
			}
		}
예제 #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a new object, given a text representation (e.g., from the clipboard), unless
		/// we are in a footnote or in back translation.
		/// </summary>
		/// <param name="cache">FDO cache representing the DB connection to use</param>
		/// <param name="sTextRep">Text representation of object</param>
		/// <param name="selDst">Provided for information in case it's needed to generate
		/// the new object (E.g., footnotes might need it to generate the proper sequence
		/// letter)</param>
		/// <param name="kodt">The object data type to use for embedding the new object
		/// </param>
		/// <returns>The GUID of the new object, or <c>Guid.Empty</c> if it's illegal to
		/// insert an object in this location.</returns>
		/// ------------------------------------------------------------------------------------
		public override Guid MakeObjFromText(FdoCache cache, string sTextRep,
			IVwSelection selDst, out int kodt)
		{
			CheckDisposed();

			kodt = 0;
			Guid guid = Guid.Empty;
			try
			{
				// Prevent objects from getting created in invalid locations: for example,
				// we are in a footnote, a picture caption or the back translation
				int tagSelection;
				int hvoSelection;
				GetSelectedScrElement(out tagSelection, out hvoSelection);
				if (tagSelection == (int)ScrBook.ScrBookTags.kflidFootnotes ||
					tagSelection == 0 || (m_viewType & TeViewType.FootnoteView) != 0 ||
					IsPictureSelected || IsBackTranslation)
				{
					return guid;
				}

				IScrBook book = GetCurrentBook(cache);

				if (!CmPicture.IsPicture(sTextRep))
				{
					if (m_lastFootnoteTextRepSelection == CurrentSelection)
						m_newFootnoteIndex++; // same selection, increment footnote index
					else
						m_newFootnoteIndex = FindFootnotePosition(book, CurrentSelection);

					// try to make footnote
					StFootnote footnote = StFootnote.CreateFromStringRep((CmObject)book,
						(int)ScrBook.ScrBookTags.kflidFootnotes, sTextRep, m_newFootnoteIndex,
						ScrStyleNames.FootnoteMarker);
					guid = cache.GetGuidFromId(footnote.Hvo);
					kodt = (int)FwObjDataTypes.kodtOwnNameGuidHot;
					//ScrFootnote.RecalculateFootnoteMarkers(book, 0);
					m_lastFootnoteTextRepSelection = CurrentSelection;
				}
			}
			catch
			{
				// try a different type
			}

			return guid == Guid.Empty ?
				base.MakeObjFromText(cache, sTextRep, selDst, out kodt) : guid;
		}
예제 #4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Refreshes cache for all footnotes in the StText containing the paragraph.  We only
		/// use this method when verses of a paragraph are changed - this will only happen on
		/// content paragraphs of a ScrSection.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoObj"></param>
		/// ------------------------------------------------------------------------------------
		internal static void RefreshCacheForParagraph(FdoCache cache, int hvoObj)
		{
			int hvoPara = hvoObj;
			if (cache.GetClassOfObject(hvoObj) == CmTranslation.kClassId)
				hvoPara = cache.GetOwnerOfObject(hvoObj);

			int hvoText = cache.GetOwnerOfObject(hvoPara);
			IStText text = new StText(cache, hvoText);
			ScrSection section = new ScrSection(cache, text.OwnerHVO);
			BCVRef verseRef = new BCVRef(section.VerseRefStart);

			Dictionary<int, FootnoteHashEntry> dict;
			// Don't bother on empty cache - it will be created when needed. Need to use HVO to get GUID so we
			// don't create the book and potentially cause the refresh routine to be called.
			Guid bookGuid = cache.GetGuidFromId(section.OwnerHVO);
			if (!cache.TryGetHashtable<int, FootnoteHashEntry>(bookGuid, out dict) ||
				dict.Count == 0)
			{
				return;
			}

			AddFootnoteRefsInText(text, dict, ref verseRef);
		}
예제 #5
0
		/// <summary>
		/// Determine whether the given object is a "suffix-ish" morph type.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoMorphType"></param>
		/// <returns></returns>
		public static bool IsSuffixishType(FdoCache cache, int hvoMorphType)
		{
			Guid guid = cache.GetGuidFromId(hvoMorphType);
			switch (guid.ToString())
			{
				case kguidMorphSuffix:
				case kguidMorphSuffixingInterfix:
					return true;
				default:
					return false;
			}
		}
예제 #6
0
		/// <summary>
		/// Determine whether the given object is an affix type morph type.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoMorphType"></param>
		/// <returns></returns>
		public static bool IsAffixType(FdoCache cache, int hvoMorphType)
		{
			Guid guid = cache.GetGuidFromId(hvoMorphType);
			switch (guid.ToString())
			{
				case kguidMorphCircumfix:
				case kguidMorphInfix:
				case kguidMorphPrefix:
				case kguidMorphSimulfix:
				case kguidMorphSuffix:
				case kguidMorphSuprafix:
				case kguidMorphInfixingInterfix:
				case kguidMorphPrefixingInterfix:
				case kguidMorphSuffixingInterfix:
					return true;
				default:
					return false;
			}
		}
예제 #7
0
		/// <summary>
		/// Try to find a WfiWordform object corresponding the the focus selection.
		/// If successful return its guid, otherwise, return Guid.Empty.
		/// </summary>
		/// <returns></returns>
		internal static Guid ActiveWordform(FdoCache cache)
		{
			if (!(FwApp.App is FwXApp))
				return Guid.Empty;
			FwXWindow window = (FwApp.App as FwXApp).ActiveMainWindow as FwXWindow;
			if (window == null)
				return Guid.Empty;
			IRootSite activeView = window.ActiveView;
			if (activeView == null)
				return Guid.Empty;
			List<IVwRootBox> roots = activeView.AllRootBoxes();
			if (roots.Count < 1)
				return Guid.Empty;
			SelectionHelper helper = SelectionHelper.Create(roots[0].Site);
			if (helper == null)
				return Guid.Empty;
			ITsString word = helper.SelectedWord;
			if (word == null || word.Length == 0)
				return Guid.Empty;
			int hvoWordform = cache.LangProject.WordformInventoryOA.GetWordformId(word);
			if (hvoWordform == 0 || cache.IsDummyObject(hvoWordform))
				return Guid.Empty;
			return cache.GetGuidFromId(hvoWordform);
		}
예제 #8
0
		/// <summary>
		/// Check whether the given entry (or entry owning the given sense) is either a bound
		/// root or a bound stem.  We don't want to use those as guesses for monomorphemic
		/// words.  See LT-10323.
		/// </summary>
		private static bool IsEntryBound(FdoCache cache, int hvoComponent, int clid)
		{
			int hvoTargetEntry;
			if (clid == LexSense.kclsidLexSense)
			{
				ILexSense ls = LexSense.CreateFromDBObject(cache, hvoComponent);
				hvoTargetEntry = ls.Entry.Hvo;
				if (!(ls.MorphoSyntaxAnalysisRA is IMoStemMsa))
					return true;		// must be an affix, so it's bound by definition.
			}
			else
			{
				hvoTargetEntry = hvoComponent;
			}
			int hvoMorph = cache.MainCacheAccessor.get_ObjectProp(hvoTargetEntry,
				(int)LexEntry.LexEntryTags.kflidLexemeForm);
			if (hvoMorph != 0)
			{
				int hvoMorphType = cache.MainCacheAccessor.get_ObjectProp(hvoMorph,
					(int)MoForm.MoFormTags.kflidMorphType);
				if (hvoMorphType != 0)
				{
					if (MoMorphType.IsAffixType(cache, hvoMorphType))
						return true;
					Guid guid = cache.GetGuidFromId(hvoMorphType);
					if (guid == new Guid(MoMorphType.kguidMorphBoundRoot) ||
						guid == new Guid(MoMorphType.kguidMorphBoundStem))
					{
						return true;
					}
				}
			}
			return false;
		}