fix<Repository, History>: wrong context menu IsEnabled state.

* 'Pull' should always enabled for local branch with remote upstream
* 'Discard All Changes' for current branch should only be enabled when there's at least one changes
* 'Fast Forward' should check if target local branch has any commit ahead of it's upstream
This commit is contained in:
leo 2024-03-01 19:12:22 +08:00
parent 280ef60111
commit 307e5a5ef0
2 changed files with 3 additions and 5 deletions

View file

@ -272,14 +272,13 @@ namespace SourceGit.ViewModels {
submenu.Icon = App.CreateMenuIcon("Icons.Branch"); submenu.Icon = App.CreateMenuIcon("Icons.Branch");
submenu.Header = current.Name; submenu.Header = current.Name;
var dirty = !string.IsNullOrEmpty(current.UpstreamTrackStatus);
if (!string.IsNullOrEmpty(current.Upstream)) { if (!string.IsNullOrEmpty(current.Upstream)) {
var upstream = current.Upstream.Substring(13); var upstream = current.Upstream.Substring(13);
var fastForward = new MenuItem(); var fastForward = new MenuItem();
fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream); fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream);
fastForward.Icon = App.CreateMenuIcon("Icons.FastForward"); fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
fastForward.IsEnabled = dirty; fastForward.IsEnabled = !string.IsNullOrEmpty(current.UpstreamTrackStatus) && current.UpstreamTrackStatus.IndexOf('↑') < 0; ;
fastForward.Click += (o, e) => { fastForward.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Merge(_repo, upstream, current.Name)); if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Merge(_repo, upstream, current.Name));
e.Handled = true; e.Handled = true;
@ -289,7 +288,6 @@ namespace SourceGit.ViewModels {
var pull = new MenuItem(); var pull = new MenuItem();
pull.Header = new Views.NameHighlightedTextBlock("BranchCM.Pull", upstream); pull.Header = new Views.NameHighlightedTextBlock("BranchCM.Pull", upstream);
pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Icon = App.CreateMenuIcon("Icons.Pull");
pull.IsEnabled = dirty;
pull.Click += (o, e) => { pull.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(_repo, null)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(_repo, null));
e.Handled = true; e.Handled = true;
@ -300,7 +298,7 @@ namespace SourceGit.ViewModels {
var push = new MenuItem(); var push = new MenuItem();
push.Header = new Views.NameHighlightedTextBlock("BranchCM.Push", current.Name); push.Header = new Views.NameHighlightedTextBlock("BranchCM.Push", current.Name);
push.Icon = App.CreateMenuIcon("Icons.Push"); push.Icon = App.CreateMenuIcon("Icons.Push");
push.IsEnabled = _repo.Remotes.Count > 0 && dirty; push.IsEnabled = _repo.Remotes.Count > 0;
push.Click += (o, e) => { push.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Push(_repo, current)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Push(_repo, current));
e.Handled = true; e.Handled = true;

View file

@ -597,6 +597,7 @@ namespace SourceGit.ViewModels {
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("BranchCM.DiscardAll"); discard.Header = App.Text("BranchCM.DiscardAll");
discard.Icon = App.CreateMenuIcon("Icons.Undo"); discard.Icon = App.CreateMenuIcon("Icons.Undo");
discard.IsEnabled = _workingCopy.Count > 0;
discard.Click += (o, e) => { discard.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Discard(this)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Discard(this));
e.Handled = true; e.Handled = true;
@ -619,7 +620,6 @@ namespace SourceGit.ViewModels {
var pull = new MenuItem(); var pull = new MenuItem();
pull.Header = new Views.NameHighlightedTextBlock("BranchCM.Pull", upstream); pull.Header = new Views.NameHighlightedTextBlock("BranchCM.Pull", upstream);
pull.Icon = App.CreateMenuIcon("Icons.Pull"); pull.Icon = App.CreateMenuIcon("Icons.Pull");
pull.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus);
pull.Click += (o, e) => { pull.Click += (o, e) => {
if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(this, null)); if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(this, null));
e.Handled = true; e.Handled = true;