Skip to content

Commit

Permalink
Allow showing Disabled errors as error panel instead of toast
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaller committed Jan 14, 2024
1 parent 84e1d15 commit 83337d9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/gui/context/menu_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ func (self *MenuContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Bin

func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error {
if selectedItem != nil && selectedItem.DisabledReason != nil {
if selectedItem.DisabledReason.ShowErrorInPanel {
return self.c.ErrorMsg(selectedItem.DisabledReason.Text)
}

self.c.ErrorToast(self.c.Tr.DisabledMenuItemPrefix + selectedItem.DisabledReason.Text)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ func (self *LocalCommitsController) notMidRebase() *types.DisabledReason {
// For getting disabled reason
func (self *LocalCommitsController) canFindCommitForQuickStart() *types.DisabledReason {
if _, err := self.findCommitForQuickStartInteractiveRebase(); err != nil {
return &types.DisabledReason{Text: err.Error()}
return &types.DisabledReason{Text: err.Error(), ShowErrorInPanel: true}
}

return nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ func (gui *Gui) callKeybindingHandler(binding *types.Binding) error {
disabledReason = binding.GetDisabledReason()
}
if disabledReason != nil {
if disabledReason.ShowErrorInPanel {
return gui.c.ErrorMsg(disabledReason.Text)
}

gui.c.ErrorToast(gui.Tr.DisabledMenuItemPrefix + disabledReason.Text)
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/gui/types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ type MenuSection struct {

type DisabledReason struct {
Text string

// When trying to invoke a disabled key binding or menu item, we normally
// show the disabled reason as a toast; setting this to true shows it as an
// error panel instead. This is useful if the text is very long, or if it is
// important enough to show it more prominently, or both.
ShowErrorInPanel bool
}

type MenuItem struct {
Expand Down
5 changes: 4 additions & 1 deletion pkg/integration/tests/interactive_rebase/quick_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ var QuickStart = NewIntegrationTest(NewIntegrationTestArgs{
// Verify we can't quick start from main
Press(keys.Commits.StartInteractiveRebase)

t.ExpectToast(Equals("Disabled: Cannot start interactive rebase: the HEAD commit is a merge commit or is present on the main branch, so there is no appropriate base commit to start the rebase from. You can start an interactive rebase from a specific commit by selecting the commit and pressing `e`."))
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Equals("Cannot start interactive rebase: the HEAD commit is a merge commit or is present on the main branch, so there is no appropriate base commit to start the rebase from. You can start an interactive rebase from a specific commit by selecting the commit and pressing `e`.")).
Confirm()

t.Views().Branches().
Focus().
Expand Down

0 comments on commit 83337d9

Please sign in to comment.