Skip to content

Commit 678420c

Browse files
committed
Revert "Replaced JFileChooser with FileDialog in 'Add .zip library'"
This reverts commit 7cb1440.
1 parent 33ff495 commit 678420c

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

app/src/processing/app/Base.java

+12-18
Original file line numberDiff line numberDiff line change
@@ -2340,27 +2340,21 @@ static public int calcFolderSize(File folder) {
23402340
}
23412341

23422342
public void handleAddLibrary() {
2343-
// get the frontmost window frame for placing file dialog
2344-
FileDialog fd = new FileDialog(activeEditor, tr("Select a zip file or a folder containing the library you'd like to add"), FileDialog.LOAD);
2345-
File home = new File(System.getProperty("user.home"));
2346-
if (home.isDirectory()) {
2347-
fd.setDirectory(home.getAbsolutePath());
2348-
}
2349-
if (OSUtils.isWindows()) {
2350-
// Workaround: AWT FileDialog doesn't not support native file filters on Windows...
2351-
// https://stackoverflow.com/questions/12558413/how-to-filter-file-type-in-filedialog
2352-
fd.setFile("*.zip");
2353-
}
2354-
fd.setFilenameFilter((dir, name) -> name.toLowerCase().endsWith(".zip"));
2355-
fd.setVisible(true);
2343+
JFileChooser fileChooser = new JFileChooser(System.getProperty("user.home"));
2344+
fileChooser.setDialogTitle(tr("Select a zip file or a folder containing the library you'd like to add"));
2345+
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
2346+
fileChooser.setFileFilter(new FileNameExtensionFilter(tr("ZIP files or folders"), "zip"));
23562347

2357-
String directory = fd.getDirectory();
2358-
String filename = fd.getFile();
2348+
Dimension preferredSize = fileChooser.getPreferredSize();
2349+
fileChooser.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200));
23592350

2360-
// User canceled selection
2361-
if (filename == null) return;
2351+
int returnVal = fileChooser.showOpenDialog(activeEditor);
2352+
2353+
if (returnVal != JFileChooser.APPROVE_OPTION) {
2354+
return;
2355+
}
23622356

2363-
File sourceFile = new File(directory, filename);
2357+
File sourceFile = fileChooser.getSelectedFile();
23642358
File tmpFolder = null;
23652359

23662360
try {

0 commit comments

Comments
 (0)