-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_static.go
85 lines (71 loc) · 1.54 KB
/
menu_static.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"cmp"
"fmt"
"github.com/gdamore/tcell/v2"
)
type MenuStatic struct {
*MenuFolder
Index int
Description string
}
func (m *MenuStatic) Validate() error {
if err := m.MenuFolder.Validate(); err != nil {
return err
}
if m.Description == "" {
return fmt.Errorf("Description must be set for MenuStatic=%s", m.GetPath())
}
if m.GetParentPath() != "" {
return fmt.Errorf("ParentPath must be empty for MenuStatic=%s", m.GetPath())
}
return nil
}
func (m *MenuStatic) Compare(other MenuItem) int {
if other == nil {
return 1
}
otherMenu, ok := other.(*MenuStatic)
if !ok {
return cmp.Compare(m.GetID(), other.GetID())
}
return cmp.Compare(m.Index, otherMenu.Index)
}
func (m *MenuStatic) OnChangedFunc() {
detailsPanel.Clear()
detailsPanel.SetText(m.Description)
currentFocusKeys = []string{}
}
func (m *MenuStatic) OnSelectedFunc() {
positionLine.Clear()
positionLine.SetText(m.GetPath())
switch m.ID {
case "Networks":
currentMenuItemKeys = []string{
"<n> New Network",
}
default:
currentMenuItemKeys = []string{}
}
}
func (m *MenuStatic) OnDoneFunc() {
positionLine.Clear()
positionLine.SetText(m.GetPath())
currentMenuItemKeys = []string{}
}
func (m *MenuStatic) CurrentMenuInputCapture(event *tcell.EventKey) *tcell.EventKey {
switch m.ID {
case "Networks":
switch event.Key() {
case tcell.KeyRune:
switch event.Rune() {
case 'n':
newNetworkDialog.SetFocus(0)
pages.ShowPage(newNetworkPage)
app.SetFocus(newNetworkDialog)
return nil
}
}
}
return event
}