mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-23 01:36:57 -08:00
feature<Launcher>: finish restore opened tabs
This commit is contained in:
parent
d895beb3f4
commit
49154afe48
3 changed files with 45 additions and 1 deletions
|
@ -21,6 +21,27 @@ namespace SourceGit.ViewModels {
|
||||||
public Launcher() {
|
public Launcher() {
|
||||||
Pages = new AvaloniaList<LauncherPage>();
|
Pages = new AvaloniaList<LauncherPage>();
|
||||||
AddNewTab();
|
AddNewTab();
|
||||||
|
|
||||||
|
if (Preference.Instance.RestoreTabs) {
|
||||||
|
foreach (var id in Preference.Instance.OpenedTabs) {
|
||||||
|
var node = Preference.FindNode(id);
|
||||||
|
if (node == null) continue;
|
||||||
|
|
||||||
|
OpenRepositoryInTab(node, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Quit() {
|
||||||
|
Preference.Instance.OpenedTabs.Clear();
|
||||||
|
|
||||||
|
if (Preference.Instance.RestoreTabs) {
|
||||||
|
foreach (var page in Pages) {
|
||||||
|
if (page.Node.IsRepository) Preference.Instance.OpenedTabs.Add(page.Node.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Preference.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddNewTab() {
|
public void AddNewTab() {
|
||||||
|
@ -130,6 +151,7 @@ namespace SourceGit.ViewModels {
|
||||||
page = new LauncherPage(node, repo);
|
page = new LauncherPage(node, repo);
|
||||||
Pages.Add(page);
|
Pages.Add(page);
|
||||||
} else {
|
} else {
|
||||||
|
page = ActivePage;
|
||||||
page.Node = node;
|
page.Node = node;
|
||||||
page.View = new Views.Repository() { DataContext = repo };
|
page.View = new Views.Repository() { DataContext = repo };
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,11 @@ namespace SourceGit.ViewModels {
|
||||||
set => SetProperty(ref _repositoryNodes, value);
|
set => SetProperty(ref _repositoryNodes, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<string> OpenedTabs {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new List<string>();
|
||||||
|
|
||||||
public static void AddNode(RepositoryNode node, RepositoryNode to = null) {
|
public static void AddNode(RepositoryNode node, RepositoryNode to = null) {
|
||||||
var collection = to == null ? _instance._repositoryNodes : to.SubNodes;
|
var collection = to == null ? _instance._repositoryNodes : to.SubNodes;
|
||||||
var list = new List<RepositoryNode>();
|
var list = new List<RepositoryNode>();
|
||||||
|
@ -177,6 +182,10 @@ namespace SourceGit.ViewModels {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RepositoryNode FindNode(string id) {
|
||||||
|
return FindNodeRecursive(id, _instance.RepositoryNodes);
|
||||||
|
}
|
||||||
|
|
||||||
public static void MoveNode(RepositoryNode node, RepositoryNode to = null) {
|
public static void MoveNode(RepositoryNode node, RepositoryNode to = null) {
|
||||||
if (to == null && _instance._repositoryNodes.Contains(node)) return;
|
if (to == null && _instance._repositoryNodes.Contains(node)) return;
|
||||||
if (to != null && to.SubNodes.Contains(node)) return;
|
if (to != null && to.SubNodes.Contains(node)) return;
|
||||||
|
@ -222,6 +231,17 @@ namespace SourceGit.ViewModels {
|
||||||
File.WriteAllText(_savePath, data);
|
File.WriteAllText(_savePath, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static RepositoryNode FindNodeRecursive(string id, AvaloniaList<RepositoryNode> collection) {
|
||||||
|
foreach (var node in collection) {
|
||||||
|
if (node.Id == id) return node;
|
||||||
|
|
||||||
|
var sub = FindNodeRecursive(id, node.SubNodes);
|
||||||
|
if (sub != null) return sub;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList<RepositoryNode> collection) {
|
private static bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList<RepositoryNode> collection) {
|
||||||
if (collection.Contains(node)) {
|
if (collection.Contains(node)) {
|
||||||
collection.Remove(node);
|
collection.Remove(node);
|
||||||
|
|
|
@ -43,7 +43,9 @@ namespace SourceGit.Views {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClosing(WindowClosingEventArgs e) {
|
protected override void OnClosing(WindowClosingEventArgs e) {
|
||||||
ViewModels.Preference.Save();
|
var vm = DataContext as ViewModels.Launcher;
|
||||||
|
vm.Quit();
|
||||||
|
|
||||||
base.OnClosing(e);
|
base.OnClosing(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue