Skip to content

Commit 8e00662

Browse files
author
Federico Fissore
committed
introducing template sketch with empty setup and loop functions. see #1138
1 parent ac66cf7 commit 8e00662

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

app/src/processing/app/Base.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,10 @@ protected String createNewUntitled() throws IOException {
652652

653653
// Make an empty pde file
654654
File newbieFile = new File(newbieDir, newbieName + ".ino");
655-
new FileOutputStream(newbieFile); // create the file
655+
if (!newbieFile.createNewFile()) {
656+
throw new IOException();
657+
}
658+
FileUtils.copyFile(new File(System.getProperty("user.dir"), "TemplateSketch.ino"), newbieFile);
656659
return newbieFile.getAbsolutePath();
657660
}
658661

app/src/processing/app/helpers/FileUtils.java

+22-18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ public static boolean isSubDirectory(File base, File child) {
3535
return false;
3636
}
3737

38+
public static void copyFile(File source, File dest) throws IOException {
39+
FileInputStream fis = null;
40+
FileOutputStream fos = null;
41+
try {
42+
fis = new FileInputStream(source);
43+
fos = new FileOutputStream(dest);
44+
byte[] buf = new byte[4096];
45+
int readBytes = -1;
46+
while ((readBytes = fis.read(buf, 0, buf.length)) != -1) {
47+
fos.write(buf, 0, readBytes);
48+
}
49+
} finally {
50+
if (fis != null) {
51+
fis.close();
52+
}
53+
if (fos != null) {
54+
fos.close();
55+
}
56+
}
57+
}
58+
3859
public static void copy(File sourceFolder, File destFolder) throws IOException {
3960
for (File file : sourceFolder.listFiles()) {
4061
File destFile = new File(destFolder, file.getName());
@@ -44,24 +65,7 @@ public static void copy(File sourceFolder, File destFolder) throws IOException {
4465
}
4566
copy(file, destFile);
4667
} else {
47-
FileInputStream fis = null;
48-
FileOutputStream fos = null;
49-
try {
50-
fis = new FileInputStream(file);
51-
fos = new FileOutputStream(destFile);
52-
byte[] buf = new byte[4096];
53-
int readBytes = -1;
54-
while ((readBytes = fis.read(buf, 0, buf.length)) != -1) {
55-
fos.write(buf, 0, readBytes);
56-
}
57-
} finally {
58-
if (fis != null) {
59-
fis.close();
60-
}
61-
if (fos != null) {
62-
fos.close();
63-
}
64-
}
68+
copyFile(file, destFile);
6569
}
6670
}
6771
}

build/build.xml

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@
9797
<fileset dir="shared/examples" />
9898
</copy>
9999

100+
<!-- copy shared template -->
101+
<copy file="shared/TemplateSketch.ino" todir="${target.path}/" />
102+
100103
<!-- Unzip documentation -->
101104
<unzip dest="${target.path}" src="shared/reference.zip" overwrite="false"/>
102105

build/shared/TemplateSketch.ino

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
void setup() {
2+
// put your setup code here, to run once:
3+
4+
}
5+
6+
void loop() {
7+
// put your main code here, to run repeatedly:
8+
9+
}

0 commit comments

Comments
 (0)