diff options
-rw-r--r-- | pkg/gui/controllers/files_controller.go | 6 | ||||
-rw-r--r-- | pkg/gui/controllers/files_controller_remove.go | 85 | ||||
-rw-r--r-- | pkg/gui/discard_changes_menu_panel.go | 87 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 8 |
4 files changed, 91 insertions, 95 deletions
diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 8ce768ac6..b8e853d48 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -142,6 +142,12 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co Description: self.c.Tr.LcIgnoreFile, }, { + Key: getKey(config.Universal.Remove), + Handler: self.checkSelectedFileNode(self.remove), + Description: self.c.Tr.LcViewDiscardOptions, + OpensMenu: true, + }, + { Key: getKey(config.Files.RefreshFiles), Handler: self.refresh, Description: self.c.Tr.LcRefreshFiles, diff --git a/pkg/gui/controllers/files_controller_remove.go b/pkg/gui/controllers/files_controller_remove.go new file mode 100644 index 000000000..42d1df8b0 --- /dev/null +++ b/pkg/gui/controllers/files_controller_remove.go @@ -0,0 +1,85 @@ +package controllers + +import ( + "github.com/jesseduffield/lazygit/pkg/gui/filetree" + "github.com/jesseduffield/lazygit/pkg/gui/types" +) + +// splitting this action out into its own file because it's self-contained + +func (self *FilesController) remove(node *filetree.FileNode) error { + var menuItems []*types.MenuItem + if node.File == nil { + menuItems = []*types.MenuItem{ + { + DisplayString: self.c.Tr.LcDiscardAllChanges, + OnPress: func() error { + self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInDirectory) + if err := self.git.WorkingTree.DiscardAllDirChanges(node); err != nil { + return self.c.Error(err) + } + return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) + }, + }, + } + + if node.GetHasStagedChanges() && node.GetHasUnstagedChanges() { + menuItems = append(menuItems, &types.MenuItem{ + DisplayString: self.c.Tr.LcDiscardUnstagedChanges, + OnPress: func() error { + self.c.LogAction(self.c.Tr.Actions.DiscardUnstagedChangesInDirectory) + if err := self.git.WorkingTree.DiscardUnstagedDirChanges(node); err != nil { + return self.c.Error(err) + } + + return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) + }, + }) + } + } else { + file := node.File + + submodules := self.getSubmodules() + if file.IsSubmodule(submodules) { + submodule := file.SubmoduleConfig(submodules) + + menuItems = []*types.MenuItem{ + { + DisplayString: self.c.Tr.LcSubmoduleStashAndReset, + OnPress: func() error { + return self.ResetSubmodule(submodule) + }, + }, + } + } else { + menuItems = []*types.MenuItem{ + { + DisplayString: self.c.Tr.LcDiscardAllChanges, + OnPress: func() error { + self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile) + if err := self.git.WorkingTree.DiscardAllFileChanges(file); err != nil { + return self.c.Error(err) + } + return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) + }, + }, + } + + if file.HasStagedChanges && file.HasUnstagedChanges { + menuItems = append(menuItems, &types.MenuItem{ + DisplayString: self.c.Tr.LcDiscardUnstagedChanges, + OnPress: func() error { + self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile) + if err := self.git.WorkingTree.DiscardUnstagedFileChanges(file); err != nil { + return self.c.Error(err) + } + + return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) + }, + }) + } + } + } + + return self.c.Menu(types.CreateMenuOptions{Title: node.GetPath(), Items: menuItems}) +} diff --git a/pkg/gui/discard_changes_menu_panel.go b/pkg/gui/discard_changes_menu_panel.go deleted file mode 100644 index 5da349314..000000000 --- a/pkg/gui/discard_changes_menu_panel.go +++ /dev/null @@ -1,87 +0,0 @@ -package gui - -import ( - "github.com/jesseduffield/lazygit/pkg/gui/types" -) - -func (gui *Gui) handleCreateDiscardMenu() error { - node := gui.getSelectedFileNode() - if node == nil { - return nil - } - - var menuItems []*types.MenuItem - if node.File == nil { - menuItems = []*types.MenuItem{ - { - DisplayString: gui.c.Tr.LcDiscardAllChanges, - OnPress: func() error { - gui.c.LogAction(gui.c.Tr.Actions.DiscardAllChangesInDirectory) - if err := gui.git.WorkingTree.DiscardAllDirChanges(node); err != nil { - return gui.c.Error(err) - } - return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) - }, - }, - } - - if node.GetHasStagedChanges() && node.GetHasUnstagedChanges() { - menuItems = append(menuItems, &types.MenuItem{ - DisplayString: gui.c.Tr.LcDiscardUnstagedChanges, - OnPress: func() error { - gui.c.LogAction(gui.c.Tr.Actions.DiscardUnstagedChangesInDirectory) - if err := gui.git.WorkingTree.DiscardUnstagedDirChanges(node); err != nil { - return gui.c.Error(err) - } - - return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) - }, - }) - } - } else { - file := node.File - - submodules := gui.State.Submodules - if file.IsSubmodule(submodules) { - submodule := file.SubmoduleConfig(submodules) - - menuItems = []*types.MenuItem{ - { - DisplayString: gui.c.Tr.LcSubmoduleStashAndReset, - OnPress: func() error { - return gui.Controllers.Files.ResetSubmodule(submodule) - }, - }, - } - } else { - menuItems = []*types.MenuItem{ - { - DisplayString: gui.c.Tr.LcDiscardAllChanges, - OnPress: func() error { - gui.c.LogAction(gui.c.Tr.Actions.DiscardAllChangesInFile) - if err := gui.git.WorkingTree.DiscardAllFileChanges(file); err != nil { - return gui.c.Error(err) - } - return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) - }, - }, - } - - if file.HasStagedChanges && file.HasUnstagedChanges { - menuItems = append(menuItems, &types.MenuItem{ - DisplayString: gui.c.Tr.LcDiscardUnstagedChanges, - OnPress: func() error { - gui.c.LogAction(gui.c.Tr.Actions.DiscardAllUnstagedChangesInFile) - if err := gui.git.WorkingTree.DiscardUnstagedFileChanges(file); err != nil { - return gui.c.Error(err) - } - - return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}}) - }, - }) - } - } - } - - return gui.c.Menu(types.CreateMenuOptions{Title: node.GetPath(), Items: menuItems}) -} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index b47c34994..f2d44690c 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -357,14 +357,6 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding { { ViewName: "files", Contexts: []string{string(context.FILES_CONTEXT_KEY)}, - Key: gui.getKey(config.Universal.Remove), - Handler: gui.handleCreateDiscardMenu, - Description: gui.c.Tr.LcViewDiscardOptions, - OpensMenu: true, - }, - { - ViewName: "files", - Contexts: []string{string(context.FILES_CONTEXT_KEY)}, Key: gui.getKey(config.Files.ViewResetOptions), Handler: gui.handleCreateResetMenu, Description: gui.c.Tr.LcViewResetOptions, |