Skip to content

Commit 21b1447

Browse files
authored
LT-21507: Implement Idle in Pub/Sub system
1 parent a8015e5 commit 21b1447

4 files changed

Lines changed: 22 additions & 30 deletions

File tree

Src/Common/FwUtils/EventConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static class EventConstants
2121
public const string GetContentControlParameters = "GetContentControlParameters";
2222
public const string GetToolForList = "GetToolForList";
2323
public const string HandleLocalHotlink = "HandleLocalHotlink";
24+
public const string Idle = "Idle";
2425
public const string ItemDataModified = "ItemDataModified";
2526
public const string JumpToField = "JumpToField";
2627
public const string JumpToPopupLexEntry = "JumpToPopupLexEntry";

Src/LexText/ParserUI/ParserListener.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configu
8888

8989
Subscriber.Subscribe(EventConstants.StopParser, StopParser);
9090
Subscriber.Subscribe(EventConstants.RefreshPopupWindowFonts, RefreshPopupWindowFonts);
91+
Subscriber.Subscribe(EventConstants.Idle, Idle);
9192
}
9293

9394
/// <summary>
@@ -202,16 +203,17 @@ public void DisconnectFromParser()
202203
m_parserConnection = null;
203204
}
204205

205-
public bool OnIdle(object argument)
206+
/// <summary>
207+
/// Method to handle published Idle messages.
208+
/// </summary>
209+
private void Idle(object argument)
206210
{
207211
CheckDisposed();
208212

209213
UpdateStatusPanelProgress();
210-
211-
return false; // Don't stop other people from getting the idle message
212214
}
213215

214-
// Now called by timer AND by OnIdle
216+
// Now called by timer AND by Idle
215217
private void UpdateStatusPanelProgress()
216218
{
217219
var statusMessage = ParserQueueString + " " + ParserActivityString;
@@ -367,6 +369,7 @@ protected virtual void Dispose(bool disposing)
367369
{
368370
Subscriber.Unsubscribe(EventConstants.StopParser, StopParser);
369371
Subscriber.Unsubscribe(EventConstants.RefreshPopupWindowFonts, RefreshPopupWindowFonts);
372+
Subscriber.Unsubscribe(EventConstants.Idle, Idle);
370373

371374
// other clients may now parse
372375
// Dispose managed resources here.

Src/XCore/xCoreInterfaces/Mediator.cs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ public bool SendMessage(string messageName, object parameter)
806806

807807
/// ------------------------------------------------------------------------------------
808808
/// <summary>
809-
/// Worker method to invoke commands. It will log the call if it is not an update or idle.
809+
/// Worker method to invoke commands. It will log the call if it is not an update.
810810
/// </summary>
811811
/// <returns><c>true</c> if the message was handled, otherwise <c>false</c></returns>
812812
/// ------------------------------------------------------------------------------------
@@ -821,15 +821,12 @@ private bool SendMessageWorker(string messageName, object parameter)
821821
Debug.Fail("The convention is to send messages without the 'On' prefix. " +
822822
"That is added by the message sending code.");
823823
#endif
824-
if (messageName != "Idle")
825-
{
826-
Trace.WriteLineIf(showPendingMsgsSwitch.TraceVerbose,
827-
BuildDebugMsg("SendMessage::Looking for listeners for Msg: " + messageName),
828-
showPendingMsgsSwitch.DisplayName);
829-
}
824+
Trace.WriteLineIf(showPendingMsgsSwitch.TraceVerbose,
825+
BuildDebugMsg("SendMessage::Looking for listeners for Msg: " + messageName),
826+
showPendingMsgsSwitch.DisplayName);
830827
string methodName = "On" + messageName;
831828
// Logging
832-
if (!messageName.StartsWith("Update") && messageName != "Idle")
829+
if (!messageName.StartsWith("Update"))
833830
{
834831
// We want to log the method if any colleague handles it.
835832
// So we check the list of methods known-to-us first. If we don't find it,
@@ -1040,12 +1037,9 @@ public bool BroadcastMessage(string messageName, object parameter)
10401037
Debug.Fail("The convention is to send messages without the 'On' prefix. " +
10411038
"That is added by the message sending code.");
10421039
#endif
1043-
if (messageName != "Idle")
1044-
{
1045-
Trace.WriteLineIf(showPendingMsgsSwitch.TraceVerbose,
1046-
BuildDebugMsg("BroadcastMessage::Looking for listeners for Msg: " + messageName),
1047-
showPendingMsgsSwitch.DisplayName);
1048-
}
1040+
Trace.WriteLineIf(showPendingMsgsSwitch.TraceVerbose,
1041+
BuildDebugMsg("BroadcastMessage::Looking for listeners for Msg: " + messageName),
1042+
showPendingMsgsSwitch.DisplayName);
10491043
#if false
10501044
return InvokeOnColleagues("On" + messageName, new Type[] {typeof(object)},
10511045
new Object[] { parameter }, false, false);
@@ -1094,12 +1088,9 @@ public bool HasReceiver(string messageName)
10941088
if(messageName.Substring(0,2) == "On")
10951089
Debug.Fail("The convention is to send messages without the 'On' prefix. That is added by the message sending code.");
10961090
#endif
1097-
if (messageName != "Idle")
1098-
{
1099-
Trace.WriteLineIf(showPendingMsgsSwitch.TraceVerbose,
1100-
BuildDebugMsg("HasReceiver::Checking for listeners for Msg: " + messageName),
1101-
showPendingMsgsSwitch.DisplayName);
1102-
}
1091+
Trace.WriteLineIf(showPendingMsgsSwitch.TraceVerbose,
1092+
BuildDebugMsg("HasReceiver::Checking for listeners for Msg: " + messageName),
1093+
showPendingMsgsSwitch.DisplayName);
11031094

11041095

11051096
return InvokeOnColleagues("On"+messageName, new Type[] {typeof(object)},

Src/XCore/xWindow.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,10 +1789,8 @@ public void SynchronizedOnIdleTime()
17891789

17901790
UpdateControls();
17911791

1792-
// call OnIdle () on any colleagues that implement it.
1793-
#pragma warning disable 618 // suppress obsolete warning
1794-
m_mediator.SendMessage("Idle", null);
1795-
#pragma warning restore 618
1792+
// Notify any subscribers that the application is idle.
1793+
Publisher.Publish(new PublisherParameterObject(EventConstants.Idle, null));
17961794
}
17971795

17981796
/// <summary>
@@ -2400,8 +2398,7 @@ private void WidgetUpdateTimer_Tick(object sender, System.EventArgs e)
24002398
//mi.Invoke(this, new object [] {});
24012399

24022400
SynchronizedOnIdleTime();
2403-
// This is done in SynchronizedOnIdleTime now, as I can't see why some controls should do idle processing, and others not do it.
2404-
// m_mediator.SendMessage("Idle", this); //let listeners and other colleagues do something
2401+
// The idle notification is published in SynchronizedOnIdleTime now, as I can't see why some controls should do idle processing, and others not do it.
24052402
}
24062403

24072404
#endregion Windows Event handlers

0 commit comments

Comments
 (0)