enhance: remember the active page index for each workspace (#445)

This commit is contained in:
leo 2024-09-09 19:40:44 +08:00
parent e63034acd5
commit 9934586ee0
No known key found for this signature in database
2 changed files with 48 additions and 9 deletions

View file

@ -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);
} }
ActivePage = Pages[0]; var activeIdx = ActiveWorkspace.ActiveIdx;
if (activeIdx >= 0 && activeIdx < Pages.Count)
{
ActivePage = Pages[activeIdx];
}
else
{
ActivePage = Pages[0];
ActiveWorkspace.ActiveIdx = 0;
}
} }
else else
{ {
@ -75,14 +91,17 @@ 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 node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false); var normalized = test.StdOut.Trim().Replace("\\", "/");
Welcome.Instance.Refresh(); var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false);
OpenRepositoryInTab(node, null); Welcome.Instance.Refresh();
OpenRepositoryInTab(node, null);
}
} }
_ignoreIndexChange = false;
} }
public void AddNewTab() public void AddNewTab()
@ -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;
} }
} }

View file

@ -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;
} }
} }