-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_folder.go
57 lines (44 loc) · 1.01 KB
/
menu_folder.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
package main
import (
"fmt"
"github.com/gdamore/tcell/v2"
)
type MenuFolder struct {
ID string `json:"id"`
ParentPath string `json:"parent"`
}
func (f *MenuFolder) Validate() error {
if f.ID == "" {
return fmt.Errorf("ID must be set")
}
if f.ParentPath != "" {
if _, ok := menuItems[f.GetParentPath()]; !ok {
return fmt.Errorf("ParentPath does not exist for %s: %s", f.ID, f.ParentPath)
}
}
return nil
}
func (f *MenuFolder) GetID() string {
return f.ID
}
func (f *MenuFolder) AsFolder() *MenuFolder {
return f
}
func (f *MenuFolder) GetParentPath() string {
return f.ParentPath
}
func (f *MenuFolder) GetParent() MenuItem {
return menuItems[f.ParentPath]
}
func (f *MenuFolder) GetPath() string {
if f.ParentPath == "" {
return f.ID
}
return f.GetParent().GetPath() + " -> " + f.ID
}
func (f *MenuFolder) CurrentMenuInputCapture(event *tcell.EventKey) *tcell.EventKey {
return event
}
func (f *MenuFolder) CurrentFocusInputCapture(event *tcell.EventKey) *tcell.EventKey {
return event
}