mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Add DisabledReason field to MenuItem
This is useful to disable items that are not applicable right now because of some condition (e.g. the "delete branch" menu item when the currently checked-out branch is selected). When a DisabledReason is set on a menu item, we - show it in a tooltip (below the regular tooltip of the item, if it has one) - strike through the item's key, if it has one - show an error message with the DisabledReason if the user tries to invoke the command
This commit is contained in:
parent
679148449a
commit
7f9818cfa2
5 changed files with 26 additions and 2 deletions
|
@ -333,7 +333,7 @@ func (self *ConfirmationHelper) resizeMenu() {
|
|||
tooltip := ""
|
||||
selectedItem := self.c.Contexts().Menu.GetSelected()
|
||||
if selectedItem != nil {
|
||||
tooltip = selectedItem.Tooltip
|
||||
tooltip = self.TooltipForMenuItem(selectedItem)
|
||||
}
|
||||
tooltipHeight := getMessageHeight(true, tooltip, panelWidth) + 2 // plus 2 for the frame
|
||||
_, _ = self.c.GocuiGui().SetView(self.c.Views().Tooltip.Name(), x0, tooltipTop, x1, tooltipTop+tooltipHeight-1, 0)
|
||||
|
@ -382,3 +382,14 @@ func (self *ConfirmationHelper) IsPopupPanel(viewName string) bool {
|
|||
func (self *ConfirmationHelper) IsPopupPanelFocused() bool {
|
||||
return self.IsPopupPanel(self.c.CurrentContext().GetViewName())
|
||||
}
|
||||
|
||||
func (self *ConfirmationHelper) TooltipForMenuItem(menuItem *types.MenuItem) string {
|
||||
tooltip := menuItem.Tooltip
|
||||
if menuItem.DisabledReason != "" {
|
||||
if tooltip != "" {
|
||||
tooltip += "\n\n"
|
||||
}
|
||||
tooltip += style.FgRed.Sprintf(self.c.Tr.DisabledMenuItemPrefix) + menuItem.DisabledReason
|
||||
}
|
||||
return tooltip
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue