/// <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); } }
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); } }
/// <summary> /// Intended to be used to set the singleton HomographConfiguration in FLEx to the settings from this model /// </summary> public void ExportToHomographConfiguration(HomographConfiguration config) { config.HomographNumberBefore = HomographNumberBefore; config.ShowSenseNumberRef = ShowSenseNumber; config.ShowSenseNumberReversal = ShowSenseNumberReversal; config.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.Main, ShowHwNumber); config.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef, ShowHwNumInCrossRef); config.SetShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef, ShowHwNumInReversalCrossRef); config.WritingSystem = HomographWritingSystem; config.CustomHomographNumbers = CustomHomographNumberList; }
public DictionaryHomographConfiguration(HomographConfiguration config) { HomographNumberBefore = config.HomographNumberBefore; ShowSenseNumber = config.ShowSenseNumberRef; ShowSenseNumberReversal = config.ShowSenseNumberReversal; ShowHwNumber = config.ShowHomographNumber(HomographConfiguration.HeadwordVariant.Main); ShowHwNumInCrossRef = config.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef); ShowHwNumInReversalCrossRef = config.ShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef); HomographWritingSystem = config.WritingSystem; CustomHomographNumberList = config.CustomHomographNumbers; }
/// <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> /// Loads the model. If Cache is not null, also connects parents and references, and updates lists from the rest of the FieldWorks model. /// </summary> public void Load(LcmCache cache) { var serializer = new XmlSerializer(typeof(DictionaryConfigurationModel)); using (var reader = XmlReader.Create(FilePath)) { var model = (DictionaryConfigurationModel)serializer.Deserialize(reader); model.FilePath = FilePath; // this doesn't get [de]serialized foreach (var property in typeof(DictionaryConfigurationModel).GetProperties().Where(prop => prop.CanWrite)) { property.SetValue(this, property.GetValue(model, null), null); } } SharedItems = SharedItems ?? new List <ConfigurableDictionaryNode>(); if (cache == null) { return; } SpecifyParentsAndReferences(Parts, SharedItems); if (AllPublications) { Publications = DictionaryConfigurationController.GetAllPublications(cache); } else { DictionaryConfigurationController.FilterInvalidPublicationsFromModel(this, cache); } // Update FDO's homograph configuration from the loaded dictionary configuration homograph settings if (HomographConfiguration != null) { var wsTtype = DictionaryNodeWritingSystemOptions.WritingSystemType.Both; var availableWSs = DictionaryConfigurationController.GetCurrentWritingSystems(wsTtype, cache); if (availableWSs.Any(x => x.Id == HomographConfiguration.HomographWritingSystem)) { HomographConfiguration.ExportToHomographConfiguration(cache.ServiceLocator.GetInstance <HomographConfiguration>()); } else { HomographConfiguration.HomographWritingSystem = string.Empty; HomographConfiguration.CustomHomographNumbers = string.Empty; } } // Handle any changes to the custom field definitions. (See https://jira.sil.org/browse/LT-16430.) // The "Merge" method handles both additions and deletions. DictionaryConfigurationController.MergeCustomFieldsIntoDictionaryModel(this, cache); // Handle changes to the lists of complex form types, variant types, lexical reference types, and more! DictionaryConfigurationController.MergeTypesIntoDictionaryModel(this, cache); // Handle any deleted styles. (See https://jira.sil.org/browse/LT-16501.) DictionaryConfigurationController.EnsureValidStylesInModel(this, cache); // Handle %O numberingStyle, Should be changed as %d. (See https://jira.sil.org/browse/LT-18297.) DictionaryConfigurationController.EnsureValidNumberingStylesInModel(this.PartsAndSharedItems); //Update Writing System for an entire configuration. DictionaryConfigurationController.UpdateWritingSystemInModel(this, cache); }
public void HomographConfiguration_Persist_Saves_WritingSystemAndCustomNumbers() { var settings = new HomographConfiguration(); settings.CustomHomographNumbers = new List <string> { "a", "b", "c" }; settings.WritingSystem = "fr"; var persistanceString = settings.PersistData; Assert.That(persistanceString, Is.StringContaining("ws:fr")); Assert.That(persistanceString, Is.StringContaining("customHn:a;b;c")); }
public void HomographConfiguration_Persist_Restores_WritingSystemAndCustomNumbers() { const string oldConfigString = "ws:en customHn:1;2;3;4;00"; var settings = new HomographConfiguration(); Assert.IsTrue(string.IsNullOrEmpty(settings.WritingSystem)); CollectionAssert.IsEmpty(settings.CustomHomographNumbers); settings.PersistData = oldConfigString; Assert.AreEqual("en", settings.WritingSystem); CollectionAssert.AreEqual(new List <string> { "1", "2", "3", "4", "00" }, settings.CustomHomographNumbers); }
/// <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]; }); }
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); }
public void SetsViewDataFromDefaultsIfNoHomographConfigurationInConfigurationModel() { var hc = new HomographConfiguration(); var view = new TestHeadwordNumbersView { HomographBefore = !hc.HomographNumberBefore, ShowHomograph = !hc.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef), ShowSenseNumber = !hc.ShowSenseNumberRef }; var model = new DictionaryConfigurationModel(); // ReSharper disable once UnusedVariable var testController = new HeadwordNumbersController(view, model, Cache); view.Show(); Assert.AreEqual(view.HomographBefore, hc.HomographNumberBefore); Assert.AreEqual(view.ShowHomographOnCrossRef, hc.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef)); Assert.AreEqual(view.ShowSenseNumber, hc.ShowSenseNumberRef); }
public void HomographConfiguration_Persist_RestoresOldConfig() { // property string settings which set homograph to before, turn off the dictionary cross reference(hn:dcr), // turn off the reversal cross reference(hn:rcr), turn off show sense number in both dictionary and reversal const string oldConfigString = "before hn:dcr hn:rcr snRef snRev"; var settings = new HomographConfiguration(); Assert.IsFalse(settings.HomographNumberBefore); Assert.IsTrue(settings.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef)); Assert.IsTrue(settings.ShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef)); Assert.IsTrue(settings.ShowSenseNumberRef); Assert.IsTrue(settings.ShowSenseNumberReversal); settings.PersistData = oldConfigString; Assert.IsTrue(settings.HomographNumberBefore); Assert.IsFalse(settings.ShowHomographNumber(HomographConfiguration.HeadwordVariant.DictionaryCrossRef)); Assert.IsFalse(settings.ShowHomographNumber(HomographConfiguration.HeadwordVariant.ReversalCrossRef)); Assert.IsFalse(settings.ShowSenseNumberRef); Assert.IsFalse(settings.ShowSenseNumberReversal); }
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(); }
/// <summary> /// Method to insert the homograph number with settings into the Text /// </summary> private void InsertHomographNumber(IVwEnv vwenv, HomographConfiguration hc, int nHomograph, int defUserWs) { if (nHomograph <= 0) { return; } // Use a string builder to embed the properties in with the TsString. // this allows our TsStringCollectorEnv to properly encode the superscript. // ideally, TsStringCollectorEnv could be made smarter to handle SetIntPropValues // since AppendTss treats the given Tss as atomic. ITsIncStrBldr tsBldr = TsStringUtils.MakeIncStrBldr(); tsBldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript, (int)FwTextPropVar.ktpvEnum, (int)FwSuperscriptVal.kssvSub); tsBldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); tsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, defUserWs); StringServices.InsertHomographNumber(tsBldr, nHomograph, hc, HomographConfiguration.HeadwordVariant.Main, m_cache); vwenv.AddString(tsBldr.GetString()); }