@Override public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement psiElement) throws IncorrectOperationException { JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>("Chosen", "Document", "Sample") { @Override public PopupStep onChosen(String selectedValue, boolean finalChoice) { if ("Document".equals(selectedValue)) { openDocument(psiElement.getText()); } else if ("Sample".equals(selectedValue)) { openSample(project, editor); } return super.onChosen(selectedValue, finalChoice); } }).showInBestPositionFor(editor); }
@Override protected void selectTargets(List<PsiLiteralExpression> targets, final Consumer<List<PsiLiteralExpression>> selectionConsumer) { if (targets.size() == 1) { selectionConsumer.consume(targets); } else { JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<PsiLiteralExpression>("Choose Inspections to Highlight Suppressed Problems from", targets){ @Override public PopupStep onChosen(PsiLiteralExpression selectedValue, boolean finalChoice) { selectionConsumer.consume(Collections.singletonList(selectedValue)); return FINAL_CHOICE; } @NotNull @Override public String getTextFor(PsiLiteralExpression value) { final Object o = value.getValue(); LOG.assertTrue(o instanceof String); return (String)o; } }).showInBestPositionFor(myEditor); } }
@Override public void fix(final JComponent contextComponent, RelativePoint relativePoint) { JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationErrorQuickFix>(null, myDescription.getFixes()) { @NotNull @Override public String getTextFor(ConfigurationErrorQuickFix value) { return value.getActionName(); } @Override public PopupStep onChosen(final ConfigurationErrorQuickFix selectedValue, boolean finalChoice) { return doFinalStep(new Runnable() { @Override public void run() { selectedValue.performFix(); } }); } }).show(relativePoint); }
public static BaseListPopupStep<LibraryType> createChooseTypeStep(final ClasspathPanel classpathPanel, final ParameterizedRunnable<LibraryType> action) { return new BaseListPopupStep<LibraryType>(IdeBundle.message("popup.title.select.library.type"), getSuitableTypes(classpathPanel)) { @NotNull @Override public String getTextFor(LibraryType value) { return value != null ? value.getCreateActionName() : IdeBundle.message("create.default.library.type.action.name"); } @Override public Icon getIconFor(LibraryType aValue) { return aValue != null ? aValue.getIcon(null) : PlatformIcons.LIBRARY_ICON; } @Override public PopupStep onChosen(final LibraryType selectedValue, boolean finalChoice) { return doFinalStep(new Runnable() { @Override public void run() { action.run(selectedValue); } }); } }; }
private static ListPopupStep buildStep(@NotNull final List<Pair<AnAction, KeyStroke>> actions, final DataContext ctx) { return new BaseListPopupStep<Pair<AnAction, KeyStroke>>("Choose an action", ContainerUtil.findAll(actions, new Condition<Pair<AnAction, KeyStroke>>() { @Override public boolean value(Pair<AnAction, KeyStroke> pair) { final AnAction action = pair.getFirst(); final Presentation presentation = action.getTemplatePresentation().clone(); AnActionEvent event = new AnActionEvent(null, ctx, ActionPlaces.UNKNOWN, presentation, ActionManager.getInstance(), 0); ActionUtil.performDumbAwareUpdate(action, event, true); return presentation.isEnabled() && presentation.isVisible(); } })) { @Override public PopupStep onChosen(Pair<AnAction, KeyStroke> selectedValue, boolean finalChoice) { invokeAction(selectedValue.getFirst(), ctx); return FINAL_CHOICE; } }; }
private static ListPopup createPopup(final ArrayList<VirtualFile> files, final ArrayList<Icon> icons) { final BaseListPopupStep<VirtualFile> step = new BaseListPopupStep<VirtualFile>("File Path", files, icons) { @NotNull @Override public String getTextFor(final VirtualFile value) { return value.getPresentableName(); } @Override public PopupStep onChosen(final VirtualFile selectedValue, final boolean finalChoice) { final File selectedFile = new File(getPresentableUrl(selectedValue)); if (selectedFile.exists()) { ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { openFile(selectedFile); } }); } return FINAL_CHOICE; } }; return JBPopupFactory.getInstance().createListPopup(step); }
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()); } }
@Override public PopupStep onChosen(final VirtualFile selectedValue, boolean finalChoice) { if (selectedValue == null) { myNewBaseSelector.run(); return null; } final List<AbstractFilePatchInProgress.PatchChange> selectedChanges = myChangesTreeList.getSelectedChanges(); if (selectedChanges.size() >= 1) { for (AbstractFilePatchInProgress.PatchChange patchChange : selectedChanges) { final AbstractFilePatchInProgress patch = patchChange.getPatchInProgress(); patch.setNewBase(selectedValue); } updateTree(false); } return null; }
@Override public PopupStep onChosen(LookupElementAction selectedValue, boolean finalChoice) { final LookupElementAction.Result result = selectedValue.performLookupAction(); if (result == LookupElementAction.Result.HIDE_LOOKUP) { myLookup.hideLookup(true); } else if (result == LookupElementAction.Result.REFRESH_ITEM) { myLookup.updateLookupWidth(myLookupElement); myLookup.requestResize(); myLookup.refreshUi(false, true); } else if (result instanceof LookupElementAction.Result.ChooseItem) { myLookup.setCurrentItem(((LookupElementAction.Result.ChooseItem)result).item); CommandProcessor.getInstance().executeCommand(myLookup.getEditor().getProject(), new Runnable() { @Override public void run() { myLookup.finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR); } }, null, null); } return FINAL_CHOICE; }
private PopupStep addExcludedFramework(final @NotNull FrameworkType frameworkType) { final String projectItem = "In the whole project"; return new BaseListPopupStep<String>(null, new String[]{projectItem, "In directory..."}) { @Override public PopupStep onChosen(String selectedValue, boolean finalChoice) { if (selectedValue.equals(projectItem)) { addAndRemoveDuplicates(frameworkType, null); return FINAL_CHOICE; } else { return doFinalStep(new Runnable() { @Override public void run() { chooseDirectoryAndAdd(frameworkType); } }); } } }; }
public PopupStep onChosen(final ErrorWithFix selectedValue, final boolean finalChoice) { if (selectedValue.second instanceof PopupQuickFix) { return ((PopupQuickFix) selectedValue.second).getPopupStep(); } if (finalChoice || !myShowSuppresses) { return doFinalStep(new Runnable() { public void run() { CommandProcessor.getInstance().executeCommand(myEditor.getProject(), new Runnable() { public void run() { selectedValue.second.run(); } }, selectedValue.second.getName(), null); } }); } if (selectedValue.first.getInspectionId() != null && selectedValue.second.getComponent() != null && !(selectedValue.second instanceof SuppressFix)) { ArrayList<ErrorWithFix> suppressList = new ArrayList<ErrorWithFix>(); buildSuppressFixes(selectedValue.first, suppressList, false); return new QuickFixPopupStep(suppressList, false); } return FINAL_CHOICE; }
private void doFix(Editor editor, final DomFileElement<IdeaPlugin> element) { if (myEPCandidates.size() == 1) { registerExtension(element, myEPCandidates.get(0)); } else { final BaseListPopupStep<ExtensionPointCandidate> popupStep = new BaseListPopupStep<ExtensionPointCandidate>("Choose Extension Point", myEPCandidates) { @Override public PopupStep onChosen(ExtensionPointCandidate selectedValue, boolean finalChoice) { registerExtension(element, selectedValue); return FINAL_CHOICE; } }; JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor); } }
@Override public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final PsiModifierListOwner modifierListOwner = getElement(editor, file); if (modifierListOwner == null) throw new IncorrectOperationException(); BaseListPopupStep<Nls.Capitalization> step = new BaseListPopupStep<Nls.Capitalization>(null, Nls.Capitalization.Title, Nls.Capitalization.Sentence) { @Override public PopupStep onChosen(final Nls.Capitalization selectedValue, boolean finalChoice) { new WriteCommandAction.Simple(project) { @Override protected void run() throws Throwable { String nls = Nls.class.getName(); PsiAnnotation annotation = JavaPsiFacade.getInstance(project).getElementFactory() .createAnnotationFromText("@" + nls + "(capitalization = " + nls + ".Capitalization." + selectedValue.toString() + ")", modifierListOwner); new AddAnnotationFix(Nls.class.getName(), modifierListOwner, annotation.getParameterList().getAttributes()).applyFix(); } }.execute(); return FINAL_CHOICE; } }; JBPopupFactory.getInstance().createListPopup(step).showInBestPositionFor(editor); }
public static BaseListPopupStep<LibraryType> createChooseTypeStep(final ClasspathPanel classpathPanel, final ParameterizedRunnable<LibraryType> action) { return new BaseListPopupStep<LibraryType>(IdeBundle.message("popup.title.select.library.type"), getSuitableTypes(classpathPanel)) { @NotNull @Override public String getTextFor(LibraryType value) { return value != null ? value.getCreateActionName() : IdeBundle.message("create.default.library.type.action.name"); } @Override public Icon getIconFor(LibraryType aValue) { return aValue != null ? aValue.getIcon() : PlatformIcons.LIBRARY_ICON; } @Override public PopupStep onChosen(final LibraryType selectedValue, boolean finalChoice) { return doFinalStep(new Runnable() { @Override public void run() { action.run(selectedValue); } }); } }; }
private static ListPopup createPopup(final ArrayList<VirtualFile> files, final ArrayList<Icon> icons) { final BaseListPopupStep<VirtualFile> step = new BaseListPopupStep<VirtualFile>("File Path", files, icons) { @NotNull @Override public String getTextFor(final VirtualFile value) { return value.getPresentableName(); } @Override public PopupStep onChosen(final VirtualFile selectedValue, final boolean finalChoice) { final File selectedFile = new File(getPresentableUrl(selectedValue)); if (selectedFile.exists()) { ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { public void run() { openFile(selectedFile); } }); } return FINAL_CHOICE; } }; return JBPopupFactory.getInstance().createListPopup(step); }
@Override public PopupStep onChosen(final VirtualFile selectedValue, boolean finalChoice) { if (selectedValue == null) { myNewBaseSelector.run(); return null; } final List<FilePatchInProgress.PatchChange> selectedChanges = myChangesTreeList.getSelectedChanges(); if (selectedChanges.size() >= 1) { for (FilePatchInProgress.PatchChange patchChange : selectedChanges) { final FilePatchInProgress patch = patchChange.getPatchInProgress(); patch.setNewBase(selectedValue); } updateTree(false); } return null; }
@Override public PopupStep onChosen(LookupElementAction selectedValue, boolean finalChoice) { final LookupElementAction.Result result = selectedValue.performLookupAction(); if (result == LookupElementAction.Result.HIDE_LOOKUP) { myLookup.hide(); } else if (result == LookupElementAction.Result.REFRESH_ITEM) { myLookup.updateLookupWidth(myLookupElement); myLookup.requestResize(); myLookup.refreshUi(false, true); } else if (result instanceof LookupElementAction.Result.ChooseItem) { myLookup.setCurrentItem(((LookupElementAction.Result.ChooseItem)result).item); CommandProcessor.getInstance().executeCommand(myLookup.getEditor().getProject(), new Runnable() { @Override public void run() { myLookup.finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR); } }, null, null); } return FINAL_CHOICE; }
@Override public PopupStep onChosen(final ConfigurationActionsStep selectedValue, boolean finalChoice) { if (finalChoice) { return doFinalStep(new Runnable() { @Override public void run() { RunnerAndConfigurationSettings settings = selectedValue.getSettings(); RunManagerEx.getInstanceEx(myProject).setSelectedConfiguration(settings); doRunConfiguration(settings, myExecutorProvider.getExecutor(), myProject); } }); } else { return selectedValue; } }
private static ListPopupStep buildStep(@Nonnull final List<Pair<AnAction, KeyStroke>> actions, final DataContext ctx) { return new BaseListPopupStep<Pair<AnAction, KeyStroke>>("Choose an action", ContainerUtil.findAll(actions, pair -> { final AnAction action = pair.getFirst(); final Presentation presentation = action.getTemplatePresentation().clone(); AnActionEvent event = new AnActionEvent(null, ctx, ActionPlaces.UNKNOWN, presentation, ActionManager.getInstance(), 0); ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, event, true); return presentation.isEnabled() && presentation.isVisible(); })) { @Override public PopupStep onChosen(Pair<AnAction, KeyStroke> selectedValue, boolean finalChoice) { invokeAction(selectedValue.getFirst(), ctx); return FINAL_CHOICE; } }; }
private static ListPopup createPopup(final ArrayList<VirtualFile> files, final ArrayList<Icon> icons) { final BaseListPopupStep<VirtualFile> step = new BaseListPopupStep<VirtualFile>("File Path", files, icons) { @Nonnull @Override public String getTextFor(final VirtualFile value) { return value.getPresentableName(); } @Override public PopupStep onChosen(final VirtualFile selectedValue, final boolean finalChoice) { final File selectedFile = new File(getPresentableUrl(selectedValue)); if (selectedFile.exists()) { ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { openFile(selectedFile); } }); } return FINAL_CHOICE; } }; return JBPopupFactory.getInstance().createListPopup(step); }
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 public void fix(final JComponent contextComponent, RelativePoint relativePoint) { JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationErrorQuickFix>(null, myDescription.getFixes()) { @Nonnull @Override public String getTextFor(ConfigurationErrorQuickFix value) { return value.getActionName(); } @Override public PopupStep onChosen(final ConfigurationErrorQuickFix selectedValue, boolean finalChoice) { return doFinalStep(new Runnable() { @Override public void run() { selectedValue.performFix(); } }); } }).show(relativePoint); }
public static BaseListPopupStep<LibraryType> createChooseTypeStep(final ClasspathPanel classpathPanel, final ParameterizedRunnable<LibraryType> action) { return new BaseListPopupStep<LibraryType>(IdeBundle.message("popup.title.select.library.type"), getSuitableTypes(classpathPanel)) { @Nonnull @Override public String getTextFor(LibraryType value) { String createActionName = value != null ? value.getCreateActionName() : null; return createActionName != null ? createActionName : IdeBundle.message("create.default.library.type.action.name"); } @Override public Icon getIconFor(LibraryType aValue) { return aValue != null ? aValue.getIcon() : AllIcons.Nodes.PpLib; } @Override public PopupStep onChosen(final LibraryType selectedValue, boolean finalChoice) { return doFinalStep(new Runnable() { @Override public void run() { action.run(selectedValue); } }); } }; }
@Override public PopupStep onChosen(final ConfigurationActionsStep selectedValue, boolean finalChoice) { if (finalChoice) { return doFinalStep(new Runnable() { @Override public void run() { RunnerAndConfigurationSettings settings = selectedValue.getSettings(); RunManagerEx.getInstanceEx(myProject).setSelectedConfiguration(settings); ExecutionUtil.runConfiguration(settings, myExecutorProvider.getExecutor()); } }); } else { return selectedValue; } }
public static void startPicker(Type[] displayedTypes, RelativePoint relativePoint, final Callback callback) { ListPopup listPopup = JBPopupFactory.getInstance() .createListPopup(new BaseListPopupStep<Type>("Select Type", displayedTypes) { @NotNull @Override public String getTextFor(Type value) { return value.toString(); } @Override public PopupStep onChosen(Type selectedValue, boolean finalChoice) { callback.onTypeChose(selectedValue); return super.onChosen(selectedValue, finalChoice); } }); listPopup.show(relativePoint); }
@Override public PopupStep onChosen(Integer selectedValue, boolean finalChoice) { if (finalChoice) { if (selectedValue.equals(ADD_SUBTASK_ID)) { return doFinalStep(() -> CCNewSubtaskAction.addSubtask(myTask, myProject)); } StudySubtaskUtils.switchStep(myProject, myTask, selectedValue); } else { if (hasSubstep(selectedValue)) { return new ActionsPopupStep(myTask, selectedValue, myProject); } } return super.onChosen(selectedValue, false); }
@Override public PopupStep onChosen(String selectedValue, boolean finalChoice) { if (finalChoice) { if (selectedValue.equals(SELECT)) { StudySubtaskUtils.switchStep(myProject, myTask, mySubtaskIndex); } else { return deleteSubtask(); } } return super.onChosen(selectedValue, finalChoice); }
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); }
public void invoke(final Project project, final PsiFile file, final Editor editor, PsiElement element) { if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return; final PsiJavaCodeReferenceElement refExpr = (PsiJavaCodeReferenceElement)element.getParent(); final PsiImportStaticStatement staticImport = (PsiImportStaticStatement)refExpr.advancedResolve(true).getCurrentFileResolveScope(); final List<PsiJavaCodeReferenceElement> expressionToExpand = collectReferencesThrough(file, refExpr, staticImport); if (expressionToExpand.isEmpty()) { expand(refExpr, staticImport); staticImport.delete(); } else { if (ApplicationManager.getApplication().isUnitTestMode()) { replaceAllAndDeleteImport(expressionToExpand, refExpr, staticImport); } else { final BaseListPopupStep<String> step = new BaseListPopupStep<String>("Multiple Similar Calls Found", new String[]{REPLACE_THIS_OCCURRENCE, REPLACE_ALL_AND_DELETE_IMPORT}) { @Override public PopupStep onChosen(final String selectedValue, boolean finalChoice) { new WriteCommandAction(project, ExpandStaticImportAction.this.getText()) { @Override protected void run(@NotNull Result result) throws Throwable { if (selectedValue == REPLACE_THIS_OCCURRENCE) { expand(refExpr, staticImport); } else { replaceAllAndDeleteImport(expressionToExpand, refExpr, staticImport); } } }.execute(); return FINAL_CHOICE; } }; JBPopupFactory.getInstance().createListPopup(step).showInBestPositionFor(editor); } } }
@Override public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException { final PsiModifierListOwner listOwner = getContainer(editor, file); LOG.assertTrue(listOwner != null); final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project); final PsiAnnotation[] externalAnnotations = annotationsManager.findExternalAnnotations(listOwner); LOG.assertTrue(externalAnnotations != null && externalAnnotations.length > 0); if (externalAnnotations.length == 1) { deannotate(externalAnnotations[0], project, file, annotationsManager, listOwner); return; } JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<PsiAnnotation>(CodeInsightBundle.message("deannotate.intention.chooser.title"), externalAnnotations) { @Override public PopupStep onChosen(final PsiAnnotation selectedValue, final boolean finalChoice) { deannotate(selectedValue, project, file, annotationsManager, listOwner); return PopupStep.FINAL_CHOICE; } @Override @NotNull public String getTextFor(final PsiAnnotation value) { final String qualifiedName = value.getQualifiedName(); LOG.assertTrue(qualifiedName != null); return qualifiedName; } }).showInBestPositionFor(editor); }
public ArtifactErrorPanel(final ArtifactEditorImpl artifactEditor) { myErrorLabel.setIcon(AllIcons.RunConfigurations.ConfigurationWarning); new UiNotifyConnector(myMainPanel, new Activatable.Adapter() { @Override public void showNotify() { if (myErrorText != null) { myErrorLabel.setText(myErrorText); myErrorText = null; } } }); myFixButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!myCurrentQuickFixes.isEmpty()) { if (myCurrentQuickFixes.size() == 1) { performFix(ContainerUtil.getFirstItem(myCurrentQuickFixes, null), artifactEditor); } else { JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationErrorQuickFix>(null, myCurrentQuickFixes) { @NotNull @Override public String getTextFor(ConfigurationErrorQuickFix value) { return value.getActionName(); } @Override public PopupStep onChosen(ConfigurationErrorQuickFix selectedValue, boolean finalChoice) { performFix(selectedValue, artifactEditor); return FINAL_CHOICE; } }).showUnderneathOf(myFixButton); } } } }); clearError(); }