From be2b430a99273bcbab22f716fb33a07ea8ee2be8 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.21.0


From a94ad93405daab4738a230691c4428d58187307e 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.21.0


From eeab0c20120f4b45baa9fdeabc2d444371202485 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 f0e5e0d..8980f98 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.21.0

