1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-21 10:52:14 +01:00

Merge pull request #9722 from cmaglie/msstore-hotfix

Replaced JFileChooser with FileDialog in 'Add .zip library'
This commit is contained in:
Cristian Maglie 2020-02-05 18:29:14 +01:00 committed by GitHub
commit 768c659f9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2337,21 +2337,27 @@ public class Base {
} }
public void handleAddLibrary() { public void handleAddLibrary() {
JFileChooser fileChooser = new JFileChooser(System.getProperty("user.home")); // get the frontmost window frame for placing file dialog
fileChooser.setDialogTitle(tr("Select a zip file or a folder containing the library you'd like to add")); FileDialog fd = new FileDialog(activeEditor, tr("Select a zip file or a folder containing the library you'd like to add"), FileDialog.LOAD);
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); File home = new File(System.getProperty("user.home"));
fileChooser.setFileFilter(new FileNameExtensionFilter(tr("ZIP files or folders"), "zip")); if (home.isDirectory()) {
fd.setDirectory(home.getAbsolutePath());
Dimension preferredSize = fileChooser.getPreferredSize();
fileChooser.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200));
int returnVal = fileChooser.showOpenDialog(activeEditor);
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
} }
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);
File sourceFile = fileChooser.getSelectedFile(); String directory = fd.getDirectory();
String filename = fd.getFile();
// User canceled selection
if (filename == null) return;
File sourceFile = new File(directory, filename);
File tmpFolder = null; File tmpFolder = null;
try { try {