mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Moved the sketch structure check code from Editor to SketchData.
This commit is contained in:
parent
afbbe77752
commit
5db851cf9f
@ -2128,21 +2128,10 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
// 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
|
||||||
String fileName = file.getName();
|
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, inoName);
|
|
||||||
|
|
||||||
if (pdeName.equals(fileName) || inoName.equals(fileName)) {
|
if (SketchData.checkSketchFile(file)) {
|
||||||
// no beef with this guy
|
// no beef with this guy
|
||||||
|
|
||||||
} else if (altPdeFile.exists()) {
|
|
||||||
// user selected a .java from the same sketch, but open the .pde instead
|
|
||||||
file = altPdeFile;
|
|
||||||
} else if (altInoFile.exists()) {
|
|
||||||
file = altInoFile;
|
|
||||||
} else if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
|
} else if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
|
||||||
Base.showWarning(_("Bad file selected"),
|
Base.showWarning(_("Bad file selected"),
|
||||||
_("Arduino can only open its own sketches\n" +
|
_("Arduino can only open its own sketches\n" +
|
||||||
@ -2154,13 +2143,11 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
fileName.substring(0, fileName.length() - 4);
|
fileName.substring(0, fileName.length() - 4);
|
||||||
|
|
||||||
Object[] options = { _("OK"), _("Cancel") };
|
Object[] options = { _("OK"), _("Cancel") };
|
||||||
String prompt = I18n.format(
|
String prompt = I18n.format(_("The file \"{0}\" needs to be inside\n" +
|
||||||
_("The file \"{0}\" needs to be inside\n" +
|
"a sketch folder named \"{1}\".\n" +
|
||||||
"a sketch folder named \"{1}\".\n" +
|
"Create this folder, move the file, and continue?"),
|
||||||
"Create this folder, move the file, and continue?"),
|
fileName,
|
||||||
fileName,
|
properParent);
|
||||||
properParent
|
|
||||||
);
|
|
||||||
|
|
||||||
int result = JOptionPane.showOptionDialog(this,
|
int result = JOptionPane.showOptionDialog(this,
|
||||||
prompt,
|
prompt,
|
||||||
|
@ -52,6 +52,20 @@ public class SketchData {
|
|||||||
//System.out.println("sketch dir is " + folder);
|
//System.out.println("sketch dir is " + folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public boolean checkSketchFile(File file) {
|
||||||
|
// check to make sure that this .pde file is
|
||||||
|
// in a folder of the same name
|
||||||
|
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, inoName);
|
||||||
|
|
||||||
|
return pdeName.equals(fileName) || inoName.equals(fileName) || altPdeFile.exists() || altInoFile.exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the list of files.
|
* Build the list of files.
|
||||||
* <P>
|
* <P>
|
||||||
|
Loading…
Reference in New Issue
Block a user