mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
enhance: remember the active page index for each workspace (#445)
This commit is contained in:
parent
e63034acd5
commit
9934586ee0
2 changed files with 48 additions and 9 deletions
|
@ -29,12 +29,19 @@ namespace SourceGit.ViewModels
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _activePage, value))
|
if (SetProperty(ref _activePage, value))
|
||||||
|
{
|
||||||
PopupHost.Active = value;
|
PopupHost.Active = value;
|
||||||
|
|
||||||
|
if (!_ignoreIndexChange && value is { Data: Repository })
|
||||||
|
ActiveWorkspace.ActiveIdx = Pages.IndexOf(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Launcher(string startupRepo)
|
public Launcher(string startupRepo)
|
||||||
{
|
{
|
||||||
|
_ignoreIndexChange = true;
|
||||||
|
|
||||||
Pages = new AvaloniaList<LauncherPage>();
|
Pages = new AvaloniaList<LauncherPage>();
|
||||||
AddNewTab();
|
AddNewTab();
|
||||||
|
|
||||||
|
@ -61,7 +68,16 @@ namespace SourceGit.ViewModels
|
||||||
OpenRepositoryInTab(node, null);
|
OpenRepositoryInTab(node, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var activeIdx = ActiveWorkspace.ActiveIdx;
|
||||||
|
if (activeIdx >= 0 && activeIdx < Pages.Count)
|
||||||
|
{
|
||||||
|
ActivePage = Pages[activeIdx];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ActivePage = Pages[0];
|
ActivePage = Pages[0];
|
||||||
|
ActiveWorkspace.ActiveIdx = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -75,9 +91,9 @@ namespace SourceGit.ViewModels
|
||||||
IsError = true,
|
IsError = true,
|
||||||
Message = $"Given path: '{startupRepo}' is NOT a valid repository!"
|
Message = $"Given path: '{startupRepo}' is NOT a valid repository!"
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
var normalized = test.StdOut.Trim().Replace("\\", "/");
|
var normalized = test.StdOut.Trim().Replace("\\", "/");
|
||||||
var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false);
|
var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false);
|
||||||
Welcome.Instance.Refresh();
|
Welcome.Instance.Refresh();
|
||||||
|
@ -85,6 +101,9 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ignoreIndexChange = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void AddNewTab()
|
public void AddNewTab()
|
||||||
{
|
{
|
||||||
var page = new LauncherPage();
|
var page = new LauncherPage();
|
||||||
|
@ -398,6 +417,8 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
private void SwitchWorkspace(Workspace to)
|
private void SwitchWorkspace(Workspace to)
|
||||||
{
|
{
|
||||||
|
_ignoreIndexChange = true;
|
||||||
|
|
||||||
var pref = Preference.Instance;
|
var pref = Preference.Instance;
|
||||||
foreach (var w in pref.Workspaces)
|
foreach (var w in pref.Workspaces)
|
||||||
w.IsActive = false;
|
w.IsActive = false;
|
||||||
|
@ -409,7 +430,6 @@ namespace SourceGit.ViewModels
|
||||||
CloseRepositoryInTab(one, false);
|
CloseRepositoryInTab(one, false);
|
||||||
|
|
||||||
Pages.Clear();
|
Pages.Clear();
|
||||||
ActivePage = null;
|
|
||||||
AddNewTab();
|
AddNewTab();
|
||||||
|
|
||||||
var repos = to.Repositories.ToArray();
|
var repos = to.Repositories.ToArray();
|
||||||
|
@ -430,6 +450,18 @@ namespace SourceGit.ViewModels
|
||||||
OpenRepositoryInTab(node, null);
|
OpenRepositoryInTab(node, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var activeIdx = to.ActiveIdx;
|
||||||
|
if (activeIdx >= 0 && activeIdx < Pages.Count)
|
||||||
|
{
|
||||||
|
ActivePage = Pages[activeIdx];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ActivePage = Pages[0];
|
||||||
|
to.ActiveIdx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ignoreIndexChange = false;
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,5 +481,6 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
private Workspace _activeWorkspace = null;
|
private Workspace _activeWorkspace = null;
|
||||||
private LauncherPage _activePage = null;
|
private LauncherPage _activePage = null;
|
||||||
|
private bool _ignoreIndexChange = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,12 @@ namespace SourceGit.ViewModels
|
||||||
set;
|
set;
|
||||||
} = new List<string>();
|
} = new List<string>();
|
||||||
|
|
||||||
|
public int ActiveIdx
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = 0;
|
||||||
|
|
||||||
public bool IsActive
|
public bool IsActive
|
||||||
{
|
{
|
||||||
get => _isActive;
|
get => _isActive;
|
||||||
|
@ -52,7 +58,7 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
private string _name = string.Empty;
|
private string _name = string.Empty;
|
||||||
private uint _color = 0;
|
private uint _color = 0;
|
||||||
private IBrush _brush = null;
|
|
||||||
private bool _isActive = false;
|
private bool _isActive = false;
|
||||||
|
private IBrush _brush = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue