summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context/simple_context.go
blob: 7c00e09f741087f3506cdd469b807a6a1c61b9f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package context

import (
	"github.com/jesseduffield/gocui"
	"github.com/jesseduffield/lazygit/pkg/gui/types"
)

type SimpleContext struct {
	*BaseContext
}

func NewSimpleContext(baseContext *BaseContext) *SimpleContext {
	return &SimpleContext{
		BaseContext: baseContext,
	}
}

var _ types.Context = &SimpleContext{}

// A Display context only renders a view. It has no keybindings and is not focusable.
func NewDisplayContext(key types.ContextKey, view *gocui.View, windowName string) types.Context {
	return NewSimpleContext(
		NewBaseContext(NewBaseContextOpts{
			Kind:       types.DISPLAY_CONTEXT,
			Key:        key,
			View:       view,
			WindowName: windowName,
			Focusable:  false,
			Transient:  false,
		}),
	)
}

func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) error {
	if self.highlightOnFocus {
		self.GetViewTrait().SetHighlight(true)
	}

	if self.onFocusFn != nil {
		if err := self.onFocusFn(opts); err != nil {
			return err
		}
	}

	if self.onRenderToMainFn != nil {
		if err := self.onRenderToMainFn(); err != nil {
			return err
		}
	}

	return nil
}

func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) error {
	if self.onFocusLostFn != nil {
		return self.onFocusLostFn(opts)
	}
	return nil
}

func (self *SimpleContext) HandleRender() error {
	return nil
}

func (self *SimpleContext) HandleRenderToMain() error {
	if self.onRenderToMainFn != nil {
		return self.onRenderToMainFn()
	}

	return nil
}