Find all model items that should be available in the context menu and create QActions for each, by
        using the available logic in popupmenu.PopupMenu.
972877
def _fill_context_menu_with_model_item_actions(self, context_menu: QMenu):
        
        # Get phrase folders to add to main menu
        logger.info("Rebuilding model item actions, adding all items marked for access through the tray icon.")
        folders = [folder for folder in self.config_manager.allFolders if folder.show_in_tray_menu]
        items = [item for item in self.config_manager.allItems if item.show_in_tray_menu]
        # Only extract the QActions, but discard the PopupMenu instance.
        # This is done, because the PopupMenu class is not directly usable as a context menu here.
        menu = popupmenu.PopupMenu(self.app.service, folders, items, False, "AutoKey")
        new_item_actions = menu.actions()
        context_menu.addActions(new_item_actions)
        for action in new_item_actions:  # type: QAction
            # QMenu does not take the ownership when adding QActions, so manually re-parent all actions.
            # This causes the QActions to be destroyed when the context menu is cleared or re-created.
            action.setParent(context_menu)

        if not context_menu.isEmpty():
            # Avoid a stray separator line, if no items are marked for display in the context menu.
            context_menu.addSeparator()
1008585
private void createContextMenu(List<I_CmsContextMenuEntry> entries) {

        Iterator<I_CmsContextMenuEntry> it = entries.iterator();
        while (it.hasNext()) {
            I_CmsContextMenuEntry entry = it.next();
            if (!entry.isVisible()) {
                continue;
            }
            if (entry.isSeparator()) {
                addSeparator();
            } else {
                A_CmsContextMenuItem item = entry.generateMenuItem();
                if (entry.hasSubMenu()) {
                    CmsContextMenu submenu = new CmsContextMenu(entry.getSubMenu(), m_isFixed, m_popup);
                    item.setSubMenu(submenu);
                    addItem(item);
                } else {
                    addItem(item);
                }
            }

        }
    }
100258
def filterOptions(self, text):
        
        if not text:
            self._completer.hide()
            self._completer.setCurrentItem(None)
            return

        # block the signals
        self._completer.setUpdatesEnabled(False)
        self._completer.blockSignals(True)

        # initialize the actions
        menu = self.parent()
        if not self._initialized:
            self.addItems([menu] + menu.findChildren(QMenu))
            self._initialized = True

        # filter the actions in the search view
        visible_count = 0
        item_count = self._completer.topLevelItemCount()
        for i in range(item_count):
            item = self._completer.topLevelItem(i)
            check = nativestring(item.text(0)).lower()
            hidden = not nativestring(text).lower() in check
            item.setHidden(hidden)
            visible_count += 1 if not hidden else 0

        # show the popup widget if it is not visible
        if not self._completer.isVisible():
            point = QPoint(-1, self.height())
            width = menu.width()
            height = menu.height() - self.height() - 1
            height = max(height, 22 * min(visible_count, 5))
            
            self._completer.move(self.mapToGlobal(point))
            self._completer.resize(width, height)
            self._completer.show()

        # restore signals
        self._completer.setUpdatesEnabled(True)
        self._completer.blockSignals(False)
1266535
public void setSelectedMenuItems(final List<? extends MenuItemSelectable> selectedItems) {
		MenuModel model = getOrCreateComponentModel();
		if (selectedItems == null || selectedItems.isEmpty()) {
			model.selectedMenuItems = null;
		} else {
			List<MenuItemSelectable> items = new ArrayList<>();
			for (MenuItemSelectable item : selectedItems) {
				if (item.isSelectAllowed()) {
					items.add(item);
				}
			}
			if (items.isEmpty()) {
				model.selectedMenuItems = null;
			} else {
				model.selectedMenuItems = items;
			}
		}
	}
1351090
private void initContextMenu() {

        m_contextMenu.removeItems();
        MenuItem main = m_contextMenu.addItem("", null);
        main.setIcon(FontOpenCms.CONTEXT_MENU);
        main.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_MENU_TITLE_0));
        CmsContextMenuTreeBuilder treeBuilder = new CmsContextMenuTreeBuilder(getDialogContext());
        CmsTreeNode<I_CmsContextMenuItem> tree = treeBuilder.buildAll(
            OpenCms.getWorkplaceAppManager().getMenuItemProvider().getMenuItems());
        for (CmsTreeNode<I_CmsContextMenuItem> node : tree.getChildren()) {
            createMenuEntry(main, node, treeBuilder);
        }
    }
1327154
protected function postActions()
    {
        if ($this->option('createaction') != null) {
            $this->createAction();
        }
        if ($this->option('menu') != null) {
            $this->createMenu();
        }
        if ($this->option('model') != null) {
            $this->createModel($this->argument('link'));
        }
    }
772023
def set_context_menu(self, context_menu):
        
        self.context_menu = context_menu
        self.context_menu.tree_view = self
        self.context_menu.init_actions()
        for action in self.context_menu.actions():
            self.addAction(action)
387483
private void initContextMenauAndToolBar() {
        toolbar = new JToolBar();
        toolbar.add(new Button(saveAction));
        toolbar.add(new Button(printAction));
        toolbar.addSeparator();
        toolbar.add(new Button(zoomInAction));
        toolbar.add(new Button(zoomOutAction));
        toolbar.add(new Button(resetAction));
        toolbar.addSeparator();
        toolbar.add(new Button(enlargePlotAreaAction));
        toolbar.add(new Button(shrinkPlotAreaAction));
        toolbar.add(new Button(increaseHeightAction));
        toolbar.add(new Button(decreaseHeightAction));
        toolbar.add(new Button(increaseWidthAction));
        toolbar.add(new Button(decreaseWidthAction));
        toolbar.addSeparator();
        toolbar.add(new Button(propertyAction));
    
        decreaseHeightAction.setEnabled(false);
        decreaseWidthAction.setEnabled(false);
        
        //Initialize popup menu.
        popup = new JPopupMenu();        
        popup.add(new JMenuItem(saveAction));
        popup.add(new JMenuItem(printAction));
        popup.addSeparator();
        popup.add(new JMenuItem(zoomInAction));
        popup.add(new JMenuItem(zoomOutAction));
        popup.add(new JMenuItem(resetAction));
        popup.addSeparator();
        popup.add(new JMenuItem(enlargePlotAreaAction));
        popup.add(new JMenuItem(shrinkPlotAreaAction));
        popup.add(new JMenuItem(increaseHeightAction));
        popup.add(new JMenuItem(decreaseHeightAction));
        popup.add(new JMenuItem(increaseWidthAction));
        popup.add(new JMenuItem(decreaseWidthAction));
        popup.addSeparator();
        popup.add(new JMenuItem(propertyAction));
        
        AncestorListener ancestorListener = new AncestorListener() {

            @Override
            public void ancestorAdded(AncestorEvent ae) {
                boolean inScrollPane = false;
                Container parent = getParent();
                while (parent != null) {
                    if (parent instanceof JScrollPane) {
                        inScrollPane = true;
                        scrollPane = (JScrollPane) parent;
                        break;
                    }
                    
                    parent = parent.getParent();
                }
                
                increaseHeightAction.setEnabled(inScrollPane);
                increaseWidthAction.setEnabled(inScrollPane);
            }

            @Override
            public void ancestorRemoved(AncestorEvent ae) {
            }

            @Override
            public void ancestorMoved(AncestorEvent ae) {
            }
        };
        
        addAncestorListener(ancestorListener);
    }
160969
def showContextMenu(self, pos):
        
        contextMenu = QtWidgets.QMenu()
        addInspectorActionsToMenu(contextMenu, self.execInspectorDialogAction,
                                  self.inspectorActionGroup)
        contextMenu.exec_(self.mapToGlobal(pos))
932642
def init_with_context(self, context):
        
        super(AppIconList, self).init_with_context(context)
        apps = self.children

        # Standard model only has a title, change_url and add_url.
        # Restore the app_name and name, so icons can be matched.
        for app in apps:
            app_name = self._get_app_name(app)
            app['name'] = app_name

            for model in app['models']:
                try:
                    model_name = self._get_model_name(model)
                    model['name'] = model_name
                    model['icon'] = self.get_icon_for_model(app_name, model_name) or appsettings.FLUENT_DASHBOARD_DEFAULT_ICON
                except ValueError:
                    model['icon'] = appsettings.FLUENT_DASHBOARD_DEFAULT_ICON

                # Automatically add STATIC_URL before relative icon paths.
                model['icon'] = self.get_icon_url(model['icon'])
                model['app_name'] = app_name
458596
def add_actions_to_context_menu(self, menu):
        """"""
        inspect_action = create_action(self, _("Inspect current object"),
                                    QKeySequence(get_shortcut('console',
                                                    'inspect current object')),
                                    icon=ima.icon('MessageBoxInformation'),
                                    triggered=self.inspect_object)

        clear_line_action = create_action(self, _("Clear line or block"),
                                          QKeySequence(get_shortcut(
                                                  'console',
                                                  'clear line')),
                                          triggered=self.clear_line)

        reset_namespace_action = create_action(self, _("Remove all variables"),
                                               QKeySequence(get_shortcut(
                                                       'ipython_console',
                                                       'reset namespace')),
                                               icon=ima.icon('editdelete'),
                                               triggered=self.reset_namespace)

        clear_console_action = create_action(self, _("Clear console"),
                                             QKeySequence(get_shortcut('console',
                                                               'clear shell')),
                                             triggered=self.clear_console)

        quit_action = create_action(self, _("&Quit"), icon=ima.icon('exit'),
                                    triggered=self.exit_callback)

        add_actions(menu, (None, inspect_action, clear_line_action,
                           clear_console_action, reset_namespace_action,
                           None, quit_action))
        return menu
248979
private void createMenus(Collection<ActionRef> parents, Collection<ActionRef> actions)
    {
        for (final ActionRef action : actions)
        {
            final Featurable menu = createMenu(action);
            if (!action.getRefs().isEmpty())
            {
                generateSubMenu(actions, action, menu);
            }
            else if (action.hasCancel())
            {
                previous.put(action, parents);
                generateCancel(action, menu);
            }
        }
        for (final Featurable current : menus)
        {
            handler.add(current);
        }
    }
644020
def get_crud_menus(self):
        
        results = defaultdict(list)
        for object_type in settings.OBJECT_MENU:
            for model_data in settings.OBJECT_MENU[object_type]:
                if self.current.has_permission(model_data.get('wf', model_data['name'])):
                    self._add_crud(model_data, object_type, results)
        return results
110601
def add_menu(self, menu):
        
        self._menus.append(menu)
        self._menus = sorted(list(set(self._menus)), key=lambda x: x.title())
        for action in menu.actions():
            action.setShortcutContext(QtCore.Qt.WidgetShortcut)
        self.addActions(menu.actions())
600134
def create(cls):
        

        class NewPopupCreateView(PopupCreateView, cls.parent_class):
            model = cls.model
            form_class = cls.form_class
            popup_name = cls.get_class_verbose_name()
            template_name = cls.get_template_name_create()
            permission_required = cls.get_permission_required('create')

            def get_context_data(self, **kwargs):
                kwargs.update(cls.context_for_all)
                kwargs.update(cls.context_for_create)
                return super(NewPopupCreateView, self).get_context_data(**kwargs)

        return NewPopupCreateView
821278
void rebuildMenu() {

        if (!getSelectedIds().isEmpty() && (m_menuBuilder != null)) {
            m_menu.removeAllItems();
            m_menuBuilder.buildContextMenu(getContextProvider().getDialogContext(), m_menu);
        }
    }
218044
def _showItemContextMenu(self, item, point, col):
        """"""
        menu = getattr(item, '_menu', None)
        if menu:
            settitle = getattr(item, '_set_menu_title', None)
            if settitle:
                settitle()
            # self._current_item tells callbacks what item the menu was referring to
            point = self.etw.mapToGlobal(point)
            self._current_item = item
            self.etw.clearSelection()
            self.etw.setItemSelected(item, True)
            menu.exec_(point)
        else:
            self._current_item = None