mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-24 13:45:00 +00:00
feature: when toggle a local branch filter, if it has a tracked upstream branch, do the same for the upstream branch (#513)
This commit is contained in:
parent
85b83990a8
commit
a8ce4e6d95
5 changed files with 54 additions and 16 deletions
|
@ -428,12 +428,23 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private void OnToggleFilter(object sender, RoutedEventArgs e)
|
||||
private void OnToggleFilterClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleButton toggle && DataContext is ViewModels.Repository repo)
|
||||
if (DataContext is ViewModels.Repository repo &&
|
||||
sender is ToggleButton toggle &&
|
||||
toggle.DataContext is ViewModels.BranchTreeNode { Backend: Models.Branch branch } node)
|
||||
{
|
||||
if (toggle.DataContext is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
|
||||
repo.UpdateFilter(branch.FullName, toggle.IsChecked == true);
|
||||
bool filtered = toggle.IsChecked == true;
|
||||
List<string> filters = [branch.FullName];
|
||||
if (branch.IsLocal && !string.IsNullOrEmpty(branch.Upstream))
|
||||
{
|
||||
filters.Add(branch.Upstream);
|
||||
|
||||
node.IsFiltered = filtered;
|
||||
UpdateUpstreamFilterState(repo.RemoteBranchTrees, branch.Upstream, filtered);
|
||||
}
|
||||
|
||||
repo.UpdateFilters(filters, filtered);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
|
@ -466,6 +477,23 @@ namespace SourceGit.Views
|
|||
CollectBranchesInNode(outs, sub);
|
||||
}
|
||||
|
||||
private bool UpdateUpstreamFilterState(List<ViewModels.BranchTreeNode> collection, string upstream, bool isFiltered)
|
||||
{
|
||||
foreach (var node in collection)
|
||||
{
|
||||
if (node.Backend is Models.Branch b && b.FullName == upstream)
|
||||
{
|
||||
node.IsFiltered = isFiltered;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.Backend is Models.Remote r && upstream.StartsWith($"refs/remotes/{r.Name}/", StringComparison.Ordinal))
|
||||
return UpdateUpstreamFilterState(node.Children, upstream, isFiltered);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool _disableSelectionChangingEvent = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue