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
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,7 @@ private static OptionsPayload Apply(LcmCache cache, Mediator mediator, PropertyT
// LexOptionsDlg's m_pendingUiModeDisabledTools apply. Live like the mode itself — no restart.
var newDisabledTools = state.UIModeDisabledTools ?? string.Empty;
if ((settings.UIModeDisabledTools ?? string.Empty) != newDisabledTools)
{
settings.UIModeDisabledTools = newDisabledTools;
if (propertyTable != null)
{
propertyTable.SetProperty(UIFrameworkResolver.UIModeDisabledToolsPropertyName, newDisabledTools, true);
propertyTable.SetPropertyPersistence(UIFrameworkResolver.UIModeDisabledToolsPropertyName, false);
}
}
ApplyDisabledToolsLive(propertyTable, settings, newDisabledTools);

// User-interface language: switch the current thread's UI culture live (matches
// LexOptionsDlg.m_btnOK_Click), then persist registry value + project WS + reload the string
Expand Down Expand Up @@ -492,8 +485,9 @@ private static void UninstallPlugin(XmlDocument managerDoc, Mediator mediator, s
}

// Applies a UI-mode change live: persist into settings + mirror+broadcast through the PropertyTable
// so the open views (RecordBrowseView/RecordEditView) re-resolve without a restart.
private static void ApplyUiModeLive(PropertyTable propertyTable, FwApplicationSettingsBase settings, string mode)
// so the open views (RecordBrowseView/RecordEditView) re-resolve without a restart, and updates the
// crash-report value to match so a report reflects the mode active at crash time, not just at startup.
internal static void ApplyUiModeLive(PropertyTable propertyTable, FwApplicationSettingsBase settings, string mode)
{
var norm = NormalizeUiMode(mode);
settings.UIMode = norm;
Expand All @@ -502,6 +496,20 @@ private static void ApplyUiModeLive(PropertyTable propertyTable, FwApplicationSe
propertyTable.SetProperty(UIModePropertyName, norm, true);
propertyTable.SetPropertyPersistence(UIModePropertyName, false);
}
ErrorReporter.AddProperty("AvaloniaUIMode", norm);
}

// Applies a disabled-tools change live: persist into settings + mirror+broadcast through the
// PropertyTable, and keep the crash-report value in step, mirroring ApplyUiModeLive.
internal static void ApplyDisabledToolsLive(PropertyTable propertyTable, FwApplicationSettingsBase settings, string disabledTools)
{
settings.UIModeDisabledTools = disabledTools;
if (propertyTable != null)
{
propertyTable.SetProperty(UIFrameworkResolver.UIModeDisabledToolsPropertyName, disabledTools, true);
propertyTable.SetPropertyPersistence(UIFrameworkResolver.UIModeDisabledToolsPropertyName, false);
}
ErrorReporter.AddProperty("AvaloniaDisabledTools", disabledTools);
}

internal static string NormalizeUiMode(string mode) =>
Expand Down
3 changes: 3 additions & 0 deletions Src/LexText/LexTextControls/LexOptionsDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using SIL.LCModel.Utils;
using SIL.LCModel;
using SIL.PlatformUtilities;
using SIL.Reporting;
using SIL.Settings;
using SIL.Utils;
using XCore;
Expand Down Expand Up @@ -154,6 +155,8 @@ private void m_btnOK_Click(object sender, EventArgs e)
m_propertyTable.SetProperty(UIModePropertyName, newUiMode, true);
m_propertyTable.SetPropertyPersistence(UIModePropertyName, false);
}
// Keep the crash-report value in step with a live toggle, not just the startup seed.
ErrorReporter.AddProperty("AvaloniaUIMode", newUiMode);
}

m_sNewUserWs = m_userInterfaceChooser.NewUserWs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,48 @@ namespace LexTextControlsTests
[TestFixture]
public class AvaloniaOptionsDialogLauncherTests
{
[TearDown]
public void TearDown()
{
ErrorReport.Properties.Remove("AvaloniaUIMode");
ErrorReport.Properties.Remove("AvaloniaDisabledTools");
}

// ----- ApplyUiModeLive / ApplyDisabledToolsLive (the crash-report mirror behind Apply) -----

[Test]
public void ApplyUiModeLive_PersistsBroadcastsAndRecordsForCrashReports()
{
var settings = new TestFwApplicationSettings { UIMode = "Legacy" };
using (var mediator = new Mediator())
using (var propertyTable = new PropertyTable(mediator))
{
SIL.FieldWorks.LexText.Controls.AvaloniaOptionsDialogLauncher.ApplyUiModeLive(
propertyTable, settings, "new");

Assert.That(settings.UIMode, Is.EqualTo("New"));
Assert.That(propertyTable.GetStringProperty("UIMode", "Legacy"), Is.EqualTo("New"));
Assert.That(ErrorReport.Properties["AvaloniaUIMode"], Is.EqualTo("New"));
}
}

[Test]
public void ApplyDisabledToolsLive_PersistsBroadcastsAndRecordsForCrashReports()
{
var settings = new TestFwApplicationSettings { UIMode = "New" };
using (var mediator = new Mediator())
using (var propertyTable = new PropertyTable(mediator))
{
SIL.FieldWorks.LexText.Controls.AvaloniaOptionsDialogLauncher.ApplyDisabledToolsLive(
propertyTable, settings, "lexiconEdit,posEdit");

Assert.That(settings.UIModeDisabledTools, Is.EqualTo("lexiconEdit,posEdit"));
Assert.That(propertyTable.GetStringProperty("UIModeDisabledTools", null),
Is.EqualTo("lexiconEdit,posEdit"));
Assert.That(ErrorReport.Properties["AvaloniaDisabledTools"], Is.EqualTo("lexiconEdit,posEdit"));
}
}

// ----- UIModeGates.ShouldUseAvaloniaUI (the shared New-mode gate, hoisted to FwUtils so checking
// it never loads the Avalonia assemblies) -----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ namespace LexTextControlsTests
[Apartment(System.Threading.ApartmentState.STA)]
public class LexOptionsDlgTests
{
[TearDown]
public void TearDown()
{
ErrorReport.Properties.Remove("AvaloniaUIMode");
}

[Test]
public void OkClick_SavesUIModeAndMirrorsItIntoPropertyTable()
{
Expand All @@ -39,6 +45,8 @@ public void OkClick_SavesUIModeAndMirrorsItIntoPropertyTable()
Assert.That(propertyTable.GetStringProperty("UIMode", "Legacy"), Is.EqualTo("New"));
// UIMode flips live (RecordEditView settles and re-resolves on the spot) — no restart needed.
Assert.That(dlg.RestartPromptCount, Is.EqualTo(0));
Assert.That(ErrorReport.Properties["AvaloniaUIMode"], Is.EqualTo("New"),
"a live toggle must update the crash-report value, not just the startup seed");
}
}

Expand All @@ -61,6 +69,8 @@ public void OkClick_LeavesLegacyWhenUserDoesNotChangeSelection()
Assert.That(settings.SaveCalls, Is.EqualTo(1));
Assert.That(propertyTable.GetStringProperty("UIMode", "Legacy"), Is.EqualTo("Legacy"));
Assert.That(dlg.RestartPromptCount, Is.EqualTo(0));
Assert.That(ErrorReport.Properties.ContainsKey("AvaloniaUIMode"), Is.False,
"an unchanged selection must not touch the crash-report value");
}
}

Expand Down
4 changes: 4 additions & 0 deletions Src/xWorks/FwXWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ internal static void SeedUIModeProperties(PropertyTable propertyTable, string se
propertyTable.SetProperty(UIFrameworkResolver.UIModeDisabledToolsPropertyName,
settingsDisabledTools ?? string.Empty, false);
propertyTable.SetPropertyPersistence(UIFrameworkResolver.UIModeDisabledToolsPropertyName, false);

// Record for crash reports; everything else about the crash comes from the trace.
ErrorReporter.AddProperty("AvaloniaUIMode", UIFrameworkResolver.NormalizeUIMode(settingsUiMode));
ErrorReporter.AddProperty("AvaloniaDisabledTools", settingsDisabledTools ?? string.Empty);
}

/// ------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using NUnit.Framework;
using SIL.FieldWorks.Common.FwAvalonia;
using SIL.Reporting;
using XCore;

namespace SIL.FieldWorks.XWorks
Expand Down Expand Up @@ -33,6 +34,8 @@ public void TearDown()
{
m_propertyTable.Dispose();
m_mediator.Dispose();
ErrorReport.Properties.Remove("AvaloniaUIMode");
ErrorReport.Properties.Remove("AvaloniaDisabledTools");
}

[TestCase("New", "New")]
Expand Down Expand Up @@ -61,5 +64,14 @@ public void SeedUIModeProperties_SeedsDisabledTools_AndNullBecomesEmpty()
Assert.That(m_propertyTable.GetStringProperty(
UIFrameworkResolver.UIModeDisabledToolsPropertyName, null), Is.EqualTo(""));
}

[Test]
public void SeedUIModeProperties_RecordsModeAndDisabledToolsForCrashReports()
{
FwXWindow.SeedUIModeProperties(m_propertyTable, "New", "lexiconEdit,posEdit");

Assert.That(ErrorReport.Properties["AvaloniaUIMode"], Is.EqualTo("New"));
Assert.That(ErrorReport.Properties["AvaloniaDisabledTools"], Is.EqualTo("lexiconEdit,posEdit"));
}
}
}
Loading