From 307e5a5ef00f8ad099493cd3f479cd205d6df9f9 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 1 Mar 2024 19:12:22 +0800 Subject: [PATCH] fix: 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 --- src/ViewModels/Histories.cs | 6 ++---- src/ViewModels/Repository.cs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index d945368e..578d6300 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -272,14 +272,13 @@ namespace SourceGit.ViewModels { submenu.Icon = App.CreateMenuIcon("Icons.Branch"); submenu.Header = current.Name; - var dirty = !string.IsNullOrEmpty(current.UpstreamTrackStatus); if (!string.IsNullOrEmpty(current.Upstream)) { var upstream = current.Upstream.Substring(13); var fastForward = new MenuItem(); fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream); fastForward.Icon = App.CreateMenuIcon("Icons.FastForward"); - fastForward.IsEnabled = dirty; + fastForward.IsEnabled = !string.IsNullOrEmpty(current.UpstreamTrackStatus) && current.UpstreamTrackStatus.IndexOf('↑') < 0; ; fastForward.Click += (o, e) => { if (PopupHost.CanCreatePopup()) PopupHost.ShowAndStartPopup(new Merge(_repo, upstream, current.Name)); e.Handled = true; @@ -289,7 +288,6 @@ namespace SourceGit.ViewModels { var pull = new MenuItem(); pull.Header = new Views.NameHighlightedTextBlock("BranchCM.Pull", upstream); pull.Icon = App.CreateMenuIcon("Icons.Pull"); - pull.IsEnabled = dirty; pull.Click += (o, e) => { if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(_repo, null)); e.Handled = true; @@ -300,7 +298,7 @@ namespace SourceGit.ViewModels { var push = new MenuItem(); push.Header = new Views.NameHighlightedTextBlock("BranchCM.Push", current.Name); push.Icon = App.CreateMenuIcon("Icons.Push"); - push.IsEnabled = _repo.Remotes.Count > 0 && dirty; + push.IsEnabled = _repo.Remotes.Count > 0; push.Click += (o, e) => { if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Push(_repo, current)); e.Handled = true; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 6caf4f12..c19d0a25 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -597,6 +597,7 @@ namespace SourceGit.ViewModels { var discard = new MenuItem(); discard.Header = App.Text("BranchCM.DiscardAll"); discard.Icon = App.CreateMenuIcon("Icons.Undo"); + discard.IsEnabled = _workingCopy.Count > 0; discard.Click += (o, e) => { if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Discard(this)); e.Handled = true; @@ -619,7 +620,6 @@ namespace SourceGit.ViewModels { var pull = new MenuItem(); pull.Header = new Views.NameHighlightedTextBlock("BranchCM.Pull", upstream); pull.Icon = App.CreateMenuIcon("Icons.Pull"); - pull.IsEnabled = !string.IsNullOrEmpty(branch.UpstreamTrackStatus); pull.Click += (o, e) => { if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Pull(this, null)); e.Handled = true;