private static ListPopupStep createStep( String title, @NotNull ActionGroup actionGroup, @NotNull DataContext dataContext, boolean showNumbers, boolean useAlphaAsNumbers, boolean showDisabledActions, boolean honorActionMnemonics, Condition<AnAction> preselectActionCondition, @Nullable String actionPlace) { final Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); LOG.assertTrue(component != null, "dataContext has no component for new ListPopupStep"); final ActionStepBuilder builder = new ActionStepBuilder( dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics); if (actionPlace != null) { builder.setActionPlace(actionPlace); } builder.buildGroup(actionGroup); final List<ActionItem> items = builder.getItems(); return new ActionPopupStep( items, title, component, showNumbers || honorActionMnemonics && itemsHaveMnemonics(items), preselectActionCondition, false, showDisabledActions); }
@NotNull @Override public RelativePoint guessBestPopupLocation(@NotNull DataContext dataContext) { Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); JComponent focusOwner = component instanceof JComponent ? (JComponent) component : null; if (focusOwner == null) { Project project = PlatformDataKeys.PROJECT.getData(dataContext); IdeFrameImpl frame = project == null ? null : ((WindowManagerEx) WindowManager.getInstance()).getFrame(project); focusOwner = frame == null ? null : frame.getRootPane(); if (focusOwner == null) { throw new IllegalArgumentException("focusOwner cannot be null"); } } final Point point = PlatformDataKeys.CONTEXT_MENU_POINT.getData(dataContext); if (point != null) { return new RelativePoint(focusOwner, point); } Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); if (editor != null && focusOwner == editor.getContentComponent()) { return guessBestPopupLocation(editor); } else { return guessBestPopupLocation(focusOwner); } }
public ActionGroupPopup( final String title, @NotNull ActionGroup actionGroup, @NotNull DataContext dataContext, boolean showNumbers, boolean useAlphaAsNumbers, boolean showDisabledActions, boolean honorActionMnemonics, final Runnable disposeCallback, final int maxRowCount, final Condition<AnAction> preselectActionCondition, @Nullable final String actionPlace) { super( createStep( title, actionGroup, dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics, preselectActionCondition, actionPlace), maxRowCount); myDisposeCallback = disposeCallback; myComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { final JList list = (JList) e.getSource(); final ActionItem actionItem = (ActionItem) list.getSelectedValue(); if (actionItem == null) return; AnAction action = actionItem.getAction(); Presentation presentation = new Presentation(); presentation.setDescription(action.getTemplatePresentation().getDescription()); final String actualActionPlace = actionPlace == null ? ActionPlaces.UNKNOWN : actionPlace; action.update( new AnActionEvent( null, DataManager.getInstance().getDataContext(myComponent), actualActionPlace, presentation, ActionManager.getInstance(), 0)); ActionMenu.showDescriptionInStatusBar( true, myComponent, presentation.getDescription()); } }); }