List of usage examples for com.intellij.openapi.keymap KeymapUtil getKeyStroke
@Nullable
public static KeyStroke getKeyStroke(@NotNull final ShortcutSet shortcutSet)
From source file:com.intellij.compiler.actions.BuildArtifactAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { final Project project = getEventProject(e); if (project == null) return;// w w w .j a v a2s. co m final List<Artifact> artifacts = ArtifactUtil.getArtifactWithOutputPaths(project); if (artifacts.isEmpty()) return; List<ArtifactPopupItem> items = new ArrayList<ArtifactPopupItem>(); if (artifacts.size() > 1) { items.add(0, new ArtifactPopupItem(null, "All Artifacts", EmptyIcon.ICON_16)); } Set<Artifact> selectedArtifacts = new HashSet<Artifact>( ArtifactsWorkspaceSettings.getInstance(project).getArtifactsToBuild()); TIntArrayList selectedIndices = new TIntArrayList(); if (Comparing.haveEqualElements(artifacts, selectedArtifacts) && selectedArtifacts.size() > 1) { selectedIndices.add(0); selectedArtifacts.clear(); } for (Artifact artifact : artifacts) { final ArtifactPopupItem item = new ArtifactPopupItem(artifact, artifact.getName(), artifact.getArtifactType().getIcon()); if (selectedArtifacts.contains(artifact)) { selectedIndices.add(items.size()); } items.add(item); } final ProjectSettingsService projectSettingsService = ProjectSettingsService.getInstance(project); final ArtifactAwareProjectSettingsService settingsService = projectSettingsService instanceof ArtifactAwareProjectSettingsService ? (ArtifactAwareProjectSettingsService) projectSettingsService : null; final ChooseArtifactStep step = new ChooseArtifactStep(items, artifacts.get(0), project, settingsService); step.setDefaultOptionIndices(selectedIndices.toNativeArray()); final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance().createListPopup(step); final KeyStroke editKeyStroke = KeymapUtil.getKeyStroke(CommonShortcuts.getEditSource()); if (settingsService != null && editKeyStroke != null) { popup.registerAction("editArtifact", editKeyStroke, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { Object[] values = popup.getSelectedValues(); popup.cancel(); settingsService.openArtifactSettings( values.length > 0 ? ((ArtifactPopupItem) values[0]).getArtifact() : null); } }); } popup.showCenteredInCurrentWindow(project); }
From source file:com.intellij.debugger.actions.JvmSmartStepIntoHandler.java
License:Apache License
/** * Override this if you haven't PsiMethod, like in Kotlin. * * @param position//from w ww . j a v a 2 s .com * @param session * @param fileEditor * @return false to continue for another handler or for default action (step into) */ public boolean doSmartStep(SourcePosition position, final DebuggerSession session, TextEditor fileEditor) { final List<SmartStepTarget> targets = findSmartStepTargets(position); if (!targets.isEmpty()) { final SmartStepTarget firstTarget = targets.get(0); if (targets.size() == 1) { session.stepInto(true, createMethodFilter(firstTarget)); } else { final Editor editor = fileEditor.getEditor(); final PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(editor, targets, new PsiMethodListPopupStep.OnChooseRunnable() { public void execute(SmartStepTarget chosenTarget) { session.stepInto(true, createMethodFilter(chosenTarget)); } }); final ListPopup popup = new ListPopupImpl(popupStep) { @Override protected JComponent createContent() { registerExtraHandleShortcuts(XDebuggerActions.STEP_INTO); registerExtraHandleShortcuts(XDebuggerActions.SMART_STEP_INTO); return super.createContent(); } private void registerExtraHandleShortcuts(String actionName) { AnAction action = ActionManager.getInstance().getAction(actionName); KeyStroke stroke = KeymapUtil.getKeyStroke(action.getShortcutSet()); if (stroke != null) { registerAction("handleSelection " + stroke, stroke, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { handleSelect(true); } }); } } }; popup.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { popupStep.getScopeHighlighter().dropHighlight(); if (!e.getValueIsAdjusting()) { final SmartStepTarget selectedTarget = (SmartStepTarget) ((JBList) e.getSource()) .getSelectedValue(); if (selectedTarget != null) { highlightTarget(popupStep, selectedTarget); } } } }); highlightTarget(popupStep, firstTarget); final RelativePoint point = DebuggerUIUtil.calcPopupLocation(editor, position.getLine()); popup.show(point); } return true; } return false; }
From source file:com.intellij.xdebugger.impl.ui.DebuggerUIUtil.java
License:Apache License
public static void registerExtraHandleShortcuts(final ListPopupImpl popup, String actionName) { AnAction action = ActionManager.getInstance().getAction(actionName); KeyStroke stroke = KeymapUtil.getKeyStroke(action.getShortcutSet()); if (stroke != null) { popup.registerAction("handleSelection " + stroke, stroke, new AbstractAction() { @Override//w w w .j a va2 s. c o m public void actionPerformed(ActionEvent e) { popup.handleSelect(true); } }); } }