예제 #1
0
        /// <summary>
        /// Returns a TsString with the entry headword and a sense number if there
        /// are more than one senses.
        /// </summary>
        public ITsString OwnerOutlineNameForWs(ILexSense sense, int wsVern, HomographConfiguration.HeadwordVariant hv)
        {
            var entry = sense.Entry;
            int hn;

            if (!m_homographNumbers.TryGetValue(entry.Hvo, out hn))
            {
                hn = entry.HomographNumber;                 // unknown entry, use its own HN instead of our override
            }
            ITsIncStrBldr tisb = TsIncStrBldrClass.Create();

            tisb.AppendTsString(StringServices.HeadWordForWsAndHn(entry, wsVern, hn, "", hv));
            var hc = sense.Services.GetInstance <HomographConfiguration>();

            if (hc.ShowSenseNumber(hv) && HasMoreThanOneSense(entry))
            {
                // These int props may not be needed, but they're safe.
                tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0,
                                      Cache.DefaultAnalWs);
                tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                     HomographConfiguration.ksSenseReferenceNumberStyle);
                tisb.Append(" ");
                tisb.Append(GetSenseNumber(sense));
            }
            return(tisb.GetString());
        }
예제 #2
0
        /// <summary>
        /// Get what would be produced for the headword of the specified entry in the specified WS,
        /// if it had the specified homograph number. (This is useful when overriding homograph
        /// numbers because items are omitted in a particular publication.) Use the specified default
        /// Citation Form if no Cf or Lf is present in the entry, and return an empty string for the
        /// whole method if there is no real or default Cf.
        /// </summary>
        public static ITsString HeadWordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph, string defaultCf,
                                                   HomographConfiguration.HeadwordVariant hv)
        {
            var hc           = entry.Services.GetInstance <HomographConfiguration>();
            var citationForm = CitationFormWithAffixTypeStaticForWs(entry, wsVern, defaultCf);

            if (String.IsNullOrEmpty(citationForm))
            {
                return(entry.Cache.TsStrFactory.EmptyString(wsVern));
            }
            var tisb = TsIncStrBldrClass.Create();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
            if (hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv);
            }
            tisb.Append(citationForm);

            // (EricP) Tried to automatically update the homograph number, but doing that here will
            // steal away manual changes to the HomographNumber column. Also suppressing PropChanged
            // is necessary when HomographNumber column is enabled, otherwise changing the entry index can hang.
            //using (new IgnorePropChanged(cache, PropChangedHandling.SuppressView))
            //{
            //	  ValidateExistingHomographs(CollectHomographs(cache, ShortName1StaticForWs(cache, hvo, wsVern), 0, morphType));
            //}

            if (!hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv);
            }
            return(tisb.GetString());
        }
예제 #3
0
 /// <summary>
 /// This method will use the current homograph-number settings to insert the homograph number into the string
 /// </summary>
 public static void InsertHomographNumber(ITsIncStrBldr tisb, int nHomograph, HomographConfiguration hc,
                                          HomographConfiguration.HeadwordVariant hv, LcmCache cache)
 {
     if (nHomograph > 0 && hc.ShowHomographNumber(hv))
     {
         tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, HomographConfiguration.ksHomographNumberStyle);
         if (!string.IsNullOrEmpty(hc.WritingSystem))
         {
             tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, cache.WritingSystemFactory.GetWsFromStr(hc.WritingSystem));
         }
         else
         {
             tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, cache.DefaultVernWs);
         }
         var hnString = nHomograph.ToString();
         if (hc.CustomHomographNumbers.Count == 10)
         {
             for (var i = 0; i < 10; ++i)
             {
                 hnString = hnString.Replace(i.ToString(), hc.CustomHomographNumbers[i]);
             }
         }
         tisb.Append(hnString);
         tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
     }
 }
예제 #4
0
        private static void AddHeadwordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph,
                                                  HomographConfiguration.HeadwordVariant hv, ITsIncStrBldr tisb, string citationForm)
        {
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
            var hc = entry.Services.GetInstance <HomographConfiguration>();

            if (hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv);
            }
            tisb.Append(citationForm);

            // (EricP) Tried to automatically update the homograph number, but doing that here will
            // steal away manual changes to the HomographNumber column. Also suppressing PropChanged
            // is necessary when HomographNumber column is enabled, otherwise changing the entry index can hang.
            //using (new IgnorePropChanged(cache, PropChangedHandling.SuppressView))
            //{
            //	  ValidateExistingHomographs(CollectHomographs(cache, ShortName1StaticForWs(cache, hvo, wsVern), 0, morphType));
            //}

            if (!hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv);
            }
        }
예제 #5
0
 private static void InsertHomographNumber(TsIncStrBldr tisb, int nHomograph, HomographConfiguration hc,
                                           HomographConfiguration.HeadwordVariant hv)
 {
     if (nHomograph > 0 && hc.ShowHomographNumber(hv))
     {
         tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, HomographConfiguration.ksHomographNumberStyle);
         tisb.Append(nHomograph.ToString());
         tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
     }
 }
예제 #6
0
        /// <summary>
        /// This method should have the same logic as the (above) HeadWordForWsAndHn().
        /// </summary>
        /// <param name="tisb"></param>
        /// <param name="entry"></param>
        /// <param name="wsVern"></param>
        /// <param name="nHomograph"></param>
        /// <param name="defaultCf"></param>
        /// <param name="hv"></param>
        internal static void AddHeadWordForWsAndHn(ITsIncStrBldr tisb, ILexEntry entry, int wsVern, int nHomograph, string defaultCf,
                                                   HomographConfiguration.HeadwordVariant hv)
        {
            var citationForm = CitationFormWithAffixTypeStaticForWs(entry, wsVern, defaultCf);

            if (String.IsNullOrEmpty(citationForm))
            {
                tisb.AppendTsString(entry.Cache.TsStrFactory.EmptyString(wsVern));                 // avoids COM Exception!
                return;
            }
            AddHeadwordForWsAndHn(entry, wsVern, nHomograph, hv, tisb, citationForm);
        }
예제 #7
0
        private void TrySenseOutlineName(Func <ILexSense, int, ITsString> reader, HomographConfiguration.HeadwordVariant hv,
                                         Action turnOffSenseNumber)
        {
            ResetConfiguration();
            VerifyTss(reader(m_kickS1, m_wsVern), new[] { new Run("kick", m_wsVern, "") });
            VerifyTss(reader(m_rightDirectionS1, m_wsVern),
                      new[] { new Run("right", m_wsVern, ""), new Run("2", m_wsVern, HomographConfiguration.ksHomographNumberStyle) });
            var numAfterCorrect2Runs = new[] { new Run("right", m_wsVern, ""),
                                               new Run("1", m_wsVern, HomographConfiguration.ksHomographNumberStyle),
                                               new Run(" ", m_wsVern, ""),
                                               new Run("2", m_wsAnalysis, HomographConfiguration.ksSenseReferenceNumberStyle) };

            VerifyTss(reader(m_rightCorrectS2, m_wsVern), numAfterCorrect2Runs);
            // Owner outline is affected by putting homograph number first.
            m_hc.HomographNumberBefore = true;
            VerifyTss(reader(m_kickS1, m_wsVern), new[] { new Run("kick", m_wsVern, "") });
            VerifyTss(reader(m_rightDirectionS1, m_wsVern),
                      new[] { new Run("2", m_wsVern, HomographConfiguration.ksHomographNumberStyle), new Run("right", m_wsVern, "") });
            var numBeforeCorrect2Runs = new[] { new Run("1", m_wsVern, HomographConfiguration.ksHomographNumberStyle),
                                                new Run("right ", m_wsVern, ""),
                                                new Run("2", m_wsAnalysis, HomographConfiguration.ksSenseReferenceNumberStyle) };

            VerifyTss(reader(m_rightCorrectS2, m_wsVern), numBeforeCorrect2Runs);
            // Not by hiding HN in main or reversal cross-refs
            m_hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef, false);
            m_hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef, false);
            m_hc.SetShowHomographNumber(hv, true);
            VerifyTss(reader(m_rightCorrectS2, m_wsVern), numBeforeCorrect2Runs);

            // Hiding HN in appropriate kind of cross-refs also hides sense number.
            m_hc.SetShowHomographNumber(hv, false);
            VerifyTss(reader(m_kickS1, m_wsVern), new[] { new Run("kick", m_wsVern, "") });
            VerifyTss(reader(m_rightDirectionS1, m_wsVern), new[] { new Run("right", m_wsVern, "") });
            VerifyTss(reader(m_rightCorrectS2, m_wsVern), new[] { new Run("right", m_wsVern, "") });

            // .. even if it's in the normal position
            m_hc.HomographNumberBefore = false;
            VerifyTss(reader(m_rightCorrectS2, m_wsVern), new[] { new Run("right", m_wsVern, "") });

            // but it can be turned on again...
            m_hc.SetShowHomographNumber(hv, true);
            VerifyTss(reader(m_rightCorrectS2, m_wsVern), numAfterCorrect2Runs);

            // We can also turn just the sense number off...
            turnOffSenseNumber();
            VerifyTss(reader(m_rightCorrectS2, m_wsVern),
                      new[]
            {
                new Run("right", m_wsVern, ""),
                new Run("1", m_wsVern, HomographConfiguration.ksHomographNumberStyle)
            });
        }
예제 #8
0
        /// <summary>
        /// Get what would be produced for the headword of the specified entry in the specified WS,
        /// if it had the specified homograph number. (This is useful when overriding homograph
        /// numbers because items are omitted in a particular publication.) Use the specified default
        /// Citation Form if no Cf or Lf is present in the entry, and return an empty string for the
        /// whole method if there is no real or default Cf.
        /// </summary>
        public static ITsString HeadWordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph, string defaultCf,
                                                   HomographConfiguration.HeadwordVariant hv)
        {
            var citationForm = CitationFormWithAffixTypeStaticForWs(entry, wsVern, defaultCf);

            if (String.IsNullOrEmpty(citationForm))
            {
                return(entry.Cache.TsStrFactory.EmptyString(wsVern));
            }
            var tisb = TsIncStrBldrClass.Create();

            AddHeadwordForWsAndHn(entry, wsVern, nHomograph, hv, tisb, citationForm);
            return(tisb.GetString());
        }
예제 #9
0
        private static void AddHeadwordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph, HomographConfiguration.HeadwordVariant hv,
                                                  ITsIncStrBldr tisb, string citationForm, LcmCache cache)
        {
            var ws = cache?.WritingSystemFactory?.get_EngineOrNull(wsVern);

            // Audio writing systems actually store a filename and should not have homograph numbers attached
            if (IsAudioWritingSystem(ws))
            {
                tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
                tisb.Append(citationForm);
                return;
            }
            var hc = entry.Services.GetInstance <HomographConfiguration>();

            if (hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv, cache);
            }
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
            tisb.Append(citationForm);

            if (!hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv, cache);
            }
        }
예제 #10
0
        private static void AddHeadwordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph, HomographConfiguration.HeadwordVariant hv,
                                                  ITsIncStrBldr tisb, string citationForm, LcmCache cache)
        {
            var hc = entry.Services.GetInstance <HomographConfiguration>();

            if (hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv, cache);
            }
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
            tisb.Append(citationForm);

            if (!hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv, cache);
            }
        }