mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the gui package purely for the sake of better encapsulation
This commit is contained in:
parent
826128a8e0
commit
8edad826ca
101 changed files with 3331 additions and 2877 deletions
|
@ -1,8 +1,8 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
|
@ -41,23 +41,17 @@ func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) {
|
|||
}
|
||||
|
||||
func (self *guiCommon) PushContext(context types.Context, opts ...types.OnFocusOpts) error {
|
||||
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)
|
||||
return self.gui.pushContext(context, opts...)
|
||||
}
|
||||
|
||||
func (self *guiCommon) PopContext() error {
|
||||
return self.gui.popContext()
|
||||
}
|
||||
|
||||
func (self *guiCommon) ReplaceContext(context types.Context) error {
|
||||
return self.gui.replaceContext(context)
|
||||
}
|
||||
|
||||
func (self *guiCommon) CurrentContext() types.Context {
|
||||
return self.gui.currentContext()
|
||||
}
|
||||
|
@ -66,6 +60,10 @@ func (self *guiCommon) CurrentStaticContext() types.Context {
|
|||
return self.gui.currentStaticContext()
|
||||
}
|
||||
|
||||
func (self *guiCommon) CurrentSideContext() types.Context {
|
||||
return self.gui.currentSideContext()
|
||||
}
|
||||
|
||||
func (self *guiCommon) IsCurrentContext(c types.Context) bool {
|
||||
return self.CurrentContext().GetKey() == c.GetKey()
|
||||
}
|
||||
|
@ -78,14 +76,54 @@ func (self *guiCommon) SaveAppState() error {
|
|||
return self.gui.Config.SaveAppState()
|
||||
}
|
||||
|
||||
func (self *guiCommon) GetConfig() config.AppConfigurer {
|
||||
return self.gui.Config
|
||||
}
|
||||
|
||||
func (self *guiCommon) ResetViewOrigin(view *gocui.View) {
|
||||
self.gui.resetViewOrigin(view)
|
||||
}
|
||||
|
||||
func (self *guiCommon) SetViewContent(view *gocui.View, content string) {
|
||||
self.gui.setViewContent(view, content)
|
||||
}
|
||||
|
||||
func (self *guiCommon) Render() {
|
||||
self.gui.render()
|
||||
}
|
||||
|
||||
func (self *guiCommon) Views() types.Views {
|
||||
return self.gui.Views
|
||||
}
|
||||
|
||||
func (self *guiCommon) Git() *commands.GitCommand {
|
||||
return self.gui.git
|
||||
}
|
||||
|
||||
func (self *guiCommon) OS() *oscommands.OSCommand {
|
||||
return self.gui.os
|
||||
}
|
||||
|
||||
func (self *guiCommon) Modes() *types.Modes {
|
||||
return self.gui.State.Modes
|
||||
}
|
||||
|
||||
func (self *guiCommon) Model() *types.Model {
|
||||
return self.gui.State.Model
|
||||
}
|
||||
|
||||
func (self *guiCommon) Mutexes() types.Mutexes {
|
||||
return self.gui.Mutexes
|
||||
}
|
||||
|
||||
func (self *guiCommon) OpenSearch() {
|
||||
_ = self.gui.handleOpenSearch(self.gui.currentViewName())
|
||||
}
|
||||
|
||||
func (self *guiCommon) GocuiGui() *gocui.Gui {
|
||||
return self.gui.g
|
||||
}
|
||||
|
||||
func (self *guiCommon) OnUIThread(f func() error) {
|
||||
self.gui.onUIThread(f)
|
||||
}
|
||||
|
@ -102,3 +140,7 @@ func (self *guiCommon) MainViewPairs() types.MainViewPairs {
|
|||
MergeConflicts: self.gui.mergingMainContextPair(),
|
||||
}
|
||||
}
|
||||
|
||||
func (self *guiCommon) State() types.IStateAccessor {
|
||||
return self.gui.stateAccessor
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue