MCPcopy Index your code
hub / github.com/processing/processing / addTemplateFiles

Method addTemplateFiles

app/src/processing/app/Mode.java:251–282  ·  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

249 * @throws IOException if the file somehow already exists
250 */
251 public File addTemplateFiles(File sketchFolder,
252 String sketchName) throws IOException {
253 // Make an empty .pde file
254 File newbieFile =
255 new File(sketchFolder, sketchName + "." + getDefaultExtension());
256
257 try {
258 // First see if the user has overridden the default template
259 File templateFolder = checkSketchbookTemplate();
260
261 // Next see if the Mode has its own template
262 if (templateFolder == null) {
263 templateFolder = getTemplateFolder();
264 }
265 if (templateFolder.exists()) {
266 Util.copyDir(templateFolder, sketchFolder);
267 File templateFile =
268 new File(sketchFolder, "sketch." + getDefaultExtension());
269 if (!templateFile.renameTo(newbieFile)) {
270 System.err.println("Error while assigning the sketch template.");
271 }
272 } else {
273 if (!newbieFile.createNewFile()) {
274 System.err.println(newbieFile + " already exists.");
275 }
276 }
277 } catch (Exception e) {
278 // just spew out this error and try to recover below
279 e.printStackTrace();
280 }
281 return newbieFile;
282 }
283
284
285 /**

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