summaryrefslogtreecommitdiffstats
path: root/pkg/gui/scoping_menu_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-28 16:28:35 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-29 11:37:29 +1100
commit624ae45ebb3f54499a25c4eba0844fa971277c34 (patch)
treeca20f93742858b2b4231d083e5b6abdab61d69ba /pkg/gui/scoping_menu_panel.go
parent2756b82f5733c2099c43279ebb1a962101411142 (diff)
allow scoped mode where the commits/reflog/stash panels are scoped to a file
WIP restrict certain actions in scoped mode WIP
Diffstat (limited to 'pkg/gui/scoping_menu_panel.go')
-rw-r--r--pkg/gui/scoping_menu_panel.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/pkg/gui/scoping_menu_panel.go b/pkg/gui/scoping_menu_panel.go
new file mode 100644
index 000000000..d1c2f85e3
--- /dev/null
+++ b/pkg/gui/scoping_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("scopeTo"), fileName),
+ onPress: func() error {
+ gui.State.LogScope = fileName
+ return gui.Errors.ErrRestart
+ },
+ })
+ }
+
+ menuItems = append(menuItems, &menuItem{
+ displayString: gui.Tr.SLocalize("fileToScopeToOption"),
+ onPress: func() error {
+ return gui.createPromptPanel(gui.g, v, gui.Tr.SLocalize("enterFileName"), "", func(g *gocui.Gui, promptView *gocui.View) error {
+ gui.State.LogScope = strings.TrimSpace(promptView.Buffer())
+ return gui.Errors.ErrRestart
+ })
+ },
+ })
+
+ if gui.inScopedMode() {
+ menuItems = append(menuItems, &menuItem{
+ displayString: gui.Tr.SLocalize("exitOutOfScopedMode"),
+ onPress: func() error {
+ gui.State.LogScope = ""
+ return gui.Errors.ErrRestart
+ },
+ })
+ }
+
+ return gui.createMenu(gui.Tr.SLocalize("scopingMenuTitle"), menuItems, createMenuOptions{showCancel: true})
+}