diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml
index 142d3fae..bf7d660e 100644
--- a/src/Resources/Locales/en_US.axaml
+++ b/src/Resources/Locales/en_US.axaml
@@ -342,6 +342,7 @@
Configure this repository
CONTINUE
Open In File Browser
+ Filter Branches
LOCAL BRANCHES
Navigate To HEAD
Create Branch
diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml
index 1739af5c..9f464b79 100644
--- a/src/Resources/Locales/zh_CN.axaml
+++ b/src/Resources/Locales/zh_CN.axaml
@@ -342,6 +342,7 @@
配置本仓库
下一步
在文件浏览器中打开
+ 过滤显示分支
本地分支
定位HEAD
新建分支
diff --git a/src/Models/BranchTreeNode.cs b/src/ViewModels/BranchTreeNode.cs
similarity index 86%
rename from src/Models/BranchTreeNode.cs
rename to src/ViewModels/BranchTreeNode.cs
index 66296519..23e0b90a 100644
--- a/src/Models/BranchTreeNode.cs
+++ b/src/ViewModels/BranchTreeNode.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using Avalonia.Collections;
-namespace SourceGit.Models
+namespace SourceGit.ViewModels
{
public enum BranchTreeNodeType
{
@@ -23,12 +23,12 @@ namespace SourceGit.Models
public bool IsUpstreamTrackStatusVisible
{
- get => IsBranch && !string.IsNullOrEmpty((Backend as Branch).UpstreamTrackStatus);
+ get => IsBranch && !string.IsNullOrEmpty((Backend as Models.Branch).UpstreamTrackStatus);
}
public string UpstreamTrackStatus
{
- get => Type == BranchTreeNodeType.Branch ? (Backend as Branch).UpstreamTrackStatus : "";
+ get => Type == BranchTreeNodeType.Branch ? (Backend as Models.Branch).UpstreamTrackStatus : "";
}
public bool IsRemote
@@ -48,7 +48,7 @@ namespace SourceGit.Models
public bool IsCurrent
{
- get => IsBranch && (Backend as Branch).IsCurrent;
+ get => IsBranch && (Backend as Models.Branch).IsCurrent;
}
public class Builder
@@ -56,7 +56,7 @@ namespace SourceGit.Models
public List Locals => _locals;
public List Remotes => _remotes;
- public void Run(List branches, List remotes)
+ public void Run(List branches, List remotes, bool bForceExpanded)
{
foreach (var remote in remotes)
{
@@ -66,7 +66,7 @@ namespace SourceGit.Models
Name = remote.Name,
Type = BranchTreeNodeType.Remote,
Backend = remote,
- IsExpanded = _expanded.Contains(path),
+ IsExpanded = bForceExpanded || _expanded.Contains(path),
};
_maps.Add(path, node);
@@ -78,13 +78,13 @@ namespace SourceGit.Models
var isFiltered = _filters.Contains(branch.FullName);
if (branch.IsLocal)
{
- MakeBranchNode(branch, _locals, "local", isFiltered);
+ MakeBranchNode(branch, _locals, "local", isFiltered, bForceExpanded);
}
else
{
var remote = _remotes.Find(x => x.Name == branch.Remote);
if (remote != null)
- MakeBranchNode(branch, remote.Children, $"remote/{remote.Name}", isFiltered);
+ MakeBranchNode(branch, remote.Children, $"remote/{remote.Name}", isFiltered, bForceExpanded);
}
}
@@ -113,7 +113,7 @@ namespace SourceGit.Models
}
}
- private void MakeBranchNode(Branch branch, List roots, string prefix, bool isFiltered)
+ private void MakeBranchNode(Models.Branch branch, List roots, string prefix, bool isFiltered, bool bForceExpanded)
{
var subs = branch.Name.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
@@ -132,8 +132,8 @@ namespace SourceGit.Models
}
BranchTreeNode lastFolder = null;
- string path = prefix;
- for (int i = 0; i < subs.Length - 1; i++)
+ var path = prefix;
+ for (var i = 0; i < subs.Length - 1; i++)
{
path = string.Concat(path, "/", subs[i]);
if (_maps.TryGetValue(path, out var value))
@@ -146,7 +146,7 @@ namespace SourceGit.Models
{
Name = subs[i],
Type = BranchTreeNodeType.Folder,
- IsExpanded = branch.IsCurrent || _expanded.Contains(path),
+ IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(path),
};
roots.Add(lastFolder);
_maps.Add(path, lastFolder);
@@ -157,7 +157,7 @@ namespace SourceGit.Models
{
Name = subs[i],
Type = BranchTreeNodeType.Folder,
- IsExpanded = branch.IsCurrent || _expanded.Contains(path),
+ IsExpanded = bForceExpanded || branch.IsCurrent || _expanded.Contains(path),
};
_maps.Add(path, folder);
lastFolder.Children.Add(folder);
@@ -186,7 +186,7 @@ namespace SourceGit.Models
}
else
{
- return (int)(l.Type) - (int)(r.Type);
+ return (int)l.Type - (int)r.Type;
}
});
diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs
index 0e67f11b..8a81c595 100644
--- a/src/ViewModels/Repository.cs
+++ b/src/ViewModels/Repository.cs
@@ -89,6 +89,21 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _selectedView, value);
}
+ [JsonIgnore]
+ public string SearchBranchFilter
+ {
+ get => _searchBranchFilter;
+ set
+ {
+ if (SetProperty(ref _searchBranchFilter, value))
+ {
+ var builder = BuildBranchTree(_branches, _remotes);
+ LocalBranchTrees = builder.Locals;
+ RemoteBranchTrees = builder.Remotes;
+ }
+ }
+ }
+
[JsonIgnore]
public List Remotes
{
@@ -104,14 +119,14 @@ namespace SourceGit.ViewModels
}
[JsonIgnore]
- public List LocalBranchTrees
+ public List LocalBranchTrees
{
get => _localBranchTrees;
private set => SetProperty(ref _localBranchTrees, value);
}
[JsonIgnore]
- public List RemoteBranchTrees
+ public List RemoteBranchTrees
{
get => _remoteBranchTrees;
private set => SetProperty(ref _remoteBranchTrees, value);
@@ -422,6 +437,11 @@ namespace SourceGit.ViewModels
SearchedCommits = visible;
}
+ public void ClearSearchBranchFilter()
+ {
+ SearchBranchFilter = string.Empty;
+ }
+
public void SetWatcherEnabled(bool enabled)
{
if (_watcher != null)
@@ -533,12 +553,7 @@ namespace SourceGit.ViewModels
{
var branches = new Commands.QueryBranches(FullPath).Result();
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);
+ var builder = BuildBranchTree(branches, remotes);
Dispatcher.UIThread.Invoke(() =>
{
@@ -1354,6 +1369,32 @@ namespace SourceGit.ViewModels
return menu;
}
+ private BranchTreeNode.Builder BuildBranchTree(List branches, List remotes)
+ {
+ var builder = new BranchTreeNode.Builder();
+ builder.SetFilters(Filters);
+
+ if (string.IsNullOrEmpty(_searchBranchFilter))
+ {
+ builder.CollectExpandedNodes(_localBranchTrees, true);
+ builder.CollectExpandedNodes(_remoteBranchTrees, false);
+ builder.Run(branches, remotes, false);
+ }
+ else
+ {
+ var visibles = new List();
+ foreach (var b in branches)
+ {
+ if (b.FullName.Contains(_searchBranchFilter, StringComparison.OrdinalIgnoreCase))
+ visibles.Add(b);
+ }
+
+ builder.Run(visibles, remotes, true);
+ }
+
+ return builder;
+ }
+
private string _fullpath = string.Empty;
private string _gitDir = string.Empty;
private Models.GitFlow _gitflow = new Models.GitFlow();
@@ -1372,10 +1413,12 @@ namespace SourceGit.ViewModels
private bool _isTagGroupExpanded = false;
private bool _isSubmoduleGroupExpanded = false;
+ private string _searchBranchFilter = string.Empty;
+
private List _remotes = new List();
private List _branches = new List();
- private List _localBranchTrees = new List();
- private List _remoteBranchTrees = new List();
+ private List _localBranchTrees = new List();
+ private List _remoteBranchTrees = new List();
private List _tags = new List();
private List _submodules = new List();
private bool _canCommitWithPush = false;
diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml
index c854faa2..c455ec37 100644
--- a/src/Views/Repository.axaml
+++ b/src/Views/Repository.axaml
@@ -109,7 +109,7 @@
-
+
@@ -159,9 +159,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
+
@@ -208,13 +241,13 @@
-
+
-
-
-
+
@@ -250,7 +283,7 @@
-
+
@@ -259,7 +292,7 @@
-
-
+
@@ -328,7 +361,7 @@
-