fix<Repository>: filter not working

This commit is contained in:
leo 2024-02-06 17:52:16 +08:00
parent 5781a22b4c
commit 98e65c0f11
4 changed files with 44 additions and 10 deletions

View file

@ -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<BranchTreeNode> Children { get; set; } = new List<BranchTreeNode>();
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<string> filters) {
_filters.AddRange(filters);
}
public void CollectExpandedNodes(List<BranchTreeNode> nodes, bool isLocal) {
CollectExpandedNodes(nodes, isLocal ? "local" : "remote");
}
@ -82,7 +89,7 @@ namespace SourceGit.Models {
}
}
private void MakeBranchNode(Branch branch, List<BranchTreeNode> roots, string prefix) {
private void MakeBranchNode(Branch branch, List<BranchTreeNode> 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<BranchTreeNode> _locals = new List<BranchTreeNode>();
private List<BranchTreeNode> _remotes = new List<BranchTreeNode>();
private HashSet<string> _expanded = new HashSet<string>();
private List<string> _filters = new List<string>();
private Dictionary<string, BranchTreeNode> _maps = new Dictionary<string, BranchTreeNode>();
}
}

View file

@ -2,5 +2,6 @@
public class Tag {
public string Name { get; set; }
public string SHA { get; set; }
public bool IsFiltered { get; set; }
}
}

View file

@ -23,12 +23,12 @@ namespace SourceGit.ViewModels {
public AvaloniaList<string> Filters {
get;
private set;
set;
} = new AvaloniaList<string>();
public AvaloniaList<string> CommitMessages {
get;
private set;
set;
} = new AvaloniaList<string>();
[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;
});

View file

@ -178,7 +178,14 @@
<TextBlock Classes="monospace" FontSize="10" HorizontalAlignment="Center" Margin="9,0" Text="{Binding UpstreamTrackStatus}"/>
</Border>
<ToggleButton Grid.Column="3" Classes="filter" Margin="0,0,8,0" Background="Transparent" IsVisible="{Binding IsBranch}" Checked="OnToggleFilter" Unchecked="OnToggleFilter"/>
<ToggleButton Grid.Column="3"
Classes="filter"
Margin="0,0,8,0"
Background="Transparent"
IsVisible="{Binding IsBranch}"
Checked="OnToggleFilter"
Unchecked="OnToggleFilter"
IsChecked="{Binding IsFiltered}"/>
</Grid>
</TreeDataTemplate>
</TreeView.ItemTemplate>
@ -204,8 +211,17 @@
<Path Grid.Column="0" Classes="folder_icon" Width="10" Height="10" Margin="0,2,0,0" IsVisible="{Binding IsFolder}" VerticalAlignment="Center"/>
<Path Grid.Column="0" Width="10" Height="10" Margin="0,4,0,0" Data="{StaticResource Icons.Remote}" IsVisible="{Binding IsRemote}" VerticalAlignment="Center"/>
<Path Grid.Column="0" Width="10" Height="10" Data="{StaticResource Icons.Branch}" IsVisible="{Binding IsBranch}" VerticalAlignment="Center"/>
<TextBlock Grid.Column="1" Text="{Binding Name}" Classes="monospace" FontSize="12" Margin="8,0,4,0"/>
<ToggleButton Grid.Column="2" Classes="filter" Margin="0,0,8,0" Background="Transparent" Checked="OnToggleFilter" Unchecked="OnToggleFilter" IsVisible="{Binding IsBranch}"/>
<ToggleButton Grid.Column="2"
Classes="filter"
Margin="0,0,8,0"
Background="Transparent"
Checked="OnToggleFilter"
Unchecked="OnToggleFilter"
IsVisible="{Binding IsBranch}"
IsChecked="{Binding IsFiltered}"/>
</Grid>
</TreeDataTemplate>
</TreeView.ItemTemplate>
@ -251,7 +267,7 @@
<DataGridTemplateColumn Width="*" Header="NAME">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate x:DataType="{x:Type m:Tag}">
<TextBlock Text="{Binding Name}" Classes="monospace" FontSize="12" />
<TextBlock Text="{Binding Name}" Classes="monospace" FontSize="12" TextTrimming="CharacterEllipsis" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
@ -259,7 +275,12 @@
<DataGridTemplateColumn Header="FILTER">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate x:DataType="{x:Type m:Tag}">
<ToggleButton Grid.Column="2" Classes="filter" Margin="0,0,8,0" Background="Transparent" Checked="OnToggleFilter" Unchecked="OnToggleFilter"/>
<ToggleButton Classes="filter"
Margin="0,0,8,0"
Background="Transparent"
Checked="OnToggleFilter"
Unchecked="OnToggleFilter"
IsChecked="{Binding IsFiltered}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>