diff options
-rw-r--r-- | pkg/gui/controllers/basic_commits_controller.go | 17 | ||||
-rw-r--r-- | pkg/i18n/english.go | 2 |
2 files changed, 16 insertions, 3 deletions
diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index 5a4e4190e..d2e494991 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -84,9 +84,10 @@ func (self *BasicCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ DisplayOnScreen: true, }, { - Key: opts.GetKey(opts.Config.Commits.CherryPickCopy), - Handler: self.withItem(self.copyRange), - Description: self.c.Tr.CherryPickCopy, + Key: opts.GetKey(opts.Config.Commits.CherryPickCopy), + Handler: self.withItem(self.copyRange), + GetDisabledReason: self.require(self.itemRangeSelected(self.canCopyCommits)), + Description: self.c.Tr.CherryPickCopy, Tooltip: utils.ResolvePlaceholderString(self.c.Tr.CherryPickCopyTooltip, map[string]string{ "paste": keybindings.Label(opts.Config.Commits.PasteCommits), @@ -292,6 +293,16 @@ func (self *BasicCommitsController) copyRange(*models.Commit) error { return self.c.Helpers().CherryPick.CopyRange(self.context.GetCommits(), self.context) } +func (self *BasicCommitsController) canCopyCommits(selectedCommits []*models.Commit, startIdx int, endIdx int) *types.DisabledReason { + for _, commit := range selectedCommits { + if commit.Sha == "" { + return &types.DisabledReason{Text: self.c.Tr.CannotCherryPickNonCommit, ShowErrorInPanel: true} + } + } + + return nil +} + func (self *BasicCommitsController) handleOldCherryPickKey() error { msg := utils.ResolvePlaceholderString(self.c.Tr.OldCherryPickKeyWarning, map[string]string{ diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 5ff58d085..8f54e4bd6 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -302,6 +302,7 @@ type TranslationSet struct { PasteCommits string SureCherryPick string CherryPick string + CannotCherryPickNonCommit string Donate string AskQuestion string PrevLine string @@ -1242,6 +1243,7 @@ func EnglishTranslationSet() TranslationSet { PasteCommits: "Paste (cherry-pick)", SureCherryPick: "Are you sure you want to cherry-pick the copied commits onto this branch?", CherryPick: "Cherry-pick", + CannotCherryPickNonCommit: "Cannot cherry-pick this kind of todo item", Donate: "Donate", AskQuestion: "Ask Question", PrevLine: "Select previous line", |