1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

move more actions into controller

This commit is contained in:
Jesse Duffield
2023-03-23 22:05:25 +11:00
parent 71753770ad
commit f8c9ce33c2
12 changed files with 160 additions and 123 deletions

View File

@ -18,13 +18,20 @@ type ContextMgr struct {
ContextStack []types.Context
sync.RWMutex
gui *Gui
allContexts *context.ContextTree
}
func NewContextMgr(initialContext types.Context, gui *Gui) *ContextMgr {
func NewContextMgr(
initialContext types.Context,
gui *Gui,
allContexts *context.ContextTree,
) *ContextMgr {
return &ContextMgr{
ContextStack: []types.Context{initialContext},
RWMutex: sync.RWMutex{},
gui: gui,
allContexts: allContexts,
}
}
@ -286,3 +293,28 @@ func (self *ContextMgr) ForEach(f func(types.Context)) {
func (self *ContextMgr) IsCurrent(c types.Context) bool {
return self.Current().GetKey() == c.GetKey()
}
// all list contexts
func (self *ContextMgr) AllList() []types.IListContext {
var listContexts []types.IListContext
for _, context := range self.allContexts.Flatten() {
if listContext, ok := context.(types.IListContext); ok {
listContexts = append(listContexts, listContext)
}
}
return listContexts
}
func (self *ContextMgr) AllPatchExplorer() []types.IPatchExplorerContext {
var listContexts []types.IPatchExplorerContext
for _, context := range self.allContexts.Flatten() {
if listContext, ok := context.(types.IPatchExplorerContext); ok {
listContexts = append(listContexts, listContext)
}
}
return listContexts
}