Beispiel #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
        }
        /// <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));
        }
        /// <summary>
        /// Try to find a WfiWordform object corresponding the the focus selection.
        /// If successful return its guid, otherwise, return Guid.Empty.
        /// </summary>
        /// <returns></returns>
        private ITsString ActiveWord()
        {
            if (InFriendliestTool)
            {
                // we should be able to get our info from the current record clerk.
                // but return null if we can't get the info, otherwise we allow the user to
                // bring up the change spelling dialog and crash because no wordform can be found (LT-8766).
                RecordClerk clerk = m_mediator.PropertyTable.GetValue("ActiveClerk") as RecordClerk;
                if (clerk == null || clerk.CurrentObject == null)
                {
                    return(null);
                }
                IWfiWordform wfiWordform = clerk.CurrentObject as IWfiWordform;
                if (wfiWordform == null)
                {
                    return(null);
                }
                ITsString tssVern = wfiWordform.Form.BestVernacularAlternative;
                return(tssVern);
            }
            if (!(FwApp.App is FwXApp))
            {
                return(null);
            }
            FwXWindow window = (FwApp.App as FwXApp).ActiveMainWindow as FwXWindow;

            if (window == null)
            {
                return(null);
            }
            IRootSite activeView = window.ActiveView;

            if (activeView == null)
            {
                return(null);
            }
            List <IVwRootBox> roots = activeView.AllRootBoxes();

            if (roots.Count < 1)
            {
                return(null);
            }
            SelectionHelper helper = SelectionHelper.Create(roots[0].Site);

            if (helper == null)
            {
                return(null);
            }
            ITsString tssWord = helper.SelectedWord;

            if (tssWord != null)
            {
                // Check for a valid vernacular writing system.  (See LT-8892.)
                int      ws    = StringUtils.GetWsAtOffset(tssWord, 0);
                FdoCache cache = m_mediator.PropertyTable.GetValue("cache") as FdoCache;
                if (cache.LangProject.VernWssRC.Contains(ws))
                {
                    return(tssWord);
                }
            }
            return(null);
        }