refactor to only have one context per view

This commit is contained in:
Jesse Duffield 2022-06-13 11:01:26 +10:00
parent 6dfef08efc
commit 524bf83a4a
372 changed files with 28866 additions and 6902 deletions

View file

@ -1,6 +1,8 @@
package gui
import (
"errors"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@ -39,7 +41,17 @@ func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) {
}
func (self *guiCommon) PushContext(context types.Context, opts ...types.OnFocusOpts) error {
return self.gui.pushContext(context, opts...)
singleOpts := types.OnFocusOpts{}
if len(opts) > 0 {
// using triple dot but you should only ever pass one of these opt structs
if len(opts) > 1 {
return errors.New("cannot pass multiple opts to pushContext")
}
singleOpts = opts[0]
}
return self.gui.pushContext(context, singleOpts)
}
func (self *guiCommon) PopContext() error {
@ -50,6 +62,14 @@ func (self *guiCommon) CurrentContext() types.Context {
return self.gui.currentContext()
}
func (self *guiCommon) CurrentStaticContext() types.Context {
return self.gui.currentStaticContext()
}
func (self *guiCommon) IsCurrentContext(c types.Context) bool {
return self.CurrentContext().GetKey() == c.GetKey()
}
func (self *guiCommon) GetAppState() *config.AppState {
return self.gui.Config.GetAppState()
}