use of com.intellij.openapi.fileChooser.FileChooser 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