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
3 changes: 1 addition & 2 deletions DistFiles/Language Explorer/Configuration/Main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@ I (RandyR) brought them into this file, just to keep track of them for the time
<!-- ********************************************************** -->

<statusbar>
<!-- At runtime, put text in these by setting the property 'StatusPanelMessage',
'StatusPanelProgress', etc. to something -->
<!-- At runtime, XWindow.SetStatusPanelText(id, text) puts text in the panel with that id. -->
<panel id="Message" width="Contents" minwidth="40"/>
<panel id="Progress" width="Contents" minwidth="40"/>
<panel id="Area"/>
Expand Down
13 changes: 3 additions & 10 deletions Src/Common/Controls/XMLViews/XmlBrowseRDEView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ public override void OnPropertyChanged(string propName)
/*
* Starting up with Domains being startup tool.
* currentContentControlObject
* StatusPanelProgress
*
* Switching away from Domains to another tool in same area.
* currentContentControlParameters
Expand All @@ -216,21 +215,15 @@ public override void OnPropertyChanged(string propName)
* currentContentControlObject
*
* Switch to another domain
* StatusPanelRecordNumber
* StatusPanelMessage
* StatusPanelRecordNumber
* StatusPanelMessage
* -selected
* SemanticDomainList-selected
* ActiveClerkSelectedObject
* SelectedTreeBarNode
*/

// "currentContentControlObject" occurs in two incoming contexts,
// and one switching away context.
// We only need to handle the switching away context, but how to tell them apart?
// JohnT: don't handle switching to another domain by catching StatusPanelRecordNumber;
// too unreliable. Catch that by override of RootObjectHvo below.
// "currentContentControlObject" occurs in two incoming contexts and one
// switching-away context, which cannot be told apart. Switching domains is
// caught by the RootObjectHvo override below.
if (propName == "areaChoiceParameters" // Switching to another area
|| propName == "currentContentControlParameters") // Switching to another tool in same area
{
Expand Down
5 changes: 2 additions & 3 deletions Src/LexText/ParserUI/ParserListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ private void Idle(object argument)
// Now called by timer AND by Idle
private void UpdateStatusPanelProgress()
{
var statusMessage = ParserQueueString + " " + ParserActivityString;
m_propertyTable.SetProperty("StatusPanelProgress", statusMessage, true);
m_propertyTable.SetPropertyPersistence("StatusPanelProgress", false);
var window = m_propertyTable.GetWindow() as XWindow;
window?.SetStatusPanelText("Progress", ParserQueueString + " " + ParserActivityString);

if (m_parserConnection != null)
{
Expand Down
78 changes: 78 additions & 0 deletions Src/XCore/xCoreTests/XWindowStatusPanelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) 2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using System.Threading;
using System.Windows.Forms;
using System.Xml;
using NUnit.Framework;

namespace XCore
{
/// <summary>
/// The status bar panel text contract of <see cref="XWindow"/>.
/// </summary>
[TestFixture]
[Apartment(ApartmentState.STA)]
public class XWindowStatusPanelTests
{
/// <summary>
/// A window whose status bar is built from a statusbar element alone, with no other UI.
/// </summary>
private sealed class StatusBarOnlyWindow : XWindow
{
public void LoadStatusBar(string windowXml)
{
var doc = new XmlDocument();
doc.LoadXml(windowXml);
CreateStatusBar(doc.DocumentElement);
}
}

private const string TwoPanels =
"<window><statusbar>"
+ "<panel id=\"Message\"/><panel id=\"RecordNumber\" width=\"Contents\"/>"
+ "</statusbar></window>";

private static string PanelText(XWindow window, string panelId)
{
return window.PropTable.GetValue<StatusBarPanel>(panelId).Text;
}

[Test]
public void SetStatusPanelText_ShowsTheTextInThePanelWithThatId()
{
using (var window = new StatusBarOnlyWindow())
{
window.LoadStatusBar(TwoPanels);

window.SetStatusPanelText("RecordNumber", "3/12");

Assert.That(PanelText(window, "RecordNumber"), Is.EqualTo("3/12"));
Assert.That(PanelText(window, "Message"), Is.Empty);
}
}

[Test]
public void SetStatusPanelText_IgnoresAnIdNoPanelHas()
{
using (var window = new StatusBarOnlyWindow())
{
window.LoadStatusBar(TwoPanels);

Assert.That(() => window.SetStatusPanelText("Progress", "parsing"), Throws.Nothing);
Assert.That(() => window.SetStatusPanelText(null, "parsing"), Throws.Nothing);

Assert.That(PanelText(window, "Message"), Is.Empty);
Assert.That(PanelText(window, "RecordNumber"), Is.Empty);
}
}

[Test]
public void SetStatusPanelText_IgnoresAWindowWithNoStatusBar()
{
using (var window = new StatusBarOnlyWindow())
Assert.That(() => window.SetStatusPanelText("Message", "hello"), Throws.Nothing);
}
}
}
22 changes: 10 additions & 12 deletions Src/XCore/xWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,16 @@ protected void CreateStatusBar(XmlNode windowConfigurationNode)
}
}

/// <summary>
/// Shows <paramref name="text"/> in the status bar panel configured with the id
/// <paramref name="panelId"/>. Does nothing when no panel has that id.
/// </summary>
public void SetStatusPanelText(string panelId, string text)
{
if (panelId != null && m_statusPanels.TryGetValue(panelId, out var panel))
panel.Text = text;
}

protected void RestoreWindowSettings(bool wasCrashDuringPreviousStartup)
{
string id = XmlUtils.GetAttributeValue(m_windowConfigurationNode, "settingsId");
Expand Down Expand Up @@ -1904,18 +1914,6 @@ public virtual void OnPropertyChanged(string name)
case "BestStyleName":
SynchronizedOnIdleTime();
break;

default:
if (name.Length > 11 && name.Substring(0, 11) == "StatusPanel")
{
string panelName = name.Substring(11);
if (m_statusPanels.ContainsKey(panelName))
{
StatusBarPanel panel = m_statusPanels[panelName];
panel.Text = m_propertyTable.GetStringProperty(name, "");
}
}
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Src/xWorks/GeneratedHtmlViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configu
m_configurationParameters = configurationParameters;
mediator.AddColleague(this);

m_propertyTable.SetProperty("StatusPanelRecordNumber", "", true);
m_propertyTable.SetPropertyPersistence("StatusPanelRecordNumber", false);
// This viewer has no record list, so the record position panel shows nothing.
(m_propertyTable.GetWindow() as XWindow)?.SetStatusPanelText("RecordNumber", "");

#if notnow
m_htmlControl.Browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Browser_DocumentCompleted);
Expand Down
14 changes: 8 additions & 6 deletions Src/xWorks/RecordClerk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class RecordClerk : IDisposable, IxCoreColleague, IRecordListUpdater, IAn
protected RecordBarHandler m_recordBarHandler;
protected RecordList m_list;

private const string StatusBarRecordNumber = "StatusPanelRecordNumber";
private const string StatusBarRecordNumber = "RecordNumber";

/// <summary>
/// The record list might need access to this just to check membership of an object quickly.
Expand Down Expand Up @@ -1867,7 +1867,7 @@ private void ResetStatusBarMessageForCurrentObject()
// deleted objects don't have a cache (and other properties) so it was crashing. LT-3160, LT-3121,...
msg = GetStatusBarMsgForCurrentObject();
}
ResetStatusBarPanel("StatusPanelMessage", msg);
ResetStatusBarPanel("Message", msg);
}

protected virtual string GetStatusBarMsgForCurrentObject()
Expand All @@ -1887,10 +1887,10 @@ protected virtual string GetStatusBarMsgForCurrentObject()
return msg;
}

private void ResetStatusBarPanel(string panel, string msg)
private void ResetStatusBarPanel(string panelId, string text)
{
m_propertyTable.SetProperty(panel, msg, true);
m_propertyTable.SetPropertyPersistence(panel, false);
var window = m_propertyTable.GetWindow() as XWindow;
window?.SetStatusPanelText(panelId, text);
}

/// <summary>
Expand Down Expand Up @@ -2886,7 +2886,9 @@ protected void UpdateFilterStatusBarPanel()
if (fIgnore)
{
// Set the value so that it can be picked up by the dialog (or whoever).
ResetStatusBarPanel("DialogFilterStatus", FilterStatusContents(m_list.Filter != null && m_list.Filter.IsUserVisible) ?? String.Empty);
m_propertyTable.SetProperty("DialogFilterStatus",
FilterStatusContents(m_list.Filter != null && m_list.Filter.IsUserVisible) ?? String.Empty, false);
m_propertyTable.SetPropertyPersistence("DialogFilterStatus", false);
return;
}
var b = m_propertyTable.GetValue<StatusBarTextBox>("Filter");
Expand Down
Loading