From 98e65c0f11533adacc8383b0362cc47fbf3cf471 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 6 Feb 2024 17:52:16 +0800 Subject: [PATCH] fix: filter not working --- src/Models/BranchTreeNode.cs | 18 ++++++++++++++---- src/Models/Tag.cs | 1 + src/ViewModels/Repository.cs | 6 ++++-- src/Views/Repository.axaml | 29 +++++++++++++++++++++++++---- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/Models/BranchTreeNode.cs b/src/Models/BranchTreeNode.cs index 1635ff6e..f2e1da63 100644 --- a/src/Models/BranchTreeNode.cs +++ b/src/Models/BranchTreeNode.cs @@ -1,4 +1,5 @@ -using System; +using Avalonia.Collections; +using System; using System.Collections.Generic; namespace SourceGit.Models { @@ -13,6 +14,7 @@ namespace SourceGit.Models { public BranchTreeNodeType Type { get; set; } public object Backend { get; set; } public bool IsExpanded { get; set; } + public bool IsFiltered { get; set; } public List Children { get; set; } = new List(); public bool IsUpstreamTrackStatusVisible { @@ -58,11 +60,12 @@ namespace SourceGit.Models { } foreach (var branch in branches) { + var isFiltered = _filters.Contains(branch.FullName); if (branch.IsLocal) { - MakeBranchNode(branch, _locals, "local"); + MakeBranchNode(branch, _locals, "local", isFiltered); } else { var remote = _remotes.Find(x => x.Name == branch.Remote); - if (remote != null) MakeBranchNode(branch, remote.Children, $"remote/{remote.Name}"); + if (remote != null) MakeBranchNode(branch, remote.Children, $"remote/{remote.Name}", isFiltered); } } @@ -70,6 +73,10 @@ namespace SourceGit.Models { SortNodes(_remotes); } + public void SetFilters(AvaloniaList filters) { + _filters.AddRange(filters); + } + public void CollectExpandedNodes(List nodes, bool isLocal) { CollectExpandedNodes(nodes, isLocal ? "local" : "remote"); } @@ -82,7 +89,7 @@ namespace SourceGit.Models { } } - private void MakeBranchNode(Branch branch, List roots, string prefix) { + private void MakeBranchNode(Branch branch, List roots, string prefix, bool isFiltered) { var subs = branch.Name.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (subs.Length == 1) { @@ -91,6 +98,7 @@ namespace SourceGit.Models { Type = BranchTreeNodeType.Branch, Backend = branch, IsExpanded = false, + IsFiltered = isFiltered, }; roots.Add(node); return; @@ -127,6 +135,7 @@ namespace SourceGit.Models { Type = BranchTreeNodeType.Branch, Backend = branch, IsExpanded = false, + IsFiltered = isFiltered, }; lastFolder.Children.Add(last); } @@ -146,6 +155,7 @@ namespace SourceGit.Models { private List _locals = new List(); private List _remotes = new List(); private HashSet _expanded = new HashSet(); + private List _filters = new List(); private Dictionary _maps = new Dictionary(); } } diff --git a/src/Models/Tag.cs b/src/Models/Tag.cs index a6e10db4..6f51a06e 100644 --- a/src/Models/Tag.cs +++ b/src/Models/Tag.cs @@ -2,5 +2,6 @@ public class Tag { public string Name { get; set; } public string SHA { get; set; } + public bool IsFiltered { get; set; } } } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 5cc94874..db70e47f 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -23,12 +23,12 @@ namespace SourceGit.ViewModels { public AvaloniaList Filters { get; - private set; + set; } = new AvaloniaList(); public AvaloniaList CommitMessages { get; - private set; + set; } = new AvaloniaList(); [JsonIgnore] @@ -401,6 +401,7 @@ namespace SourceGit.ViewModels { var remotes = new Commands.QueryRemotes(FullPath).Result(); var builder = new Models.BranchTreeNode.Builder(); + builder.SetFilters(Filters); builder.CollectExpandedNodes(_localBranchTrees, true); builder.CollectExpandedNodes(_remoteBranchTrees, false); builder.Run(branches, remotes); @@ -418,6 +419,7 @@ namespace SourceGit.ViewModels { public void RefreshTags() { var tags = new Commands.QueryTags(FullPath).Result(); + foreach (var tag in tags) tag.IsFiltered = Filters.Contains(tag.Name); Dispatcher.UIThread.Invoke(() => { Tags = tags; }); diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 7e9ca0a9..db0dedf9 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -178,7 +178,14 @@ - + @@ -204,8 +211,17 @@ + - + + @@ -251,7 +267,7 @@ - + @@ -259,7 +275,12 @@ - +