diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-05-30 22:45:56 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-06-06 20:50:19 +1000 |
commit | 0f0fda16605059ebae73d29f0e4b9b5d1455ce73 (patch) | |
tree | 6d14bff955e00ee16f3170a0e0f80b7edc89d980 /pkg/gui | |
parent | bd2170a99cb996f2e00467a3416645a85eaf0549 (diff) |
allow stashing staged changes
reinstate old stash functionality with the 's' keybinding
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/files_panel.go | 43 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 10 | ||||
-rw-r--r-- | pkg/gui/menu_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/stash_panel.go | 9 |
4 files changed, 56 insertions, 8 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 3d2001ac1..043c6ceab 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -627,3 +627,46 @@ func (gui *Gui) handleCustomCommand(g *gocui.Gui, v *gocui.View) error { return gui.Errors.ErrSubProcess }) } + +type stashOption struct { + description string + handler func() error +} + +// GetDisplayStrings is a function. +func (o *stashOption) GetDisplayStrings(isFocused bool) []string { + return []string{o.description} +} + +func (gui *Gui) handleCreateStashMenu(g *gocui.Gui, v *gocui.View) error { + options := []*stashOption{ + { + description: gui.Tr.SLocalize("stashAllChanges"), + handler: func() error { + return gui.handleStashSave(gui.GitCommand.StashSave) + }, + }, + { + description: gui.Tr.SLocalize("stashStagedChanges"), + handler: func() error { + return gui.handleStashSave(gui.GitCommand.StashSaveStagedChanges) + }, + }, + { + description: gui.Tr.SLocalize("cancel"), + handler: func() error { + return nil + }, + }, + } + + handleMenuPress := func(index int) error { + return options[index].handler() + } + + return gui.createMenu(gui.Tr.SLocalize("stashOptions"), options, len(options), handleMenuPress) +} + +func (gui *Gui) handleStashChanges(g *gocui.Gui, v *gocui.View) error { + return gui.handleStashSave(gui.GitCommand.StashSave) +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 5cbd7b6eb..ce12cf66f 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -230,10 +230,16 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Description: gui.Tr.SLocalize("refreshFiles"), }, { ViewName: "files", + Key: 's', + Modifier: gocui.ModNone, + Handler: gui.handleStashChanges, + Description: gui.Tr.SLocalize("stashAllChanges"), + }, { + ViewName: "files", Key: 'S', Modifier: gocui.ModNone, - Handler: gui.handleStashSave, - Description: gui.Tr.SLocalize("stashFiles"), + Handler: gui.handleCreateStashMenu, + Description: gui.Tr.SLocalize("viewStashOptions"), }, { ViewName: "files", Key: 'a', diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index 66dabd03e..370c7fa5a 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -70,7 +70,7 @@ func (gui *Gui) createMenu(title string, items interface{}, itemCount int, handl wrappedHandlePress := func(g *gocui.Gui, v *gocui.View) error { selectedLine := gui.State.Panels.Menu.SelectedLine if err := handlePress(selectedLine); err != nil { - return err + return gui.createErrorPanel(gui.g, err.Error()) } if _, err := gui.g.View("menu"); err == nil { if _, err := gui.g.SetViewOnBottom("menu"); err != nil { diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index 9c1851971..4a2b463ce 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -130,16 +130,15 @@ func (gui *Gui) stashDo(g *gocui.Gui, v *gocui.View, method string) error { return gui.refreshFiles() } -func (gui *Gui) handleStashSave(g *gocui.Gui, filesView *gocui.View) error { +func (gui *Gui) handleStashSave(stashFunc func(message string) error) error { if len(gui.trackedFiles()) == 0 && len(gui.stagedFiles()) == 0 { - return gui.createErrorPanel(g, gui.Tr.SLocalize("NoTrackedStagedFilesStash")) + return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoTrackedStagedFilesStash")) } - gui.createPromptPanel(g, filesView, gui.Tr.SLocalize("StashChanges"), func(g *gocui.Gui, v *gocui.View) error { - if err := gui.GitCommand.StashSave(gui.trimmedContent(v)); err != nil { + return gui.createPromptPanel(gui.g, gui.getFilesView(), gui.Tr.SLocalize("StashChanges"), func(g *gocui.Gui, v *gocui.View) error { + if err := stashFunc(gui.trimmedContent(v)); err != nil { gui.createErrorPanel(g, err.Error()) } gui.refreshStashEntries(g) return gui.refreshFiles() }) - return nil } |