mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-13 11:50:28 +02:00
move diffing menu action to controller
This commit is contained in:
parent
7848958326
commit
2da300f2fb
69
pkg/gui/controllers/diffing_menu_action.go
Normal file
69
pkg/gui/controllers/diffing_menu_action.go
Normal file
@ -0,0 +1,69 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
type DiffingMenuAction struct {
|
||||
c *ControllerCommon
|
||||
}
|
||||
|
||||
func (self *DiffingMenuAction) Call() error {
|
||||
names := self.c.Helpers().Diff.CurrentDiffTerminals()
|
||||
|
||||
menuItems := []*types.MenuItem{}
|
||||
for _, name := range names {
|
||||
name := name
|
||||
menuItems = append(menuItems, []*types.MenuItem{
|
||||
{
|
||||
Label: fmt.Sprintf("%s %s", self.c.Tr.LcDiff, name),
|
||||
OnPress: func() error {
|
||||
self.c.Modes().Diffing.Ref = name
|
||||
// can scope this down based on current view but too lazy right now
|
||||
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||
},
|
||||
},
|
||||
}...)
|
||||
}
|
||||
|
||||
menuItems = append(menuItems, []*types.MenuItem{
|
||||
{
|
||||
Label: self.c.Tr.LcEnterRefToDiff,
|
||||
OnPress: func() error {
|
||||
return self.c.Prompt(types.PromptOpts{
|
||||
Title: self.c.Tr.LcEnteRefName,
|
||||
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRefsSuggestionsFunc(),
|
||||
HandleConfirm: func(response string) error {
|
||||
self.c.Modes().Diffing.Ref = strings.TrimSpace(response)
|
||||
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||
},
|
||||
})
|
||||
},
|
||||
},
|
||||
}...)
|
||||
|
||||
if self.c.Modes().Diffing.Active() {
|
||||
menuItems = append(menuItems, []*types.MenuItem{
|
||||
{
|
||||
Label: self.c.Tr.LcSwapDiff,
|
||||
OnPress: func() error {
|
||||
self.c.Modes().Diffing.Reverse = !self.c.Modes().Diffing.Reverse
|
||||
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||
},
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.LcExitDiffMode,
|
||||
OnPress: func() error {
|
||||
self.c.Modes().Diffing = diffing.New()
|
||||
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||
},
|
||||
},
|
||||
}...)
|
||||
}
|
||||
|
||||
return self.c.Menu(types.CreateMenuOptions{Title: self.c.Tr.DiffingMenuTitle, Items: menuItems})
|
||||
}
|
@ -75,6 +75,18 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
|
||||
Description: self.c.Tr.LcOpenFilteringMenu,
|
||||
OpensMenu: true,
|
||||
},
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.DiffingMenu),
|
||||
Handler: self.createDiffingMenu,
|
||||
Description: self.c.Tr.LcOpenDiffingMenu,
|
||||
OpensMenu: true,
|
||||
},
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.DiffingMenuAlt),
|
||||
Handler: self.createDiffingMenu,
|
||||
Description: self.c.Tr.LcOpenDiffingMenu,
|
||||
OpensMenu: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,3 +121,7 @@ func (self *GlobalController) createOptionsMenu() error {
|
||||
func (self *GlobalController) createFilteringMenu() error {
|
||||
return (&FilteringMenuAction{c: self.c}).Call()
|
||||
}
|
||||
|
||||
func (self *GlobalController) createDiffingMenu() error {
|
||||
return (&DiffingMenuAction{c: self.c}).Call()
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
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})
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
func (gui *Gui) validateNotInFilterMode() bool {
|
||||
if gui.State.Modes.Filtering.Active() {
|
||||
_ = gui.c.Confirm(types.ConfirmOpts{
|
||||
Title: gui.c.Tr.MustExitFilterModeTitle,
|
||||
Prompt: gui.c.Tr.MustExitFilterModePrompt,
|
||||
HandleConfirm: gui.helpers.Mode.ExitFilterMode,
|
||||
})
|
||||
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
@ -29,6 +29,19 @@ func (gui *Gui) outsideFilterMode(f func() error) func() error {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) validateNotInFilterMode() bool {
|
||||
if gui.State.Modes.Filtering.Active() {
|
||||
_ = gui.c.Confirm(types.ConfirmOpts{
|
||||
Title: gui.c.Tr.MustExitFilterModeTitle,
|
||||
Prompt: gui.c.Tr.MustExitFilterModePrompt,
|
||||
HandleConfirm: gui.helpers.Mode.ExitFilterMode,
|
||||
})
|
||||
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// only to be called from the cheatsheet generate script. This mutates the Gui struct.
|
||||
func (self *Gui) GetCheatsheetKeybindings() []*types.Binding {
|
||||
self.g = &gocui.Gui{}
|
||||
@ -188,20 +201,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
||||
Handler: self.handleCopySelectedSideContextItemToClipboard,
|
||||
Description: self.c.Tr.LcCopyCommitFileNameToClipboard,
|
||||
},
|
||||
{
|
||||
ViewName: "",
|
||||
Key: opts.GetKey(opts.Config.Universal.DiffingMenu),
|
||||
Handler: self.handleCreateDiffingMenuPanel,
|
||||
Description: self.c.Tr.LcOpenDiffingMenu,
|
||||
OpensMenu: true,
|
||||
},
|
||||
{
|
||||
ViewName: "",
|
||||
Key: opts.GetKey(opts.Config.Universal.DiffingMenuAlt),
|
||||
Handler: self.handleCreateDiffingMenuPanel,
|
||||
Description: self.c.Tr.LcOpenDiffingMenu,
|
||||
OpensMenu: true,
|
||||
},
|
||||
{
|
||||
ViewName: "",
|
||||
Key: opts.GetKey(opts.Config.Universal.ExtrasMenu),
|
||||
|
Loading…
x
Reference in New Issue
Block a user