mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
enhance: re-calculate the opened repositories in active workspace (#511)
This commit is contained in:
parent
28c59ee0ab
commit
acf71a30b8
2 changed files with 36 additions and 10 deletions
|
@ -32,8 +32,8 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
PopupHost.Active = value;
|
||||
|
||||
if (!_ignoreIndexChange && value is { Data: Repository })
|
||||
ActiveWorkspace.ActiveIdx = Pages.IndexOf(value);
|
||||
if (!_ignoreIndexChange && value is { Data: Repository repo})
|
||||
ActiveWorkspace.ActiveIdx = ActiveWorkspace.Repositories.IndexOf(repo.FullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,10 +131,22 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public void MoveTab(LauncherPage from, LauncherPage to)
|
||||
{
|
||||
_ignoreIndexChange = true;
|
||||
|
||||
var fromIdx = Pages.IndexOf(from);
|
||||
var toIdx = Pages.IndexOf(to);
|
||||
Pages.Move(fromIdx, toIdx);
|
||||
ActivePage = from;
|
||||
|
||||
ActiveWorkspace.Repositories.Clear();
|
||||
foreach (var p in Pages)
|
||||
{
|
||||
if (p.Data is Repository r)
|
||||
ActiveWorkspace.Repositories.Add(r.FullPath);
|
||||
}
|
||||
ActiveWorkspace.ActiveIdx = ActiveWorkspace.Repositories.IndexOf(from.Node.Id);
|
||||
|
||||
_ignoreIndexChange = false;
|
||||
}
|
||||
|
||||
public void GotoNextTab()
|
||||
|
@ -164,7 +176,9 @@ namespace SourceGit.ViewModels
|
|||
var last = Pages[0];
|
||||
if (last.Data is Repository repo)
|
||||
{
|
||||
ActiveWorkspace.Repositories.Remove(repo.FullPath);
|
||||
ActiveWorkspace.Repositories.Clear();
|
||||
ActiveWorkspace.ActiveIdx = 0;
|
||||
|
||||
Models.AutoFetchManager.Instance.RemoveRepository(repo.FullPath);
|
||||
repo.Close();
|
||||
|
||||
|
@ -180,6 +194,7 @@ namespace SourceGit.ViewModels
|
|||
App.Quit(0);
|
||||
}
|
||||
|
||||
_ignoreIndexChange = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -213,6 +228,8 @@ namespace SourceGit.ViewModels
|
|||
if (Pages.Count == 1)
|
||||
return;
|
||||
|
||||
_ignoreIndexChange = true;
|
||||
|
||||
var id = ActivePage.Node.Id;
|
||||
foreach (var one in Pages)
|
||||
{
|
||||
|
@ -221,12 +238,17 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
Pages = new AvaloniaList<LauncherPage> { ActivePage };
|
||||
ActiveWorkspace.ActiveIdx = 0;
|
||||
OnPropertyChanged(nameof(Pages));
|
||||
|
||||
_ignoreIndexChange = false;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public void CloseRightTabs()
|
||||
{
|
||||
_ignoreIndexChange = true;
|
||||
|
||||
var endIdx = Pages.IndexOf(ActivePage);
|
||||
for (var i = Pages.Count - 1; i > endIdx; i--)
|
||||
{
|
||||
|
@ -234,6 +256,7 @@ namespace SourceGit.ViewModels
|
|||
Pages.Remove(Pages[i]);
|
||||
}
|
||||
|
||||
_ignoreIndexChange = false;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
|
@ -270,7 +293,6 @@ namespace SourceGit.ViewModels
|
|||
};
|
||||
|
||||
repo.Open();
|
||||
ActiveWorkspace.AddRepository(repo.FullPath);
|
||||
Models.AutoFetchManager.Instance.AddRepository(repo.FullPath, repo.GitDir);
|
||||
|
||||
if (page == null)
|
||||
|
@ -294,6 +316,16 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
ActivePage = page;
|
||||
|
||||
ActiveWorkspace.Repositories.Clear();
|
||||
foreach (var p in Pages)
|
||||
{
|
||||
if (p.Data is Repository r)
|
||||
ActiveWorkspace.Repositories.Add(r.FullPath);
|
||||
}
|
||||
|
||||
if (!_ignoreIndexChange)
|
||||
ActiveWorkspace.ActiveIdx = ActiveWorkspace.Repositories.IndexOf(node.Id);
|
||||
}
|
||||
|
||||
public void DispatchNotification(string pageId, string message, bool isError)
|
||||
|
|
|
@ -51,12 +51,6 @@ namespace SourceGit.ViewModels
|
|||
get => new SolidColorBrush(_color);
|
||||
}
|
||||
|
||||
public void AddRepository(string repo)
|
||||
{
|
||||
if (!Repositories.Contains(repo))
|
||||
Repositories.Add(repo);
|
||||
}
|
||||
|
||||
private string _name = string.Empty;
|
||||
private uint _color = 4278221015;
|
||||
private bool _isActive = false;
|
||||
|
|
Loading…
Reference in a new issue