feature: add context menu to switch histories filter mode to selected commit

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2024-11-21 20:50:51 +08:00
parent e6e1e4e82e
commit 8bd5bd864e
No known key found for this signature in database
5 changed files with 121 additions and 0 deletions

View file

@ -542,6 +542,7 @@
<x:String x:Key="Text.Repository.EnableReflog" xml:space="preserve">Enable '--reflog' Option</x:String>
<x:String x:Key="Text.Repository.Explore" xml:space="preserve">Open in File Browser</x:String>
<x:String x:Key="Text.Repository.Filter" xml:space="preserve">Search Branches/Tags/Submodules</x:String>
<x:String x:Key="Text.Repository.FilterCommits" xml:space="preserve">Visibility in Graph</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">Unset</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">Hide in commit graph</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">Filter in commit graph</x:String>

View file

@ -546,6 +546,7 @@
<x:String x:Key="Text.Repository.EnableReflog" xml:space="preserve">启用 --reflog 选项</x:String>
<x:String x:Key="Text.Repository.Explore" xml:space="preserve">在文件浏览器中打开</x:String>
<x:String x:Key="Text.Repository.Filter" xml:space="preserve">快速查找分支/标签/子模块</x:String>
<x:String x:Key="Text.Repository.FilterCommits" xml:space="preserve">设置在列表中的可见性</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">不指定</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">在提交列表中隐藏</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">使用其对提交列表过滤</x:String>

View file

@ -545,6 +545,7 @@
<x:String x:Key="Text.Repository.EnableReflog" xml:space="preserve">啟用 [--reflog] 選項</x:String>
<x:String x:Key="Text.Repository.Explore" xml:space="preserve">在檔案瀏覽器中開啟</x:String>
<x:String x:Key="Text.Repository.Filter" xml:space="preserve">快速搜尋分支/標籤/子模組</x:String>
<x:String x:Key="Text.Repository.FilterCommits" xml:space="preserve">設定在列表中的可視性</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Default" xml:space="preserve">不指定</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Exclude" xml:space="preserve">在提交清單中隱藏</x:String>
<x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">使用其來篩選提交清單</x:String>

View file

@ -703,12 +703,117 @@ namespace SourceGit.ViewModels
return menu;
}
private Models.FilterMode GetFilterMode(string pattern)
{
foreach (var filter in _repo.Settings.HistoriesFilters)
{
if (filter.Pattern.Equals(pattern, StringComparison.Ordinal))
return filter.Mode;
}
return Models.FilterMode.None;
}
private void FillBranchVisibilityMenu(MenuItem submenu, Models.Branch branch)
{
var visibility = new MenuItem();
visibility.Icon = App.CreateMenuIcon("Icons.Eye");
visibility.Header = App.Text("Repository.FilterCommits");
var exclude = new MenuItem();
exclude.Icon = App.CreateMenuIcon("Icons.EyeClose");
exclude.Header = App.Text("Repository.FilterCommits.Exclude");
exclude.Click += (_, e) =>
{
_repo.SetBranchFilterMode(branch, Models.FilterMode.Excluded);
e.Handled = true;
};
var filterMode = GetFilterMode(branch.FullName);
if (filterMode == Models.FilterMode.None)
{
var include = new MenuItem();
include.Icon = App.CreateMenuIcon("Icons.Filter");
include.Header = App.Text("Repository.FilterCommits.Include");
include.Click += (_, e) =>
{
_repo.SetBranchFilterMode(branch, Models.FilterMode.Included);
e.Handled = true;
};
visibility.Items.Add(include);
visibility.Items.Add(exclude);
}
else
{
var unset = new MenuItem();
unset.Header = App.Text("Repository.FilterCommits.Default");
unset.Click += (_, e) =>
{
_repo.SetBranchFilterMode(branch, Models.FilterMode.None);
e.Handled = true;
};
visibility.Items.Add(exclude);
visibility.Items.Add(unset);
}
submenu.Items.Add(visibility);
submenu.Items.Add(new MenuItem() { Header = "-" });
}
private void FillTagVisibilityMenu(MenuItem submenu, Models.Tag tag)
{
var visibility = new MenuItem();
visibility.Icon = App.CreateMenuIcon("Icons.Eye");
visibility.Header = App.Text("Repository.FilterCommits");
var exclude = new MenuItem();
exclude.Icon = App.CreateMenuIcon("Icons.EyeClose");
exclude.Header = App.Text("Repository.FilterCommits.Exclude");
exclude.Click += (_, e) =>
{
_repo.SetTagFilterMode(tag, Models.FilterMode.Excluded);
e.Handled = true;
};
var filterMode = GetFilterMode(tag.Name);
if (filterMode == Models.FilterMode.None)
{
var include = new MenuItem();
include.Icon = App.CreateMenuIcon("Icons.Filter");
include.Header = App.Text("Repository.FilterCommits.Include");
include.Click += (_, e) =>
{
_repo.SetTagFilterMode(tag, Models.FilterMode.Included);
e.Handled = true;
};
visibility.Items.Add(include);
visibility.Items.Add(exclude);
}
else
{
var unset = new MenuItem();
unset.Header = App.Text("Repository.FilterCommits.Default");
unset.Click += (_, e) =>
{
_repo.SetTagFilterMode(tag, Models.FilterMode.None);
e.Handled = true;
};
visibility.Items.Add(exclude);
visibility.Items.Add(unset);
}
submenu.Items.Add(visibility);
submenu.Items.Add(new MenuItem() { Header = "-" });
}
private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current)
{
var submenu = new MenuItem();
submenu.Icon = App.CreateMenuIcon("Icons.Branch");
submenu.Header = current.Name;
FillBranchVisibilityMenu(submenu, current);
if (!string.IsNullOrEmpty(current.Upstream))
{
var upstream = current.Upstream.Substring(13);
@ -786,6 +891,8 @@ namespace SourceGit.ViewModels
submenu.Icon = App.CreateMenuIcon("Icons.Branch");
submenu.Header = branch.Name;
FillBranchVisibilityMenu(submenu, branch);
var checkout = new MenuItem();
checkout.Header = new Views.NameHighlightedTextBlock("BranchCM.Checkout", branch.Name);
checkout.Icon = App.CreateMenuIcon("Icons.Check");
@ -858,6 +965,8 @@ namespace SourceGit.ViewModels
submenu.Icon = App.CreateMenuIcon("Icons.Branch");
submenu.Header = name;
FillBranchVisibilityMenu(submenu, branch);
var checkout = new MenuItem();
checkout.Header = new Views.NameHighlightedTextBlock("BranchCM.Checkout", name);
checkout.Icon = App.CreateMenuIcon("Icons.Check");
@ -903,6 +1012,8 @@ namespace SourceGit.ViewModels
submenu.Icon = App.CreateMenuIcon("Icons.Tag");
submenu.MinWidth = 200;
FillTagVisibilityMenu(submenu, tag);
var push = new MenuItem();
push.Header = new Views.NameHighlightedTextBlock("TagCM.Push", tag.Name);
push.Icon = App.CreateMenuIcon("Icons.Push");

View file

@ -707,6 +707,13 @@ namespace SourceGit.ViewModels
RefreshHistoriesFilters();
}
public void SetBranchFilterMode(Models.Branch branch, Models.FilterMode mode)
{
var node = FindBranchNode(branch.IsLocal ? _localBranchTrees : _remoteBranchTrees, branch.FullName);
if (node != null)
SetBranchFilterMode(node, mode);
}
public void SetBranchFilterMode(BranchTreeNode node, Models.FilterMode mode)
{
var isLocal = node.Path.StartsWith("refs/heads/", StringComparison.Ordinal);