diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-29 10:35:12 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-29 11:37:29 +1100 |
commit | d90d9d7330ff5ba5161c70d6b8e11cb7b87c9b47 (patch) | |
tree | b972890726ff846b5fdd5f7d659c0f31a7bf2aca /pkg/gui/filtering_menu_panel.go | |
parent | a8db672ffbeba92a32ad34f475760c78aa73303e (diff) |
reset state on each Run() call
Diffstat (limited to 'pkg/gui/filtering_menu_panel.go')
-rw-r--r-- | pkg/gui/filtering_menu_panel.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/pkg/gui/filtering_menu_panel.go b/pkg/gui/filtering_menu_panel.go new file mode 100644 index 000000000..316ea95d0 --- /dev/null +++ b/pkg/gui/filtering_menu_panel.go @@ -0,0 +1,58 @@ +package gui + +import ( + "fmt" + "strings" + + "github.com/jesseduffield/gocui" +) + +func (gui *Gui) handleCreateScopingMenuPanel(g *gocui.Gui, v *gocui.View) error { + fileName := "" + switch v.Name() { + case "files": + file, err := gui.getSelectedFile(gui.g) + if err == nil { + fileName = file.Name + } + case "commitFiles": + file := gui.getSelectedCommitFile(gui.g) + if file != nil { + fileName = file.Name + } + } + + menuItems := []*menuItem{} + + if fileName != "" { + menuItems = append(menuItems, &menuItem{ + displayString: fmt.Sprintf("%s '%s'", gui.Tr.SLocalize("filterBy"), fileName), + onPress: func() error { + gui.State.FilterPath = fileName + return gui.Errors.ErrRestart + }, + }) + } + + menuItems = append(menuItems, &menuItem{ + displayString: gui.Tr.SLocalize("filterPathOption"), + onPress: func() error { + return gui.createPromptPanel(gui.g, v, gui.Tr.SLocalize("enterFileName"), "", func(g *gocui.Gui, promptView *gocui.View) error { + gui.State.FilterPath = strings.TrimSpace(promptView.Buffer()) + return gui.Errors.ErrRestart + }) + }, + }) + + if gui.inFilterMode() { + menuItems = append(menuItems, &menuItem{ + displayString: gui.Tr.SLocalize("exitFilterMode"), + onPress: func() error { + gui.State.FilterPath = "" + return gui.Errors.ErrRestart + }, + }) + } + + return gui.createMenu(gui.Tr.SLocalize("FilteringMenuTitle"), menuItems, createMenuOptions{showCancel: true}) +} |