1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-13 13:59:06 +02:00

Allow showing Disabled errors as error panel instead of toast

This commit is contained in:
Stefan Haller 2024-01-13 20:30:18 +01:00
parent 84e1d15079
commit 83337d9fa8
5 changed files with 19 additions and 2 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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 {

View File

@ -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().