Beispiel #1
0
 public void FindEntryForWordform_EmptyString()
 {
     using (var lexEntryUi = LexEntryUi.FindEntryForWordform(Cache,
                                                             TsStringUtils.EmptyString(Cache.DefaultVernWs)))
     {
         Assert.IsNull(lexEntryUi);
     }
 }
Beispiel #2
0
 public void FindEntryForWordform_EmptyString()
 {
     using (var lexEntryUi = LexEntryUi.FindEntryForWordform(Cache,
                                                             Cache.TsStrFactory.MakeString(string.Empty, Cache.DefaultVernWs)))
     {
         Assert.IsNull(lexEntryUi);
     }
 }
Beispiel #3
0
        public void FindEntryNotMatchingCase()
        {
            // Setup
            var servLoc  = Cache.ServiceLocator;
            var langProj = Cache.LangProject;
            var lexDb    = langProj.LexDbOA;
            // Create a WfiWordform with some string.
            // We need this wordform to get a real hvo, flid, and ws.
            // Make Spanish be the vern ws.
            var spanish = servLoc.WritingSystemManager.Get("es");

            langProj.AddToCurrentVernacularWritingSystems(spanish);
            langProj.CurAnalysisWss = "en";
            langProj.DefaultVernacularWritingSystem = spanish;
            var defVernWs = spanish.Handle;
            var entry1    = servLoc.GetInstance <ILexEntryFactory>().Create(
                "Uppercaseword", "Uppercasegloss", new SandboxGenericMSA());
            var entry2 = servLoc.GetInstance <ILexEntryFactory>().Create(
                "lowercaseword", "lowercasegloss", new SandboxGenericMSA());

            // SUT
            // First make sure it works with the same case
            using (var lexEntryUi = LexEntryUi.FindEntryForWordform(Cache,
                                                                    TsStringUtils.MakeString("Uppercaseword", Cache.DefaultVernWs)))
            {
                Assert.IsNotNull(lexEntryUi);
                Assert.AreEqual(entry1.Hvo, lexEntryUi.Object.Hvo, "Found wrong object");
            }
            using (var lexEntryUi = LexEntryUi.FindEntryForWordform(Cache,
                                                                    TsStringUtils.MakeString("lowercaseword", Cache.DefaultVernWs)))
            {
                Assert.IsNotNull(lexEntryUi);
                Assert.AreEqual(entry2.Hvo, lexEntryUi.Object.Hvo, "Found wrong object");
            }
            // Now make sure it works with the wrong case
            using (var lexEntryUi = LexEntryUi.FindEntryForWordform(Cache,
                                                                    TsStringUtils.MakeString("uppercaseword", Cache.DefaultVernWs)))
            {
                Assert.IsNotNull(lexEntryUi);
                Assert.AreEqual(entry1.Hvo, lexEntryUi.Object.Hvo, "Found wrong object");
            }
            using (var lexEntryUi = LexEntryUi.FindEntryForWordform(Cache,
                                                                    TsStringUtils.MakeString("LowerCASEword", Cache.DefaultVernWs)))
            {
                Assert.IsNotNull(lexEntryUi);
                Assert.AreEqual(entry2.Hvo, lexEntryUi.Object.Hvo, "Found wrong object");
            }
        }
Beispiel #4
0
        private LexEntryUi GetSelWord()
        {
            IVwSelection sel = m_view.RootBox.Selection;

            if (sel == null)
            {
                return(null);
            }
            IVwSelection sel2 = sel.EndPoint(false);

            if (sel2 == null)
            {
                return(null);
            }
            IVwSelection sel3 = sel2.GrowToWord();

            if (sel3 == null)
            {
                return(null);
            }
            ITsString tss;
            int       ichMin, ichLim, hvo, tag, ws;
            bool      fAssocPrev;

            sel3.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws);
            sel3.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws);

            ITsString tssWf = (m_cdaTemp as ISilDataAccess).get_StringProp(hvo, tag);

            if (tssWf == null || tssWf.Length == 0)
            {
                return(null);
            }

            // Ignore what part of it is selected...we want the entry whose whole citation form
            // the selection is part of.
            //string wf = tssWf.Text.Substring(ichMin, ichLim - ichMin);
            return(LexEntryUi.FindEntryForWordform(m_cache, tssWf));
        }
Beispiel #5
0
        public void FindEntryForWordform_EmptyString()
        {
            ITsStrBldr emptyString = TsStrBldrClass.Create();

            Assert.IsNull(LexEntryUi.FindEntryForWordform(Cache, emptyString.GetString()));
        }
Beispiel #6
0
        internal static void DisplayEntry(FdoCache cache, IWin32Window owner, Mediator mediatorIn,
                                          IHelpTopicProvider helpProvider, string helpFileKey, ITsString tssWfIn)
        {
            ITsString  tssWf = tssWfIn;
            LexEntryUi leui  = LexEntryUi.FindEntryForWordform(cache, tssWf);

            // if we do not find a match for the word then try converting it to lowercase and see if there
            // is an entry in the lexicon for the Wordform in lowercase. This is needed for occurences of
            // words which are capitalized at the beginning of sentences.  LT-7444 RickM
            if (leui == null)
            {
                //We need to be careful when converting to lowercase therefore use Icu.ToLower()
                //get the WS of the tsString
                int wsWf = StringUtils.GetWsAtOffset(tssWf, 0);
                //use that to get the locale for the WS, which is used for
                string        wsLocale = cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(wsWf).IcuLocale;
                string        sLower   = Icu.ToLower(tssWf.Text, wsLocale);
                ITsTextProps  ttp      = tssWf.get_PropertiesAt(0);
                ITsStrFactory tsf      = TsStrFactoryClass.Create();
                tssWf = tsf.MakeStringWithPropsRgch(sLower, sLower.Length, ttp);
                leui  = LexEntryUi.FindEntryForWordform(cache, tssWf);
            }

            // Ensure that we have a valid mediator with the proper string table.
            bool        fRestore = false;
            StringTable stOrig   = null;
            Mediator    mediator = EnsureValidMediator(mediatorIn, out fRestore, out stOrig);
            FdoCache    cache2   = (FdoCache)mediator.PropertyTable.GetValue("cache");

            if (cache2 != cache)
            {
                mediator.PropertyTable.SetProperty("cache", cache);
            }
            EnsureWindowConfiguration(mediator);
            EnsureFlexVirtuals(cache, mediator);
            IVwStylesheet styleSheet = GetStyleSheet(cache, mediator);

            if (leui == null)
            {
                int hvoLe = ShowFindEntryDialog(cache, mediator, tssWf, owner);
                if (hvoLe == 0)
                {
                    // Restore the original string table in the mediator if needed.
                    if (fRestore)
                    {
                        mediator.StringTbl = stOrig;
                    }
                    return;
                }
                leui = new LexEntryUi(new LexEntry(cache, hvoLe));
            }
            if (mediator != null)
            {
                leui.Mediator = mediator;
            }
            leui.ShowSummaryDialog(owner, tssWf, helpProvider, helpFileKey, styleSheet);
            // Restore the original string table in the mediator if needed.
            if (fRestore)
            {
                mediator.StringTbl = stOrig;
            }
        }