summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-02-05 14:42:56 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-17 19:13:40 +1100
commit482bdc4f1ea5448c5e98697ae66221e544ea40dd (patch)
tree7df478f9870e3dddc85f77d7b77439bed16e3c7b /pkg/gui/context
parent8e3484d8e98faf12f8395eaf5f9e8381f77a8e52 (diff)
more refactoring
Diffstat (limited to 'pkg/gui/context')
-rw-r--r--pkg/gui/context/base_context.go20
-rw-r--r--pkg/gui/context/context.go3
2 files changed, 21 insertions, 2 deletions
diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go
index c61f57cf4..5dbc3cbf4 100644
--- a/pkg/gui/context/base_context.go
+++ b/pkg/gui/context/base_context.go
@@ -1,6 +1,7 @@
package context
import (
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -11,8 +12,8 @@ type BaseContext struct {
windowName string
onGetOptionsMap func() map[string]string
- keybindingsFns []types.KeybindingsFn
- keybindings []*types.Binding
+ keybindingsFns []types.KeybindingsFn
+ mouseKeybindingsFns []types.MouseKeybindingsFn
*ParentContextMgr
}
@@ -80,3 +81,18 @@ func (self *BaseContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Bin
func (self *BaseContext) AddKeybindingsFn(fn types.KeybindingsFn) {
self.keybindingsFns = append(self.keybindingsFns, fn)
}
+
+func (self *BaseContext) AddMouseKeybindingsFn(fn types.MouseKeybindingsFn) {
+ self.mouseKeybindingsFns = append(self.mouseKeybindingsFns, fn)
+}
+
+func (self *BaseContext) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
+ bindings := []*gocui.ViewMouseBinding{}
+ for i := range self.mouseKeybindingsFns {
+ // the first binding in the bindings array takes precedence but we want the
+ // last keybindingsFn to take precedence to we add them in reverse
+ bindings = append(bindings, self.mouseKeybindingsFns[len(self.mouseKeybindingsFns)-1-i](opts)...)
+ }
+
+ return bindings
+}
diff --git a/pkg/gui/context/context.go b/pkg/gui/context/context.go
index 20d67a5a7..b45a089be 100644
--- a/pkg/gui/context/context.go
+++ b/pkg/gui/context/context.go
@@ -3,6 +3,7 @@ package context
import "github.com/jesseduffield/lazygit/pkg/gui/types"
const (
+ GLOBAL_CONTEXT_KEY types.ContextKey = "global"
STATUS_CONTEXT_KEY types.ContextKey = "status"
FILES_CONTEXT_KEY types.ContextKey = "files"
LOCAL_BRANCHES_CONTEXT_KEY types.ContextKey = "localBranches"
@@ -29,6 +30,7 @@ const (
)
var AllContextKeys = []types.ContextKey{
+ GLOBAL_CONTEXT_KEY,
STATUS_CONTEXT_KEY,
FILES_CONTEXT_KEY,
LOCAL_BRANCHES_CONTEXT_KEY,
@@ -55,6 +57,7 @@ var AllContextKeys = []types.ContextKey{
}
type ContextTree struct {
+ Global types.Context
Status types.Context
Files *WorkingTreeContext
Submodules types.IListContext