mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-17 22:15:59 +01:00
fix(settings): a first start has nothing to save before the simulator starts
With no eu07.ini of the player's own, starting the simulator asked to save changes nobody made. The UART tune box and the Vulkan device box went by TextChanged, which Avalonia raises later from the dispatcher: the text the page put there while loading came back as an edit once the window was shown. Both now go by their Text property, which changes at once and is passed over while the page loads; typing in them still counts.
This commit is contained in:
39
StarterNG.Tests/SettingsFirstStartTests.cs
Normal file
39
StarterNG.Tests/SettingsFirstStartTests.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>The settings page on a start with no eu07.ini of the player's own yet.</summary>
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class SettingsFirstStartTests
|
||||
{
|
||||
[Fact]
|
||||
public void A_first_start_has_nothing_to_save_before_the_simulator_starts()
|
||||
{
|
||||
var files = new InMemoryFileSystem();
|
||||
files.WriteAllText(TestInstallation.At("eu07.ini"), "width 1920\nheight 1080\nendconfig\n");
|
||||
var installation = new TestInstallation(files);
|
||||
installation.Environment.AsWindows();
|
||||
var services = AppServices.Initialize(installation.Paths, installation.Files, installation.Clock,
|
||||
installation.Environment);
|
||||
services.SettingsStore.Load();
|
||||
services.SettingsStore.StartAtHighWithoutOwnSettings();
|
||||
|
||||
HeadlessDrawing.Ensure();
|
||||
// The page reads the graphics cards away from the window and comes back to it, as in the application.
|
||||
var context = SynchronizationContext.Current;
|
||||
SynchronizationContext.SetSynchronizationContext(new Avalonia.Threading.AvaloniaSynchronizationContext());
|
||||
Avalonia.Controls.Window? window = null;
|
||||
try
|
||||
{
|
||||
var page = new StarterNG.Views.Settings();
|
||||
window = Controls.Show(page, 1600, 1000, themed: true);
|
||||
Assert.False(page.HasUnsavedChanges);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window?.Close();
|
||||
SynchronizationContext.SetSynchronizationContext(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -966,11 +966,11 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
OnControlChanged();
|
||||
};
|
||||
UartEnabledCb.IsCheckedChanged += (_, _) => ValidateUart();
|
||||
UartTuneBox.TextChanged += (_, _) =>
|
||||
OnTextEdited(UartTuneBox, () =>
|
||||
{
|
||||
ValidateUart();
|
||||
OnControlChanged();
|
||||
};
|
||||
});
|
||||
App.Loc.LanguageChanged += UpdateUartTexts;
|
||||
UpdateUartTexts();
|
||||
}
|
||||
@@ -1511,7 +1511,7 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
nud.ValueChanged += (_, _) => OnControlChanged();
|
||||
break;
|
||||
case TextBox box when ReferenceEquals(box, VulkanDeviceTb):
|
||||
box.TextChanged += (_, _) => OnControlChanged();
|
||||
OnTextEdited(box, OnControlChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1521,6 +1521,18 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
toggle.IsCheckedChanged += (_, _) => OnControlChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The text as it changes, not TextChanged: that one comes later, from the
|
||||
/// dispatcher, so the text the page itself put there while loading came back
|
||||
/// as an edit once the window was shown - the first start asked to save.
|
||||
/// </summary>
|
||||
private static void OnTextEdited(TextBox box, Action edited) =>
|
||||
box.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.Property == TextBox.TextProperty)
|
||||
edited();
|
||||
};
|
||||
|
||||
private void OnControlChanged()
|
||||
{
|
||||
MarkDirty();
|
||||
@@ -1533,8 +1545,7 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
if (_loading || _dirty)
|
||||
return;
|
||||
|
||||
_dirty = true;
|
||||
UpdateSaveState();
|
||||
_dirty = true; UpdateSaveState();
|
||||
}
|
||||
|
||||
/// <summary>Edits on the page, or of the keys, not saved yet: what "Niezapisane zmiany" tells.</summary>
|
||||
|
||||
Reference in New Issue
Block a user