mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
8edad826ca
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the gui package purely for the sake of better encapsulation
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
func (gui *Gui) handleCreateDiffingMenuPanel() error {
|
|
names := gui.helpers.Diff.CurrentDiffTerminals()
|
|
|
|
menuItems := []*types.MenuItem{}
|
|
for _, name := range names {
|
|
name := name
|
|
menuItems = append(menuItems, []*types.MenuItem{
|
|
{
|
|
Label: fmt.Sprintf("%s %s", gui.c.Tr.LcDiff, name),
|
|
OnPress: func() error {
|
|
gui.State.Modes.Diffing.Ref = name
|
|
// can scope this down based on current view but too lazy right now
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
|
},
|
|
},
|
|
}...)
|
|
}
|
|
|
|
menuItems = append(menuItems, []*types.MenuItem{
|
|
{
|
|
Label: gui.c.Tr.LcEnterRefToDiff,
|
|
OnPress: func() error {
|
|
return gui.c.Prompt(types.PromptOpts{
|
|
Title: gui.c.Tr.LcEnteRefName,
|
|
FindSuggestionsFunc: gui.helpers.Suggestions.GetRefsSuggestionsFunc(),
|
|
HandleConfirm: func(response string) error {
|
|
gui.State.Modes.Diffing.Ref = strings.TrimSpace(response)
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
|
},
|
|
})
|
|
},
|
|
},
|
|
}...)
|
|
|
|
if gui.State.Modes.Diffing.Active() {
|
|
menuItems = append(menuItems, []*types.MenuItem{
|
|
{
|
|
Label: gui.c.Tr.LcSwapDiff,
|
|
OnPress: func() error {
|
|
gui.State.Modes.Diffing.Reverse = !gui.State.Modes.Diffing.Reverse
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
|
},
|
|
},
|
|
{
|
|
Label: gui.c.Tr.LcExitDiffMode,
|
|
OnPress: func() error {
|
|
gui.State.Modes.Diffing = diffing.New()
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
|
},
|
|
},
|
|
}...)
|
|
}
|
|
|
|
return gui.c.Menu(types.CreateMenuOptions{Title: gui.c.Tr.DiffingMenuTitle, Items: menuItems})
|
|
}
|