MCPcopy Index your code
hub / github.com/benfry/processing4 / addTemplateFiles

Method addTemplateFiles

app/src/processing/app/Mode.java:204–235  ·  view source on GitHub ↗

Add files to a folder to create an empty sketch. This can be overridden to add template files to a sketch for Modes that need them. @param sketchFolder the directory where the new sketch should live @param sketchName the name of the new sketch @return the main file for the sketch to be opened via h

(File sketchFolder,
                               String sketchName)

Source from the content-addressed store, hash-verified

202 * @throws IOException if the file somehow already exists
203 */
204 public File addTemplateFiles(File sketchFolder,
205 String sketchName) throws IOException {
206 // Make an empty .pde file
207 File newbieFile =
208 new File(sketchFolder, sketchName + "." + getDefaultExtension());
209
210 try {
211 // First see if the user has overridden the default template
212 File templateFolder = checkSketchbookTemplate();
213
214 // Next see if the Mode has its own template
215 if (templateFolder == null) {
216 templateFolder = getTemplateFolder();
217 }
218 if (templateFolder.exists()) {
219 Util.copyDir(templateFolder, sketchFolder);
220 File templateFile =
221 new File(sketchFolder, "sketch." + getDefaultExtension());
222 if (!templateFile.renameTo(newbieFile)) {
223 System.err.println("Error while assigning the sketch template.");
224 }
225 } else {
226 if (!newbieFile.createNewFile()) {
227 System.err.println(newbieFile + " already exists.");
228 }
229 }
230 } catch (Exception e) {
231 // just spew out this error and try to recover below
232 e.printStackTrace();
233 }
234 return newbieFile;
235 }
236
237
238 /**

Callers 1

handleNewMethod · 0.80

Calls 7

getDefaultExtensionMethod · 0.95
getTemplateFolderMethod · 0.95
copyDirMethod · 0.95
renameToMethod · 0.80
printlnMethod · 0.45
printStackTraceMethod · 0.45

Tested by

no test coverage detected