enhance: support save RepositoryNode changes instantly

This commit is contained in:
Gadfly 2024-09-02 12:05:24 +08:00
parent 28b6ce4993
commit c85293c86a
No known key found for this signature in database
3 changed files with 15 additions and 11 deletions

View file

@ -75,6 +75,12 @@ namespace SourceGit
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
var pref = ViewModels.Preference.Instance; var pref = ViewModels.Preference.Instance;
pref.PropertyChanged += (_1, _2) =>
{
#pragma warning disable CS4014
pref.SaveAsync();
#pragma warning restore CS4014
};
SetLocale(pref.Locale); SetLocale(pref.Locale);
SetTheme(pref.Theme, pref.ThemeOverrides); SetTheme(pref.Theme, pref.ThemeOverrides);
SetFonts(pref.DefaultFontFamily, pref.MonospaceFontFamily, pref.OnlyUseMonoFontInEditor); SetFonts(pref.DefaultFontFamily, pref.MonospaceFontFamily, pref.OnlyUseMonoFontInEditor);

View file

@ -356,6 +356,9 @@ namespace SourceGit.ViewModels
return string.Compare(l.Name, r.Name, StringComparison.Ordinal); return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
}); });
#pragma warning disable CS4014
SaveAsync();
#pragma warning restore CS4014
} }
public RepositoryNode FindNode(string id) public RepositoryNode FindNode(string id)
@ -400,6 +403,9 @@ namespace SourceGit.ViewModels
public void RemoveNode(RepositoryNode node) public void RemoveNode(RepositoryNode node)
{ {
RemoveNodeRecursive(node, RepositoryNodes); RemoveNodeRecursive(node, RepositoryNodes);
#pragma warning disable CS4014
SaveAsync();
#pragma warning restore CS4014
} }
public void SortByRenamedNode(RepositoryNode node) public void SortByRenamedNode(RepositoryNode node)
@ -412,6 +418,9 @@ namespace SourceGit.ViewModels
return string.Compare(l.Name, r.Name, StringComparison.Ordinal); return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
}); });
#pragma warning disable CS4014
SaveAsync();
#pragma warning restore CS4014
} }
public void Save() public void Save()
@ -446,14 +455,6 @@ namespace SourceGit.ViewModels
await File.WriteAllTextAsync(_savePath, data); 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<RepositoryNode> collection) private RepositoryNode FindNodeRecursive(string id, List<RepositoryNode> collection)
{ {
foreach (var node in collection) foreach (var node in collection)

View file

@ -261,9 +261,6 @@ namespace SourceGit.Views
if (sender is CheckBox box) if (sender is CheckBox box)
{ {
ViewModels.Preference.Instance.UseSystemWindowFrame = box.IsChecked == true; ViewModels.Preference.Instance.UseSystemWindowFrame = box.IsChecked == true;
#pragma warning disable CS4014
ViewModels.Preference.Instance.SaveAsync();
#pragma warning restore CS4014
var dialog = new ConfirmRestart(); var dialog = new ConfirmRestart();
App.OpenDialog(dialog); App.OpenDialog(dialog);