2018-08-28 20:13:01 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2021-11-02 12:16:00 +02:00
|
|
|
"errors"
|
2018-08-28 20:13:01 +02:00
|
|
|
"fmt"
|
2018-08-29 13:43:59 +02:00
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2019-10-18 09:48:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
2018-08-28 20:13:01 +02:00
|
|
|
)
|
|
|
|
|
2020-08-23 02:50:27 +02:00
|
|
|
func (gui *Gui) getMenuOptions() map[string]string {
|
2022-01-16 05:46:53 +02:00
|
|
|
keybindingConfig := gui.c.UserConfig.Keybinding
|
2020-10-03 06:54:55 +02:00
|
|
|
|
2020-08-23 02:50:27 +02:00
|
|
|
return map[string]string{
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.getKeyDisplay(keybindingConfig.Universal.Return): gui.c.Tr.LcClose,
|
|
|
|
fmt.Sprintf("%s %s", gui.getKeyDisplay(keybindingConfig.Universal.PrevItem), gui.getKeyDisplay(keybindingConfig.Universal.NextItem)): gui.c.Tr.LcNavigate,
|
|
|
|
gui.getKeyDisplay(keybindingConfig.Universal.Select): gui.c.Tr.LcExecute,
|
2018-08-28 20:13:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
// note: items option is mutated by this function
|
2022-01-29 10:09:20 +02:00
|
|
|
func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
|
2022-01-28 11:44:36 +02:00
|
|
|
if !opts.HideCancel {
|
2020-02-14 13:07:56 +02:00
|
|
|
// this is mutative but I'm okay with that for now
|
2022-01-29 10:09:20 +02:00
|
|
|
opts.Items = append(opts.Items, &types.MenuItem{
|
2022-05-08 06:23:32 +02:00
|
|
|
LabelColumns: []string{gui.c.Tr.LcCancel},
|
2022-01-28 11:44:36 +02:00
|
|
|
OnPress: func() error {
|
2020-02-14 13:07:56 +02:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
for _, item := range opts.Items {
|
2022-05-08 06:23:32 +02:00
|
|
|
if item.OpensMenu && item.LabelColumns != nil {
|
2021-11-02 12:16:00 +02:00
|
|
|
return errors.New("Message for the developer of this app: you've set opensMenu with displaystrings on the menu panel. Bad developer!. Apologies, user")
|
|
|
|
}
|
2020-02-14 13:07:56 +02:00
|
|
|
}
|
|
|
|
|
2022-05-08 04:46:48 +02:00
|
|
|
gui.State.Contexts.Menu.SetMenuItems(opts.Items)
|
|
|
|
gui.State.Contexts.Menu.SetSelectedLineIdx(0)
|
|
|
|
|
|
|
|
gui.Views.Menu.Title = opts.Title
|
|
|
|
gui.Views.Menu.FgColor = theme.GocuiDefaultTextColor
|
|
|
|
gui.Views.Menu.SetOnSelectItem(gui.onSelectItemWrapper(func(selectedLine int) error {
|
2020-04-21 11:25:05 +02:00
|
|
|
return nil
|
|
|
|
}))
|
2020-08-20 00:24:35 +02:00
|
|
|
|
2022-05-08 04:46:48 +02:00
|
|
|
gui.Views.Tooltip.Wrap = true
|
|
|
|
gui.Views.Tooltip.FgColor = theme.GocuiDefaultTextColor
|
|
|
|
gui.Views.Tooltip.Visible = true
|
2022-03-27 08:15:17 +02:00
|
|
|
|
|
|
|
// resetting keybindings so that the menu-specific keybindings are registered
|
|
|
|
if err := gui.resetKeybindings(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
_ = gui.c.PostRefreshUpdate(gui.State.Contexts.Menu)
|
2020-08-20 00:24:35 +02:00
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
// TODO: ensure that if we're opened a menu from within a menu that it renders correctly
|
|
|
|
return gui.c.PushContext(gui.State.Contexts.Menu)
|
2020-08-20 00:24:35 +02:00
|
|
|
}
|