From 0f0fda16605059ebae73d29f0e4b9b5d1455ce73 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Thu, 30 May 2019 22:45:56 +1000 Subject: allow stashing staged changes reinstate old stash functionality with the 's' keybinding --- pkg/gui/files_panel.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'pkg/gui/files_panel.go') 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) +} -- cgit v1.2.3