This class stores various settings related to how homograph numbers (and sense numbers) are displayed.
		/// <summary>
		/// Set the properties of the HC passed in to those indicated by the dialog.
		/// </summary>
		public void GetResults(HomographConfiguration hc)
		{
			hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.Main, !m_radioHide.Checked);
			hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef,
				!m_radioHide.Checked && m_chkShowHomographNumInDict.Checked);
			hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef,
				!m_radioHide.Checked && m_chkShowHomographNumInReversal.Checked);
			hc.HomographNumberBefore = m_radioBefore.Checked;
			hc.ShowSenseNumberRef = !m_radioHide.Checked && m_chkShowSenseNumInDict.Checked;
			hc.ShowSenseNumberReversal = !m_radioHide.Checked && m_chkShowSenseNumInReversal.Checked;

		}
		/// <summary>
		/// It's convenient to test pretty much all these functions with one set of data.
		/// </summary>
		///
		public override void FixtureSetup()
		{
			base.FixtureSetup();
			m_wsVern = Cache.DefaultVernWs;
			m_wsAnalysis = Cache.DefaultAnalWs;
			m_hc = Cache.ServiceLocator.GetInstance<HomographConfiguration>();
			UndoableUnitOfWorkHelper.Do("undoit", "redoit", m_actionHandler,
				() =>
					{
						m_kick = MakeEntry("kick", "strike with foot");
						m_kickS1 = m_kick.SensesOS[0];
						m_rightCorrect = MakeEntry("right", "correct");
						m_rightCorrectS2 = MakeSense(m_rightCorrect, "morally perfect");
						m_rightDirection = MakeEntry("right", "turn right");
						m_rightDirectionS1 = m_rightDirection.SensesOS[0];
					});
		}
		protected string m_helpTopic = ""; // Default help topic ID


		public void SetupDialog(HomographConfiguration hc, FdoCache cache, FwStyleSheet stylesheet, IApp app,
			IHelpTopicProvider helpTopicProvider)
		{
			SetHelpTopic("khtpConfigureHomograph"); // Default help topic ID
			m_helpProvider = new HelpProvider();
			m_helpProvider.SetHelpNavigator(this, HelpNavigator.Topic);
			m_helpProvider.SetShowHelp(this, true);

			m_cache = cache;
			m_stylesheet = stylesheet;
			m_app = app;
			m_helpTopicProvider = helpTopicProvider;
			if (m_helpTopicProvider != null)
			{
				m_helpProvider.HelpNamespace = m_helpTopicProvider.HelpFile;
				SetHelpButtonEnabled();
			}

			if (hc.ShowHomographNumber(HomographConfiguration.HeadwordVariant.Main))
			{
				m_radioHide.Checked = false;
				m_radioBefore.Checked = hc.HomographNumberBefore;
				m_radioAfter.Checked = !hc.HomographNumberBefore;
				m_chkShowSenseNumInDict.Checked = hc.ShowSenseNumberRef;
				m_chkShowSenseNumInReversal.Checked = hc.ShowSenseNumberReversal;
			}
			else
			{
				m_radioHide.Checked = true;
				m_radioBefore.Checked = false;
				m_radioAfter.Checked = false;
				m_chkShowSenseNumInDict.Checked = false;
				m_chkShowSenseNumInReversal.Checked = false;
			}
			m_chkShowHomographNumInDict.Checked =
				hc.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef);
			m_chkShowHomographNumInReversal.Checked =
				hc.ShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef);
			EnableControls();
		}
		public void PersistData()
		{
			var hc = new HomographConfiguration();
			Assert.That(hc.PersistData, Is.EqualTo(""));
			hc.HomographNumberBefore = true;
			hc.ShowSenseNumberRef = false;
			Assert.That(hc.PersistData, Is.EqualTo("before snRef "));
			var hc2 = new HomographConfiguration();
			hc2.PersistData = hc.PersistData;
			Assert.That(hc2.ShowSenseNumberRef, Is.False);
			Assert.That(hc2.HomographNumberBefore, Is.True);
			Assert.That(hc2.ShowSenseNumberReversal, Is.True);

			hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.Main, false);
			hc2.PersistData = hc.PersistData;
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.Main), Is.False);
			Assert.That(hc2.HomographNumberBefore, Is.False);

			hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.Main, true);
			hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef, false);
			hc2.PersistData = hc.PersistData;
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.Main), Is.True);
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef), Is.False);
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef), Is.True);

			hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef, false);
			hc2.PersistData = hc.PersistData;
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.Main), Is.True);
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef), Is.False);
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef), Is.False);

			hc.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef, true);
			hc2.PersistData = hc.PersistData;
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.Main), Is.True);
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef), Is.True);
			Assert.That(hc2.ShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef), Is.False);

			hc.ShowSenseNumberRef = true;
			hc.ShowSenseNumberReversal = false;
			hc2.PersistData = hc.PersistData;
			Assert.That(hc2.ShowSenseNumberRef, Is.True);
			Assert.That(hc2.ShowSenseNumberReversal, Is.False);
		}
		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(" 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)
					});
		}
Example #6
0
		private static void InsertHomographNumber(ITsIncStrBldr 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);
			}
		}
Example #7
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);
		}
Example #8
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);
		}
Example #9
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();
		}
 /// <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();
 }