Files
haikuports/dev-embedded/arduino/patches/JFileChooser-1.6.1.patchset
2022-06-29 23:26:42 +10:00

178 lines
6.2 KiB
Plaintext

From daf12b26bf71bfffa7952d9b7de3697886b09cb4 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 d844b4c..c034bef 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 2f142d0..21b5576 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.36.1
From a9e0d3dfd3c1f1ecb671208d6fa8d30431a9bbc3 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 21b5576..00501c5 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.36.1
From 7fa36cdbe4dda233438793895e44c23becbfe76d Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 17 Jul 2019 19:39:27 +1000
Subject: Fix build
diff --git a/Base.java b/Base.java
index c034bef..24db056 100644
--- a/Base.java
+++ b/Base.java
@@ -31,7 +31,6 @@ import processing.app.helpers.filefilters.OnlyDirs;
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
import processing.app.javax.swing.filechooser.FileNameExtensionFilter;
import processing.app.legacy.PApplet;
-import processing.app.macosx.ThinkDifferent;
import processing.app.packages.Library;
import processing.app.packages.LibraryList;
import processing.app.tools.MenuScroller;
@@ -199,8 +198,6 @@ public class Base {
public Base(String[] args) throws Exception {
getPlatform().init();
- if (OSUtils.isMacOS())
- ThinkDifferent.init(this);
String sketchbookPath = BaseNoGui.getSketchbookPath();
--
2.36.1