refactor: move settings of repository, such as filters, commit message, from Preference to each repository's gitdir.

* avoid invalid repository setting remains in preference.json
* supports to restore tabs that not added to the Welcome page
This commit is contained in:
leo 2024-07-01 11:57:13 +08:00
parent 56a42dd6e8
commit 7f389b2e6f
No known key found for this signature in database
18 changed files with 187 additions and 209 deletions

View file

@ -187,6 +187,18 @@ namespace SourceGit
}
}
public static async Task<string> GetClipboardTextAsync()
{
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (desktop.MainWindow.Clipboard is { } clipboard)
{
return await clipboard.GetTextAsync();
}
}
return default;
}
public static string Text(string key, params object[] args)
{
var fmt = Current.FindResource($"Text.{key}") as string;
@ -259,6 +271,21 @@ namespace SourceGit
});
}
public static ViewModels.Repository FindOpenedRepository(string repoPath)
{
if (Current is App app && app._launcher != null)
{
foreach (var page in app._launcher.Pages)
{
var id = page.Node.Id.Replace("\\", "/");
if (id == repoPath && page.Data is ViewModels.Repository repo)
return repo;
}
}
return null;
}
public static void Quit()
{
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
@ -288,9 +315,10 @@ namespace SourceGit
_launcher = new ViewModels.Launcher();
desktop.MainWindow = new Views.Launcher() { DataContext = _launcher };
if (ViewModels.Preference.Instance.ShouldCheck4UpdateOnStartup)
var pref = ViewModels.Preference.Instance;
if (pref.ShouldCheck4UpdateOnStartup)
{
ViewModels.Preference.Save();
pref.Save();
Check4Update();
}
}
@ -317,18 +345,6 @@ namespace SourceGit
});
}
public static async Task<string> GetClipboardTextAsync()
{
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (desktop.MainWindow.Clipboard is { } clipboard)
{
return await clipboard.GetTextAsync();
}
}
return default;
}
private ViewModels.Launcher _launcher = null;
private ResourceDictionary _activeLocale = null;
private ResourceDictionary _colorOverrides = null;