optimize(*): speed up for openning same repository that already opened before

This commit is contained in:
leo 2020-08-05 16:21:40 +08:00
parent 65d89897f1
commit 073c189f18
4 changed files with 22 additions and 12 deletions

View file

@ -54,8 +54,8 @@ namespace SourceGit {
if (main == null) return null;
if (repo == null) return (main.Tabs[0].Page as UI.Manager).popupManager;
for (int i = 1; i < main.openedTabs.Items.Count; i++) {
var opened = main.openedTabs.Items[i] as UI.Launcher.Tab;
for (int i = 1; i < main.Tabs.Count; i++) {
var opened = main.Tabs[i];
if (opened.Repo.Path == repo.Path) {
return (opened.Page as UI.Dashboard).popupManager;
}

View file

@ -958,7 +958,8 @@ namespace SourceGit.UI {
sub.Path = Path.Combine(repo.Path, path);
sub.Name = Path.GetFileName(path);
sub.Parent = repo;
sub.Open();
if (!(App.Current.MainWindow as Launcher).GotoRepo(sub)) sub.Open();
}
#endregion

View file

@ -48,14 +48,6 @@ namespace SourceGit.UI {
Git.Repository.OnOpen = repo => {
Dispatcher.Invoke(() => {
for (int i = 1; i < openedTabs.Items.Count; i++) {
var opened = openedTabs.Items[i] as Tab;
if (opened.Repo.Path == repo.Path) {
openedTabs.SelectedItem = opened;
return;
}
}
var tab = new Tab() {
Title = repo.Parent == null ? repo.Name : $"{repo.Parent.Name} : {repo.Name}",
Repo = repo,
@ -76,6 +68,23 @@ namespace SourceGit.UI {
openedTabs.SelectedItem = Tabs[0];
}
/// <summary>
/// Goto opened repository.
/// </summary>
/// <param name="repo"></param>
/// <returns></returns>
public bool GotoRepo(Git.Repository repo) {
for (int i = 1; i < Tabs.Count; i++) {
var opened = Tabs[i];
if (opened.Repo.Path == repo.Path) {
openedTabs.SelectedItem = opened;
return true;
}
}
return false;
}
#region LAYOUT_CONTENT
/// <summary>
/// Close repository tab.

View file

@ -402,7 +402,7 @@ namespace SourceGit.UI {
}
var repo = App.Preference.AddRepository(path, "");
repo.Open();
if (!(App.Current.MainWindow as Launcher).GotoRepo(repo)) repo.Open();
}
/// <summary>