From 513aee050806b89d20811d4d344b327a9494e8ea Mon Sep 17 00:00:00 2001
From: mark-sil <83427558+mark-sil@users.noreply.github.com>
Date: Fri, 20 Feb 2026 14:16:48 -0500
Subject: [PATCH] LT-21506: Move SetInitialContentObject to Pub/Sub
Cherry-pick from the PubSub branch to the main branch using
the following command:
git cherry-pick --no-commit ff2471c0
---
Src/LexText/LexTextDll/AreaListener.cs | 6 ++---
Src/XCore/xWindow.cs | 32 +++++++++++---------------
2 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/Src/LexText/LexTextDll/AreaListener.cs b/Src/LexText/LexTextDll/AreaListener.cs
index 569ce2fe92..61ecee5ef7 100644
--- a/Src/LexText/LexTextDll/AreaListener.cs
+++ b/Src/LexText/LexTextDll/AreaListener.cs
@@ -130,6 +130,7 @@ protected virtual void Dispose(bool disposing)
Subscriber.Unsubscribe(EventConstants.SetToolFromName, SetToolFromName);
Subscriber.Unsubscribe(EventConstants.ReloadAreaTools, ReloadAreaTools);
Subscriber.Unsubscribe(EventConstants.GetContentControlParameters, GetContentControlParameters);
+ Subscriber.Unsubscribe(EventConstants.SetInitialContentObject, SetInitialContentObject);
// Dispose managed resources here.
if (m_mediator != null)
@@ -152,6 +153,7 @@ public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configu
mediator.AddColleague(this);
m_ctotalLists = 0;
m_ccustomLists = 0;
+ Subscriber.Subscribe(EventConstants.SetInitialContentObject, SetInitialContentObject);
Subscriber.Subscribe(EventConstants.SetToolFromName, SetToolFromName);
Subscriber.Subscribe(EventConstants.ReloadAreaTools, ReloadAreaTools);
Subscriber.Subscribe(EventConstants.GetContentControlParameters, GetContentControlParameters);
@@ -845,7 +847,7 @@ private static string GetCustomListClerkName(ICmPossibilityList curList)
///
///
///
- public bool OnSetInitialContentObject(object windowConfigurationNode)
+ private void SetInitialContentObject(object windowConfigurationNode)
{
CheckDisposed();
@@ -865,8 +867,6 @@ public bool OnSetInitialContentObject(object windowConfigurationNode)
m_propertyTable.SetPropertyPersistence("areaChoice", false);
ActivateToolForArea(areaName);
-
- return true; //we handled this.
}
///
diff --git a/Src/XCore/xWindow.cs b/Src/XCore/xWindow.cs
index d1dbd5c9f6..d0ea5efe68 100644
--- a/Src/XCore/xWindow.cs
+++ b/Src/XCore/xWindow.cs
@@ -442,6 +442,7 @@ private void BootstrapPart1()
InitializeComponent();
Subscriber.Subscribe(EventConstants.PrepareToRefresh, PrepareToRefresh);
+ Subscriber.Subscribe(EventConstants.SetInitialContentObject, SetInitialContentObject);
}
///
@@ -801,7 +802,7 @@ protected virtual void LoadUIFromXmlDocument(XmlDocument configuration, string c
// Add the content control
// Note: We should be able to do it directly, since everything needed is in the default properties.
- SetInitialContentObject(m_windowConfigurationNode);
+ Publisher.Publish(new PublisherParameterObject(EventConstants.SetInitialContentObject, m_windowConfigurationNode));
m_sidebarAdapter.FinishInit();
m_menuBarAdapter.FinishInit();
@@ -1219,34 +1220,28 @@ protected ChoiceGroupCollection MakeGroupSet(XmlNode m_windowConfigurationNode,
return groupset;
}
- private void SetInitialContentObject(XmlNode windowConfigurationNode)
- {
- //allow colleagues (i.e. a listener that has been installed, or, if there are none of those listening, then
- //our own "OnSetInitialContentObject" handler, to choose what our initial content control will be.
- m_mediator.SendMessage("SetInitialContentObject", windowConfigurationNode);
- }
-
///
- /// this is called by xWindow just before it sets the initial control which will actually
- /// take over the content area. if no listener response to this message first, then this is called
- /// and we determine the controlled by looking at the "" element in the configuration file.
+ /// This is called by xWindow just before it sets the initial control which will actually take over the content area.
+ /// If there are other listeners we assume that they will handle the content object related properties.
+ /// If no other listeners exist then we determine the control by looking at the "" element in the configuration file.
///
- /// this handler relies on the configuration file having a element.
+ /// This handler relies on the configuration file having a element.
///
///
- public bool OnSetInitialContentObject(object windowConfigurationNode)
+ private void SetInitialContentObject(object windowConfigurationNode)
{
+ // We only want to handle this if there are no other listeners
+ if (Subscriber.Subscriptions[EventConstants.SetInitialContentObject].Count > 1)
+ return;
CheckDisposed();
XmlNode contentClassNode = ((XmlNode)windowConfigurationNode).SelectSingleNode("contentClass");
if (contentClassNode == null)
- throw new ArgumentException("xWindow.OnSetInitialContentObject called. The area listener should have been tried first and handled this. " + m_mediator.GetColleaguesDumpString());
- else
- ChangeContentObjectIfPossible(XmlUtils.GetAttributeValue(contentClassNode, "assemblyPath"),
- XmlUtils.GetAttributeValue(contentClassNode, "class"), contentClassNode);
+ throw new ArgumentException("xWindow.SetInitialContentObject called. The area listener should have been tried first and handled this. " + m_mediator.GetColleaguesDumpString());
- return true; //we handled this.
+ ChangeContentObjectIfPossible(XmlUtils.GetAttributeValue(contentClassNode, "assemblyPath"),
+ XmlUtils.GetAttributeValue(contentClassNode, "class"), contentClassNode);
}
public bool OnShowNotification(object notificationText)
@@ -1320,6 +1315,7 @@ protected override void Dispose(bool disposing)
private void ShutDownPart1()
{
Subscriber.Unsubscribe(EventConstants.PrepareToRefresh, PrepareToRefresh);
+ Subscriber.Unsubscribe(EventConstants.SetInitialContentObject, SetInitialContentObject);
if (m_mediator != null)
{