From 7028e08390d1b42504f635452287025d6c24f1f6 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 23 Dec 2024 16:56:49 +0800 Subject: [PATCH] enhance: remove invalid expanded node records in repository's settings --- src/ViewModels/BranchTreeNode.cs | 8 ++++++++ src/ViewModels/Repository.cs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/ViewModels/BranchTreeNode.cs b/src/ViewModels/BranchTreeNode.cs index a8232047..698dc7ad 100644 --- a/src/ViewModels/BranchTreeNode.cs +++ b/src/ViewModels/BranchTreeNode.cs @@ -58,6 +58,7 @@ namespace SourceGit.ViewModels { public List Locals => _locals; public List Remotes => _remotes; + public List InvalidExpandedNodes => _invalidExpandedNodes; public void SetExpandedNodes(List 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 _locals = new List(); private readonly List _remotes = new List(); + private readonly List _invalidExpandedNodes = new List(); private readonly HashSet _expanded = new HashSet(); } } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 993597a5..82197bdf 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -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 {