-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmenu.go
47 lines (43 loc) · 1.05 KB
/
menu.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
package main
import (
"github.com/chenqinghe/walk"
"github.com/chenqinghe/walk/declarative"
"reflect"
)
func buildMenu(declMenu declarative.Menu) (*walk.Menu, error) {
menu, err := walk.NewMenu()
if err != nil {
return nil, err
}
for _, v := range declMenu.Items {
switch t := v.(type) {
case declarative.Menu:
m, err := buildMenu(t)
if err != nil {
return nil, err
}
menu.Actions().AddMenu(m)
case *declarative.Menu:
m, err := buildMenu(*t)
if err != nil {
return nil, err
}
menu.Actions().AddMenu(m)
case declarative.Action:
action := walk.NewAction()
action.SetText(t.Text)
action.Triggered().Attach(t.OnTriggered)
menu.Actions().Add(action)
case *declarative.Action:
action := walk.NewAction()
action.SetText(t.Text)
action.Triggered().Attach(t.OnTriggered)
menu.Actions().Add(action)
case declarative.Separator, *declarative.Separator:
menu.Actions().Add(walk.NewSeparatorAction())
default:
panic("unsupported MenuItem:" + reflect.TypeOf(v).String())
}
}
return menu, nil
}