Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/arduino/Arduino.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@arduino.cc>2020-02-05 17:56:34 +0300
committerCristian Maglie <c.maglie@arduino.cc>2020-02-05 17:56:37 +0300
commit7cb14400068529bbb917241880a92ab918a4d7bd (patch)
tree2ca3d65a25866cb1a04eade69580f3fac4ecacc7
parent0dbff59b13bc85d6acf973cd38cbc31d169e6c05 (diff)
Replaced JFileChooser with FileDialog in 'Add .zip library'1.8.11-ms-store-1
For some reason the combination of the AdoptJDKJre 8 and Microsoft store do not like JFileChooser. This commit replace JFileChooser with a FileDialog that seems to work without issues.
-rw-r--r--app/src/processing/app/Base.java30
1 files changed, 18 insertions, 12 deletions
diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java
index d8e9b1cac..d9096375e 100644
--- a/app/src/processing/app/Base.java
+++ b/app/src/processing/app/Base.java
@@ -2337,21 +2337,27 @@ public class Base {
}
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 {