-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathex_menuitem.go
160 lines (154 loc) · 4.79 KB
/
ex_menuitem.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package electron
import "github.com/gopherjs/gopherjs/js"
// MenuItem roles
const (
RoleUndo = "undo"
RoleRedo = "redo"
RoleCut = "cut"
RoleCopy = "copy"
RolePaste = "paste"
RolePasteandmatchstyle = "pasteandmatchstyle"
RoleSelectall = "selectall"
RoleDelete = "delete"
// minimize - Minimize current window
RoleMinimize = "minimize"
// close - Close current window
RoleClose = "close"
// quit- Quit the application
RoleQuit = "quit-"
// reload - Reload the current window
RoleReload = "reload"
// toggledevtools - Toggle developer tools in the current window
RoleToggledevtools = "toggledevtools"
// togglefullscreen- Toggle full screen mode on the current window
RoleTogglefullscreen = "togglefullscreen-"
// resetzoom - Reset the focused page’s zoom level to the original size
RoleResetzoom = "resetzoom"
// zoomin - Zoom in the focused page by 10%
RoleZoomin = "zoomin"
// zoomout - Zoom out the focused page by 10%
RoleZoomout = "zoomout"
// On macOS role can also have following additional values:
// When specifying role on macOS, label and accelerator are the only options that
// will affect the MenuItem. All other options will be ignored.
RoleCOS = "cOS"
// about - Map to the orderFrontStandardAboutPanel action
RoleAbout = "about"
// hide - Map to the hide action
RoleHide = "hide"
// hideothers - Map to the hideOtherApplications action
RoleHideothers = "hideothers"
// unhide - Map to the unhideAllApplications action
RoleUnhide = "unhide"
// startspeaking - Map to the startSpeaking action
RoleStartspeaking = "startspeaking"
// stopspeaking - Map to the stopSpeaking action
RoleStopspeaking = "stopspeaking"
// front - Map to the arrangeInFront action
RoleFront = "front"
// zoom - Map to the performZoom action
RoleZoom = "zoom"
// window - The submenu is a “Window” menu
RoleWindow = "window"
// help - The submenu is a “Help” menu
RoleHelp = "help"
// services - The submenu is a “Services” menu
RoleServices = "services "
)
type MenuItemOptionEx struct {
// *js.Object
// click Function (optional) - Will be called with click(menuItem, browserWindow, event)
// when the menu item is clicked.
// menuItem MenuItem
// browserWindow BrowserWindow
// event Event
// Click func(item *Item, w *browserwindow.BrowserWindow, event *js.Object) `js:"click"`
Click func()
ClickEx func(item *MenuItem)
// role String (optional) - Define the action of the menu item,
// when specified the click property will be ignored.
Role string
// type String (optional) - Can be normal, separator, submenu, checkbox or radio.
Type string
// label String - (optional)
Label string
// sublabel String - (optional)
Sublabel string
// accelerator Accelerator (optional)
// icon (NativeImage | String) (optional)
Icon *NativeImage
// enabled Boolean (optional) - If false, the menu item will be greyed out and unclickable.
Enabled bool
// visible Boolean (optional) - If false, the menu item will be entirely hidden.
Visible bool
// checked Boolean (optional) - Should only be specified for checkbox or radio type menu items.
Checked bool
// submenu (MenuItemConstructorOptions[] | Menu) (optional) -
// Should be specified for submenu type menu items.
// If submenu is specified, the type: 'submenu' can be omitted.
// If the value is not a Menu then it will be automatically converted to one using Menu.buildFromTemplate.
SubMenuOptions []MenuItemOptionEx
SubMenu *Menu
// id String (optional) - Unique within a single menu.
// If defined then it can be used as a reference to this item by the position attribute.
ID string
// position String (optional) - This field allows fine-grained definition of
// the specific location within a given menu.
Position string
}
func (o *MenuItemOptionEx) toMap() js.M {
m := make(js.M)
if o.Click != nil {
m["click"] = o.Click
}
if o.ClickEx != nil {
m["click"] = o.ClickEx
}
if o.Role != "" {
m["role"] = o.Role
}
if o.Type != "" {
m["type"] = o.Type
}
if o.Label != "" {
m["label"] = o.Label
}
if o.Sublabel != "" {
m["sublabel"] = o.Sublabel
}
if o.Icon != nil {
m["icon"] = o.Icon
}
if o.Enabled != false {
m["enabled"] = o.Enabled
}
if o.Visible != false {
m["visible"] = o.Visible
}
if o.Checked != false {
m["checked"] = o.Checked
}
if o.SubMenuOptions != nil {
subm := make(js.S, 0)
for _, opt := range o.SubMenuOptions {
subm = append(subm, opt.toMap())
}
m["submenu"] = subm
}
if o.SubMenu != nil {
m["submenu"] = o.SubMenu
}
if o.ID != "" {
m["id"] = o.ID
}
if o.Position != "" {
m["position"] = o.Position
}
return m
}
func NewItemEx(opt MenuItemOptionEx) *MenuItem {
o := electron.Get("Menu").Call("MenuItem", opt.toMap())
return &MenuItem{
Object: o,
}
}