From 5c17aadafbfab41a63b0dc6c8c822f473016a14d Mon Sep 17 00:00:00 2001 From: mark-sil <83427558+mark-sil@users.noreply.github.com> Date: Tue, 27 Jan 2026 10:54:26 -0500 Subject: [PATCH 1/2] LT-21512: Move GetContentControlParameters to Pub/Sub Cherry-pick from the PubSub branch to the main branch using the following command: git cherry-pick --no-commit b82f926e After the cherry-pick additional edits were made to resolve conflicts and standardize on the use of: using static SIL.FieldWorks.Common.FwUtils.FwUtils; --- Src/LexText/LexTextDll/AreaListener.cs | 16 +++++++----- .../PreHistoricMigrator.cs | 3 ++- Src/xWorks/ExportDialog.cs | 2 +- .../StubContentControlProvider.cs | 26 ++++++++++++++++--- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Src/LexText/LexTextDll/AreaListener.cs b/Src/LexText/LexTextDll/AreaListener.cs index 6d36ee52ca..287c2e0778 100644 --- a/Src/LexText/LexTextDll/AreaListener.cs +++ b/Src/LexText/LexTextDll/AreaListener.cs @@ -129,6 +129,7 @@ protected virtual void Dispose(bool disposing) { Subscriber.Unsubscribe(EventConstants.SetToolFromName, SetToolFromName); Subscriber.Unsubscribe(EventConstants.ReloadAreaTools, ReloadAreaTools); + Subscriber.Unsubscribe(EventConstants.GetContentControlParameters, GetContentControlParameters); // Dispose managed resources here. if (m_mediator != null) @@ -153,6 +154,7 @@ public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configu m_ccustomLists = 0; Subscriber.Subscribe(EventConstants.SetToolFromName, SetToolFromName); Subscriber.Subscribe(EventConstants.ReloadAreaTools, ReloadAreaTools); + Subscriber.Subscribe(EventConstants.GetContentControlParameters, GetContentControlParameters); } private DateTime m_lastToolChange = DateTime.MinValue; @@ -959,15 +961,18 @@ private XmlNode GetToolNodeForArea(string areaName, out string toolName) } /// - /// This is designed to be called by reflection through the mediator, when something typically in xWorks needs to get - /// the parameter node for a given tool. The last argument is a one-item array used to return the result, - /// since I don't think we handle Out parameters in our SendMessage protocol. + /// This subscriber is called when the GetContentControlParameters event is published. + /// Typically used when something in xWorks needs to get the parameter node for a given tool. + /// The last argument is a one-item array used to return the result because we + /// don't have return values or out parameters in our Publish/Subscribe protocol. /// - public bool OnGetContentControlParameters(object parameterObj) + private void GetContentControlParameters(object parameterObj) { var param = parameterObj as Tuple; if (param == null) - return false; // we sure can't handle it; should we throw? + { + return; // we sure can't handle it; should we throw? + } string area = param.Item1; string tool = param.Item2; XmlNode[] result = param.Item3; @@ -976,7 +981,6 @@ public bool OnGetContentControlParameters(object parameterObj) { result[0] = node.SelectSingleNode("control"); } - return true; // whatever happened, we did the best that can be done. } protected string GetCurrentAreaName() diff --git a/Src/xWorks/DictionaryConfigurationMigrators/PreHistoricMigrator.cs b/Src/xWorks/DictionaryConfigurationMigrators/PreHistoricMigrator.cs index e70ff19271..33e86850c1 100644 --- a/Src/xWorks/DictionaryConfigurationMigrators/PreHistoricMigrator.cs +++ b/Src/xWorks/DictionaryConfigurationMigrators/PreHistoricMigrator.cs @@ -13,6 +13,7 @@ using SIL.FieldWorks.Common.Controls; using SIL.LCModel.Core.KernelInterfaces; using SIL.FieldWorks.Common.FwUtils; +using static SIL.FieldWorks.Common.FwUtils.FwUtils; using SIL.FieldWorks.Common.Widgets; using SIL.LCModel; using SIL.LCModel.DomainServices; @@ -127,7 +128,7 @@ private XmlNode GetConfigureLayoutsNodeForTool(string tool) { var collector = new XmlNode[1]; var parameter = new Tuple("lexicon", tool, collector); - m_mediator.SendMessage("GetContentControlParameters", parameter); + Publisher.Publish(new PublisherParameterObject(EventConstants.GetContentControlParameters, parameter)); var controlNode = collector[0]; var parameters = controlNode.SelectSingleNode("parameters"); var configureLayouts = XmlUtils.FindNode(parameters, "configureLayouts"); diff --git a/Src/xWorks/ExportDialog.cs b/Src/xWorks/ExportDialog.cs index b34741bc8f..47e5b84684 100644 --- a/Src/xWorks/ExportDialog.cs +++ b/Src/xWorks/ExportDialog.cs @@ -519,7 +519,7 @@ private Control EnsureViewInfo() } var collector = new XmlNode[1]; var parameter = new Tuple(area, tool, collector); - m_mediator.SendMessage("GetContentControlParameters", parameter); + Publisher.Publish(new PublisherParameterObject(EventConstants.GetContentControlParameters, parameter)); var controlNode = collector[0]; Debug.Assert(controlNode != null); XmlNode dynLoaderNode = controlNode.SelectSingleNode("dynamicloaderinfo"); diff --git a/Src/xWorks/xWorksTests/DictionaryConfigurationMigrators/StubContentControlProvider.cs b/Src/xWorks/xWorksTests/DictionaryConfigurationMigrators/StubContentControlProvider.cs index 2fcb328dcb..6665a6d6c2 100644 --- a/Src/xWorks/xWorksTests/DictionaryConfigurationMigrators/StubContentControlProvider.cs +++ b/Src/xWorks/xWorksTests/DictionaryConfigurationMigrators/StubContentControlProvider.cs @@ -5,6 +5,8 @@ using System; using System.Xml; using NUnit.Framework; +using SIL.FieldWorks.Common.FwUtils; +using static SIL.FieldWorks.Common.FwUtils.FwUtils; using XCore; namespace SIL.FieldWorks.XWorks.DictionaryConfigurationMigrators @@ -14,7 +16,7 @@ namespace SIL.FieldWorks.XWorks.DictionaryConfigurationMigrators /// tools for testing export functionality. /// /// To use add the following to your TestFixtureSetup: m_mediator.AddColleague(new StubContentControlProvider()); - internal class StubContentControlProvider : IxCoreColleague + internal class StubContentControlProvider : IxCoreColleague, IDisposable { private const string m_contentControlDictionary = @" @@ -63,6 +65,7 @@ public StubContentControlProvider() var reversalDoc = new XmlDocument(); reversalDoc.LoadXml(m_contentControlReversal); m_testControlRevNode = reversalDoc.DocumentElement; + Subscriber.Subscribe(EventConstants.GetContentControlParameters, GetContentControlParameters); } public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configurationParameters) @@ -78,18 +81,33 @@ public IxCoreColleague[] GetMessageTargets() /// This is called by reflection through the mediator. We need so that we can migrate through the PreHistoricMigrator. /// // ReSharper disable once UnusedMember.Local - private bool OnGetContentControlParameters(object parameterObj) + private void GetContentControlParameters(object parameterObj) { var param = parameterObj as Tuple; if (param == null) - return false; + return; var result = param.Item3; Assert.That(param.Item2 == "lexiconDictionary" || param.Item2 == "reversalToolEditComplete", "No params for tool: " + param.Item2); result[0] = param.Item2 == "lexiconDictionary" ? m_testControlDictNode : m_testControlRevNode; - return true; } public bool ShouldNotCall { get { return false; } } public int Priority { get { return 1; }} + + public void Dispose() + { + GC.SuppressFinalize(this); + Dispose(true); + } + + public void Dispose(bool disposeCalled) + { + Subscriber.Unsubscribe(EventConstants.GetContentControlParameters, GetContentControlParameters); + } + + ~StubContentControlProvider() + { + Dispose(false); + } } } \ No newline at end of file From a7a97a6c270fd458bdef46511f858832d64392d9 Mon Sep 17 00:00:00 2001 From: mark-sil <83427558+mark-sil@users.noreply.github.com> Date: Tue, 27 Jan 2026 12:01:42 -0500 Subject: [PATCH 2/2] Add Debug.WriteLineIf() --- .../StubContentControlProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/xWorks/xWorksTests/DictionaryConfigurationMigrators/StubContentControlProvider.cs b/Src/xWorks/xWorksTests/DictionaryConfigurationMigrators/StubContentControlProvider.cs index 6665a6d6c2..987dfba3b8 100644 --- a/Src/xWorks/xWorksTests/DictionaryConfigurationMigrators/StubContentControlProvider.cs +++ b/Src/xWorks/xWorksTests/DictionaryConfigurationMigrators/StubContentControlProvider.cs @@ -102,6 +102,7 @@ public void Dispose() public void Dispose(bool disposeCalled) { + System.Diagnostics.Debug.WriteLineIf(!disposeCalled, "****** Missing Dispose() call for " + GetType().Name + ". ****** "); Subscriber.Unsubscribe(EventConstants.GetContentControlParameters, GetContentControlParameters); }