mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
Changing extension from .pde to .ino.
Renames all .pde files in a sketch to .ino upon opening. Prompts the user the first time this happens; if the rename is cancelled, the sketch is not opened and the user will be prompted next time a sketch with a .pde file is opened. Otherwise, renames files in all future opened sketches automatically (without prompting). Still allows for opening of .pde files and includes them in the sketchbook and examples menus. Still need to check the file association code. http://code.google.com/p/arduino/issues/detail?id=13
This commit is contained in:
parent
b3c92d834f
commit
e2213d4721
@ -545,7 +545,7 @@ public class Base {
|
|||||||
newbieDir.mkdirs();
|
newbieDir.mkdirs();
|
||||||
|
|
||||||
// Make an empty pde file
|
// 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
|
new FileOutputStream(newbieFile); // create the file
|
||||||
return newbieFile.getAbsolutePath();
|
return newbieFile.getAbsolutePath();
|
||||||
}
|
}
|
||||||
@ -637,7 +637,8 @@ public class Base {
|
|||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
// TODO this doesn't seem to ever be used. AWESOME.
|
// TODO this doesn't seem to ever be used. AWESOME.
|
||||||
//System.out.println("check filter on " + dir + " " + name);
|
//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]);
|
File subfolder = new File(folder, list[i]);
|
||||||
if (!subfolder.isDirectory()) continue;
|
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 a .pde file of the same prefix as the folder exists..
|
||||||
if (entry.exists()) {
|
if (entry.exists()) {
|
||||||
//String sanityCheck = sanitizedName(list[i]);
|
//String sanityCheck = sanitizedName(list[i]);
|
||||||
|
@ -2020,14 +2020,65 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
* modifications (if any) to the previous sketch need to be saved.
|
* modifications (if any) to the previous sketch need to be saved.
|
||||||
*/
|
*/
|
||||||
protected boolean handleOpenInternal(String path) {
|
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
|
// check to make sure that this .pde file is
|
||||||
// in a folder of the same name
|
// in a folder of the same name
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
File parentFile = new File(file.getParent());
|
File parentFile = new File(file.getParent());
|
||||||
String parentName = parentFile.getName();
|
String parentName = parentFile.getName();
|
||||||
String pdeName = parentName + ".pde";
|
String pdeName = parentName + ".ino";
|
||||||
File altFile = new File(file.getParent(), pdeName);
|
File altFile = new File(file.getParent(), pdeName);
|
||||||
|
|
||||||
if (pdeName.equals(file.getName())) {
|
if (pdeName.equals(file.getName())) {
|
||||||
// no beef with this guy
|
// no beef with this guy
|
||||||
|
|
||||||
@ -2037,10 +2088,10 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
path = altFile.getAbsolutePath();
|
path = altFile.getAbsolutePath();
|
||||||
//System.out.println("found alt file in same folder");
|
//System.out.println("found alt file in same folder");
|
||||||
|
|
||||||
} else if (!path.endsWith(".pde")) {
|
} else if (!path.endsWith(".ino")) {
|
||||||
Base.showWarning("Bad file selected",
|
Base.showWarning("Bad file selected",
|
||||||
"Processing can only open its own sketches\n" +
|
"Processing can only open its own sketches\n" +
|
||||||
"and other files ending in .pde", null);
|
"and other files ending in .ino", null);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -315,7 +315,7 @@ public class Sketch {
|
|||||||
renamingCode = true;
|
renamingCode = true;
|
||||||
String prompt = (currentIndex == 0) ?
|
String prompt = (currentIndex == 0) ?
|
||||||
"New name for sketch:" : "New name for file:";
|
"New name for sketch:" : "New name for file:";
|
||||||
String oldName = (current.isExtension("pde")) ?
|
String oldName = (current.isExtension("ino")) ?
|
||||||
current.getPrettyName() : current.getFileName();
|
current.getPrettyName() : current.getFileName();
|
||||||
editor.status.edit(prompt, oldName);
|
editor.status.edit(prompt, oldName);
|
||||||
}
|
}
|
||||||
@ -495,7 +495,7 @@ public class Sketch {
|
|||||||
}
|
}
|
||||||
// if successful, set base properties for the 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();
|
String newMainFilePath = newMainFile.getAbsolutePath();
|
||||||
|
|
||||||
// having saved everything and renamed the folder and the main .pde,
|
// 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
|
// 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);
|
code[0].saveAs(newFile);
|
||||||
|
|
||||||
editor.handleOpenUnchecked(newFile.getPath(),
|
editor.handleOpenUnchecked(newFile.getPath(),
|
||||||
@ -1261,7 +1261,7 @@ public class Sketch {
|
|||||||
StringBuffer bigCode = new StringBuffer();
|
StringBuffer bigCode = new StringBuffer();
|
||||||
int bigCount = 0;
|
int bigCount = 0;
|
||||||
for (SketchCode sc : code) {
|
for (SketchCode sc : code) {
|
||||||
if (sc.isExtension("pde")) {
|
if (sc.isExtension("ino")) {
|
||||||
sc.setPreprocOffset(bigCount);
|
sc.setPreprocOffset(bigCount);
|
||||||
bigCode.append(sc.getProgram());
|
bigCode.append(sc.getProgram());
|
||||||
bigCode.append('\n');
|
bigCode.append('\n');
|
||||||
@ -1357,7 +1357,7 @@ public class Sketch {
|
|||||||
}
|
}
|
||||||
// sc.setPreprocName(filename);
|
// 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
|
// The compiler and runner will need this to have a proper offset
|
||||||
sc.addPreprocOffset(headerOffset);
|
sc.addPreprocOffset(headerOffset);
|
||||||
}
|
}
|
||||||
@ -1386,7 +1386,7 @@ public class Sketch {
|
|||||||
// SketchCode errorCode = null;
|
// SketchCode errorCode = null;
|
||||||
// if (filename.equals(appletJavaFile)) {
|
// if (filename.equals(appletJavaFile)) {
|
||||||
// for (SketchCode code : getCode()) {
|
// for (SketchCode code : getCode()) {
|
||||||
// if (code.isExtension("pde")) {
|
// if (code.isExtension("ino")) {
|
||||||
// if (line >= code.getPreprocOffset()) {
|
// if (line >= code.getPreprocOffset()) {
|
||||||
// errorCode = code;
|
// errorCode = code;
|
||||||
// }
|
// }
|
||||||
@ -1791,7 +1791,7 @@ public class Sketch {
|
|||||||
* Returns the default extension for this editor setup.
|
* Returns the default extension for this editor setup.
|
||||||
*/
|
*/
|
||||||
public String getDefaultExtension() {
|
public String getDefaultExtension() {
|
||||||
return "pde";
|
return "ino";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1799,7 +1799,7 @@ public class Sketch {
|
|||||||
* Returns a String[] array of proper extensions.
|
* Returns a String[] array of proper extensions.
|
||||||
*/
|
*/
|
||||||
public String[] getExtensions() {
|
public String[] getExtensions() {
|
||||||
return new String[] { "pde", "c", "cpp", "h" };
|
return new String[] { "ino", "c", "cpp", "h" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user