From 0b13c3ca87313a94d5c7972db39b7e64fbea5d67 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 15 Sep 2023 17:46:21 +0200 Subject: [PATCH] Disabled paste when there are no copied commits --- pkg/gui/controllers/helpers/cherry_pick_helper.go | 4 ++++ pkg/gui/controllers/local_commits_controller.go | 15 ++++++++++++--- pkg/i18n/english.go | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 2e8a11f7d..e27e469b6 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -85,6 +85,10 @@ func (self *CherryPickHelper) Paste() error { }) } +func (self *CherryPickHelper) CanPaste() bool { + return self.getData().Active() +} + func (self *CherryPickHelper) Reset() error { self.getData().ContextKey = "" self.getData().CherryPickedCommits = nil diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index a71968795..2c4794195 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -110,9 +110,10 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ Description: self.c.Tr.MoveUpCommit, }, { - Key: opts.GetKey(opts.Config.Commits.PasteCommits), - Handler: self.paste, - Description: self.c.Tr.PasteCommits, + Key: opts.GetKey(opts.Config.Commits.PasteCommits), + Handler: self.paste, + GetDisabledReason: self.getDisabledReasonForPaste, + Description: self.c.Tr.PasteCommits, }, { Key: opts.GetKey(opts.Config.Commits.MarkCommitAsBaseForRebase), @@ -1001,6 +1002,14 @@ func (self *LocalCommitsController) paste() error { return self.c.Helpers().CherryPick.Paste() } +func (self *LocalCommitsController) getDisabledReasonForPaste() string { + if !self.c.Helpers().CherryPick.CanPaste() { + return self.c.Tr.NoCopiedCommits + } + + return "" +} + func (self *LocalCommitsController) markAsBaseCommit(commit *models.Commit) error { if commit.Sha == self.c.Modes().MarkedBaseCommit.GetSha() { // Reset when invoking it again on the marked commit diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 0f30f72f7..0aa1baeb8 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -612,6 +612,7 @@ type TranslationSet struct { PleaseGoToURL string DisabledMenuItemPrefix string NoCommitSelected string + NoCopiedCommits string Actions Actions Bisect Bisect Log Log @@ -1403,6 +1404,7 @@ func EnglishTranslationSet() TranslationSet { PleaseGoToURL: "Please go to {{.url}}", DisabledMenuItemPrefix: "Disabled: ", NoCommitSelected: "No commit selected", + NoCopiedCommits: "No copied commits", Actions: Actions{ // TODO: combine this with the original keybinding descriptions (those are all in lowercase atm) CheckoutCommit: "Checkout commit",