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
16 changes: 10 additions & 6 deletions Src/LexText/LexTextDll/AreaListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example:

if (m_mediator != null)
Expand All @@ -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;
Expand Down Expand Up @@ -959,15 +961,18 @@ private XmlNode GetToolNodeForArea(string areaName, out string toolName)
}

/// <summary>
/// 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.
/// </summary>
public bool OnGetContentControlParameters(object parameterObj)
private void GetContentControlParameters(object parameterObj)
{
var param = parameterObj as Tuple<string, string, XmlNode[]>;
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;
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,7 +128,7 @@ private XmlNode GetConfigureLayoutsNodeForTool(string tool)
{
var collector = new XmlNode[1];
var parameter = new Tuple<string, string, XmlNode[]>("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");
Expand Down
2 changes: 1 addition & 1 deletion Src/xWorks/ExportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private Control EnsureViewInfo()
}
var collector = new XmlNode[1];
var parameter = new Tuple<string, string, XmlNode[]>(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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,7 +16,7 @@ namespace SIL.FieldWorks.XWorks.DictionaryConfigurationMigrators
/// tools for testing export functionality.
/// </summary>
/// <remarks>To use add the following to your TestFixtureSetup: m_mediator.AddColleague(new StubContentControlProvider());</remarks>
internal class StubContentControlProvider : IxCoreColleague
internal class StubContentControlProvider : IxCoreColleague, IDisposable
{
private const string m_contentControlDictionary =
@"<control>
Expand Down Expand Up @@ -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)
Expand All @@ -78,18 +81,34 @@ public IxCoreColleague[] GetMessageTargets()
/// This is called by reflection through the mediator. We need so that we can migrate through the PreHistoricMigrator.
/// </summary>
// ReSharper disable once UnusedMember.Local
private bool OnGetContentControlParameters(object parameterObj)
private void GetContentControlParameters(object parameterObj)
{
var param = parameterObj as Tuple<string, string, XmlNode[]>;
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)
{
System.Diagnostics.Debug.WriteLineIf(!disposeCalled, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
Subscriber.Unsubscribe(EventConstants.GetContentControlParameters, GetContentControlParameters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, unsubscribing during garbage collection may not be a good idea.

}

~StubContentControlProvider()
{
Dispose(false);
}
}
}
Loading