Compare commits

..

No commits in common. "d777b14b895185da73eefef8a06830c42d2b5f26" and "c16a412aa388684ce1e0d2217820abc8ad7c267b" have entirely different histories.

20 changed files with 278 additions and 690 deletions

View file

@ -48,18 +48,8 @@
var cmd = new Command(); var cmd = new Command();
cmd.WorkingDirectory = repo; cmd.WorkingDirectory = repo;
cmd.Context = repo; cmd.Context = repo;
bool exists = new Remote(repo).HasBranch(remote, name);
if (exists)
{
cmd.SSHKey = new Config(repo).Get($"remote.{remote}.sshkey"); cmd.SSHKey = new Config(repo).Get($"remote.{remote}.sshkey");
cmd.Args = $"push {remote} --delete {name}"; cmd.Args = $"push {remote} --delete {name}";
}
else
{
cmd.Args = $"branch -D -r {remote}/{name}";
}
return cmd.Exec(); return cmd.Exec();
} }
} }

View file

@ -45,14 +45,5 @@
Args = "remote set-url" + (isPush ? " --push " : " ") + $"{name} {url}"; Args = "remote set-url" + (isPush ? " --push " : " ") + $"{name} {url}";
return Exec(); return Exec();
} }
public bool HasBranch(string remote, string branch)
{
SSHKey = new Config(WorkingDirectory).Get($"remote.{remote}.sshkey");
Args = $"ls-remote {remote} {branch}";
var rs = ReadToEnd();
return rs.IsSuccess && rs.StdOut.Trim().Length > 0;
}
} }
} }

View file

@ -1,60 +0,0 @@
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.Models
{
public enum FilterType
{
LocalBranch = 0,
LocalBranchFolder,
RemoteBranch,
RemoteBranchFolder,
Tag,
}
public enum FilterMode
{
None = 0,
Included,
Excluded,
}
public class Filter : ObservableObject
{
public string Pattern
{
get => _pattern;
set => SetProperty(ref _pattern, value);
}
public FilterType Type
{
get;
set;
} = FilterType.LocalBranch;
public FilterMode Mode
{
get => _mode;
set => SetProperty(ref _mode, value);
}
public bool IsBranch
{
get => Type != FilterType.Tag;
}
public Filter()
{
}
public Filter(string pattern, FilterType type, FilterMode mode)
{
_pattern = pattern;
_mode = mode;
Type = type;
}
private string _pattern = string.Empty;
private FilterMode _mode = FilterMode.None;
}
}

View file

@ -1,9 +1,4 @@
using System; using Avalonia.Collections;
using System.Collections.Generic;
using System.Text;
using Avalonia.Collections;
using Avalonia.Threading;
namespace SourceGit.Models namespace SourceGit.Models
{ {
@ -81,11 +76,11 @@ namespace SourceGit.Models
set; set;
} = true; } = true;
public AvaloniaList<Filter> HistoriesFilters public AvaloniaList<string> Filters
{ {
get; get;
set; set;
} = new AvaloniaList<Filter>(); } = new AvaloniaList<string>();
public AvaloniaList<CommitTemplate> CommitTemplates public AvaloniaList<CommitTemplate> CommitTemplates
{ {
@ -153,177 +148,6 @@ namespace SourceGit.Models
set; set;
} = "---"; } = "---";
public FilterMode GetHistoriesFilterMode(string pattern, FilterType type)
{
foreach (var filter in HistoriesFilters)
{
if (filter.Type != type)
continue;
if (filter.Pattern.Equals(pattern, StringComparison.Ordinal))
return filter.Mode;
}
return FilterMode.None;
}
public bool UpdateHistoriesFilter(string pattern, FilterType type, FilterMode mode)
{
for (int i = 0; i < HistoriesFilters.Count; i++)
{
var filter = HistoriesFilters[i];
if (filter.Type != type)
continue;
if (filter.Pattern.Equals(pattern, StringComparison.Ordinal))
{
if (mode == FilterMode.None)
{
HistoriesFilters.RemoveAt(i);
return true;
}
if (mode != filter.Mode)
{
filter.Mode = mode;
return true;
}
}
}
if (mode != FilterMode.None)
{
HistoriesFilters.Add(new Filter(pattern, type, mode));
return true;
}
return false;
}
public string BuildHistoriesFilter()
{
var builder = new StringBuilder();
var excludedBranches = new List<string>();
var excludedRemotes = new List<string>();
var excludedTags = new List<string>();
var includedBranches = new List<string>();
var includedRemotes = new List<string>();
var includedTags = new List<string>();
foreach (var filter in HistoriesFilters)
{
if (filter.Type == FilterType.LocalBranch)
{
var name = filter.Pattern.Substring(11);
var b = $"{name.Substring(0, name.Length - 1)}[{name[^1]}]";
if (filter.Mode == FilterMode.Included)
includedBranches.Add(b);
else if (filter.Mode == FilterMode.Excluded)
excludedBranches.Add(b);
}
else if (filter.Type == FilterType.LocalBranchFolder)
{
if (filter.Mode == FilterMode.Included)
includedBranches.Add($"{filter.Pattern.Substring(11)}/*");
else if (filter.Mode == FilterMode.Excluded)
excludedBranches.Add($"{filter.Pattern.Substring(11)}/*");
}
else if (filter.Type == FilterType.RemoteBranch)
{
var name = filter.Pattern.Substring(13);
var r = $"{name.Substring(0, name.Length - 1)}[{name[^1]}]";
if (filter.Mode == FilterMode.Included)
includedRemotes.Add(r);
else if (filter.Mode == FilterMode.Excluded)
excludedRemotes.Add(r);
}
else if (filter.Type == FilterType.RemoteBranchFolder)
{
if (filter.Mode == FilterMode.Included)
includedRemotes.Add($"{filter.Pattern.Substring(13)}/*");
else if (filter.Mode == FilterMode.Excluded)
excludedRemotes.Add($"{filter.Pattern.Substring(13)}/*");
}
else if (filter.Type == FilterType.Tag)
{
var name = filter.Pattern;
var t = $"{name.Substring(0, name.Length - 1)}[{name[^1]}]";
if (filter.Mode == FilterMode.Included)
includedTags.Add(t);
else if (filter.Mode == FilterMode.Excluded)
excludedTags.Add(t);
}
}
foreach (var b in excludedBranches)
{
builder.Append("--exclude=");
builder.Append(b);
builder.Append(' ');
}
if (includedBranches.Count > 0)
{
foreach (var b in includedBranches)
{
builder.Append("--branches=");
builder.Append(b);
builder.Append(' ');
}
}
else if (excludedBranches.Count > 0)
{
builder.Append("--branches ");
}
foreach (var r in excludedRemotes)
{
builder.Append("--exclude=");
builder.Append(r);
builder.Append(' ');
}
if (includedRemotes.Count > 0)
{
foreach (var r in includedRemotes)
{
builder.Append("--remotes=");
builder.Append(r);
builder.Append(' ');
}
}
else if (excludedRemotes.Count > 0)
{
builder.Append("--remotes ");
}
foreach (var t in excludedTags)
{
builder.Append("--exclude=");
builder.Append(t);
builder.Append(' ');
}
if (includedTags.Count > 0)
{
foreach (var t in includedTags)
{
builder.Append("--tags=");
builder.Append(t);
builder.Append(' ');
}
}
else if (excludedTags.Count > 0)
{
builder.Append("--tags ");
}
return builder.ToString();
}
public void PushCommitMessage(string message) public void PushCommitMessage(string message)
{ {
var existIdx = CommitMessages.IndexOf(message); var existIdx = CommitMessages.IndexOf(message);

View file

@ -1,19 +1,10 @@
using CommunityToolkit.Mvvm.ComponentModel; namespace SourceGit.Models
namespace SourceGit.Models
{ {
public class Tag : ObservableObject public class Tag
{ {
public string Name { get; set; } = string.Empty; public string Name { get; set; }
public string SHA { get; set; } = string.Empty; public string SHA { get; set; }
public string Message { get; set; } = string.Empty; public string Message { get; set; }
public bool IsFiltered { get; set; }
public FilterMode FilterMode
{
get => _filterMode;
set => SetProperty(ref _filterMode, value);
}
private FilterMode _filterMode = FilterMode.None;
} }
} }

View file

@ -1038,6 +1038,35 @@
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
</Style> </Style>
<Style Selector="ToggleButton.filter">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Template">
<ControlTemplate>
<Border Background="Transparent">
<Path x:Name="PART_IndicatorIcon"
Width="12"
Data="{StaticResource Icons.Filter}"
Fill="Transparent"
StrokeThickness="1"
Stroke="{DynamicResource Brush.FG2}"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="ToggleButton.filter:pressed">
<Setter Property="RenderTransform" Value="scale(1)"/>
</Style>
<Style Selector="ToggleButton.filter:checked /template/ Path#PART_IndicatorIcon">
<Setter Property="Fill" Value="{DynamicResource Brush.FG2}"/>
</Style>
<Style Selector="ToggleButton.filter:pointerover /template/ Path#PART_IndicatorIcon">
<Setter Property="Stroke" Value="{DynamicResource Brush.Accent}"/>
</Style>
<Style Selector="ToggleButton.tree_expander"> <Style Selector="ToggleButton.tree_expander">
<Setter Property="Margin" Value="0" /> <Setter Property="Margin" Value="0" />
<Setter Property="Width" Value="9" /> <Setter Property="Width" Value="9" />

View file

@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using Avalonia; using Avalonia;
using Avalonia.Collections;
using Avalonia.Media; using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@ -11,16 +13,15 @@ namespace SourceGit.ViewModels
public class BranchTreeNode : ObservableObject public class BranchTreeNode : ObservableObject
{ {
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
public string Path { get; private set; } = string.Empty;
public object Backend { get; private set; } = null; public object Backend { get; private set; } = null;
public int Depth { get; set; } = 0; public int Depth { get; set; } = 0;
public bool IsSelected { get; set; } = false; public bool IsSelected { get; set; } = false;
public List<BranchTreeNode> Children { get; private set; } = new List<BranchTreeNode>(); public List<BranchTreeNode> Children { get; private set; } = new List<BranchTreeNode>();
public Models.FilterMode FilterMode public bool IsFiltered
{ {
get => _filterMode; get => _isFiltered;
set => SetProperty(ref _filterMode, value); set => SetProperty(ref _isFiltered, value);
} }
public bool IsExpanded public bool IsExpanded
@ -50,7 +51,7 @@ namespace SourceGit.ViewModels
get => Backend is Models.Branch b ? b.FriendlyName : null; get => Backend is Models.Branch b ? b.FriendlyName : null;
} }
private Models.FilterMode _filterMode = Models.FilterMode.None; private bool _isFiltered = false;
private bool _isExpanded = false; private bool _isExpanded = false;
private CornerRadius _cornerRadius = new CornerRadius(4); private CornerRadius _cornerRadius = new CornerRadius(4);
@ -59,25 +60,18 @@ namespace SourceGit.ViewModels
public List<BranchTreeNode> Locals => _locals; public List<BranchTreeNode> Locals => _locals;
public List<BranchTreeNode> Remotes => _remotes; public List<BranchTreeNode> Remotes => _remotes;
public Builder(Models.RepositorySettings settings)
{
_settings = settings;
}
public void Run(List<Models.Branch> branches, List<Models.Remote> remotes, bool bForceExpanded) public void Run(List<Models.Branch> branches, List<Models.Remote> remotes, bool bForceExpanded)
{ {
var folders = new Dictionary<string, BranchTreeNode>(); var folders = new Dictionary<string, BranchTreeNode>();
foreach (var remote in remotes) foreach (var remote in remotes)
{ {
var path = $"refs/remotes/{remote.Name}"; var path = $"remote/{remote.Name}";
var node = new BranchTreeNode() var node = new BranchTreeNode()
{ {
Name = remote.Name, Name = remote.Name,
Path = path,
Backend = remote, Backend = remote,
IsExpanded = bForceExpanded || _expanded.Contains(path), IsExpanded = bForceExpanded || _expanded.Contains(path),
FilterMode = _settings.GetHistoriesFilterMode(path, Models.FilterType.RemoteBranchFolder)
}; };
folders.Add(path, node); folders.Add(path, node);
@ -86,15 +80,16 @@ namespace SourceGit.ViewModels
foreach (var branch in branches) foreach (var branch in branches)
{ {
var isFiltered = _filters.Contains(branch.FullName);
if (branch.IsLocal) if (branch.IsLocal)
{ {
MakeBranchNode(branch, _locals, folders, "refs/heads", bForceExpanded); MakeBranchNode(branch, _locals, folders, "local", isFiltered, bForceExpanded);
} }
else else
{ {
var remote = _remotes.Find(x => x.Name == branch.Remote); var remote = _remotes.Find(x => x.Name == branch.Remote);
if (remote != null) if (remote != null)
MakeBranchNode(branch, remote.Children, folders, $"refs/remotes/{remote.Name}", bForceExpanded); MakeBranchNode(branch, remote.Children, folders, $"remote/{remote.Name}", isFiltered, bForceExpanded);
} }
} }
@ -103,33 +98,42 @@ namespace SourceGit.ViewModels
SortNodes(_remotes); SortNodes(_remotes);
} }
public void CollectExpandedNodes(List<BranchTreeNode> nodes) public void SetFilters(AvaloniaList<string> filters)
{
_filters.AddRange(filters);
}
public void CollectExpandedNodes(List<BranchTreeNode> nodes, bool isLocal)
{
CollectExpandedNodes(nodes, isLocal ? "local" : "remote");
}
private void CollectExpandedNodes(List<BranchTreeNode> nodes, string prefix)
{ {
foreach (var node in nodes) foreach (var node in nodes)
{ {
if (node.Backend is Models.Branch) if (node.Backend is Models.Branch)
continue; continue;
var path = prefix + "/" + node.Name;
if (node.IsExpanded) if (node.IsExpanded)
_expanded.Add(node.Path); _expanded.Add(path);
CollectExpandedNodes(node.Children); CollectExpandedNodes(node.Children, path);
} }
} }
private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Dictionary<string, BranchTreeNode> folders, string prefix, bool bForceExpanded) private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Dictionary<string, BranchTreeNode> folders, string prefix, bool isFiltered, bool bForceExpanded)
{ {
var fullpath = $"{prefix}/{branch.Name}";
var sepIdx = branch.Name.IndexOf('/', StringComparison.Ordinal); var sepIdx = branch.Name.IndexOf('/', StringComparison.Ordinal);
if (sepIdx == -1 || branch.IsDetachedHead) if (sepIdx == -1 || branch.IsDetachedHead)
{ {
roots.Add(new BranchTreeNode() roots.Add(new BranchTreeNode()
{ {
Name = branch.Name, Name = branch.Name,
Path = fullpath,
Backend = branch, Backend = branch,
IsExpanded = false, IsExpanded = false,
FilterMode = _settings.GetHistoriesFilterMode(fullpath, branch.IsLocal ? Models.FilterType.LocalBranch : Models.FilterType.RemoteBranch), IsFiltered = isFiltered,
}); });
return; return;
} }
@ -152,9 +156,7 @@ namespace SourceGit.ViewModels
lastFolder = new BranchTreeNode() lastFolder = new BranchTreeNode()
{ {
Name = name, Name = name,
Path = folder,
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder), IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
FilterMode = _settings.GetHistoriesFilterMode(folder, branch.IsLocal ? Models.FilterType.LocalBranchFolder : Models.FilterType.RemoteBranchFolder),
}; };
roots.Add(lastFolder); roots.Add(lastFolder);
folders.Add(folder, lastFolder); folders.Add(folder, lastFolder);
@ -164,9 +166,7 @@ namespace SourceGit.ViewModels
var cur = new BranchTreeNode() var cur = new BranchTreeNode()
{ {
Name = name, Name = name,
Path = folder,
IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder), IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(folder),
FilterMode = _settings.GetHistoriesFilterMode(folder, branch.IsLocal ? Models.FilterType.LocalBranchFolder : Models.FilterType.RemoteBranchFolder),
}; };
lastFolder.Children.Add(cur); lastFolder.Children.Add(cur);
folders.Add(folder, cur); folders.Add(folder, cur);
@ -179,11 +179,10 @@ namespace SourceGit.ViewModels
lastFolder?.Children.Add(new BranchTreeNode() lastFolder?.Children.Add(new BranchTreeNode()
{ {
Name = System.IO.Path.GetFileName(branch.Name), Name = Path.GetFileName(branch.Name),
Path = fullpath,
Backend = branch, Backend = branch,
IsExpanded = false, IsExpanded = false,
FilterMode = _settings.GetHistoriesFilterMode(fullpath, branch.IsLocal ? Models.FilterType.LocalBranchFolder : Models.FilterType.RemoteBranchFolder), IsFiltered = isFiltered,
}); });
} }
@ -204,10 +203,10 @@ namespace SourceGit.ViewModels
SortNodes(node.Children); SortNodes(node.Children);
} }
private readonly Models.RepositorySettings _settings = null;
private readonly List<BranchTreeNode> _locals = new List<BranchTreeNode>(); private readonly List<BranchTreeNode> _locals = new List<BranchTreeNode>();
private readonly List<BranchTreeNode> _remotes = new List<BranchTreeNode>(); private readonly List<BranchTreeNode> _remotes = new List<BranchTreeNode>();
private readonly HashSet<string> _expanded = new HashSet<string>(); private readonly HashSet<string> _expanded = new HashSet<string>();
private readonly List<string> _filters = new List<string>();
} }
} }
} }

View file

@ -65,7 +65,7 @@ namespace SourceGit.ViewModels
{ {
var b = _repo.Branches.Find(x => x.IsLocal && x.Name == Branch); var b = _repo.Branches.Find(x => x.IsLocal && x.Name == Branch);
if (b != null) if (b != null)
_repo.UpdateHistoriesFilterAfterCheckout(b); _repo.AutoAddBranchFilterPostCheckout(b);
_repo.MarkBranchesDirtyManually(); _repo.MarkBranchesDirtyManually();
_repo.SetWatcherEnabled(true); _repo.SetWatcherEnabled(true);

View file

@ -127,7 +127,7 @@ namespace SourceGit.ViewModels
{ {
if (CheckoutAfterCreated) if (CheckoutAfterCreated)
{ {
_repo.UpdateHistoriesFilterAfterCheckout(new Models.Branch() _repo.AutoAddBranchFilterPostCheckout(new Models.Branch()
{ {
FullName = $"refs/heads/{_name}", FullName = $"refs/heads/{_name}",
Upstream = BasedOn is Models.Branch { IsLocal: false } remoteBranch ? remoteBranch.FullName : string.Empty, Upstream = BasedOn is Models.Branch { IsLocal: false } remoteBranch ? remoteBranch.FullName : string.Empty,

View file

@ -56,7 +56,7 @@ namespace SourceGit.ViewModels
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null) if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
{ {
SetProgressDescription("Deleting remote-tracking branch..."); SetProgressDescription("Deleting tracking remote branch...");
Commands.Branch.DeleteRemote(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name); Commands.Branch.DeleteRemote(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name);
} }
} }

View file

@ -1,5 +1,4 @@
using System; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SourceGit.ViewModels namespace SourceGit.ViewModels
@ -58,17 +57,10 @@ namespace SourceGit.ViewModels
var succ = Commands.Branch.Rename(_repo.FullPath, Target.Name, _name); var succ = Commands.Branch.Rename(_repo.FullPath, Target.Name, _name);
CallUIThread(() => CallUIThread(() =>
{ {
if (succ) if (succ && _repo.Settings.Filters.Contains(oldName))
{ {
foreach (var filter in _repo.Settings.HistoriesFilters) _repo.Settings.Filters.Remove(oldName);
{ _repo.Settings.Filters.Add($"refs/heads/{_name}");
if (filter.Type == Models.FilterType.LocalBranch &&
filter.Pattern.Equals(oldName, StringComparison.Ordinal))
{
filter.Pattern = $"refs/heads/{_name}";
break;
}
}
} }
_repo.MarkBranchesDirtyManually(); _repo.MarkBranchesDirtyManually();

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -588,6 +587,18 @@ namespace SourceGit.ViewModels
Filter = string.Empty; Filter = string.Empty;
} }
public void ClearHistoriesFilter()
{
_settings.Filters.Clear();
Task.Run(() =>
{
RefreshBranches();
RefreshTags();
RefreshCommits();
});
}
public void ClearSearchCommitFilter() public void ClearSearchCommitFilter()
{ {
SearchCommitFilter = string.Empty; SearchCommitFilter = string.Empty;
@ -685,21 +696,53 @@ namespace SourceGit.ViewModels
NavigateToCommit(_currentBranch.Head); NavigateToCommit(_currentBranch.Head);
} }
public void ClearHistoriesFilter() public void AutoAddBranchFilterPostCheckout(Models.Branch local)
{ {
_settings.HistoriesFilters.Clear(); if (_settings.Filters.Count == 0 || _settings.Filters.Contains(local.FullName))
return;
Task.Run(() => var hasLeft = false;
foreach (var b in _branches)
{ {
RefreshBranches(); if (!b.FullName.Equals(local.FullName, StringComparison.Ordinal) &&
RefreshTags(); !b.FullName.Equals(local.Upstream, StringComparison.Ordinal) &&
RefreshCommits(); !_settings.Filters.Contains(b.FullName))
}); {
hasLeft = true;
break;
}
} }
public void UpdateHistoriesFilterAfterCheckout(Models.Branch local) if (!hasLeft)
_settings.Filters.Clear();
else if (string.IsNullOrEmpty(local.Upstream) || _settings.Filters.Contains(local.Upstream))
_settings.Filters.Add(local.FullName);
else
_settings.Filters.AddRange([local.FullName, local.Upstream]);
}
public void UpdateFilters(List<string> filters, bool toggle)
{ {
// TODO: var changed = false;
if (toggle)
{
foreach (var filter in filters)
{
if (!_settings.Filters.Contains(filter))
{
_settings.Filters.Add(filter);
changed = true;
}
}
}
else
{
foreach (var filter in filters)
changed |= _settings.Filters.Remove(filter);
}
if (changed)
Task.Run(RefreshCommits);
} }
public void StashAll(bool autoStart) public void StashAll(bool autoStart)
@ -791,7 +834,7 @@ namespace SourceGit.ViewModels
{ {
var tags = new Commands.QueryTags(_fullpath).Result(); var tags = new Commands.QueryTags(_fullpath).Result();
foreach (var tag in tags) foreach (var tag in tags)
tag.FilterMode = _settings.GetHistoriesFilterMode(tag.Name, Models.FilterType.Tag); tag.IsFiltered = _settings.Filters.Contains(tag.Name);
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
@ -804,21 +847,49 @@ namespace SourceGit.ViewModels
{ {
Dispatcher.UIThread.Invoke(() => _histories.IsLoading = true); Dispatcher.UIThread.Invoke(() => _histories.IsLoading = true);
var builder = new StringBuilder(); var limits = $"-{Preference.Instance.MaxHistoryCommits} ";
builder.Append($"-{Preference.Instance.MaxHistoryCommits} ");
if (_enableReflog) if (_enableReflog)
builder.Append("--reflog "); limits += "--reflog ";
if (_enableFirstParentInHistories) if (_enableFirstParentInHistories)
builder.Append("--first-parent "); limits += "--first-parent ";
var invalidFilters = new List<Models.Filter>(); var validFilters = new List<string>();
var filters = _settings.BuildHistoriesFilter(); foreach (var filter in _settings.Filters)
if (string.IsNullOrEmpty(filters)) {
builder.Append("--branches --remotes --tags"); if (filter.StartsWith("refs/", StringComparison.Ordinal))
{
if (_branches.FindIndex(x => x.FullName == filter) >= 0)
validFilters.Add(filter);
}
else else
builder.Append(filters); {
if (_tags.FindIndex(t => t.Name == filter) >= 0)
validFilters.Add(filter);
}
}
var commits = new Commands.QueryCommits(_fullpath, builder.ToString()).Result(); if (validFilters.Count > 0)
{
limits += string.Join(" ", validFilters);
if (_settings.Filters.Count != validFilters.Count)
{
Dispatcher.UIThread.Invoke(() =>
{
_settings.Filters.Clear();
_settings.Filters.AddRange(validFilters);
});
}
}
else
{
if (_settings.Filters.Count != 0)
Dispatcher.UIThread.Invoke(() => _settings.Filters.Clear());
limits += "--exclude=refs/stash --all";
}
var commits = new Commands.QueryCommits(_fullpath, limits).Result();
var graph = Models.CommitGraph.Parse(commits, _enableFirstParentInHistories); var graph = Models.CommitGraph.Parse(commits, _enableFirstParentInHistories);
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
@ -1990,11 +2061,13 @@ namespace SourceGit.ViewModels
private BranchTreeNode.Builder BuildBranchTree(List<Models.Branch> branches, List<Models.Remote> remotes) private BranchTreeNode.Builder BuildBranchTree(List<Models.Branch> branches, List<Models.Remote> remotes)
{ {
var builder = new BranchTreeNode.Builder(_settings); var builder = new BranchTreeNode.Builder();
builder.SetFilters(_settings.Filters);
if (string.IsNullOrEmpty(_filter)) if (string.IsNullOrEmpty(_filter))
{ {
builder.CollectExpandedNodes(_localBranchTrees); builder.CollectExpandedNodes(_localBranchTrees, true);
builder.CollectExpandedNodes(_remoteBranchTrees); builder.CollectExpandedNodes(_remoteBranchTrees, false);
builder.Run(branches, remotes, false); builder.Run(branches, remotes, false);
} }
else else

View file

@ -22,6 +22,16 @@ namespace SourceGit.ViewModels
get => Tag == null; get => Tag == null;
} }
public bool IsFiltered
{
get => Tag?.IsFiltered ?? false;
set
{
if (Tag != null)
Tag.IsFiltered = value;
}
}
public bool IsExpanded public bool IsExpanded
{ {
get => _isExpanded; get => _isExpanded;

View file

@ -24,10 +24,6 @@
<Style Selector="ListBoxItem" x:DataType="vm:BranchTreeNode"> <Style Selector="ListBoxItem" x:DataType="vm:BranchTreeNode">
<Setter Property="CornerRadius" Value="{Binding CornerRadius}"/> <Setter Property="CornerRadius" Value="{Binding CornerRadius}"/>
</Style> </Style>
<Style Selector="ListBoxItem:pointerover v|FilterModeSwitchButton">
<Setter Property="IsNoneVisible" Value="True"/>
</Style>
</ListBox.Styles> </ListBox.Styles>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
@ -48,7 +44,7 @@
<!-- Content Area (allows double-click) --> <!-- Content Area (allows double-click) -->
<Grid Grid.Column="1" <Grid Grid.Column="1"
Background="Transparent" Background="Transparent"
ColumnDefinitions="18,*,Auto,20" ColumnDefinitions="18,*,Auto,Auto"
DoubleTapped="OnDoubleTappedBranchNode"> DoubleTapped="OnDoubleTappedBranchNode">
<!-- Icon --> <!-- Icon -->
@ -71,8 +67,15 @@
Foreground="{DynamicResource Brush.BadgeFG}" Foreground="{DynamicResource Brush.BadgeFG}"
Background="{DynamicResource Brush.Badge}"/> Background="{DynamicResource Brush.Badge}"/>
<!-- Filter Mode Switcher --> <!-- Filter Toggle Button -->
<v:FilterModeSwitchButton Grid.Column="3" Mode="{Binding FilterMode}"/> <ToggleButton Grid.Column="3"
Classes="filter"
Margin="0,0,8,0"
Background="Transparent"
IsVisible="{Binding IsBranch}"
IsChecked="{Binding IsFiltered}"
Click="OnToggleFilterClicked"
ToolTip.Tip="{DynamicResource Text.Filter}"/>
</Grid> </Grid>
</Grid> </Grid>
</DataTemplate> </DataTemplate>

View file

@ -428,6 +428,28 @@ namespace SourceGit.Views
} }
} }
private void OnToggleFilterClicked(object sender, RoutedEventArgs e)
{
if (DataContext is ViewModels.Repository repo &&
sender is ToggleButton toggle &&
toggle.DataContext is ViewModels.BranchTreeNode { Backend: Models.Branch branch } node)
{
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;
}
private void MakeRows(List<ViewModels.BranchTreeNode> rows, List<ViewModels.BranchTreeNode> nodes, int depth) private void MakeRows(List<ViewModels.BranchTreeNode> rows, List<ViewModels.BranchTreeNode> nodes, int depth)
{ {
foreach (var node in nodes) foreach (var node in nodes)
@ -455,6 +477,23 @@ namespace SourceGit.Views
CollectBranchesInNode(outs, sub); 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; private bool _disableSelectionChangingEvent = false;
} }
} }

View file

@ -1,41 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.FilterModeSwitchButton"
x:Name="ThisControl">
<Button Classes="icon_button"
Width="12" Height="12"
Padding="0"
Background="Transparent"
VerticalContentAlignment="Center"
Click="OnChangeFilterModeButtonClicked">
<Grid>
<Path Width="12" Height="12"
Data="{StaticResource Icons.Eye}"
Fill="{DynamicResource Brush.FG2}">
<Path.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="#ThisControl.Mode" Converter="{x:Static ObjectConverters.Equal}" ConverterParameter="{x:Static m:FilterMode.None}"/>
<MultiBinding Converter="{x:Static BoolConverters.Or}">
<Binding Path="#ThisControl.IsNoneVisible"/>
<Binding Path="#ThisControl.IsContextMenuOpening"/>
</MultiBinding>
</MultiBinding>
</Path.IsVisible>
</Path>
<Path Width="12" Height="12"
Data="{StaticResource Icons.Filter}"
Fill="{DynamicResource Brush.Accent}"
IsVisible="{Binding #ThisControl.Mode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:FilterMode.Included}}"/>
<Path Width="12" Height="12"
Data="{StaticResource Icons.EyeClose}"
Fill="{DynamicResource Brush.Accent}"
IsVisible="{Binding #ThisControl.Mode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:FilterMode.Excluded}}"/>
</Grid>
</Button>
</UserControl>

View file

@ -1,256 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
namespace SourceGit.Views
{
public partial class FilterModeSwitchButton : UserControl
{
public static readonly StyledProperty<Models.FilterMode> ModeProperty =
AvaloniaProperty.Register<FilterModeSwitchButton, Models.FilterMode>(nameof(Mode));
public Models.FilterMode Mode
{
get => GetValue(ModeProperty);
set => SetValue(ModeProperty, value);
}
public static readonly StyledProperty<bool> IsNoneVisibleProperty =
AvaloniaProperty.Register<FilterModeSwitchButton, bool>(nameof(IsNoneVisible));
public bool IsNoneVisible
{
get => GetValue(IsNoneVisibleProperty);
set => SetValue(IsNoneVisibleProperty, value);
}
public static readonly StyledProperty<bool> IsContextMenuOpeningProperty =
AvaloniaProperty.Register<FilterModeSwitchButton, bool>(nameof(IsContextMenuOpening));
public bool IsContextMenuOpening
{
get => GetValue(IsContextMenuOpeningProperty);
set => SetValue(IsContextMenuOpeningProperty, value);
}
public FilterModeSwitchButton()
{
InitializeComponent();
}
private void OnChangeFilterModeButtonClicked(object sender, RoutedEventArgs e)
{
var repoView = this.FindAncestorOfType<Repository>();
if (repoView == null)
return;
var repo = repoView.DataContext as ViewModels.Repository;
if (repo == null)
return;
var button = sender as Button;
if (button == null)
return;
if (DataContext is Models.Tag tag)
{
var mode = tag.FilterMode;
var none = new MenuItem();
none.Icon = App.CreateMenuIcon("Icons.Eye");
none.Header = "Default";
none.IsEnabled = mode != Models.FilterMode.None;
none.Click += (_, ev) =>
{
UpdateTagFilterMode(repo, tag, Models.FilterMode.None);
ev.Handled = true;
};
var include = new MenuItem();
include.Icon = App.CreateMenuIcon("Icons.Filter");
include.Header = "Filter";
include.IsEnabled = mode != Models.FilterMode.Included;
include.Click += (_, ev) =>
{
UpdateTagFilterMode(repo, tag, Models.FilterMode.Included);
ev.Handled = true;
};
var exclude = new MenuItem();
exclude.Icon = App.CreateMenuIcon("Icons.EyeClose");
exclude.Header = "Hide";
exclude.IsEnabled = mode != Models.FilterMode.Excluded;
exclude.Click += (_, ev) =>
{
UpdateTagFilterMode(repo, tag, Models.FilterMode.Excluded);
ev.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(none);
menu.Items.Add(include);
menu.Items.Add(exclude);
if (mode == Models.FilterMode.None)
{
IsContextMenuOpening = true;
menu.Closed += (_, _) => IsContextMenuOpening = false;
}
menu.Open(button);
}
else if (DataContext is ViewModels.BranchTreeNode node)
{
var mode = node.FilterMode;
var none = new MenuItem();
none.Icon = App.CreateMenuIcon("Icons.Eye");
none.Header = "Default";
none.IsEnabled = mode != Models.FilterMode.None;
none.Click += (_, ev) =>
{
UpdateBranchFilterMode(repo, node, Models.FilterMode.None);
ev.Handled = true;
};
var include = new MenuItem();
include.Icon = App.CreateMenuIcon("Icons.Filter");
include.Header = "Filter";
include.IsEnabled = mode != Models.FilterMode.Included;
include.Click += (_, ev) =>
{
UpdateBranchFilterMode(repo, node, Models.FilterMode.Included);
ev.Handled = true;
};
var exclude = new MenuItem();
exclude.Icon = App.CreateMenuIcon("Icons.EyeClose");
exclude.Header = "Hide";
exclude.IsEnabled = mode != Models.FilterMode.Excluded;
exclude.Click += (_, ev) =>
{
UpdateBranchFilterMode(repo, node, Models.FilterMode.Excluded);
ev.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(none);
menu.Items.Add(include);
menu.Items.Add(exclude);
if (mode == Models.FilterMode.None)
{
IsContextMenuOpening = true;
menu.Closed += (_, _) => IsContextMenuOpening = false;
}
menu.Open(button);
}
e.Handled = true;
}
private void UpdateTagFilterMode(ViewModels.Repository repo, Models.Tag tag, Models.FilterMode mode)
{
var changed = repo.Settings.UpdateHistoriesFilter(tag.Name, Models.FilterType.Tag, mode);
if (changed)
{
tag.FilterMode = mode;
Task.Run(repo.RefreshCommits);
}
}
private void UpdateBranchFilterMode(ViewModels.Repository repo, ViewModels.BranchTreeNode node, Models.FilterMode mode)
{
var isLocal = node.Path.StartsWith("refs/heads/", StringComparison.Ordinal);
var type = isLocal ? Models.FilterType.LocalBranch : Models.FilterType.RemoteBranch;
var tree = isLocal ? repo.LocalBranchTrees : repo.RemoteBranchTrees;
if (node.Backend is Models.Branch branch)
{
var changed = repo.Settings.UpdateHistoriesFilter(node.Path, type, mode);
if (!changed)
return;
node.FilterMode = mode;
}
else
{
var changed = repo.Settings.UpdateHistoriesFilter(node.Path, isLocal ? Models.FilterType.LocalBranchFolder : Models.FilterType.RemoteBranchFolder, mode);
if (!changed)
return;
node.FilterMode = mode;
ResetChildrenBranchNodeFilterMode(repo, node, isLocal);
}
var parentType = isLocal ? Models.FilterType.LocalBranchFolder : Models.FilterType.RemoteBranchFolder;
var cur = node;
do
{
var lastSepIdx = cur.Path.LastIndexOf('/');
if (lastSepIdx <= 0)
break;
var parentPath = cur.Path.Substring(0, lastSepIdx);
var parent = FindParentNode(tree, parentPath);
if (parent == null)
break;
repo.Settings.UpdateHistoriesFilter(parent.Path, parentType, Models.FilterMode.None);
parent.FilterMode = Models.FilterMode.None;
cur = parent;
} while (true);
Task.Run(repo.RefreshCommits);
}
private void ResetChildrenBranchNodeFilterMode(ViewModels.Repository repo, ViewModels.BranchTreeNode node, bool isLocal)
{
foreach (var child in node.Children)
{
child.FilterMode = Models.FilterMode.None;
if (child.IsBranch)
{
var type = isLocal ? Models.FilterType.LocalBranch : Models.FilterType.RemoteBranch;
repo.Settings.UpdateHistoriesFilter(child.Path, type, Models.FilterMode.None);
}
else
{
var type = isLocal ? Models.FilterType.LocalBranchFolder : Models.FilterType.RemoteBranchFolder;
repo.Settings.UpdateHistoriesFilter(child.Path, type, Models.FilterMode.None);
ResetChildrenBranchNodeFilterMode(repo, child, isLocal);
}
}
}
private ViewModels.BranchTreeNode FindParentNode(List<ViewModels.BranchTreeNode> nodes, string parent)
{
foreach (var node in nodes)
{
if (node.IsBranch)
continue;
if (node.Path.Equals(parent, StringComparison.Ordinal))
return node;
if (parent.StartsWith(node.Path, StringComparison.Ordinal))
{
var founded = FindParentNode(node.Children, parent);
if (founded != null)
return founded;
}
}
return null;
}
}
}

View file

@ -256,7 +256,7 @@
<ListBox Grid.Row="7" <ListBox Grid.Row="7"
x:Name="SubmoduleList" x:Name="SubmoduleList"
Height="0" Height="0"
Margin="12,0,4,0" Margin="8,0,4,0"
Classes="repo_left_content_list" Classes="repo_left_content_list"
ItemsSource="{Binding VisibleSubmodules}" ItemsSource="{Binding VisibleSubmodules}"
SelectionMode="Single" SelectionMode="Single"
@ -312,7 +312,7 @@
<ListBox Grid.Row="9" <ListBox Grid.Row="9"
x:Name="WorktreeList" x:Name="WorktreeList"
Height="0" Height="0"
Margin="12,0,4,0" Margin="8,0,4,0"
Classes="repo_left_content_list" Classes="repo_left_content_list"
ItemsSource="{Binding Worktrees}" ItemsSource="{Binding Worktrees}"
SelectionMode="Single" SelectionMode="Single"
@ -577,14 +577,14 @@
<Border.IsVisible> <Border.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}"> <MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="SelectedViewIndex" Converter="{x:Static c:IntConverters.IsZero}"/> <Binding Path="SelectedViewIndex" Converter="{x:Static c:IntConverters.IsZero}"/>
<Binding Path="Settings.HistoriesFilters.Count" Converter="{x:Static c:IntConverters.IsGreaterThanZero}"/> <Binding Path="Settings.Filters.Count" Converter="{x:Static c:IntConverters.IsGreaterThanZero}"/>
</MultiBinding> </MultiBinding>
</Border.IsVisible> </Border.IsVisible>
<Grid Height="28" ColumnDefinitions="Auto,*,Auto"> <Grid Height="28" ColumnDefinitions="Auto,*,Auto">
<TextBlock Grid.Column="0" Margin="8,0,0,0" Classes="table_header" Text="{DynamicResource Text.Repository.FilterCommitPrefix}"/> <TextBlock Grid.Column="0" Margin="8,0,0,0" Classes="table_header" Text="{DynamicResource Text.Repository.FilterCommitPrefix}"/>
<ItemsControl Grid.Column="1" Margin="8,0,0,0" ItemsSource="{Binding Settings.HistoriesFilters}"> <ItemsControl Grid.Column="1" Margin="8,0,0,0" ItemsSource="{Binding Settings.Filters}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" VerticalAlignment="Center"/> <VirtualizingStackPanel Orientation="Horizontal" VerticalAlignment="Center"/>
@ -592,24 +592,10 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate DataType="m:Filter"> <DataTemplate>
<Grid Height="20" Margin="0,0,6,0"> <Border Height="20" Margin="0,0,6,0" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}" CornerRadius="12">
<Border BorderThickness="1" <TextBlock Classes="primary" Text="{Binding Converter={x:Static c:StringConverters.TrimRefsPrefix}}" Margin="8,0"/>
BorderBrush="Green" </Border>
CornerRadius="12"
IsVisible="{Binding Mode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:FilterMode.Included}}"/>
<Border BorderThickness="1"
BorderBrush="Red"
CornerRadius="12"
IsVisible="{Binding Mode, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:FilterMode.Excluded}}"/>
<StackPanel Orientation="Horizontal" Margin="8,0">
<Path Width="10" Height="10" Data="{StaticResource Icons.Branch}" IsVisible="{Binding IsBranch}"/>
<Path Width="10" Height="10" Data="{StaticResource Icons.Tag}" IsVisible="{Binding !IsBranch}"/>
<TextBlock Classes="primary" Text="{Binding Pattern, Converter={x:Static c:StringConverters.TrimRefsPrefix}}" Margin="4,0,0,0"/>
</StackPanel>
</Grid>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>

View file

@ -12,10 +12,6 @@
<Style Selector="ListBoxItem"> <Style Selector="ListBoxItem">
<Setter Property="CornerRadius" Value="4"/> <Setter Property="CornerRadius" Value="4"/>
</Style> </Style>
<Style Selector="ListBoxItem:pointerover v|FilterModeSwitchButton">
<Setter Property="IsNoneVisible" Value="True"/>
</Style>
</UserControl.Styles> </UserControl.Styles>
<UserControl.DataTemplates> <UserControl.DataTemplates>
@ -48,13 +44,14 @@
Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}" Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}"
Margin="8,0,0,0"/> Margin="8,0,0,0"/>
<ContentControl Grid.Column="3" Content="{Binding Tag}"> <ToggleButton Grid.Column="3"
<ContentControl.DataTemplates> Classes="filter"
<DataTemplate DataType="m:Tag"> Margin="0,0,8,0"
<v:FilterModeSwitchButton Mode="{Binding FilterMode}"/> Background="Transparent"
</DataTemplate> Click="OnToggleFilterClicked"
</ContentControl.DataTemplates> IsChecked="{Binding IsFiltered, Mode=TwoWay}"
</ContentControl> IsVisible="{Binding !IsFolder}"
ToolTip.Tip="{DynamicResource Text.Filter}"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
@ -63,28 +60,32 @@
<DataTemplate DataType="vm:TagCollectionAsList"> <DataTemplate DataType="vm:TagCollectionAsList">
<ListBox Classes="repo_left_content_list" <ListBox Classes="repo_left_content_list"
Margin="12,0,0,0"
ItemsSource="{Binding Tags}" ItemsSource="{Binding Tags}"
SelectionMode="Single" SelectionMode="Single"
SelectionChanged="OnRowSelectionChanged"> SelectionChanged="OnRowSelectionChanged">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate DataType="m:Tag"> <DataTemplate DataType="m:Tag">
<Grid ColumnDefinitions="Auto,*,20" <Grid ColumnDefinitions="Auto,*,Auto"
Background="Transparent" Background="Transparent"
ContextRequested="OnRowContextRequested" ContextRequested="OnRowContextRequested"
ToolTip.Tip="{Binding Message}"> ToolTip.Tip="{Binding Message}">
<Path Grid.Column="0" <Path Grid.Column="0"
Margin="4,0,0,0" Width="10" Height="10"
Width="12" Height="12" Margin="8,0,0,0"
Data="{StaticResource Icons.Tag}"/> Data="{StaticResource Icons.Tag}"/>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="1"
Classes="primary" Classes="primary"
Text="{Binding Name}" Text="{Binding Name}"
Margin="8,0,0,0" Margin="8,0,0,0"/>
TextTrimming="CharacterEllipsis"/>
<v:FilterModeSwitchButton Grid.Column="2" Mode="{Binding FilterMode}"/> <ToggleButton Grid.Column="2"
Classes="filter"
Margin="0,0,8,0"
Background="Transparent"
Click="OnToggleFilterClicked"
IsChecked="{Binding IsFiltered, Mode=TwoWay}"
ToolTip.Tip="{DynamicResource Text.Filter}"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>

View file

@ -65,7 +65,7 @@ namespace SourceGit.Views
} }
if (node.Tag != null) if (node.Tag != null)
CreateContent(new Thickness(0, 0, 0, 0), "Icons.Tag"); CreateContent(new Thickness(0, 2, 0, 0), "Icons.Tag");
else if (node.IsExpanded) else if (node.IsExpanded)
CreateContent(new Thickness(0, 2, 0, 0), "Icons.Folder.Open"); CreateContent(new Thickness(0, 2, 0, 0), "Icons.Folder.Open");
else else
@ -247,6 +247,23 @@ namespace SourceGit.Views
} }
} }
private void OnToggleFilterClicked(object sender, RoutedEventArgs e)
{
if (sender is ToggleButton toggle && DataContext is ViewModels.Repository repo)
{
var target = null as Models.Tag;
if (toggle.DataContext is ViewModels.TagTreeNode node)
target = node.Tag;
else if (toggle.DataContext is Models.Tag tag)
target = tag;
if (target != null)
repo.UpdateFilters([target.Name], toggle.IsChecked == true);
}
e.Handled = true;
}
private void MakeTreeRows(List<ViewModels.TagTreeNode> rows, List<ViewModels.TagTreeNode> nodes) private void MakeTreeRows(List<ViewModels.TagTreeNode> rows, List<ViewModels.TagTreeNode> nodes)
{ {
foreach (var node in nodes) foreach (var node in nodes)