-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
page_stack.go
53 lines (43 loc) · 953 Bytes
/
page_stack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package view
import (
"context"
"github.com/derailed/k9s/internal/model"
"github.com/derailed/k9s/internal/ui"
)
// PageStack represents a stack of pages.
type PageStack struct {
*ui.Pages
app *App
}
// NewPageStack returns a new page stack.
func NewPageStack() *PageStack {
return &PageStack{
Pages: ui.NewPages(),
}
}
// Init initializes the view.
func (p *PageStack) Init(ctx context.Context) (err error) {
if p.app, err = extractApp(ctx); err != nil {
return err
}
p.Stack.AddListener(p)
return nil
}
// StackPushed notifies a new page was added.
func (p *PageStack) StackPushed(c model.Component) {
c.Start()
p.app.SetFocus(c)
}
// StackPopped notifies a page was removed.
func (p *PageStack) StackPopped(o, top model.Component) {
o.Stop()
p.StackTop(top)
}
// StackTop notifies for the top component.
func (p *PageStack) StackTop(top model.Component) {
if top == nil {
return
}
top.Start()
p.app.SetFocus(top)
}