2022-02-05 08:04:10 +02:00
|
|
|
package context
|
2021-04-11 05:17:20 +02:00
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
import (
|
2022-06-13 03:01:26 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
2022-01-16 05:46:53 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
|
|
)
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
type SimpleContext struct {
|
2022-02-05 08:04:10 +02:00
|
|
|
*BaseContext
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
|
2023-03-21 12:01:58 +02:00
|
|
|
func NewSimpleContext(baseContext *BaseContext) *SimpleContext {
|
2022-01-29 10:09:20 +02:00
|
|
|
return &SimpleContext{
|
2022-12-30 14:24:24 +02:00
|
|
|
BaseContext: baseContext,
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
var _ types.Context = &SimpleContext{}
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
// 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 {
|
2023-02-16 12:31:10 +02:00
|
|
|
if self.highlightOnFocus {
|
|
|
|
self.GetViewTrait().SetHighlight(true)
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
if self.onFocusFn != nil {
|
|
|
|
if err := self.onFocusFn(opts); err != nil {
|
2021-11-21 03:48:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
if self.onRenderToMainFn != nil {
|
|
|
|
if err := self.onRenderToMainFn(); err != nil {
|
2021-11-21 03:48:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) error {
|
2022-12-30 14:24:24 +02:00
|
|
|
if self.onFocusLostFn != nil {
|
|
|
|
return self.onFocusLostFn(opts)
|
2021-04-11 05:17:20 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
func (self *SimpleContext) HandleRender() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
func (self *SimpleContext) HandleRenderToMain() error {
|
2022-12-30 14:24:24 +02:00
|
|
|
if self.onRenderToMainFn != nil {
|
|
|
|
return self.onRenderToMainFn()
|
2021-11-21 03:48:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|