enhance: remove invalid expanded node records in repository's settings

This commit is contained in:
leo 2024-12-23 16:56:49 +08:00
parent ec94c8c1b4
commit 7028e08390
No known key found for this signature in database
2 changed files with 11 additions and 0 deletions

View file

@ -58,6 +58,7 @@ namespace SourceGit.ViewModels
{
public List<BranchTreeNode> Locals => _locals;
public List<BranchTreeNode> Remotes => _remotes;
public List<string> InvalidExpandedNodes => _invalidExpandedNodes;
public void SetExpandedNodes(List<string> expanded)
{
@ -98,6 +99,12 @@ namespace SourceGit.ViewModels
}
}
foreach (var path in _expanded)
{
if (!folders.ContainsKey(path))
_invalidExpandedNodes.Add(path);
}
folders.Clear();
SortNodes(_locals);
SortNodes(_remotes);
@ -188,6 +195,7 @@ namespace SourceGit.ViewModels
private readonly List<BranchTreeNode> _locals = new List<BranchTreeNode>();
private readonly List<BranchTreeNode> _remotes = new List<BranchTreeNode>();
private readonly List<string> _invalidExpandedNodes = new List<string>();
private readonly HashSet<string> _expanded = new HashSet<string>();
}
}

View file

@ -2088,6 +2088,9 @@ namespace SourceGit.ViewModels
{
builder.SetExpandedNodes(_settings.ExpandedBranchNodesInSideBar);
builder.Run(branches, remotes, false);
foreach (var invalid in builder.InvalidExpandedNodes)
_settings.ExpandedBranchNodesInSideBar.Remove(invalid);
}
else
{