Skip to content

Commit 5db851c

Browse files
bitroncmaglie
authored andcommitted
Moved the sketch structure check code from Editor to SketchData.
1 parent afbbe77 commit 5db851c

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

app/src/processing/app/Editor.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,21 +2128,10 @@ protected boolean handleOpenInternal(File file) {
21282128
// check to make sure that this .pde file is
21292129
// in a folder of the same name
21302130
String fileName = file.getName();
2131-
File parent = file.getParentFile();
2132-
String parentName = parent.getName();
2133-
String pdeName = parentName + ".pde";
2134-
File altPdeFile = new File(parent, pdeName);
2135-
String inoName = parentName + ".ino";
2136-
File altInoFile = new File(parent, inoName);
2137-
2138-
if (pdeName.equals(fileName) || inoName.equals(fileName)) {
2131+
2132+
if (SketchData.checkSketchFile(file)) {
21392133
// no beef with this guy
21402134

2141-
} else if (altPdeFile.exists()) {
2142-
// user selected a .java from the same sketch, but open the .pde instead
2143-
file = altPdeFile;
2144-
} else if (altInoFile.exists()) {
2145-
file = altInoFile;
21462135
} else if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
21472136
Base.showWarning(_("Bad file selected"),
21482137
_("Arduino can only open its own sketches\n" +
@@ -2154,13 +2143,11 @@ protected boolean handleOpenInternal(File file) {
21542143
fileName.substring(0, fileName.length() - 4);
21552144

21562145
Object[] options = { _("OK"), _("Cancel") };
2157-
String prompt = I18n.format(
2158-
_("The file \"{0}\" needs to be inside\n" +
2159-
"a sketch folder named \"{1}\".\n" +
2160-
"Create this folder, move the file, and continue?"),
2161-
fileName,
2162-
properParent
2163-
);
2146+
String prompt = I18n.format(_("The file \"{0}\" needs to be inside\n" +
2147+
"a sketch folder named \"{1}\".\n" +
2148+
"Create this folder, move the file, and continue?"),
2149+
fileName,
2150+
properParent);
21642151

21652152
int result = JOptionPane.showOptionDialog(this,
21662153
prompt,

app/src/processing/app/SketchData.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ public int compare(SketchCode x, SketchCode y) {
5252
//System.out.println("sketch dir is " + folder);
5353
}
5454

55+
static public boolean checkSketchFile(File file) {
56+
// check to make sure that this .pde file is
57+
// in a folder of the same name
58+
String fileName = file.getName();
59+
File parent = file.getParentFile();
60+
String parentName = parent.getName();
61+
String pdeName = parentName + ".pde";
62+
File altPdeFile = new File(parent, pdeName);
63+
String inoName = parentName + ".ino";
64+
File altInoFile = new File(parent, inoName);
65+
66+
return pdeName.equals(fileName) || inoName.equals(fileName) || altPdeFile.exists() || altInoFile.exists();
67+
}
68+
5569
/**
5670
* Build the list of files.
5771
* <P>

0 commit comments

Comments
 (0)