diff --git a/pkg/gui/controllers/diffing_menu_action.go b/pkg/gui/controllers/diffing_menu_action.go new file mode 100644 index 000000000..951286ece --- /dev/null +++ b/pkg/gui/controllers/diffing_menu_action.go @@ -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}) +} diff --git a/pkg/gui/controllers/global_controller.go b/pkg/gui/controllers/global_controller.go index 04a3aef89..540318ac7 100644 --- a/pkg/gui/controllers/global_controller.go +++ b/pkg/gui/controllers/global_controller.go @@ -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() +} diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go deleted file mode 100644 index 9d3ff1943..000000000 --- a/pkg/gui/diffing.go +++ /dev/null @@ -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}) -} diff --git a/pkg/gui/filtering.go b/pkg/gui/filtering.go deleted file mode 100644 index f068e8fa9..000000000 --- a/pkg/gui/filtering.go +++ /dev/null @@ -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 -} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 11c7f3640..040d634b8 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -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),