From 28c93da73b4be72562363190baa22b3d661754a2 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 14 Nov 2024 21:12:18 +0800 Subject: [PATCH] ux: show `Unset` menu item only if it is necessary (#690) Signed-off-by: leo --- src/Views/FilterModeSwitchButton.axaml.cs | 73 +++++++++++------------ 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/src/Views/FilterModeSwitchButton.axaml.cs b/src/Views/FilterModeSwitchButton.axaml.cs index f253158b..5b1f1b2b 100644 --- a/src/Views/FilterModeSwitchButton.axaml.cs +++ b/src/Views/FilterModeSwitchButton.axaml.cs @@ -71,19 +71,25 @@ namespace SourceGit.Views if (button == null) return; + var menu = new ContextMenu(); + var mode = Models.FilterMode.None; if (DataContext is Models.Tag tag) { - var mode = tag.FilterMode; + mode = tag.FilterMode; - var none = new MenuItem(); - none.Icon = App.CreateMenuIcon("Icons.Eye"); - none.Header = App.Text("Repository.FilterCommits.Default"); - none.IsEnabled = mode != Models.FilterMode.None; - none.Click += (_, ev) => + if (mode != Models.FilterMode.None) { - UpdateTagFilterMode(repo, tag, Models.FilterMode.None); - ev.Handled = true; - }; + var unset = new MenuItem(); + unset.Header = App.Text("Repository.FilterCommits.Default"); + unset.Click += (_, ev) => + { + UpdateTagFilterMode(repo, tag, Models.FilterMode.None); + ev.Handled = true; + }; + + menu.Items.Add(unset); + menu.Items.Add(new MenuItem() { Header = "-" }); + } var include = new MenuItem(); include.Icon = App.CreateMenuIcon("Icons.Filter"); @@ -105,32 +111,26 @@ namespace SourceGit.Views 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; + mode = node.FilterMode; - var none = new MenuItem(); - none.Icon = App.CreateMenuIcon("Icons.Eye"); - none.Header = App.Text("Repository.FilterCommits.Default"); - none.IsEnabled = mode != Models.FilterMode.None; - none.Click += (_, ev) => + if (mode != Models.FilterMode.None) { - UpdateBranchFilterMode(repo, node, Models.FilterMode.None); - ev.Handled = true; - }; + var unset = new MenuItem(); + unset.Header = App.Text("Repository.FilterCommits.Default"); + unset.Click += (_, ev) => + { + UpdateBranchFilterMode(repo, node, Models.FilterMode.None); + ev.Handled = true; + }; + + menu.Items.Add(unset); + menu.Items.Add(new MenuItem() { Header = "-" }); + } var include = new MenuItem(); include.Icon = App.CreateMenuIcon("Icons.Filter"); @@ -152,20 +152,17 @@ namespace SourceGit.Views 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); } + if (mode == Models.FilterMode.None) + { + IsContextMenuOpening = true; + menu.Closed += (_, _) => IsContextMenuOpening = false; + } + + menu.Open(button); e.Handled = true; }