use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class DeannotateIntentionAction method invoke.
@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);
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class ExternalJavaDocAction method showExternalJavadoc.
public static void showExternalJavadoc(PsiElement element, PsiElement originalElement, String docUrl, DataContext dataContext) {
DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
if (provider instanceof ExternalDocumentationHandler && ((ExternalDocumentationHandler) provider).handleExternal(element, originalElement)) {
return;
}
Project project = dataContext.getData(CommonDataKeys.PROJECT);
final Component contextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
ApplicationManager.getApplication().executeOnPooledThread(() -> {
List<String> urls;
if (StringUtil.isEmptyOrSpaces(docUrl)) {
urls = ReadAction.compute(() -> provider.getUrlFor(element, originalElement));
} else {
urls = Collections.singletonList(docUrl);
}
if (provider instanceof ExternalDocumentationProvider && urls != null && urls.size() > 1) {
for (String url : urls) {
List<String> thisUrlList = Collections.singletonList(url);
String doc = ((ExternalDocumentationProvider) provider).fetchExternalDocumentation(project, element, thisUrlList);
if (doc != null) {
urls = thisUrlList;
break;
}
}
}
final List<String> finalUrls = urls;
ApplicationManager.getApplication().invokeLater(() -> {
if (ContainerUtil.isEmpty(finalUrls)) {
if (element != null && provider instanceof ExternalDocumentationProvider) {
ExternalDocumentationProvider externalDocumentationProvider = (ExternalDocumentationProvider) provider;
if (externalDocumentationProvider.canPromptToConfigureDocumentation(element)) {
externalDocumentationProvider.promptToConfigureDocumentation(element);
}
}
} else if (finalUrls.size() == 1) {
BrowserUtil.browse(finalUrls.get(0));
} else {
JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>("Choose external documentation root", ArrayUtil.toStringArray(finalUrls)) {
@Override
public PopupStep onChosen(final String selectedValue, final boolean finalChoice) {
BrowserUtil.browse(selectedValue);
return FINAL_CHOICE;
}
}).showInBestPositionFor(DataManager.getInstance().getDataContext(contextComponent));
}
}, ModalityState.NON_MODAL);
});
}
use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.
the class StudyNewProjectPanel method setupBrowseButton.
private void setupBrowseButton() {
if (SystemInfo.isMac && !UIUtil.isUnderDarcula())
myBrowseButton.putClientProperty("JButton.buttonType", null);
myBrowseButton.setIcon(InteractiveLearningIcons.InterpreterGear);
final FileChooserDescriptor fileChooser = new FileChooserDescriptor(true, false, false, true, false, false) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return file.isDirectory() || StudyUtils.isZip(file.getName());
}
@Override
public boolean isFileSelectable(VirtualFile file) {
return StudyUtils.isZip(file.getName());
}
};
myBrowseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final BaseListPopupStep<String> popupStep = new BaseListPopupStep<String>("", "Add local course", LOGIN_TO_STEPIC) {
@Override
public PopupStep onChosen(final String selectedValue, boolean finalChoice) {
return doFinalStep(() -> {
if ("Add local course".equals(selectedValue)) {
Project[] projects = ProjectManager.getInstance().getOpenProjects();
FileChooser.chooseFile(fileChooser, null, projects.length == 0 ? null : projects[0].getBaseDir(), file -> {
String fileName = file.getPath();
int oldSize = myAvailableCourses.size();
CourseInfo courseInfo = myGenerator.addLocalCourse(fileName);
if (courseInfo != null) {
if (oldSize != myAvailableCourses.size()) {
myCoursesComboBox.addItem(courseInfo);
}
myCoursesComboBox.setSelectedItem(courseInfo);
setOK();
} else {
setError(INVALID_COURSE);
myCoursesComboBox.removeAllItems();
myCoursesComboBox.addItem(CourseInfo.INVALID_COURSE);
for (CourseInfo course : myAvailableCourses) {
myCoursesComboBox.addItem(course);
}
myCoursesComboBox.setSelectedItem(CourseInfo.INVALID_COURSE);
}
});
} else if (LOGIN_TO_STEPIC.equals(selectedValue)) {
showLoginDialog(true, "Signing In And Getting Stepik Course List");
}
});
}
};
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(popupStep);
popup.showInScreenCoordinates(myBrowseButton, myBrowseButton.getLocationOnScreen());
}
});
}
Aggregations