diff --git a/src/App.axaml.cs b/src/App.axaml.cs index ffce8a51..c6ae4513 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -75,6 +75,12 @@ namespace SourceGit AvaloniaXamlLoader.Load(this); var pref = ViewModels.Preference.Instance; + pref.PropertyChanged += (_1, _2) => + { +#pragma warning disable CS4014 + pref.SaveAsync(); +#pragma warning restore CS4014 + }; SetLocale(pref.Locale); SetTheme(pref.Theme, pref.ThemeOverrides); SetFonts(pref.DefaultFontFamily, pref.MonospaceFontFamily, pref.OnlyUseMonoFontInEditor); diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index afe40cf5..a7aa6532 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -356,6 +356,9 @@ namespace SourceGit.ViewModels return string.Compare(l.Name, r.Name, StringComparison.Ordinal); }); +#pragma warning disable CS4014 + SaveAsync(); +#pragma warning restore CS4014 } public RepositoryNode FindNode(string id) @@ -400,6 +403,9 @@ namespace SourceGit.ViewModels public void RemoveNode(RepositoryNode node) { RemoveNodeRecursive(node, RepositoryNodes); +#pragma warning disable CS4014 + SaveAsync(); +#pragma warning restore CS4014 } public void SortByRenamedNode(RepositoryNode node) @@ -412,6 +418,9 @@ namespace SourceGit.ViewModels return string.Compare(l.Name, r.Name, StringComparison.Ordinal); }); +#pragma warning disable CS4014 + SaveAsync(); +#pragma warning restore CS4014 } public void Save() @@ -446,14 +455,6 @@ namespace SourceGit.ViewModels await File.WriteAllTextAsync(_savePath, data); } - protected override void OnPropertyChanged(PropertyChangedEventArgs e) - { - base.OnPropertyChanged(e); -#pragma warning disable CS4014 - SaveAsync(); -#pragma warning restore CS4014 - } - private RepositoryNode FindNodeRecursive(string id, List collection) { foreach (var node in collection) diff --git a/src/Views/Preference.axaml.cs b/src/Views/Preference.axaml.cs index 6fedd052..25dbfd96 100644 --- a/src/Views/Preference.axaml.cs +++ b/src/Views/Preference.axaml.cs @@ -261,9 +261,6 @@ namespace SourceGit.Views if (sender is CheckBox box) { ViewModels.Preference.Instance.UseSystemWindowFrame = box.IsChecked == true; -#pragma warning disable CS4014 - ViewModels.Preference.Instance.SaveAsync(); -#pragma warning restore CS4014 var dialog = new ConfirmRestart(); App.OpenDialog(dialog);