2021-04-11 13:17:20 +10:00
package gui
2022-01-16 14:46:53 +11:00
import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
2021-04-11 13:17:20 +10:00
type BasicContext struct {
2022-01-16 14:46:53 +11:00
OnFocus func ( opts ... types . OnFocusOpts ) error
2021-11-21 12:48:49 +11:00
OnFocusLost func ( ) error
OnRender func ( ) error
// this is for pushing some content to the main view
2022-01-16 14:46:53 +11:00
OnRenderToMain func ( opts ... types . OnFocusOpts ) error
Kind types . ContextKind
Key types . ContextKey
2021-04-11 13:17:20 +10:00
ViewName string
WindowName string
OnGetOptionsMap func ( ) map [ string ] string
2022-01-16 14:46:53 +11:00
ParentContext types . Context
2021-04-11 13:17:20 +10:00
// we can't know on the calling end whether a Context is actually a nil value without reflection, so we're storing this flag here to tell us. There has got to be a better way around this
hasParent bool
}
2022-01-16 14:46:53 +11:00
var _ types . Context = & BasicContext { }
2021-11-21 12:48:49 +11:00
func ( self * BasicContext ) GetOptionsMap ( ) map [ string ] string {
if self . OnGetOptionsMap != nil {
return self . OnGetOptionsMap ( )
2021-04-11 13:17:20 +10:00
}
return nil
}
2022-01-16 14:46:53 +11:00
func ( self * BasicContext ) SetParentContext ( context types . Context ) {
2021-11-21 12:48:49 +11:00
self . ParentContext = context
self . hasParent = true
2021-04-11 13:17:20 +10:00
}
2022-01-16 14:46:53 +11:00
func ( self * BasicContext ) GetParentContext ( ) ( types . Context , bool ) {
2021-11-21 12:48:49 +11:00
return self . ParentContext , self . hasParent
2021-04-11 13:17:20 +10:00
}
2021-11-21 12:48:49 +11:00
func ( self * BasicContext ) SetWindowName ( windowName string ) {
self . WindowName = windowName
2021-04-11 13:17:20 +10:00
}
2021-11-21 12:48:49 +11:00
func ( self * BasicContext ) GetWindowName ( ) string {
windowName := self . WindowName
2021-04-11 13:17:20 +10:00
if windowName != "" {
return windowName
}
// TODO: actually set this for everything so we don't default to the view name
2021-11-21 12:48:49 +11:00
return self . ViewName
2021-04-11 13:17:20 +10:00
}
2021-11-21 12:48:49 +11:00
func ( self * BasicContext ) HandleRender ( ) error {
if self . OnRender != nil {
return self . OnRender ( )
2021-04-11 13:17:20 +10:00
}
return nil
}
2021-11-21 12:48:49 +11:00
func ( self * BasicContext ) GetViewName ( ) string {
return self . ViewName
2021-04-11 13:17:20 +10:00
}
2022-01-16 14:46:53 +11:00
func ( self * BasicContext ) HandleFocus ( opts ... types . OnFocusOpts ) error {
2021-11-21 12:48:49 +11:00
if self . OnFocus != nil {
if err := self . OnFocus ( opts ... ) ; err != nil {
return err
}
}
if self . OnRenderToMain != nil {
if err := self . OnRenderToMain ( opts ... ) ; err != nil {
return err
}
}
return nil
2021-04-11 13:17:20 +10:00
}
2021-11-21 12:48:49 +11:00
func ( self * BasicContext ) HandleFocusLost ( ) error {
if self . OnFocusLost != nil {
return self . OnFocusLost ( )
2021-04-11 13:17:20 +10:00
}
return nil
}
2021-11-21 12:48:49 +11:00
func ( self * BasicContext ) HandleRenderToMain ( ) error {
if self . OnRenderToMain != nil {
return self . OnRenderToMain ( )
}
return nil
}
2022-01-16 14:46:53 +11:00
func ( self * BasicContext ) GetKind ( ) types . ContextKind {
2021-11-21 12:48:49 +11:00
return self . Kind
2021-04-11 13:17:20 +10:00
}
2022-01-16 14:46:53 +11:00
func ( self * BasicContext ) GetKey ( ) types . ContextKey {
2021-11-21 12:48:49 +11:00
return self . Key
2021-04-11 13:17:20 +10:00
}