Add Item to a Menu, with action
    m = Menu(parent, menu, label, longtext, action=None)
174449
def MenuItem(parent, menu, label='', longtext='', action=None, default=True,
             **kws):
    
    item = menu.Append(-1, label, longtext, **kws)
    kind = item.GetKind()
    if kind == wx.ITEM_CHECK:
        item.Check(default)
    if callable(action):
        parent.Bind(wx.EVT_MENU, action, item)
    return item
867290
function () {
        var self = this;

        function activateMenuItemsByValue(menu, value) {
          if (menu instanceof Menu) {
            menu.items().each(function (ctrl) {
              if (!ctrl.hasMenus()) {
                ctrl.active(ctrl.value() === value);
              }
            });
          }
        }

        function getSelectedItem(menuValues, value) {
          var selectedItem;

          if (!menuValues) {
            return;
          }

          for (var i = 0; i < menuValues.length; i++) {
            if (menuValues[i].value === value) {
              return menuValues[i];
            }

            if (menuValues[i].menu) {
              selectedItem = getSelectedItem(menuValues[i].menu, value);
              if (selectedItem) {
                return selectedItem;
              }
            }
          }
        }

        self.on('show', function (e) {
          activateMenuItemsByValue(e.control, self.value());
        });

        self.state.on('change:value', function (e) {
          var selectedItem = getSelectedItem(self.state.get('menu'), e.value);

          if (selectedItem) {
            self.text(selectedItem.text);
          } else {
            self.text(self.settings.text);
          }
        });

        return self._super();
      }
492243
public void addMenuItem(CmsAdminMenuItem item, float position) {

        m_container.addIdentifiableObject(item.getId(), item, position);
    }
551757
public static JMenuItem addMenuItem (
        ActionListener l, JMenu menu, String name)
    {
        return addMenuItem(l, menu, name, null, null);
    }
60946
def submenu key, label, &block
      item = CMenuItem.new(key, label)
      @options << item
      item.action = PromptMenu.new @caller, label, &block
    end
590770
def add_to_submenu(self, submenu_path, item):
        ''''''
        if len(submenu_path) == 0:
            self.add(item)
            return
        for m in self.items:
            if isinstance(m, MPMenuSubMenu) and submenu_path[0] == m.name:
                m.add_to_submenu(submenu_path[1:], item)
                return
        self.add(MPMenuSubMenu(submenu_path[0], []))
        self.add_to_submenu(submenu_path, item)
917504
def addAction(self, action):
        
        super(XDockToolbar, self).addAction(action)
        
        label = XDockActionLabel(action, self.minimumPixmapSize(), self)
        label.setPosition(self.position())
        
        layout = self.layout()
        layout.insertWidget(layout.count() - 1, label)
491975
public void addAction(M element, short value)
    {
        actions.put(element, Short.valueOf(value));
    }
280797
private MenuItem addInternal(int group, int id, int categoryOrder, CharSequence title) {
        final int ordering = getOrdering(categoryOrder);

        final MenuItemImpl item = new MenuItemImpl(this, group, id, categoryOrder,
                ordering, title, mDefaultShowAsAction);

        if (mCurrentMenuInfo != null) {
            // Pass along the current menu info
            item.setMenuInfo(mCurrentMenuInfo);
        }

        mItems.add(findInsertIndex(mItems, ordering), item);
        onItemsChanged(true);

        return item;
    }
744329
def add(self, text, checked=False, sort=None):
        
        if self.parent is None:
            raise exception.InvalidException('Item has no parent')
        node = self.parent.add(text, checked, sort)
        self.indent(node)
        return node
638317
def OnMenu(self, event):
        """"""

        msgtype = self.ids_msgs[event.GetId()]
        post_command_event(self.parent, msgtype)
864655
def addMenuItem( self, newItem, atItem ):
        
        tree = self.uiMenuTREE
        
        if ( not atItem ):
            tree.addTopLevelItem(newItem)
            
        elif ( atItem.data(0, Qt.UserRole) == 'menu' ):
            atItem.addChild(newItem)
        
        elif ( atItem.parent() ):
            index = atItem.parent().indexOfChild(atItem)
            atItem.parent().insertChild(index + 1, newItem)
        
        else:
            index = tree.indexOfTopLevelItem(atItem)
            tree.insertTopLevelItem(index + 1, newItem)
406605
public JMenuItem addMenuItem(JMenu menu, String actionKey, char[] rgChars)
    {
        JMenuItem menuItem;
        Action action = (Action)this.get(actionKey);
        if (action == null)
            return null;
        menu.add(menuItem = new JMenuItem(action));
        char firstChar = ActionManager.getFirstChar((String)menuItem.getAction().getValue(Action.NAME), rgChars, false);
        if (firstChar != NO_CHAR)
            menuItem.setMnemonic(firstChar);
        menuItem.setHorizontalTextPosition(JButton.RIGHT);

        return menuItem;
    }
609336
def contextMenuEvent(self, event):
        
        menu = QtWidgets.QPlainTextEdit.createStandardContextMenu(self)
        mg = self.getGlobalsMenu()

        a0 = menu.actions()[0]
        menu.insertMenu(a0, mg)
        menu.insertSeparator(a0)

        menu.addSeparator()
        a = QtWidgets.QAction('Show line numbers', menu)
        l = self.codeEditor.lineNumbers
        a.setCheckable(True)
        a.setChecked(l.isVisible())
        a.triggered.connect(lambda checked: l.show() if checked else l.hide())
        menu.addAction(a)

        menu.addSeparator()
        a = QtWidgets.QAction('Save to file', menu)
        a.triggered.connect(self.saveToFile)
        menu.addAction(a)

        menu.exec_(event.globalPos())
1080499
def add(self, callback=None, name=None, shortcut=None, alias=None,
            docstring=None, menu=None, verbose=True):
        """"""
        if callback is None:
            # Allow to use either add(func) or @add or @add(...).
            return partial(self.add, name=name, shortcut=shortcut,
                           alias=alias, menu=menu)
        assert callback

        # Get the name from the callback function if needed.
        name = name or callback.__name__
        alias = alias or _alias(name)
        name = name.replace('&', '')
        shortcut = shortcut or self._default_shortcuts.get(name, None)

        # Skip existing action.
        if name in self._actions_dict:
            return

        # Set the status tip from the function's docstring.
        docstring = docstring or callback.__doc__ or name
        docstring = re.sub(r'[ \t\r\f\v]{2,}', ' ', docstring.strip())

        # Create and register the action.
        action = _create_qaction(self.gui, name, callback,
                                 shortcut,
                                 docstring=docstring,
                                 alias=alias,
                                 )
        action_obj = Bunch(qaction=action, name=name, alias=alias,
                           shortcut=shortcut, callback=callback, menu=menu)
        if verbose and not name.startswith('_'):
            logger.log(5, "Add action `%s` (%s).", name,
                       _get_shortcut_string(action.shortcut()))
        self.gui.addAction(action)
        # Add the action to the menu.
        menu = menu or self.menu
        # Do not show private actions in the menu.
        if menu and not name.startswith('_'):
            self.gui.get_menu(menu).addAction(action)
        self._actions_dict[name] = action_obj
        # Register the alias -> name mapping.
        self._aliases[alias] = name

        # Set the callback method.
        if callback:
            setattr(self, name, callback)
1088776
def add(title_or_item, element_id=nil, options={}, &block)
      if element_id.is_a?(NSDictionary)
        options = element_id
        element_id = nil
      end

      if title_or_item.is_a?(NSMenuItem)
        item = title_or_item
        menu = nil
        retval = item
      elsif title_or_item.is_a?(NSMenu)
        menu = title_or_item
        item = self.item(menu.title, options)
        item.submenu = menu
        retval = menu
      else
        title = title_or_item
        item = self.item(title, options)

        if block
          menu = create(title)
          item.submenu = menu
          retval = menu
        else
          retval = item
        end
      end

      self.apply(:add_child, item)

      if menu && block
        menuitem_was = @menu_item
        @menu_item = item
        context(menu, &block)
        @menu_item = menuitem_was
      end

      if element_id
        create(retval, element_id)
      end

      return retval
    end
691358
def _menuitem(self, label, icon, onclick, checked=None):
        
        if checked is not None:
            item = Gtk.CheckMenuItem()
            item.set_active(checked)
        elif icon is None:
            item = Gtk.MenuItem()
        else:
            item = Gtk.ImageMenuItem()
            item.set_image(icon)
            # I don't really care for the "show icons only for nouns, not
            # for verbs" policy:
            item.set_always_show_image(True)
        if label is not None:
            item.set_label(label)
        if isinstance(onclick, Gtk.Menu):
            item.set_submenu(onclick)
        elif onclick is not None:
            item.connect('activate', onclick)
        return item