mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-26 21:17:20 -08:00
ux: show Unset
menu item only if it is necessary (#690)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
04697093a8
commit
28c93da73b
1 changed files with 35 additions and 38 deletions
|
@ -71,20 +71,26 @@ namespace SourceGit.Views
|
||||||
if (button == null)
|
if (button == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var menu = new ContextMenu();
|
||||||
|
var mode = Models.FilterMode.None;
|
||||||
if (DataContext is Models.Tag tag)
|
if (DataContext is Models.Tag tag)
|
||||||
{
|
{
|
||||||
var mode = tag.FilterMode;
|
mode = tag.FilterMode;
|
||||||
|
|
||||||
var none = new MenuItem();
|
if (mode != Models.FilterMode.None)
|
||||||
none.Icon = App.CreateMenuIcon("Icons.Eye");
|
{
|
||||||
none.Header = App.Text("Repository.FilterCommits.Default");
|
var unset = new MenuItem();
|
||||||
none.IsEnabled = mode != Models.FilterMode.None;
|
unset.Header = App.Text("Repository.FilterCommits.Default");
|
||||||
none.Click += (_, ev) =>
|
unset.Click += (_, ev) =>
|
||||||
{
|
{
|
||||||
UpdateTagFilterMode(repo, tag, Models.FilterMode.None);
|
UpdateTagFilterMode(repo, tag, Models.FilterMode.None);
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu.Items.Add(unset);
|
||||||
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||||
|
}
|
||||||
|
|
||||||
var include = new MenuItem();
|
var include = new MenuItem();
|
||||||
include.Icon = App.CreateMenuIcon("Icons.Filter");
|
include.Icon = App.CreateMenuIcon("Icons.Filter");
|
||||||
include.Header = App.Text("Repository.FilterCommits.Include");
|
include.Header = App.Text("Repository.FilterCommits.Include");
|
||||||
|
@ -105,33 +111,27 @@ namespace SourceGit.Views
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var menu = new ContextMenu();
|
|
||||||
menu.Items.Add(none);
|
|
||||||
menu.Items.Add(include);
|
menu.Items.Add(include);
|
||||||
menu.Items.Add(exclude);
|
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)
|
else if (DataContext is ViewModels.BranchTreeNode node)
|
||||||
{
|
{
|
||||||
var mode = node.FilterMode;
|
mode = node.FilterMode;
|
||||||
|
|
||||||
var none = new MenuItem();
|
if (mode != Models.FilterMode.None)
|
||||||
none.Icon = App.CreateMenuIcon("Icons.Eye");
|
{
|
||||||
none.Header = App.Text("Repository.FilterCommits.Default");
|
var unset = new MenuItem();
|
||||||
none.IsEnabled = mode != Models.FilterMode.None;
|
unset.Header = App.Text("Repository.FilterCommits.Default");
|
||||||
none.Click += (_, ev) =>
|
unset.Click += (_, ev) =>
|
||||||
{
|
{
|
||||||
UpdateBranchFilterMode(repo, node, Models.FilterMode.None);
|
UpdateBranchFilterMode(repo, node, Models.FilterMode.None);
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu.Items.Add(unset);
|
||||||
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||||
|
}
|
||||||
|
|
||||||
var include = new MenuItem();
|
var include = new MenuItem();
|
||||||
include.Icon = App.CreateMenuIcon("Icons.Filter");
|
include.Icon = App.CreateMenuIcon("Icons.Filter");
|
||||||
include.Header = App.Text("Repository.FilterCommits.Include");
|
include.Header = App.Text("Repository.FilterCommits.Include");
|
||||||
|
@ -152,10 +152,9 @@ namespace SourceGit.Views
|
||||||
ev.Handled = true;
|
ev.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var menu = new ContextMenu();
|
|
||||||
menu.Items.Add(none);
|
|
||||||
menu.Items.Add(include);
|
menu.Items.Add(include);
|
||||||
menu.Items.Add(exclude);
|
menu.Items.Add(exclude);
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == Models.FilterMode.None)
|
if (mode == Models.FilterMode.None)
|
||||||
{
|
{
|
||||||
|
@ -164,8 +163,6 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.Open(button);
|
menu.Open(button);
|
||||||
}
|
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue