diff --git a/Src/LexText/LexTextControls/DataNotebook/AnthroFieldMappingDlg.cs b/Src/LexText/LexTextControls/DataNotebook/AnthroFieldMappingDlg.cs index aafa95af1a..2ca2e08adf 100644 --- a/Src/LexText/LexTextControls/DataNotebook/AnthroFieldMappingDlg.cs +++ b/Src/LexText/LexTextControls/DataNotebook/AnthroFieldMappingDlg.cs @@ -1,20 +1,21 @@ -// Copyright (c) 2010-2017 SIL International +// Copyright (c) 2010-2026 SIL International // This software is licensed under the LGPL, version 2.1 or later // (http://www.gnu.org/licenses/lgpl-2.1.html) +using SIL.FieldWorks.Common.FwUtils; +using static SIL.FieldWorks.Common.FwUtils.FwUtils; +using SIL.FieldWorks.Common.RootSites; +using SIL.LCModel; +using SIL.LCModel.Core.Cellar; +using SIL.LCModel.Core.KernelInterfaces; +using SIL.LCModel.Infrastructure; +using SIL.Utils; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Reflection; using System.Windows.Forms; -using SIL.LCModel.Core.Cellar; -using SIL.LCModel.Core.KernelInterfaces; -using SIL.FieldWorks.Common.FwUtils; -using SIL.FieldWorks.Common.RootSites; -using SIL.LCModel; -using SIL.LCModel.Infrastructure; -using SIL.Utils; using XCore; namespace SIL.FieldWorks.LexText.Controls.DataNotebook @@ -276,49 +277,29 @@ private void m_cbDestination_SelectedIndexChanged(object sender, EventArgs e) private void m_btnAddCustom_Click(object sender, EventArgs e) { - // What we'd like to do is the following bit of code, but we can't due to - // circular dependencies that would be introduced. We could possibly move - // the dialog to another assembly/dll, but that would require reworking a - // fair number of strings that have been converted to resources. - //using (var dlg = new AddCustomFieldDlg(m_mediator, AddCustomFieldDlg.LocationType.Notebook)) - // dlg.ShowDialog(); - System.Type typeFound; - MethodInfo mi = XmlUtils.GetStaticMethod("xWorks.dll", - "SIL.FieldWorks.XWorks.AddCustomFieldDlg", - "ShowNotebookCustomFieldDlg", - "AnthroFieldMappingDlg.m_btnAddCustom_Click()", out typeFound); - if (mi != null) + // Show the ConfigureCustomFields dialog (by publisher to avoid circular dependencies) + Publisher.Publish(new PublisherParameterObject(EventConstants.ConfigureCustomFields, + new Tuple(m_mediator, m_propertyTable, AreaConstants.notebook))); + // Now, clean up our map of possible field targets and reload the field combo list. + List delFields = new List(); + foreach (int key in m_mapFlidName.Keys) { - var parameters = new object[2]; - parameters[0] = m_mediator; - parameters[1] = m_propertyTable; - mi.Invoke(typeFound, - System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | - System.Reflection.BindingFlags.NonPublic, null, parameters, null); - // Now, clean up our map of possible field targets and reload the field combo list. - List delFields = new List(); - foreach (int key in m_mapFlidName.Keys) - { - if (!m_mdc.FieldExists(key)) - delFields.Add(key); - } - foreach (int flid in delFields) - m_mapFlidName.Remove(flid); - foreach (int flid in m_mdc.GetFields(RnGenericRecTags.kClassId, false, (int)CellarPropertyTypeFilter.All)) - { - if (m_mapFlidName.ContainsKey(flid)) - continue; - if (m_mdc.IsCustom(flid)) - { - string name = m_mdc.GetFieldName(flid); - m_mapFlidName.Add(flid, name); - } - } - FillInFieldList(); + if (!m_mdc.FieldExists(key)) + delFields.Add(key); } - else + foreach (int flid in delFields) + m_mapFlidName.Remove(flid); + foreach (int flid in m_mdc.GetFields(RnGenericRecTags.kClassId, false, (int)CellarPropertyTypeFilter.All)) { + if (m_mapFlidName.ContainsKey(flid)) + continue; + if (m_mdc.IsCustom(flid)) + { + string name = m_mdc.GetFieldName(flid); + m_mapFlidName.Add(flid, name); + } } + FillInFieldList(); } private void m_btnOK_Click(object sender, EventArgs e) diff --git a/Src/LexText/LexTextControls/LexImportWizard.cs b/Src/LexText/LexTextControls/LexImportWizard.cs index 06a1c9709b..36c4ebb645 100644 --- a/Src/LexText/LexTextControls/LexImportWizard.cs +++ b/Src/LexText/LexTextControls/LexImportWizard.cs @@ -1164,7 +1164,7 @@ private void btnModifyContentMapping_Click(object sender, System.EventArgs e) contentMapping = listViewContentMapping.Items[selIndex].Tag as MarkerPresenter.ContentMapping; using (LexImportWizardMarker dlg = new LexImportWizardMarker(m_LexFields)) { - dlg.Init(contentMapping, langDescs, m_cache, m_propertyTable.GetValue("HelpTopicProvider"), m_app); + dlg.Init(contentMapping, langDescs, m_cache, m_propertyTable, m_app); DialogResult dr = dlg.ShowDialog(this); // Custom fields have to be handled independantly of the dialogresult being ok sense they diff --git a/Src/LexText/LexTextControls/LexImportWizardMarker.cs b/Src/LexText/LexTextControls/LexImportWizardMarker.cs index 44447c88e5..bed7551572 100644 --- a/Src/LexText/LexTextControls/LexImportWizardMarker.cs +++ b/Src/LexText/LexTextControls/LexImportWizardMarker.cs @@ -2,6 +2,16 @@ // This software is licensed under the LGPL, version 2.1 or later // (http://www.gnu.org/licenses/lgpl-2.1.html) +using Gecko; +using Sfm2Xml; +using SIL.FieldWorks.Common.Controls; +using SIL.FieldWorks.Common.FwUtils; +using static SIL.FieldWorks.Common.FwUtils.FwUtils; +using SIL.FieldWorks.Common.RootSites; +using SIL.LCModel; +using SIL.LCModel.Core.KernelInterfaces; +using SIL.LCModel.Core.Text; +using SIL.LCModel.Infrastructure; using System; using System.Collections; using System.ComponentModel; @@ -11,15 +21,6 @@ using System.Windows.Forms; using System.Xml; using System.Xml.Xsl; -using Gecko; -using Sfm2Xml; -using SIL.LCModel.Core.Text; -using SIL.FieldWorks.Common.Controls; -using SIL.LCModel.Core.KernelInterfaces; -using SIL.FieldWorks.Common.FwUtils; -using SIL.FieldWorks.Common.RootSites; -using SIL.LCModel; -using SIL.LCModel.Infrastructure; using XCore; using TreeView = System.Windows.Forms.TreeView; @@ -56,6 +57,7 @@ public class LexImportWizardMarker : Form private Label lblFunction; private CheckBox chkbxAutoField; private LcmCache m_cache; + private PropertyTable m_propertyTable; private IHelpTopicProvider m_helpTopicProvider; private IApp m_app; private string m_refFuncString; @@ -84,17 +86,17 @@ private void EnableLangDesc(bool enable) blbLangDesc.Enabled = cbLangDesc.Enabled = btnAddLangDesc.Enabled = enable; } - public void Init(MarkerPresenter.ContentMapping currentMarker, Hashtable uiLangsHT, LcmCache cache, - IHelpTopicProvider helpTopicProvider, IApp app) + public void Init(MarkerPresenter.ContentMapping currentMarker, Hashtable uiLangs, LcmCache cache, PropertyTable propertyTable, IApp app) { CheckDisposed(); - m_uiLangs = uiLangsHT; + m_uiLangs = uiLangs; m_cache = cache; - m_helpTopicProvider = helpTopicProvider; + m_propertyTable = propertyTable; + m_helpTopicProvider = m_propertyTable.GetValue("HelpTopicProvider"); m_app = app; - helpProvider.HelpNamespace = helpTopicProvider.HelpFile; - helpProvider.SetHelpKeyword(this, helpTopicProvider.GetHelpString(s_helpTopic)); + helpProvider.HelpNamespace = m_helpTopicProvider.HelpFile; + helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(s_helpTopic)); helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); // The following call is needed to 'correct' the current behavior of the FwOverrideComboBox control. @@ -1058,7 +1060,8 @@ private void btnAddCustomField_Click(object sender, EventArgs e) MessageBoxButtons.OK, MessageBoxIcon.Information); return; } - med.SendMessage("AddCustomField", null); + Publisher.Publish(new PublisherParameterObject(EventConstants.ConfigureCustomFields, + new Tuple(med, m_propertyTable, AreaConstants.lexicon))); // The above call can cause the Mediator to 'go away', so check it and // restore the member variable for everyone else who may be surprised diff --git a/Src/xWorks/AddCustomFieldDlg.cs b/Src/xWorks/AddCustomFieldDlg.cs index de7e80a624..234be1b8cb 100644 --- a/Src/xWorks/AddCustomFieldDlg.cs +++ b/Src/xWorks/AddCustomFieldDlg.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2018 SIL International +// Copyright (c) 2015-2026 SIL International // This software is licensed under the LGPL, version 2.1 or later // (http://www.gnu.org/licenses/lgpl-2.1.html) @@ -82,19 +82,6 @@ private enum CustomFieldType private ComboBox m_listComboBox; private Label m_listLabel; - /// - /// Provide access (via reflection) to this dialog for use by the - /// Data Notebook standard format importer. - /// - public static void ShowNotebookCustomFieldDlg(Mediator mediator, PropertyTable propertyTable) - { - using (var dlg = new AddCustomFieldDlg(mediator, propertyTable, LocationType.Notebook)) - { - if (dlg.ShowCustomFieldWarning(null)) - dlg.ShowDialog(); - } - } - public AddCustomFieldDlg(Mediator mediator, PropertyTable propertyTable, LocationType locationType) { // create member variables diff --git a/Src/xWorks/XWorksViewBase.cs b/Src/xWorks/XWorksViewBase.cs index 397c904881..e56cc91eee 100644 --- a/Src/xWorks/XWorksViewBase.cs +++ b/Src/xWorks/XWorksViewBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2003-2017 SIL International +// Copyright (c) 2003-2026 SIL International // This software is licensed under the LGPL, version 2.1 or later // (http://www.gnu.org/licenses/lgpl-2.1.html) @@ -20,19 +20,7 @@ namespace SIL.FieldWorks.XWorks { - /// - /// XmlDocView is a view that shows a complete list as a single view. - /// A RecordClerk class does most of the work of managing the list and current object. - /// list management and navigation is entirely(?) handled by the - /// RecordClerk. - /// - /// The actual view of each object is specified by a child node - /// of the view node. This specifies how to display an individual list item. - /// - /// - /// IxCoreContentControl includes IxCoreColleague now, - /// so only IxCoreContentControl needs to be declared here. - /// + /// public abstract class XWorksViewBase : XCoreUserControl, IxCoreContentControl, IPaneBarUser { #region Enumerations @@ -47,10 +35,6 @@ public enum TreebarAvailability #endregion Enumerations - #region Event declaration - - #endregion Event declaration - #region Data members /// /// Optional information bar above the main control. @@ -92,15 +76,6 @@ public enum TreebarAvailability /// Last known parent that is a MultiPane. /// private MultiPane m_mpParent; - - ///// - ///// Right-click menu for deleting Custom lists. - ///// - //private ContextMenuStrip m_contextMenu; - ///// - ///// Keeps track of when the context menu last closed. - ///// - //private long m_ticksWhenContextMenuClosed = 0; /// /// Required designer variable. /// @@ -120,7 +95,13 @@ public enum TreebarAvailability #endregion Data members - #region Consruction and disposal + #region Construction and disposal + static XWorksViewBase() + { + // Subscribe to requests to display the ConfigureCustomFields dialog only once, not once per instance + Subscriber.Subscribe(EventConstants.ConfigureCustomFields, ConfigureCustomFields); + } + /// /// Initializes a new instance of the class. /// @@ -167,7 +148,7 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } - #endregion // Consruction and disposal + #endregion // Construction and disposal #region Properties @@ -648,23 +629,14 @@ ref UIItemDisplayProperties display { CheckDisposed(); - // No, as it can be using a config node that is correctly set to false, and we really wanted some other node, - // in order to see the menu in the main Lexicon Edit tool. - // bool fEditable = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationParameters, "editable", true); - - // In order for this menu to be visible and enabled it has to be in the correct area (lexicon) - // and the right tool(s). + // For this menu to be visible and enabled, it has to be in an applicable area and an applicable tool. // Tools that allow this menu, as far as I (RandyR) can tell, as of 24 May 2007: // "lexiconEdit", "bulkEditEntries", "lexiconBrowse", and "bulkEditSenses" - // I searched through JIRA to see if there was an offical list, and couldn't find such a list. + // I searched through JIRA to see if there was an official list, and couldn't find such a list. // The old code tried to fish out some 'editable' attr from the xml file, // but in some contexts in switching tools in the Lexicon area, the config file was for the dictionary preview // control, which was set to 'false'. That makes sense, since the view itself isn't editable. - // No: if (areaChoice == "lexicon" && fEditable && (m_vectorName == "entries" || m_vectorName == "AllSenses")) - string toolChoice = m_propertyTable.GetStringProperty( - "currentContentControl", - string.Empty - ); + string toolChoice = m_propertyTable.GetStringProperty("currentContentControl", string.Empty); string areaChoice = m_propertyTable.GetStringProperty("areaChoice", string.Empty); bool inFriendlyTerritory = false; switch (areaChoice) @@ -689,43 +661,62 @@ ref UIItemDisplayProperties display return true; } - public bool OnAddCustomField(object argument) + /// + /// Display a dialog to allow users to modify Custom Fields + /// Triggered from DistFiles/Language Explorer/Configuration/Main.xml + /// + public bool OnAddCustomField(object _) { CheckDisposed(); + ConfigureCustomFields(new Tuple(m_mediator, m_propertyTable, + m_propertyTable.GetStringProperty("areaChoice", string.Empty))); + return true; // handled + } - if (SharedBackendServices.AreMultipleApplicationsConnected(Cache)) + /// + /// Display a dialog to allow users to modify Custom Fields + /// + private static void ConfigureCustomFields(object propTableAndArea) + { + if (!(propTableAndArea is Tuple args)) + { + + throw new ArgumentException(nameof(propTableAndArea)); + } + + var mediator = args.Item1; + var propertyTable = args.Item2; + var areaChoice = args.Item3; + var cache = propertyTable.GetValue("cache"); + + if (SharedBackendServices.AreMultipleApplicationsConnected(cache)) { - MessageBoxUtils.Show( - ParentForm, + MessageBoxUtils.Show(Form.ActiveForm, xWorksStrings.ksCustomFieldsCanNotBeAddedDueToOtherAppsText, xWorksStrings.ksCustomFieldsCanNotBeAddedDueToOtherAppsCaption, MessageBoxButtons.OK, - MessageBoxIcon.Warning - ); - return true; + MessageBoxIcon.Warning); + return; } - AddCustomFieldDlg.LocationType locationType = AddCustomFieldDlg.LocationType.Lexicon; - string areaChoice = m_propertyTable.GetStringProperty("areaChoice", string.Empty); + var locationType = AddCustomFieldDlg.LocationType.Lexicon; switch (areaChoice) { - case "lexicon": + case AreaConstants.lexicon: locationType = AddCustomFieldDlg.LocationType.Lexicon; break; - case "notebook": + case AreaConstants.notebook: locationType = AddCustomFieldDlg.LocationType.Notebook; break; - case "textsWords": + case AreaConstants.textsWords: locationType = AddCustomFieldDlg.LocationType.Interlinear; break; } - using (var dlg = new AddCustomFieldDlg(m_mediator, m_propertyTable, locationType)) + using (var dlg = new AddCustomFieldDlg(mediator, propertyTable, locationType)) { - if (dlg.ShowCustomFieldWarning(this)) - dlg.ShowDialog(this); + if (dlg.ShowCustomFieldWarning(Form.ActiveForm)) + dlg.ShowDialog(Form.ActiveForm); } - - return true; // handled } public bool OnDisplayConfigureList(