Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 28 additions & 47 deletions Src/LexText/LexTextControls/DataNotebook/AnthroFieldMappingDlg.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<Mediator, PropertyTable, string>(m_mediator, m_propertyTable, AreaConstants.notebook)));
// Now, clean up our map of possible field targets and reload the field combo list.
List<int> delFields = new List<int>();
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<int> delFields = new List<int>();
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)
Expand Down
2 changes: 1 addition & 1 deletion Src/LexText/LexTextControls/LexImportWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHelpTopicProvider>("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
Expand Down
35 changes: 19 additions & 16 deletions Src/LexText/LexTextControls/LexImportWizardMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<IHelpTopicProvider>("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.
Expand Down Expand Up @@ -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<Mediator, PropertyTable, string>(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
Expand Down
15 changes: 1 addition & 14 deletions Src/xWorks/AddCustomFieldDlg.cs
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -82,19 +82,6 @@ private enum CustomFieldType
private ComboBox m_listComboBox;
private Label m_listLabel;

/// <summary>
/// Provide access (via reflection) to this dialog for use by the
/// Data Notebook standard format importer.
/// </summary>
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
Expand Down
107 changes: 49 additions & 58 deletions Src/xWorks/XWorksViewBase.cs
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -20,19 +20,7 @@

namespace SIL.FieldWorks.XWorks
{
/// <summary>
/// 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 <jtview></jtview> node
/// of the view node. This specifies how to display an individual list item.
/// </summary>
/// <remarks>
/// IxCoreContentControl includes IxCoreColleague now,
/// so only IxCoreContentControl needs to be declared here.
/// </remarks>
/// <summary/>
public abstract class XWorksViewBase : XCoreUserControl, IxCoreContentControl, IPaneBarUser
{
#region Enumerations
Expand All @@ -47,10 +35,6 @@ public enum TreebarAvailability

#endregion Enumerations

#region Event declaration

#endregion Event declaration

#region Data members
/// <summary>
/// Optional information bar above the main control.
Expand Down Expand Up @@ -92,15 +76,6 @@ public enum TreebarAvailability
/// Last known parent that is a MultiPane.
/// </summary>
private MultiPane m_mpParent;

///// <summary>
///// Right-click menu for deleting Custom lists.
///// </summary>
//private ContextMenuStrip m_contextMenu;
///// <summary>
///// Keeps track of when the context menu last closed.
///// </summary>
//private long m_ticksWhenContextMenuClosed = 0;
/// <summary>
/// Required designer variable.
/// </summary>
Expand All @@ -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);
}

/// <summary>
/// Initializes a new instance of the <see cref="XWorksViewBase"/> class.
/// </summary>
Expand Down Expand Up @@ -167,7 +148,7 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

#endregion // Consruction and disposal
#endregion // Construction and disposal

#region Properties

Expand Down Expand Up @@ -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)
Expand All @@ -689,43 +661,62 @@ ref UIItemDisplayProperties display
return true;
}

public bool OnAddCustomField(object argument)
/// <summary>
/// Display a dialog to allow users to modify Custom Fields
/// Triggered from DistFiles/Language Explorer/Configuration/Main.xml
/// </summary>
public bool OnAddCustomField(object _)
{
CheckDisposed();
ConfigureCustomFields(new Tuple<Mediator, PropertyTable, string>(m_mediator, m_propertyTable,
m_propertyTable.GetStringProperty("areaChoice", string.Empty)));
return true; // handled
}

if (SharedBackendServices.AreMultipleApplicationsConnected(Cache))
/// <summary>
/// Display a dialog to allow users to modify Custom Fields
/// </summary>
private static void ConfigureCustomFields(object propTableAndArea)
{
if (!(propTableAndArea is Tuple<Mediator, PropertyTable, string> args))
{

throw new ArgumentException(nameof(propTableAndArea));
}

var mediator = args.Item1;
var propertyTable = args.Item2;
var areaChoice = args.Item3;
var cache = propertyTable.GetValue<LcmCache>("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(
Expand Down
Loading