Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'cmaglie/save-rename' into new-extension

  • Loading branch information...
commit f77de7e8c02babab3714f108903a4b177024eb82 2 parents 1627fd3 + 131f789
David A. Mellis damellis authored
95 app/src/processing/app/Editor.java
View
@@ -2048,87 +2048,38 @@ protected void handleOpenUnchecked(String path, int codeIndex,
* 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 + ".ino";
- File altFile = new File(file.getParent(), pdeName);
+ String fileName = file.getName();
+ File parent = file.getParentFile();
+ String parentName = parent.getName();
+ String pdeName = parentName + ".pde";
+ File altPdeFile = new File(parent, pdeName);
+ String inoName = parentName + ".ino";
+ File altInoFile = new File(parent, pdeName);
- if (pdeName.equals(file.getName())) {
+ if (pdeName.equals(fileName) || inoName.equals(fileName)) {
// no beef with this guy
- } else if (altFile.exists()) {
- // user selected a .java from the same sketch,
- // but open the .pde instead
- path = altFile.getAbsolutePath();
- //System.out.println("found alt file in same folder");
-
- } else if (!path.endsWith(".ino")) {
+ } else if (altPdeFile.exists()) {
+ // user selected a .java from the same sketch, but open the .pde instead
+ path = altPdeFile.getAbsolutePath();
+ } else if (altInoFile.exists()) {
+ path = altInoFile.getAbsolutePath();
+ } else if (!path.endsWith(".ino") && !path.endsWith(".pde")) {
Base.showWarning("Bad file selected",
"Processing can only open its own sketches\n" +
- "and other files ending in .ino", null);
+ "and other files ending in .ino or .pde", null);
return false;
} else {
String properParent =
- file.getName().substring(0, file.getName().length() - 4);
+ fileName.substring(0, fileName.length() - 4);
Object[] options = { "OK", "Cancel" };
String prompt =
- "The file \"" + file.getName() + "\" needs to be inside\n" +
+ "The file \"" + fileName + "\" needs to be inside\n" +
"a sketch folder named \"" + properParent + "\".\n" +
"Create this folder, move the file, and continue?";
@@ -2223,7 +2174,7 @@ public boolean handleSave(boolean immediately) {
// need to get the name, user might also cancel here
} else if (immediately) {
- handleSave2();
+ return handleSave2();
} else {
SwingUtilities.invokeLater(new Runnable() {
@@ -2236,15 +2187,16 @@ public void run() {
}
- protected void handleSave2() {
+ protected boolean handleSave2() {
toolbar.activate(EditorToolbar.SAVE);
statusNotice("Saving...");
+ boolean saved = false;
try {
- if (sketch.save()) {
+ saved = sketch.save();
+ if (saved)
statusNotice("Done Saving.");
- } else {
+ else
statusEmpty();
- }
// rebuild sketch menu in case a save-as was forced
// Disabling this for 0125, instead rebuild the menu inside
// the Save As method of the Sketch object, since that's the
@@ -2263,6 +2215,7 @@ protected void handleSave2() {
}
//toolbar.clear();
toolbar.deactivate(EditorToolbar.SAVE);
+ return saved;
}
46 app/src/processing/app/Sketch.java
View
@@ -36,6 +36,7 @@
import java.beans.*;
import java.io.*;
import java.util.*;
+import java.util.List;
import java.util.zip.*;
import javax.swing.*;
@@ -261,7 +262,6 @@ protected void sortCode() {
}
}
-
boolean renamingCode;
/**
@@ -709,13 +709,42 @@ public boolean save() throws IOException {
if (!saveAs()) return false;
}
+ // rename .pde files to .ino
+ File mainFile = new File(getMainFilePath());
+ File mainFolder = mainFile.getParentFile();
+ File[] pdeFiles = mainFolder.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.toLowerCase().endsWith(".pde");
+ }
+ });
+
+ if (pdeFiles != null && pdeFiles.length > 0) {
+ // Do rename of all .pde files to new .ino extension
+ for (File pdeFile : pdeFiles)
+ renameCodeToInoExtension(pdeFile);
+ }
+
for (int i = 0; i < codeCount; i++) {
- if (code[i].isModified()) code[i].save();
+ if (code[i].isModified())
+ code[i].save();
}
calcModified();
return true;
}
+
+ protected boolean renameCodeToInoExtension(File pdeFile) {
+ for (SketchCode c : code) {
+ if (!c.getFile().equals(pdeFile))
+ continue;
+
+ String pdeName = pdeFile.getPath();
+ pdeName = pdeName.substring(0, pdeName.length() - 4) + ".ino";
+ return c.renameTo(new File(pdeName), "ino");
+ }
+ return false;
+ }
+
/**
* Handles 'Save As' for a sketch.
@@ -1261,7 +1290,7 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
StringBuffer bigCode = new StringBuffer();
int bigCount = 0;
for (SketchCode sc : code) {
- if (sc.isExtension("ino")) {
+ if (sc.isExtension("ino") || sc.isExtension("pde")) {
sc.setPreprocOffset(bigCount);
bigCode.append(sc.getProgram());
bigCode.append('\n');
@@ -1357,7 +1386,7 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
}
// sc.setPreprocName(filename);
- } else if (sc.isExtension("ino")) {
+ } else if (sc.isExtension("ino") || sc.isExtension("pde")) {
// The compiler and runner will need this to have a proper offset
sc.addPreprocOffset(headerOffset);
}
@@ -1762,7 +1791,7 @@ public boolean isReadOnly() {
* For Processing, this is true for .pde files. (Broken out for subclasses.)
*/
public boolean hideExtension(String what) {
- return what.equals(getDefaultExtension());
+ return getHiddenExtensions().contains(what);
}
@@ -1802,12 +1831,17 @@ public String getDefaultExtension() {
return "ino";
}
+ static private List<String> hiddenExtensions = Arrays.asList("ino", "pde");
+ public List<String> getHiddenExtensions() {
+ return hiddenExtensions;
+ }
+
/**
* Returns a String[] array of proper extensions.
*/
public String[] getExtensions() {
- return new String[] { "ino", "c", "cpp", "h" };
+ return new String[] { "ino", "pde", "c", "cpp", "h" };
}
4 app/src/processing/app/SketchCode.java
View
@@ -113,8 +113,8 @@ protected boolean deleteFile() {
protected boolean renameTo(File what, String ext) {
boolean success = file.renameTo(what);
if (success) {
- this.file = what; // necessary?
- this.extension = ext;
+ file = what;
+ extension = ext;
makePrettyName();
}
return success;
Please sign in to comment.
Something went wrong with that request. Please try again.