mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-29 22:48:24 +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:
33
pkg/gui/controllers/helpers/view_helper.go
Normal file
33
pkg/gui/controllers/helpers/view_helper.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
type ViewHelper struct {
|
||||
c *types.HelperCommon
|
||||
contexts *context.ContextTree
|
||||
}
|
||||
|
||||
func NewViewHelper(c *types.HelperCommon, contexts *context.ContextTree) *ViewHelper {
|
||||
return &ViewHelper{
|
||||
c: c,
|
||||
contexts: contexts,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *ViewHelper) ContextForView(viewName string) (types.Context, bool) {
|
||||
view, err := self.c.GocuiGui().View(viewName)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
for _, context := range self.contexts.Flatten() {
|
||||
if context.GetViewName() == view.Name() {
|
||||
return context, true
|
||||
}
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
Reference in New Issue
Block a user