Skip to content

Commit 7e142e8

Browse files
committed
add template support for Modes
1 parent 16534d3 commit 7e142e8

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

app/src/processing/app/Base.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,12 +1094,17 @@ public void handleNew() {
10941094
// Make the directory for the new sketch
10951095
newbieDir.mkdirs();
10961096

1097+
// Add any template files from the Mode itself
1098+
File newbieFile = nextMode.addTemplateFiles(newbieDir, newbieName);
1099+
1100+
/*
10971101
// Make an empty pde file
10981102
File newbieFile =
10991103
new File(newbieDir, newbieName + "." + nextMode.getDefaultExtension()); //$NON-NLS-1$
11001104
if (!newbieFile.createNewFile()) {
11011105
throw new IOException(newbieFile + " already exists.");
11021106
}
1107+
*/
11031108

11041109
// Create sketch properties file if it's not the default mode.
11051110
if (!nextMode.equals(getDefaultMode())) {

app/src/processing/app/Mode.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,43 @@ public InputStream getContentStream(String path) throws FileNotFoundException {
226226
}
227227

228228

229+
/**
230+
* Add files to a folder to create an empty sketch. This can be overridden
231+
* to add template files to a sketch for Modes that need them.
232+
*
233+
* @param sketchFolder the directory where the new sketch should live
234+
* @param sketchName the name of the new sketch
235+
* @return the main file for the sketch to be opened via handleOpen()
236+
* @throws IOException if the file somehow already exists
237+
*/
238+
public File addTemplateFiles(File sketchFolder,
239+
String sketchName) throws IOException {
240+
// Make an empty .pde file
241+
File newbieFile =
242+
new File(sketchFolder, sketchName + "." + getDefaultExtension());
243+
244+
File templateFolder = getTemplateFolder();
245+
if (templateFolder.exists()) {
246+
Util.copyDir(templateFolder, sketchFolder);
247+
File templateFile =
248+
new File(sketchFolder, "sketch." + getDefaultExtension());
249+
if (!templateFile.renameTo(newbieFile)) {
250+
throw new IOException("Error while assigning the sketch template.");
251+
}
252+
} else {
253+
if (!newbieFile.createNewFile()) {
254+
throw new IOException(newbieFile + " already exists.");
255+
}
256+
}
257+
return newbieFile;
258+
}
259+
260+
261+
public File getTemplateFolder() {
262+
return getContentFile("template");
263+
}
264+
265+
229266
/**
230267
* Return the pretty/printable/menu name for this mode. This is separate from
231268
* the single word name of the folder that contains this mode. It could even

java/src/processing/mode/java/JavaEditor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,13 +1945,8 @@ protected void activateRun() {
19451945
* To initiate a "stop" action, call handleStop() instead.
19461946
*/
19471947
public void deactivateRun() {
1948-
// if (toolbar instanceof DebugToolbar){
1949-
// toolbar.deactivate(DebugToolbar.RUN);
1950-
// } else {
1951-
// toolbar.deactivate(JavaToolbar.RUN);
19521948
toolbar.deactivateRun();
19531949
debugItem.setEnabled(true);
1954-
// }
19551950
}
19561951

19571952

todo.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ X https://github.com/processing/processing/issues/4566
1313
X https://github.com/processing/processing/issues/4492
1414
X https://github.com/processing/processing/issues/4128
1515
X https://github.com/processing/processing/issues/4503
16-
17-
_ see if CLASSPATH can be set to screw up p5
16+
X see if CLASSPATH can be set to screw up p5
17+
X works fine on OS X, couldn't reproduce on Linux
18+
X add template support for Modes
1819

1920
_ modify line number color when no lines extend that far?
2021
_ https://github.com/processing/processing/pull/4560

0 commit comments

Comments
 (0)