Files
haikuports/dev-embedded/arduino/patches/JFileChooser-1.7.x.patchset
Gerasim Troeglazov 6c8716f666 Arduino: bump version
2015-10-12 20:17:31 +10:00

89 lines
3.4 KiB
Plaintext

From d9128679f6b93378adbd23d7ce20c57468ab147c Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 11 Jun 2015 18:25:51 +1000
Subject: Use JFileChooser instead of FileDialog for open files
diff --git a/Base.java b/Base.java
index 76ba797..1e930d7 100644
--- a/Base.java
+++ b/Base.java
@@ -656,30 +656,21 @@ public class Base {
*/
public void handleOpenPrompt() throws Exception {
// get the frontmost window frame for placing file dialog
- FileDialog fd = new FileDialog(activeEditor, _("Open an Arduino sketch..."), FileDialog.LOAD);
- File lastFolder = new File(Preferences.get("last.folder", getSketchbookFolder().getAbsolutePath()));
- if (lastFolder.exists() && lastFolder.isFile()) {
- lastFolder = lastFolder.getParentFile();
- }
- fd.setDirectory(lastFolder.getAbsolutePath());
-
- // Only show .pde files as eligible bachelors
- fd.setFilenameFilter(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.toLowerCase().endsWith(".ino")
- || name.toLowerCase().endsWith(".pde");
- }
- });
+ JFileChooser fd = new JFileChooser(Preferences.get("last.folder", Base.getSketchbookFolder().getAbsolutePath()));
+ fd.setDialogTitle(_("Open an Arduino sketch..."));
+ fd.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ fd.setFileFilter(new FileNameExtensionFilter(_("Sketches (*.ino, *.pde)"), "ino", "pde"));
- fd.setVisible(true);
+ Dimension preferredSize = fd.getPreferredSize();
+ fd.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200));
- String directory = fd.getDirectory();
- String filename = fd.getFile();
+ int returnVal = fd.showOpenDialog(activeEditor);
- // User canceled selection
- if (filename == null) return;
+ if (returnVal != JFileChooser.APPROVE_OPTION) {
+ return;
+ }
- File inputFile = new File(directory, filename);
+ File inputFile = fd.getSelectedFile();
Preferences.set("last.folder", inputFile.getAbsolutePath());
handleOpen(inputFile);
diff --git a/Sketch.java b/Sketch.java
index ca8d13c..a937988 100644
--- a/Sketch.java
+++ b/Sketch.java
@@ -790,16 +790,22 @@ public class Sketch {
}
// get a dialog, select a file to add to the sketch
- FileDialog fd = new FileDialog(editor, _("Select an image or other data file to copy to your sketch"), FileDialog.LOAD);
- fd.setVisible(true);
+ JFileChooser fd = new JFileChooser(Preferences.get("last.folder", Base.getSketchbookFolder().getAbsolutePath()));
+ fd.setDialogTitle(_("Select an image or other data file to copy to your sketch"));
+ fd.setFileSelectionMode(JFileChooser.FILES_ONLY);
+
+ Dimension preferredSize = fd.getPreferredSize();
+ fd.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200));
+
+ int returnVal = fd.showOpenDialog(editor);
- String directory = fd.getDirectory();
- String filename = fd.getFile();
- if (filename == null) return;
+ if (returnVal != JFileChooser.APPROVE_OPTION) {
+ return;
+ }
// copy the file into the folder. if people would rather
// it move instead of copy, they can do it by hand
- File sourceFile = new File(directory, filename);
+ File sourceFile = fd.getSelectedFile();
// now do the work of adding the file
boolean result = addFile(sourceFile);
--
2.2.2