@Override public void actionPerformed(final AnActionEvent event) { final Project project = event.getProject(); if (project == null) { return; } final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance() .createActionGroupPopup(TITLE, new PopupGroup(), event.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, true, event.getPlace()); JBPopupHelper.disableSpeedSearch(popup); JBPopupHelper.registerShiftActions(popup, TITLE, SHIFT_TITLE); JBPopupHelper.registerCtrlActions(popup, TITLE, CTRL_TITLE); popup.setAdText(AD_TEXT); popup.showCenteredInCurrentWindow(project); }
private void showHistory() { List<XExpression> expressions = myExpressionEditor.getRecentExpressions(); if (!expressions.isEmpty()) { ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) { @Override public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) { myExpressionEditor.setExpression(selectedValue); myExpressionEditor.requestFocusInEditor(); return FINAL_CHOICE; } }) { @Override protected ListCellRenderer getListElementRenderer() { return new ColoredListCellRenderer<XExpression>() { @Override protected void customizeCellRenderer(JList list, XExpression value, int index, boolean selected, boolean hasFocus) { append(value.getExpression()); } }; } }; popup.getList().setFont(EditorUtil.getEditorFont()); popup.showUnderneathOf(myExpressionEditor.getEditorComponent()); } }
private static Action createNumberAction(final int mnemonic, final ListPopupImpl listPopup, final Map<PsiElement, GotoRelatedItem> itemsMap, final Processor<Object> processor) { return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { for (final Object item : listPopup.getListStep().getValues()) { if (getMnemonic(item, itemsMap) == mnemonic) { listPopup.setFinalRunnable(new Runnable() { @Override public void run() { processor.process(item); } }); listPopup.closeOk(null); } } } }; }
private static Action createNumberAction(final int number, final ListPopupImpl listPopup, final Executor executor) { return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (listPopup.getSpeedSearch().isHoldingFilter()) return; for (final Object item : listPopup.getListStep().getValues()) { if (item instanceof ItemWrapper && ((ItemWrapper)item).getMnemonic() == number) { listPopup.setFinalRunnable(new Runnable() { @Override public void run() { execute((ItemWrapper)item, executor); } }); listPopup.closeOk(null); } } } }; }
private void registerActions(final ListPopupImpl popup) { popup.registerAction("delete", KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), new AbstractAction() { public void actionPerformed(ActionEvent e) { JList list = popup.getList(); int selectedIndex = list.getSelectedIndex(); ListPopupModel model = (ListPopupModel) list.getModel(); PopupFactoryImpl.ActionItem selectedItem = (PopupFactoryImpl.ActionItem) model.get(selectedIndex); if (selectedItem != null && selectedItem.getAction() instanceof RunGoalAction) { RunGoalAction action = (RunGoalAction) selectedItem.getAction(); boolean deleted = ApplicationComponent.getInstance().getState().removeGoal(action.getGoal()); if (deleted) { model.deleteItem(selectedItem); if (selectedIndex == list.getModel().getSize()) { // is last list.setSelectedIndex(selectedIndex - 1); } else { list.setSelectedIndex(selectedIndex); } } } } }); }
private void showHistory() { List<XExpression> expressions = myExpressionEditor.getRecentExpressions(); if (!expressions.isEmpty()) { ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) { @Override public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) { myExpressionEditor.setExpression(selectedValue); myExpressionEditor.requestFocusInEditor(); return FINAL_CHOICE; } }) { @Override protected ListCellRenderer getListElementRenderer() { return new ColoredListCellRenderer<XExpression>() { @Override protected void customizeCellRenderer(@Nonnull JList list, XExpression value, int index, boolean selected, boolean hasFocus) { append(value.getExpression()); } }; } }; popup.getList().setFont(EditorUtil.getEditorFont()); popup.showUnderneathOf(myExpressionEditor.getEditorComponent()); } }
/** * Override this if you haven't PsiMethod, like in Kotlin. * @param position * @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.sessionResumed(); 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.sessionResumed(); session.stepInto(true, createMethodFilter(chosenTarget)); } }); ListPopupImpl popup = new ListPopupImpl(popupStep); DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.STEP_INTO); DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.SMART_STEP_INTO); popup.addListSelectionListener(new ListSelectionListener() { 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); DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine()); } return true; } return false; }
private void chooseAndQualify(final Editor editor) { final BaseListPopupStep<PsiVariable> step = new BaseListPopupStep<PsiVariable>(QuickFixBundle.message("add.qualifier"), myCandidates) { @Override public PopupStep onChosen(final PsiVariable selectedValue, final boolean finalChoice) { if (selectedValue != null && finalChoice) { WriteCommandAction.runWriteCommandAction(selectedValue.getProject(), new Runnable() { @Override public void run() { qualify(selectedValue, editor); } }); } return FINAL_CHOICE; } @NotNull @Override public String getTextFor(final PsiVariable value) { return value.getName(); } @Override public Icon getIconFor(final PsiVariable aValue) { return aValue.getIcon(0); } }; final ListPopupImpl popup = new ListPopupImpl(step); popup.showInBestPositionFor(editor); }
protected WizardPopup createPopup(WizardPopup parent, PopupStep step, Object parentValue) { if (step instanceof ListPopupStep) { return new ListPopupImpl(parent, (ListPopupStep)step, parentValue); } else if (step instanceof TreePopupStep) { return new TreePopupImpl(parent, (TreePopupStep)step, parentValue); } else { throw new IllegalArgumentException(step.getClass().toString()); } }
@NotNull @Override public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes, final Runnable onNo, int defaultOptionIndex) { final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title, new String[]{yesText, noText}) { @Override public PopupStep onChosen(String selectedValue, final boolean finalChoice) { if (selectedValue.equals(yesText)) { onYes.run(); } else { onNo.run(); } return FINAL_CHOICE; } @Override public void canceled() { onNo.run(); } @Override public boolean isMnemonicsNavigationEnabled() { return true; } }; step.setDefaultOptionIndex(defaultOptionIndex); final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText); }
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 public void actionPerformed(ActionEvent e) { popup.handleSelect(true); } }); } }
private void showRemoteSelector(@NotNull Component component, @NotNull Point point) { final List<String> remotes = getRemotes(); if (remotes.size() <= 1) { return; } ListPopup popup = new ListPopupImpl(new BaseListPopupStep<String>(null, remotes) { @Override public PopupStep onChosen(String selectedValue, boolean finalChoice) { myRemoteRenderer.updateLinkText(selectedValue); if (myFireOnChangeAction != null && !myTargetEditor.isShowing()) { //fireOnChange only when editing completed myFireOnChangeAction.run(); } return super.onChosen(selectedValue, finalChoice); } }) { @Override public void cancel(InputEvent e) { super.cancel(e); if (myTargetEditor.isShowing()) { //repaint and force move focus to target editor component GitPushTargetPanel.this.repaint(); IdeFocusManager.getInstance(myProject).requestFocus(myTargetEditor, true); } } }; popup.show(new RelativePoint(component, point)); }
public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes, final Runnable onNo, int defaultOptionIndex) { final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title, new String[] { yesText, noText }) { @Override public PopupStep onChosen(String selectedValue, final boolean finalChoice) { if (selectedValue.equals(yesText)) { onYes.run(); } else { onNo.run(); } return FINAL_CHOICE; } @Override public void canceled() { } @Override public boolean isMnemonicsNavigationEnabled() { return true; } }; step.setDefaultOptionIndex(defaultOptionIndex); final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText); }
protected WizardPopup createPopup(WizardPopup parent, PopupStep step, Object parentValue) { if (step instanceof AsyncPopupStep) { return new AsyncPopupImpl(parent, (AsyncPopupStep)step, parentValue); } if (step instanceof ListPopupStep) { return new ListPopupImpl(parent, (ListPopupStep)step, parentValue); } else if (step instanceof TreePopupStep) { return new TreePopupImpl(parent, (TreePopupStep)step, parentValue); } else { throw new IllegalArgumentException(step.getClass().toString()); } }
@Nonnull @Override public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes, final Runnable onNo, int defaultOptionIndex) { final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title, yesText, noText) { @Override public PopupStep onChosen(String selectedValue, final boolean finalChoice) { return doFinalStep(selectedValue.equals(yesText) ? onYes : onNo); } @Override public void canceled() { onNo.run(); } @Override public boolean isMnemonicsNavigationEnabled() { return true; } }; step.setDefaultOptionIndex(defaultOptionIndex); final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText); }
public static void registerExtraHandleShortcuts(final ListPopupImpl popup, String... actionNames) { for (String name : actionNames) { KeyStroke stroke = KeymapUtil.getKeyStroke(ActionManager.getInstance().getAction(name).getShortcutSet()); if (stroke != null) { popup.registerAction("handleSelection " + stroke, stroke, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { popup.handleSelect(true); } }); } } }
private static Action createNumberAction(final int mnemonic, final ListPopupImpl listPopup, final Map<PsiElement, GotoRelatedItem> itemsMap, final Processor<Object> processor) { return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { for (final Object item : listPopup.getListStep().getValues()) { if (getMnemonic(item, itemsMap) == mnemonic) { listPopup.setFinalRunnable(() -> processor.process(item)); listPopup.closeOk(null); } } } }; }
private void chooseAndQualify(final Editor editor) { final BaseListPopupStep<PsiVariable> step = new BaseListPopupStep<PsiVariable>(JavaQuickFixBundle.message("add.qualifier"), myCandidates) { @Override public PopupStep onChosen(final PsiVariable selectedValue, final boolean finalChoice) { if(selectedValue != null && finalChoice) { WriteCommandAction.runWriteCommandAction(selectedValue.getProject(), new Runnable() { @Override public void run() { qualify(selectedValue, editor); } }); } return FINAL_CHOICE; } @NotNull @Override public String getTextFor(final PsiVariable value) { return value.getName(); } @Override public Icon getIconFor(final PsiVariable aValue) { return IconDescriptorUpdaters.getIcon(aValue, 0); } }; final ListPopupImpl popup = new ListPopupImpl(step); popup.showInBestPositionFor(editor); }
private void showHistory() { List<XExpression> expressions = getRecentExpressions(); if(!expressions.isEmpty()) { ListPopupImpl historyPopup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) { @Override public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) { setExpression(selectedValue); requestFocusInEditor(); return FINAL_CHOICE; } }) { @Override protected ListCellRenderer getListElementRenderer() { return new ColoredListCellRenderer<XExpression>() { @Override protected void customizeCellRenderer(@NotNull JList list, XExpression value, int index, boolean selected, boolean hasFocus) { append(value.getExpression(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } }; } }; historyPopup.getList().setFont(EditorUtil.getEditorFont()); historyPopup.showUnderneathOf(getEditorComponent()); } }
/** * Disables speed search. * * @param popup the popup to disable speed search for */ public static void disableSpeedSearch(final ListPopupImpl popup) { final SpeedSearch speedSearch = popup.getSpeedSearch(); speedSearch.setEnabled(false); speedSearch.addChangeListener(event -> speedSearch.updatePattern("")); }
@NotNull @Override public ListPopup createWizardStep(@NotNull PopupStep step) { return new ListPopupImpl((ListPopupStep)step); }
@NotNull @Override public ListPopup createListPopup(@NotNull ListPopupStep step) { return new ListPopupImpl(step); }
@NotNull @Override public ListPopup createListPopup(@NotNull ListPopupStep step, int maxRowCount) { return new ListPopupImpl(step, maxRowCount); }
private RunListElementRenderer(ListPopupImpl popup, boolean hasSideBar) { super(popup); myPopup1 = popup; myHasSideBar = hasSideBar; }
@NotNull @Override public ListPopup createWizardStep(@NotNull PopupStep step) { return new ListPopupImpl((ListPopupStep) step); }
@Override protected void showPopup(AnActionEvent e, ListPopup p) { final ListPopupImpl popup = (ListPopupImpl) p; registerActions(popup); super.showPopup(e, popup); }
@Nonnull @Override public ListPopup createWizardStep(@Nonnull PopupStep step) { return new ListPopupImpl((ListPopupStep)step); }
@Nonnull @Override public ListPopup createListPopup(@Nonnull ListPopupStep step) { return new ListPopupImpl(step); }
@Nonnull @Override public ListPopup createListPopup(@Nonnull ListPopupStep step, int maxRowCount) { return new ListPopupImpl(step, maxRowCount); }
public MyPopupListElementRenderer(ListPopupImpl aPopup) { super(aPopup); }
@RequiredDispatchThread @Override public void actionPerformed(@Nonnull AnActionEvent e) { final Project project = getEventProject(e); if (project == null) return; XLocalAttachDebuggerProvider[] providers = Extensions.getExtensions(XLocalAttachDebuggerProvider.EP); new Task.Backgroundable(project, XDebuggerBundle.message("xdebugger.attach.toLocal.action.collectingProcesses"), true, PerformInBackgroundOption.DEAF) { @Override public void run(@Nonnull ProgressIndicator indicator) { ProcessInfo[] processList = OSProcessUtil.getProcessList(); List<AttachItem> items = collectAttachItems(project, processList, indicator, providers); ApplicationManager.getApplication().invokeLater(() -> { if (project.isDisposed()) { return; } ProcessListStep step = new ProcessListStep(items, project); final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step); final JList mainList = ((ListPopupImpl) popup).getList(); ListSelectionListener listener = event -> { if (event.getValueIsAdjusting()) return; Object item = ((JList) event.getSource()).getSelectedValue(); // if a sub-list is closed, fallback to the selected value from the main list if (item == null) { item = mainList.getSelectedValue(); } if (item instanceof AttachItem) { String debuggerName = ((AttachItem)item).getSelectedDebugger().getDebuggerDisplayName(); debuggerName = StringUtil.shortenTextWithEllipsis(debuggerName, 50, 0); ((ListPopupImpl)popup).setCaption(XDebuggerBundle.message("xdebugger.attach.toLocal.popup.title", debuggerName)); } }; popup.addListSelectionListener(listener); // force first valueChanged event listener.valueChanged(new ListSelectionEvent(mainList, mainList.getMinSelectionIndex(), mainList.getMaxSelectionIndex(), false)); popup.showCenteredInCurrentWindow(project); }); } }.queue(); }