diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 48ab3aca4..65641478a 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -545,7 +545,7 @@ public class Base { newbieDir.mkdirs(); // Make an empty pde file - File newbieFile = new File(newbieDir, newbieName + ".pde"); + File newbieFile = new File(newbieDir, newbieName + ".ino"); new FileOutputStream(newbieFile); // create the file return newbieFile.getAbsolutePath(); } @@ -637,7 +637,8 @@ public class Base { public boolean accept(File dir, String name) { // TODO this doesn't seem to ever be used. AWESOME. //System.out.println("check filter on " + dir + " " + name); - return name.toLowerCase().endsWith(".pde"); + return name.toLowerCase().endsWith(".ino") + || name.toLowerCase().endsWith(".pde"); } }); @@ -1089,7 +1090,10 @@ public class Base { File subfolder = new File(folder, list[i]); if (!subfolder.isDirectory()) continue; - File entry = new File(subfolder, list[i] + ".pde"); + File entry = new File(subfolder, list[i] + ".ino"); + if (!entry.exists() && (new File(subfolder, list[i] + ".pde")).exists()) { + entry = new File(subfolder, list[i] + ".pde"); + } // if a .pde file of the same prefix as the folder exists.. if (entry.exists()) { //String sanityCheck = sanitizedName(list[i]); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index b4fedbc74..7c0638449 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2020,14 +2020,65 @@ public class Editor extends JFrame implements RunnerListener { * modifications (if any) to the previous sketch need to be saved. */ protected boolean handleOpenInternal(String path) { + // rename .pde files to .ino + File[] oldFiles = (new File(path)).getParentFile().listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return (name.toLowerCase().endsWith(".pde")); + } + }); + + if (oldFiles != null && oldFiles.length > 0) { + if (!Preferences.getBoolean("editor.update_extension")) { + Object[] options = { "OK", "Cancel" }; + String prompt = + "In Arduino 1.0, the file extension for sketches changed\n" + + "from \".pde\" to \".ino\". This version of the software only\n" + + "supports the new extension. Rename the files in this sketch\n" + + "(and future sketches) and continue?"; + + int result = JOptionPane.showOptionDialog(this, + prompt, + "New extension", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + options, + options[0]); + if (result != JOptionPane.YES_OPTION) { + return false; + } + + Preferences.setBoolean("editor.update_extension", true); + } + + for (int i = 0; i < oldFiles.length; i++) { + String oldPath = oldFiles[i].getPath(); + File newFile = new File(oldPath.substring(0, oldPath.length() - 4) + ".ino"); + try { + Base.copyFile(oldFiles[i], newFile); + } catch (IOException e) { + Base.showWarning("Error", "Could not copy to a proper location.", e); + return false; + } + + // remove the original file, so user doesn't get confused + oldFiles[i].delete(); + + // update with the new path + if (oldFiles[i].compareTo(new File(path)) == 0) { + path = newFile.getAbsolutePath(); + } + } + } + // check to make sure that this .pde file is // in a folder of the same name File file = new File(path); File parentFile = new File(file.getParent()); String parentName = parentFile.getName(); - String pdeName = parentName + ".pde"; + String pdeName = parentName + ".ino"; File altFile = new File(file.getParent(), pdeName); - + if (pdeName.equals(file.getName())) { // no beef with this guy @@ -2037,10 +2088,10 @@ public class Editor extends JFrame implements RunnerListener { path = altFile.getAbsolutePath(); //System.out.println("found alt file in same folder"); - } else if (!path.endsWith(".pde")) { + } else if (!path.endsWith(".ino")) { Base.showWarning("Bad file selected", "Processing can only open its own sketches\n" + - "and other files ending in .pde", null); + "and other files ending in .ino", null); return false; } else { diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index c6a9d769f..bdb98bbe7 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -315,7 +315,7 @@ public class Sketch { renamingCode = true; String prompt = (currentIndex == 0) ? "New name for sketch:" : "New name for file:"; - String oldName = (current.isExtension("pde")) ? + String oldName = (current.isExtension("ino")) ? current.getPrettyName() : current.getFileName(); editor.status.edit(prompt, oldName); } @@ -495,7 +495,7 @@ public class Sketch { } // if successful, set base properties for the sketch - File newMainFile = new File(newFolder, newName + ".pde"); + File newMainFile = new File(newFolder, newName + ".ino"); String newMainFilePath = newMainFile.getAbsolutePath(); // having saved everything and renamed the folder and the main .pde, @@ -860,7 +860,7 @@ public class Sketch { } // save the main tab with its new name - File newFile = new File(newFolder, newName + ".pde"); + File newFile = new File(newFolder, newName + ".ino"); code[0].saveAs(newFile); editor.handleOpenUnchecked(newFile.getPath(), @@ -1261,7 +1261,7 @@ public class Sketch { StringBuffer bigCode = new StringBuffer(); int bigCount = 0; for (SketchCode sc : code) { - if (sc.isExtension("pde")) { + if (sc.isExtension("ino")) { sc.setPreprocOffset(bigCount); bigCode.append(sc.getProgram()); bigCode.append('\n'); @@ -1357,7 +1357,7 @@ public class Sketch { } // sc.setPreprocName(filename); - } else if (sc.isExtension("pde")) { + } else if (sc.isExtension("ino")) { // The compiler and runner will need this to have a proper offset sc.addPreprocOffset(headerOffset); } @@ -1386,7 +1386,7 @@ public class Sketch { // SketchCode errorCode = null; // if (filename.equals(appletJavaFile)) { // for (SketchCode code : getCode()) { -// if (code.isExtension("pde")) { +// if (code.isExtension("ino")) { // if (line >= code.getPreprocOffset()) { // errorCode = code; // } @@ -1791,7 +1791,7 @@ public class Sketch { * Returns the default extension for this editor setup. */ public String getDefaultExtension() { - return "pde"; + return "ino"; } @@ -1799,7 +1799,7 @@ public class Sketch { * Returns a String[] array of proper extensions. */ public String[] getExtensions() { - return new String[] { "pde", "c", "cpp", "h" }; + return new String[] { "ino", "c", "cpp", "h" }; }