MCPcopy
hub / github.com/lxn/walk / insertAction

Method insertAction

menu.go:227–265  ·  view source on GitHub ↗
(action *Action, visibleChanged bool)

Source from the content-addressed store, hash-verified

225}
226
227func (m *Menu) insertAction(action *Action, visibleChanged bool) (err error) {
228 m.handleDefaultState(action)
229
230 if !visibleChanged {
231 action.addChangedHandler(m)
232 defer func() {
233 if err != nil {
234 action.removeChangedHandler(m)
235 }
236 }()
237 }
238
239 if !action.Visible() {
240 return
241 }
242
243 index := m.actions.indexInObserver(action)
244
245 var mii win.MENUITEMINFO
246
247 m.initMenuItemInfoFromAction(&mii, action)
248
249 if !win.InsertMenuItem(m.hMenu, uint32(index), true, &mii) {
250 return newError("InsertMenuItem failed")
251 }
252
253 if action.Default() {
254 win.SetMenuDefaultItem(m.hMenu, uint32(m.actions.indexInObserver(action)), true)
255 }
256
257 menu := action.menu
258 if menu != nil {
259 menu.window = m.window
260 }
261
262 m.ensureMenuBarRedrawn()
263
264 return
265}
266
267func (m *Menu) removeAction(action *Action, visibleChanged bool) error {
268 index := m.actions.indexInObserver(action)

Callers 2

onInsertedActionMethod · 0.95

Calls 9

handleDefaultStateMethod · 0.95
ensureMenuBarRedrawnMethod · 0.95
newErrorFunction · 0.85
addChangedHandlerMethod · 0.80
removeChangedHandlerMethod · 0.80
indexInObserverMethod · 0.80
DefaultMethod · 0.80
VisibleMethod · 0.65

Tested by

no test coverage detected