Skip to content
Open
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
2 changes: 1 addition & 1 deletion Src/Common/Controls/DetailControls/StringSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public override void DoHotLinkAction(string strData, ISilDataAccess sda)
FwLinkArgs linkArgs = new FwLinkArgs(url);
linkArgs.DisplayErrorMsg = false;
var retObj = new ReturnObject(linkArgs);
Publisher.Publish(new PublisherParameterObject(EventConstants.FollowLink, retObj));
Publisher.Publish(new PublisherParameterObject(EventConstants.FollowLink, retObj, PropertyTable?.GetWindow()));
if (retObj.ReturnValue)
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Common/Controls/XMLViews/FilterBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ private void MakeListChoiceFilterItem(FilterSortItem item, FwComboBox combo, str
var specialItemName =
MakeLabel(XmlUtils.GetOptionalAttributeValue(item.Spec, "specialItemName", XMLViewsStrings.ksChoose_));
var specialFilter = DynamicLoader.CreateObject(XmlUtils.FindNode(item.Spec, "dynamicloaderinfo"),
new object[] { specialItemName, m_cache, m_bv.Mediator }) as FilterComboItem;
new object[] { specialItemName, m_cache, m_bv.Mediator, m_bv.PropTable }) as FilterComboItem;
combo.Items.Add(specialFilter);
break;

Expand Down
9 changes: 6 additions & 3 deletions Src/Common/FieldWorks/FieldWorks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ private static bool LaunchApplicationFromCommandLine(FwAppArgs appArgs)

private static void WarnUserAboutFailedLiftImportIfNecessary(FwApp fwApp)
{
Publisher.Publish(new PublisherParameterObject(EventConstants.WarnUserAboutFailedLiftImportIfNecessary, null));
Publisher.Publish(new PublisherParameterObject(EventConstants.WarnUserAboutFailedLiftImportIfNecessary, null,
fwApp.ActiveMainWindow as IxWindow));
}

private static bool IsSharedXmlBackendNeeded(ProjectId projectId)
Expand Down Expand Up @@ -1847,9 +1848,11 @@ private static ProjectId ShowWelcomeDialog(FwAppArgs args, FwApp startingApp, Pr
if (projectLaunched)
{
s_projectId = projectToTry; // Window is open on this project, we must not try to initialize it again.
if (Form.ActiveForm is IxWindow mainWindow)
if (Form.ActiveForm is IxWindow)
{
Publisher.Publish(new PublisherParameterObject(EventConstants.SFMImport, null, mainWindow));
// SFMImport's subscriber is the app-level LexTextApp, which cannot be scoped,
// so this is intentionally published with a null (process-wide) scope.
Publisher.Publish(new PublisherParameterObject(EventConstants.SFMImport, null, null));
}
else
{
Expand Down
54 changes: 27 additions & 27 deletions Src/Common/FwUtils/FwUtilsTests/PubSubSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void Single_Publisher_Handler_Calls_Multiple_Publisher_on_Rentry_Does_Not

// Run test.
Assert.That(subscriber.One, Is.True);
Assert.DoesNotThrow(() => FwUtils.Publisher.Publish(new PublisherParameterObject("BadBoy", false)));
Assert.DoesNotThrow(() => FwUtils.Publisher.Publish(new PublisherParameterObject("BadBoy", false, null)));
subscriber.DoUnsubscriptions();
SomeRandomMessageSubscriber.DoUnsubscriptions();
niceGuyMultipleSubscriber.DoUnsubscriptions();
Expand Down Expand Up @@ -245,7 +245,7 @@ public void Unscoped_Publish_Delivers_To_Scoped_And_Unscoped_Subscribers()
unscopedSubscriber.DoSubscriptions();

// Run test.
FwUtils.Publisher.Publish(new PublisherParameterObject("MessageOne", false));
FwUtils.Publisher.Publish(new PublisherParameterObject("MessageOne", false, null));
Assert.That(scopedSubscriber.One, Is.False); // Delivered.
Assert.That(unscopedSubscriber.One, Is.False); // Delivered.

Expand Down Expand Up @@ -352,7 +352,7 @@ public void Prefix_Subscriptions_Honor_Scope()
[TestCase(" ")]
public void IllFormedPublisherParameterObjectThrows(string message)
{
Assert.Throws<ArgumentNullException>(() => { var dummy = new PublisherParameterObject(message); });
Assert.Throws<ArgumentNullException>(() => { var dummy = new PublisherParameterObject(message, null, null); });
}

[Test]
Expand All @@ -362,9 +362,9 @@ public void VerifyPublishMessageCalls()
Assert.Throws<ArgumentNullException>(() => FwUtils.Publisher.Publish((IList<PublisherParameterObject>)null));
var publisherParameterObject = new List<PublisherParameterObject>();
Assert.Throws<InvalidOperationException>(() => FwUtils.Publisher.Publish(publisherParameterObject));
publisherParameterObject.Add(new PublisherParameterObject("MessageOne"));
publisherParameterObject.Add(new PublisherParameterObject("MessageOne", null, null));
Assert.Throws<InvalidOperationException>(() => FwUtils.Publisher.Publish(publisherParameterObject));
publisherParameterObject.Add(new PublisherParameterObject("MessageTwo"));
publisherParameterObject.Add(new PublisherParameterObject("MessageTwo", null, null));
Assert.DoesNotThrow(() => FwUtils.Publisher.Publish(publisherParameterObject));

// Test single message Publish method override.
Expand All @@ -390,8 +390,8 @@ public void Test_PublishAtEndOfAction()
Assert.That(subscriber.One, Is.True);
Assert.That(subscriber.Two, Is.EqualTo(int.MinValue));

FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.RecordNavigation, false));
FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.SelectionChanged, int.MaxValue));
FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.RecordNavigation, false, null));
FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.SelectionChanged, int.MaxValue, null));

// Confirm that nothing changed.
Assert.That(subscriber.First, Is.Null);
Expand Down Expand Up @@ -426,8 +426,8 @@ public void Test_PublishAtEndOfAction_OrderDoesNotMatter()
Assert.That(subscriber.One, Is.True);
Assert.That(subscriber.Two, Is.EqualTo(int.MinValue));

FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.SelectionChanged, int.MaxValue));
FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.RecordNavigation, false));
FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.SelectionChanged, int.MaxValue, null));
FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.RecordNavigation, false, null));

// Confirm that nothing changed.
Assert.That(subscriber.First, Is.Null);
Expand Down Expand Up @@ -462,7 +462,7 @@ public void Test_PublishAtEndOfAction_OnlyExecuteEventsThatArePublished()
Assert.That(subscriber.One, Is.True);
Assert.That(subscriber.Two, Is.EqualTo(int.MinValue));

FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.SelectionChanged, int.MaxValue));
FwUtils.Publisher.PublishAtEndOfAction(new PublisherParameterObject(EventConstants.SelectionChanged, int.MaxValue, null));

// Confirm that nothing changed.
Assert.That(subscriber.First, Is.Null);
Expand All @@ -482,20 +482,20 @@ private static class TestPublisher
{
internal static void PublishMessageOne()
{
FwUtils.Publisher.Publish(new PublisherParameterObject("MessageOne", false));
FwUtils.Publisher.Publish(new PublisherParameterObject("MessageOne", false, null));
}

internal static void PublishMessageTwo()
{
FwUtils.Publisher.Publish(new PublisherParameterObject("MessageTwo", 2));
FwUtils.Publisher.Publish(new PublisherParameterObject("MessageTwo", 2, null));
}

internal static void PublishBothMessages()
{
var messages = new List<PublisherParameterObject>
{
new PublisherParameterObject("MessageOne", false),
new PublisherParameterObject("MessageTwo", int.MaxValue)
new PublisherParameterObject("MessageOne", false, null),
new PublisherParameterObject("MessageTwo", int.MaxValue, null)
};
FwUtils.Publisher.Publish(messages);
}
Expand All @@ -513,7 +513,7 @@ private static void SomeRandomMessageOneHandler(object newValue)

internal static void DoSubscriptions()
{
FwUtils.Subscriber.Subscribe("SomeRandomMessage", SomeRandomMessageOneHandler);
FwUtils.Subscriber.Subscribe("SomeRandomMessage", SomeRandomMessageOneHandler, null);
}

internal static void DoUnsubscriptions()
Expand Down Expand Up @@ -545,8 +545,8 @@ private void MessageTwoHandler(object newValue)

internal void DoSubscriptions()
{
FwUtils.Subscriber.Subscribe("MessageOne", MessageOneHandler);
FwUtils.Subscriber.Subscribe("MessageTwo", MessageTwoHandler);
FwUtils.Subscriber.Subscribe("MessageOne", MessageOneHandler, null);
FwUtils.Subscriber.Subscribe("MessageTwo", MessageTwoHandler, null);
}

internal void DoUnsubscriptions()
Expand All @@ -570,7 +570,7 @@ private void SecondMessageOneHandler(object newValue)

internal void DoSubscriptions()
{
FwUtils.Subscriber.Subscribe("MessageOne", SecondMessageOneHandler);
FwUtils.Subscriber.Subscribe("MessageOne", SecondMessageOneHandler, null);
}

internal void DoUnsubscriptions()
Expand All @@ -593,14 +593,14 @@ internal bool One
if (ShouldDoReentrantPublish)
{
// Bad boy! Re-entrant test should fail on this.
FwUtils.Publisher.Publish(new PublisherParameterObject("SomeRandomMessage", "Whatever"));
FwUtils.Publisher.Publish(new PublisherParameterObject("SomeRandomMessage", "Whatever", null));
}
}
}

internal void DoSubscriptions()
{
FwUtils.Subscriber.Subscribe("MessageOne", ReentrantMessageOneHandler);
FwUtils.Subscriber.Subscribe("MessageOne", ReentrantMessageOneHandler, null);
}

internal void DoUnsubscriptions()
Expand Down Expand Up @@ -633,8 +633,8 @@ internal bool One
// Bad boy! Re-entrant test should fail on this.
var messages = new List<PublisherParameterObject>
{
new PublisherParameterObject("MessageOne", false),
new PublisherParameterObject("SomeRandomMessage", "Whatever")
new PublisherParameterObject("MessageOne", false, null),
new PublisherParameterObject("SomeRandomMessage", "Whatever", null)
};
FwUtils.Publisher.Publish(messages);
}
Expand All @@ -643,7 +643,7 @@ internal bool One

internal void DoSubscriptions()
{
FwUtils.Subscriber.Subscribe("BadBoy", ReentrantBadBoyHandler);
FwUtils.Subscriber.Subscribe("BadBoy", ReentrantBadBoyHandler, null);
}

internal void DoUnsubscriptions()
Expand All @@ -667,8 +667,8 @@ private sealed class NiceGuy_MultipleSubscriber

internal void DoSubscriptions()
{
FwUtils.Subscriber.Subscribe("MessageOne", MessageOneHandler);
FwUtils.Subscriber.Subscribe("MessageTwo", MessageTwoHandler);
FwUtils.Subscriber.Subscribe("MessageOne", MessageOneHandler, null);
FwUtils.Subscriber.Subscribe("MessageTwo", MessageTwoHandler, null);
}

internal void DoUnsubscriptions()
Expand Down Expand Up @@ -777,8 +777,8 @@ private sealed class EndOfAction_MultipleSubscriber

internal void DoSubscriptions()
{
FwUtils.Subscriber.Subscribe(EventConstants.RecordNavigation, RecordNavigationHandler);
FwUtils.Subscriber.Subscribe(EventConstants.SelectionChanged, SelectionChangedHandler);
FwUtils.Subscriber.Subscribe(EventConstants.RecordNavigation, RecordNavigationHandler, null);
FwUtils.Subscriber.Subscribe(EventConstants.SelectionChanged, SelectionChangedHandler, null);
}

internal void DoUnsubscriptions()
Expand Down
8 changes: 4 additions & 4 deletions Src/Common/FwUtils/ISubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public interface ISubscriber
/// <param name="message">The message being subscribed to receive.</param>
/// <param name="messageHandler">The method on subscriber to call, when <paramref name="message"/>
/// has been published</param>
/// <param name="scope">Optional delivery scope (normally the subscriber's main window).
/// <param name="scope">Delivery scope, normally the subscriber's main window; pass null to subscribe process-wide.
/// When non-null, scoped publishes of <paramref name="message"/> are delivered only if they
/// carry the same scope. Null subscribes will receive messages from all publishers.
/// See <see cref="IPubSubScope"/>.</param>
void Subscribe(string message, Action<object> messageHandler, IPubSubScope scope = null);
void Subscribe(string message, Action<object> messageHandler, IPubSubScope scope);

/// <summary>
/// An object subscribes to messages that begin with <paramref name="messagePrefix"/> using
Expand All @@ -37,11 +37,11 @@ public interface ISubscriber
/// <param name="messagePrefix">The message prefix being subscribed to receive.</param>
/// <param name="messageHandler">The method on subscriber to call, when a message that
/// begins with <paramref name="messagePrefix"/> has been published.</param>
/// <param name="scope">Optional delivery scope (normally the subscriber's main window).
/// <param name="scope">Delivery scope, normally the subscriber's main window; pass null to subscribe process-wide.
/// When non-null, scoped publishes of matching messages are delivered only if they
/// carry the same scope. Null subscribes will receive messages from all publishers.
/// See <see cref="IPubSubScope"/>.</param>
void PrefixSubscribe(string messagePrefix, Action<string, object> messageHandler, IPubSubScope scope = null);
void PrefixSubscribe(string messagePrefix, Action<string, object> messageHandler, IPubSubScope scope);

/// <summary>
/// Register end of interest (unsubscribe) of an object in receiving <paramref name="message"/>
Expand Down
2 changes: 1 addition & 1 deletion Src/Common/FwUtils/PublisherParameterObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SIL.FieldWorks.Common.FwUtils
{
public sealed class PublisherParameterObject
{
public PublisherParameterObject(string message, object data = null, IPubSubScope scope = null)
public PublisherParameterObject(string message, object data, IPubSubScope scope)
{
if (string.IsNullOrWhiteSpace(message))
{
Expand Down
8 changes: 4 additions & 4 deletions Src/Common/FwUtils/Subscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ internal sealed class Subscriber : ISubscriber
/// <param name="message">The message being subscribed to receive.</param>
/// <param name="messageHandler">The method on subscriber to call, when <paramref name="message"/>
/// has been published</param>
/// <param name="scope">Optional delivery scope (normally the subscriber's main window).
/// <param name="scope">Delivery scope, normally the subscriber's main window; pass null to subscribe process-wide.
/// When non-null, scoped publishes of <paramref name="message"/> are delivered only if they
/// carry the same scope. Null subscribes will receive messages from all publishers.
/// See <see cref="IPubSubScope"/>.</param>
public void Subscribe(string message, Action<object> messageHandler, IPubSubScope scope = null)
public void Subscribe(string message, Action<object> messageHandler, IPubSubScope scope)
{
if (!_subscriptions.TryGetValue(message, out var subscribers))
{
Expand All @@ -54,11 +54,11 @@ public void Subscribe(string message, Action<object> messageHandler, IPubSubScop
/// <param name="messagePrefix">The message prefix being subscribed to receive.</param>
/// <param name="messageHandler">The method on subscriber to call, when a message that
/// begins with <paramref name="messagePrefix"/> has been published.</param>
/// <param name="scope">Optional delivery scope (normally the subscriber's main window).
/// <param name="scope">Delivery scope, normally the subscriber's main window; pass null to subscribe process-wide.
/// When non-null, scoped publishes of matching messages are delivered only if they
/// carry the same scope. Null subscribes will receive messages from all publishers.
/// See <see cref="IPubSubScope"/>.</param>
public void PrefixSubscribe(string messagePrefix, Action<string, object> messageHandler, IPubSubScope scope = null)
public void PrefixSubscribe(string messagePrefix, Action<string, object> messageHandler, IPubSubScope scope)
{
if (!_prefixSubscriptions.TryGetValue(messagePrefix, out var prefixSubscribers))
{
Expand Down
1 change: 1 addition & 0 deletions Src/Common/SimpleRootSite/SimpleRootSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6196,6 +6196,7 @@ private void SetupVc()
{
// This really only needs to be done once but I can't find another reliable way to do it.
((VwBaseVc) vc).Mediator = m_mediator;
((VwBaseVc) vc).PropertyTable = m_propertyTable;
}
}

Expand Down
7 changes: 6 additions & 1 deletion Src/Common/SimpleRootSite/VwBaseVc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public virtual ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int fr
/// </summary>
internal Mediator Mediator { get; set; }

/// <summary>
/// PropertyTable is supplied during first real layout by the root site (see SetupVc).
/// </summary>
protected internal PropertyTable PropertyTable { get; set; }

/// -----------------------------------------------------------------------------------
/// <summary>
/// Perform whatever action is appropriate when the user clicks on a hot link
Expand All @@ -236,7 +241,7 @@ public virtual void DoHotLinkAction(string strData, ISilDataAccess sda)

// See if we can handle it (via our own LinkListener) without starting a process.
var args = new LocalLinkArgs { Link = url };
Publisher.Publish(new PublisherParameterObject(EventConstants.HandleLocalHotlink, args));
Publisher.Publish(new PublisherParameterObject(EventConstants.HandleLocalHotlink, args, PropertyTable?.GetWindow()));
if (args.LinkHandledLocally)
{
return;
Expand Down
6 changes: 4 additions & 2 deletions Src/LexText/Interlinear/TextsFilterItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ namespace SIL.FieldWorks.IText
public class TextsFilterItem : NoChangeFilterComboItem
{
private Mediator m_mediator;
private PropertyTable m_propertyTable;

public TextsFilterItem(ITsString tssName, LcmCache cache, Mediator mediator) : base(tssName)
public TextsFilterItem(ITsString tssName, LcmCache cache, Mediator mediator, PropertyTable propertyTable) : base(tssName)
{
m_mediator = mediator;
m_propertyTable = propertyTable;
}

public override bool Invoke()
{
Publisher.Publish(new PublisherParameterObject(EventConstants.AddTexts, this));
Publisher.Publish(new PublisherParameterObject(EventConstants.AddTexts, this, m_propertyTable?.GetWindow()));

return false; // Whatever the user did, we don't currently count it as changing the filter.
}
Expand Down
4 changes: 3 additions & 1 deletion Src/LexText/LexTextDll/LexTextApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public override void DoApplicationInitialization(IProgress progressDlg)
if (progressDlg != null)
progressDlg.Message = LexTextStrings.ksLoading_;

Subscriber.Subscribe(EventConstants.SFMImport, SFMImport);
// LexTextApp is the per-application object (no single window), so this is intentionally
// subscribed with a null (process-wide) scope.
Subscriber.Subscribe(EventConstants.SFMImport, SFMImport, null);
}

/// ------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions Src/LexText/LexTextDll/LexTextDllTests/AreaListenerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void GetToolForList_KnownList_ReturnsConfiguredToolName()
parameters[0] = list;

// SUT: publish exactly as LinkListener.FollowActiveLink does.
Publisher.Publish(new PublisherParameterObject(EventConstants.GetToolForList, parameters));
Publisher.Publish(new PublisherParameterObject(EventConstants.GetToolForList, parameters, null));

// Verify: the configured tool name was returned via the payload.
Assert.That(parameters[1], Is.EqualTo("myConfiguredListEdit"));
Expand All @@ -243,7 +243,7 @@ public void GetToolForList_UnknownList_ReturnsCustomToolName()
parameters[0] = customList;

// SUT
Publisher.Publish(new PublisherParameterObject(EventConstants.GetToolForList, parameters));
Publisher.Publish(new PublisherParameterObject(EventConstants.GetToolForList, parameters, null));

// Verify: whitespace stripped from the name, with "Edit" appended.
Assert.That(parameters[1], Is.EqualTo("MyCustomListEdit"));
Expand Down
Loading
Loading