mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Warn about unsaved changes when closing settings
This commit is contained in:
parent
0544f137d0
commit
bac13eb507
@ -6,6 +6,8 @@ namespace Bloxstrap
|
|||||||
{
|
{
|
||||||
public override string FileLocation => Path.Combine(Paths.Modifications, "ClientSettings\\ClientAppSettings.json");
|
public override string FileLocation => Path.Combine(Paths.Modifications, "ClientSettings\\ClientAppSettings.json");
|
||||||
|
|
||||||
|
public bool Changed => !OriginalProp.SequenceEqual(Prop);
|
||||||
|
|
||||||
public static IReadOnlyDictionary<string, string> PresetFlags = new Dictionary<string, string>
|
public static IReadOnlyDictionary<string, string> PresetFlags = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "Network.Log", "FLogNetwork" },
|
{ "Network.Log", "FLogNetwork" },
|
||||||
@ -231,12 +233,18 @@ namespace Bloxstrap
|
|||||||
Prop[pair.Key] = pair.Value.ToString()!;
|
Prop[pair.Key] = pair.Value.ToString()!;
|
||||||
|
|
||||||
base.Save();
|
base.Save();
|
||||||
|
|
||||||
|
// clone the dictionary
|
||||||
|
OriginalProp = new(Prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
base.Load();
|
base.Load();
|
||||||
|
|
||||||
|
// clone the dictionary
|
||||||
|
OriginalProp = new(Prop);
|
||||||
|
|
||||||
// TODO - remove when activity tracking has been revamped
|
// TODO - remove when activity tracking has been revamped
|
||||||
if (GetPreset("Network.Log") != "7")
|
if (GetPreset("Network.Log") != "7")
|
||||||
SetPreset("Network.Log", "7");
|
SetPreset("Network.Log", "7");
|
||||||
|
@ -4,6 +4,8 @@ namespace Bloxstrap
|
|||||||
{
|
{
|
||||||
public class JsonManager<T> where T : class, new()
|
public class JsonManager<T> where T : class, new()
|
||||||
{
|
{
|
||||||
|
public T OriginalProp { get; set; } = new();
|
||||||
|
|
||||||
public T Prop { get; set; } = new();
|
public T Prop { get; set; } = new();
|
||||||
|
|
||||||
public virtual string FileLocation => Path.Combine(Paths.Base, $"{typeof(T).Name}.json");
|
public virtual string FileLocation => Path.Combine(Paths.Base, $"{typeof(T).Name}.json");
|
||||||
|
@ -29,12 +29,16 @@ namespace Bloxstrap.Models.SettingTasks.Base
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
App.PendingSettingTasks[Name] = this;
|
|
||||||
_newState = value;
|
_newState = value;
|
||||||
|
|
||||||
|
if (Changed)
|
||||||
|
App.PendingSettingTasks[Name] = this;
|
||||||
|
else
|
||||||
|
App.PendingSettingTasks.Remove(Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Changed => NewState != OriginalState;
|
public override bool Changed => _newState != OriginalState;
|
||||||
|
|
||||||
public BoolBaseTask(string prefix, string name) : base(prefix, name) { }
|
public BoolBaseTask(string prefix, string name) : base(prefix, name) { }
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,16 @@
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
App.PendingSettingTasks[Name] = this;
|
|
||||||
_newState = value;
|
_newState = value;
|
||||||
|
|
||||||
|
if (Changed)
|
||||||
|
App.PendingSettingTasks[Name] = this;
|
||||||
|
else
|
||||||
|
App.PendingSettingTasks.Remove(Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Changed => !NewState.Equals(OriginalState);
|
public override bool Changed => !_newState.Equals(OriginalState);
|
||||||
|
|
||||||
public IEnumerable<T> Selections { get; private set; }
|
public IEnumerable<T> Selections { get; private set; }
|
||||||
= Enum.GetValues(typeof(T)).Cast<T>().OrderBy(x =>
|
= Enum.GetValues(typeof(T)).Cast<T>().OrderBy(x =>
|
||||||
|
@ -29,12 +29,16 @@ namespace Bloxstrap.Models.SettingTasks.Base
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
App.PendingSettingTasks[Name] = this;
|
|
||||||
_newState = value;
|
_newState = value;
|
||||||
|
|
||||||
|
if (Changed)
|
||||||
|
App.PendingSettingTasks[Name] = this;
|
||||||
|
else
|
||||||
|
App.PendingSettingTasks.Remove(Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Changed => NewState != OriginalState;
|
public override bool Changed => _newState != OriginalState;
|
||||||
|
|
||||||
public StringBaseTask(string prefix, string name) : base(prefix, name) { }
|
public StringBaseTask(string prefix, string name) : base(prefix, name) { }
|
||||||
}
|
}
|
||||||
|
9
Bloxstrap/Resources/Strings.Designer.cs
generated
9
Bloxstrap/Resources/Strings.Designer.cs
generated
@ -2969,6 +2969,15 @@ namespace Bloxstrap.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to You have unsaved changes. Are you sure you want to close without saving?.
|
||||||
|
/// </summary>
|
||||||
|
public static string Menu_UnsavedChanges {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Menu.UnsavedChanges", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to They'll be kept where Bloxstrap was installed, and will automatically be restored on a reinstall..
|
/// Looks up a localized string similar to They'll be kept where Bloxstrap was installed, and will automatically be restored on a reinstall..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1139,4 +1139,7 @@ If not, then please report this exception to the maintainers of this fork. Do NO
|
|||||||
<data name="About.Translators.Title" xml:space="preserve">
|
<data name="About.Translators.Title" xml:space="preserve">
|
||||||
<value>Translators</value>
|
<value>Translators</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Menu.UnsavedChanges" xml:space="preserve">
|
||||||
|
<value>You have unsaved changes. Are you sure you want to close without saving?</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -15,7 +15,8 @@
|
|||||||
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
|
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
|
||||||
ExtendsContentIntoTitleBar="True"
|
ExtendsContentIntoTitleBar="True"
|
||||||
WindowBackdropType="Mica"
|
WindowBackdropType="Mica"
|
||||||
WindowStartupLocation="CenterScreen">
|
WindowStartupLocation="CenterScreen"
|
||||||
|
Closing="WpfUiWindow_Closing">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
@ -93,7 +94,7 @@
|
|||||||
<ui:Button Content="{x:Static resources:Strings.Menu_Save}" Appearance="Primary" Command="{Binding SaveSettingsCommand, Mode=OneWay}" />
|
<ui:Button Content="{x:Static resources:Strings.Menu_Save}" Appearance="Primary" Command="{Binding SaveSettingsCommand, Mode=OneWay}" />
|
||||||
</StatusBarItem>
|
</StatusBarItem>
|
||||||
<StatusBarItem Grid.Column="2" Padding="4,0,0,0">
|
<StatusBarItem Grid.Column="2" Padding="4,0,0,0">
|
||||||
<ui:Button Content="{x:Static resources:Strings.Common_Close}" IsCancel="True" />
|
<ui:Button Content="{x:Static resources:Strings.Common_Close}" IsCancel="True" />
|
||||||
</StatusBarItem>
|
</StatusBarItem>
|
||||||
</StatusBar>
|
</StatusBar>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
using System.Windows.Controls;
|
using System.ComponentModel;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
using Wpf.Ui.Controls.Interfaces;
|
using Wpf.Ui.Controls.Interfaces;
|
||||||
using Wpf.Ui.Mvvm.Contracts;
|
using Wpf.Ui.Mvvm.Contracts;
|
||||||
|
|
||||||
using Bloxstrap.UI.ViewModels.Settings;
|
using Bloxstrap.UI.ViewModels.Settings;
|
||||||
|
|
||||||
namespace Bloxstrap.UI.Elements.Settings
|
namespace Bloxstrap.UI.Elements.Settings
|
||||||
@ -22,7 +26,7 @@ namespace Bloxstrap.UI.Elements.Settings
|
|||||||
App.Logger.WriteLine("MainWindow::MainWindow", "Initializing menu");
|
App.Logger.WriteLine("MainWindow::MainWindow", "Initializing menu");
|
||||||
|
|
||||||
#if DEBUG // easier access
|
#if DEBUG // easier access
|
||||||
EditorWarningNavItem.Visibility = System.Windows.Visibility.Visible;
|
EditorWarningNavItem.Visibility = Visibility.Visible;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (showAlreadyRunningWarning)
|
if (showAlreadyRunningWarning)
|
||||||
@ -50,5 +54,16 @@ namespace Bloxstrap.UI.Elements.Settings
|
|||||||
public void CloseWindow() => Close();
|
public void CloseWindow() => Close();
|
||||||
|
|
||||||
#endregion INavigationWindow methods
|
#endregion INavigationWindow methods
|
||||||
|
|
||||||
|
private void WpfUiWindow_Closing(object sender, CancelEventArgs e)
|
||||||
|
{
|
||||||
|
if (App.FastFlags.Changed || App.PendingSettingTasks.Any())
|
||||||
|
{
|
||||||
|
var result = Frontend.ShowMessageBox(Strings.Menu_UnsavedChanges, MessageBoxImage.Warning, MessageBoxButton.YesNo);
|
||||||
|
|
||||||
|
if (result != MessageBoxResult.Yes)
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user