mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
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:
parent
56a42dd6e8
commit
7f389b2e6f
18 changed files with 187 additions and 209 deletions
|
@ -48,9 +48,8 @@ namespace SourceGit.ViewModels
|
|||
return;
|
||||
}
|
||||
|
||||
var gitDir = new Commands.QueryGitDir(root).Result();
|
||||
var repo = Preference.AddRepository(root, gitDir);
|
||||
var node = Preference.FindOrAddNodeByRepositoryPath(repo.FullPath, null, false);
|
||||
var normalized = root.Replace("\\", "/");
|
||||
var node = Preference.FindOrAddNodeByRepositoryPath(normalized, null, false);
|
||||
OpenRepositoryInTab(node, null);
|
||||
}
|
||||
else if (Preference.Instance.RestoreTabs)
|
||||
|
@ -59,7 +58,15 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
var node = Preference.FindNode(id);
|
||||
if (node == null)
|
||||
continue;
|
||||
{
|
||||
node = new RepositoryNode()
|
||||
{
|
||||
Id = id,
|
||||
Name = Path.GetFileName(id),
|
||||
Bookmark = 0,
|
||||
IsRepository = true,
|
||||
};
|
||||
}
|
||||
|
||||
OpenRepositoryInTab(node, null);
|
||||
}
|
||||
|
@ -72,19 +79,26 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public void Quit()
|
||||
{
|
||||
Preference.Instance.OpenedTabs.Clear();
|
||||
var pref = Preference.Instance;
|
||||
pref.OpenedTabs.Clear();
|
||||
|
||||
if (Preference.Instance.RestoreTabs)
|
||||
if (pref.RestoreTabs)
|
||||
{
|
||||
foreach (var page in Pages)
|
||||
{
|
||||
if (page.Node.IsRepository)
|
||||
Preference.Instance.OpenedTabs.Add(page.Node.Id);
|
||||
pref.OpenedTabs.Add(page.Node.Id);
|
||||
}
|
||||
}
|
||||
|
||||
Preference.Instance.LastActiveTabIdx = Pages.IndexOf(ActivePage);
|
||||
Preference.Save();
|
||||
pref.LastActiveTabIdx = Pages.IndexOf(ActivePage);
|
||||
pref.Save();
|
||||
|
||||
foreach (var page in Pages)
|
||||
{
|
||||
if (page.Data is Repository repo)
|
||||
repo.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddNewTab()
|
||||
|
@ -211,14 +225,27 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
var repo = Preference.FindRepository(node.Id);
|
||||
if (repo == null || !Path.Exists(repo.FullPath))
|
||||
if (!Path.Exists(node.Id))
|
||||
{
|
||||
var ctx = page == null ? ActivePage.Node.Id : page.Node.Id;
|
||||
App.RaiseException(ctx, "Repository does NOT exists any more. Please remove it.");
|
||||
return;
|
||||
}
|
||||
|
||||
var gitDir = new Commands.QueryGitDir(node.Id).Result();
|
||||
if (string.IsNullOrEmpty(gitDir))
|
||||
{
|
||||
var ctx = page == null ? ActivePage.Node.Id : page.Node.Id;
|
||||
App.RaiseException(ctx, "Given path is not a valid git repository!");
|
||||
return;
|
||||
}
|
||||
|
||||
var repo = new Repository()
|
||||
{
|
||||
FullPath = node.Id,
|
||||
GitDir = gitDir,
|
||||
};
|
||||
|
||||
repo.Open();
|
||||
Commands.AutoFetch.AddRepository(repo.FullPath);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue