Files
haikuports/dev-embedded/arduino/patches/JFileChooser-1.7.11.patchset
2017-04-09 17:53:43 +00:00

147 lines
5.3 KiB
Plaintext

From f874d3a990ad31b6a50c2b0696cfe4faabdc0b22 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 ec0b5fc..f0e5e0d 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.7.0
From d55081ebf35f57b0055f3d3f21602bc9e888e5cf Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 7 Apr 2017 00:31:04 +0000
Subject: Use JFileChooser instead of FileDialog for save
diff --git a/Sketch.java b/Sketch.java
index a937988..23fe2c4 100644
--- a/Sketch.java
+++ b/Sketch.java
@@ -645,25 +645,34 @@ public class Sketch {
String newName = null;
// get new name for folder
- FileDialog fd = new FileDialog(editor, _("Save sketch folder as..."), FileDialog.SAVE);
+ JFileChooser fd = new JFileChooser();
+ fd.setDialogTitle(_("Save sketch folder as..."));
+ fd.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ Dimension preferredSize = fd.getPreferredSize();
+ fd.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200));
+
if (isReadOnly() || isUntitled()) {
// default to the sketchbook folder
- fd.setDirectory(Base.getSketchbookFolder().getAbsolutePath());
+ fd.setCurrentDirectory(new File(Base.getSketchbookFolder().getAbsolutePath()));
} else {
// default to the parent folder of where this was
// on macs a .getParentFile() method is required
-
- fd.setDirectory(data.getFolder().getParentFile().getAbsolutePath());
+ fd.setCurrentDirectory(new File(data.getFolder().getParentFile().getAbsolutePath()));
}
String oldName = data.getName();
- fd.setFile(oldName);
- fd.setVisible(true);
- newParentDir = fd.getDirectory();
- newName = fd.getFile();
+ fd.setSelectedFile(new File(oldName));
+
+ int returnVal = fd.showSaveDialog(editor);
// user canceled selection
- if (newName == null) return false;
+ if (returnVal != JFileChooser.APPROVE_OPTION)
+ return false;
+
+ File saveFile = fd.getSelectedFile();
+
+ newParentDir = saveFile.getParent();
+ newName = saveFile.getName();
newName = Sketch.checkName(newName);
File newFolder = new File(newParentDir, newName);
--
2.7.0