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
{
if (SetProperty(ref _activePage, value))
{
PopupHost.Active = value;
if (!_ignoreIndexChange && value is { Data: Repository })
ActiveWorkspace.ActiveIdx = Pages.IndexOf(value);
}
}
}
public Launcher(string startupRepo)
{
_ignoreIndexChange = true;
Pages = new AvaloniaList<LauncherPage>();
AddNewTab();
@ -61,7 +68,16 @@ namespace SourceGit.ViewModels
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
{
@ -75,14 +91,17 @@ namespace SourceGit.ViewModels
IsError = true,
Message = $"Given path: '{startupRepo}' is NOT a valid repository!"
});
return;
}
var normalized = test.StdOut.Trim().Replace("\\", "/");
var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false);
Welcome.Instance.Refresh();
OpenRepositoryInTab(node, null);
else
{
var normalized = test.StdOut.Trim().Replace("\\", "/");
var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false);
Welcome.Instance.Refresh();
OpenRepositoryInTab(node, null);
}
}
_ignoreIndexChange = false;
}
public void AddNewTab()
@ -398,6 +417,8 @@ namespace SourceGit.ViewModels
private void SwitchWorkspace(Workspace to)
{
_ignoreIndexChange = true;
var pref = Preference.Instance;
foreach (var w in pref.Workspaces)
w.IsActive = false;
@ -409,7 +430,6 @@ namespace SourceGit.ViewModels
CloseRepositoryInTab(one, false);
Pages.Clear();
ActivePage = null;
AddNewTab();
var repos = to.Repositories.ToArray();
@ -430,6 +450,18 @@ namespace SourceGit.ViewModels
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();
}
@ -449,5 +481,6 @@ namespace SourceGit.ViewModels
private Workspace _activeWorkspace = null;
private LauncherPage _activePage = null;
private bool _ignoreIndexChange = false;
}
}

View file

@ -31,6 +31,12 @@ namespace SourceGit.ViewModels
set;
} = new List<string>();
public int ActiveIdx
{
get;
set;
} = 0;
public bool IsActive
{
get => _isActive;
@ -52,7 +58,7 @@ namespace SourceGit.ViewModels
private string _name = string.Empty;
private uint _color = 0;
private IBrush _brush = null;
private bool _isActive = false;
private IBrush _brush = null;
}
}