Skip to content

Replaced JFileChooser with FileDialog in 'Add .zip library' #9722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -2337,21 +2337,27 @@ static public int calcFolderSize(File folder) {
}

public void handleAddLibrary() {
JFileChooser fileChooser = new JFileChooser(System.getProperty("user.home"));
fileChooser.setDialogTitle(tr("Select a zip file or a folder containing the library you'd like to add"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setFileFilter(new FileNameExtensionFilter(tr("ZIP files or folders"), "zip"));

Dimension preferredSize = fileChooser.getPreferredSize();
fileChooser.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200));
// get the frontmost window frame for placing file dialog
FileDialog fd = new FileDialog(activeEditor, tr("Select a zip file or a folder containing the library you'd like to add"), FileDialog.LOAD);
File home = new File(System.getProperty("user.home"));
if (home.isDirectory()) {
fd.setDirectory(home.getAbsolutePath());
}
if (OSUtils.isWindows()) {
// Workaround: AWT FileDialog doesn't not support native file filters on Windows...
// https://stackoverflow.com/questions/12558413/how-to-filter-file-type-in-filedialog
fd.setFile("*.zip");
}
fd.setFilenameFilter((dir, name) -> name.toLowerCase().endsWith(".zip"));
fd.setVisible(true);

int returnVal = fileChooser.showOpenDialog(activeEditor);
String directory = fd.getDirectory();
String filename = fd.getFile();

if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
// User canceled selection
if (filename == null) return;

File sourceFile = fileChooser.getSelectedFile();
File sourceFile = new File(directory, filename);
File tmpFolder = null;

try {
Expand Down