diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 8adcb7993..c3d6382f5 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -39,6 +39,7 @@ import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.*; +import java.util.ArrayList; import java.util.List; import javax.swing.*; @@ -143,44 +144,19 @@ public class Sketch { codeFolder = new File(folder, "code"); dataFolder = new File(folder, "data"); - // get list of files in the sketch folder - String list[] = folder.list(); + List filenames = new ArrayList<>(); + List extensions = new ArrayList<>(); - // reset these because load() may be called after an - // external editor event. (fix for 0099) - codeCount = 0; + getSketchCodeFiles(filenames, extensions); - code = new SketchCode[list.length]; + codeCount = filenames.size(); + code = new SketchCode[codeCount]; - String[] extensions = mode.getExtensions(); - - for (String filename : list) { - // Ignoring the dot prefix files is especially important to avoid files - // with the ._ prefix on Mac OS X. (You'll see this with Mac files on - // non-HFS drives, i.e. a thumb drive formatted FAT32.) - if (filename.startsWith(".")) continue; - - // Don't let some wacko name a directory blah.pde or bling.java. - if (new File(folder, filename).isDirectory()) continue; - - // figure out the name without any extension - String base = filename; - // now strip off the .pde and .java extensions - for (String extension : extensions) { - if (base.toLowerCase().endsWith("." + extension)) { - base = base.substring(0, base.length() - (extension.length() + 1)); - - // Don't allow people to use files with invalid names, since on load, - // it would be otherwise possible to sneak in nasty filenames. [0116] - if (isSanitaryName(base)) { - code[codeCount++] = - new SketchCode(new File(folder, filename), extension); - } - } - } + for (int i = 0; i < codeCount; i++) { + String filename = filenames.get(i); + String extension = extensions.get(i); + code[i] = new SketchCode(new File(folder, filename), extension); } - // Remove any code that wasn't proper - code = (SketchCode[]) PApplet.subset(code, 0, codeCount); // move the main class to the first tab // start at 1, if it's at zero, don't bother @@ -204,6 +180,39 @@ public class Sketch { } + public void getSketchCodeFiles(List outFilenames, + List outExtensions) { + // get list of files in the sketch folder + String list[] = folder.list(); + + for (String filename : list) { + // Ignoring the dot prefix files is especially important to avoid files + // with the ._ prefix on Mac OS X. (You'll see this with Mac files on + // non-HFS drives, i.e. a thumb drive formatted FAT32.) + if (filename.startsWith(".")) continue; + + // Don't let some wacko name a directory blah.pde or bling.java. + if (new File(folder, filename).isDirectory()) continue; + + // figure out the name without any extension + String base = filename; + // now strip off the .pde and .java extensions + for (String extension : mode.getExtensions()) { + if (base.toLowerCase().endsWith("." + extension)) { + base = base.substring(0, base.length() - (extension.length() + 1)); + + // Don't allow people to use files with invalid names, since on load, + // it would be otherwise possible to sneak in nasty filenames. [0116] + if (isSanitaryName(base)) { + if (outFilenames != null) outFilenames.add(filename); + if (outExtensions != null) outExtensions.add(extension); + } + } + } + } + } + + /** * Reload the current sketch. Used to update the text area when * an external editor is in use. diff --git a/app/src/processing/app/ui/ChangeDetector.java b/app/src/processing/app/ui/ChangeDetector.java index 081f42334..866d2ffc4 100644 --- a/app/src/processing/app/ui/ChangeDetector.java +++ b/app/src/processing/app/ui/ChangeDetector.java @@ -5,7 +5,6 @@ import java.awt.Frame; import java.awt.event.WindowEvent; import java.awt.event.WindowFocusListener; import java.io.File; -import java.io.FilenameFilter; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; @@ -79,19 +78,12 @@ public class ChangeDetector implements WindowFocusListener { private boolean checkFileCount() { // check file count first - File sketchFolder = sketch.getFolder(); - File[] sketchFiles = sketchFolder.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String filename) { - for (String ext : editor.getMode().getExtensions()) { - if (filename.toLowerCase().endsWith(ext.toLowerCase())) { - return true; - } - } - return false; - } - }); - int fileCount = sketchFiles.length; + + List filenames = new ArrayList<>(); + + sketch.getSketchCodeFiles(filenames, null); + + int fileCount = filenames.size(); // Was considering keeping track of the last "known" number of files // (instead of using sketch.getCodeCount() here) in case the user