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

Method handleNew

app/src/processing/app/Base.java:1143–1223  ·  view source on GitHub ↗

Create a new untitled document in a new sketch window.

()

Source from the content-addressed store, hash-verified

1141 * Create a new untitled document in a new sketch window.
1142 */
1143 public void handleNew() {
1144 try {
1145 File newbieDir = null;
1146 String newbieName = null;
1147
1148 // In 0126, untitled sketches will begin in the temp folder,
1149 // and then moved to a new location because Save will default to Save As.
1150// File sketchbookDir = getSketchbookFolder();
1151 File newbieParentDir = untitledFolder;
1152
1153 String prefix = Preferences.get("editor.untitled.prefix");
1154
1155 // Use a generic name like sketch_031008a, the date plus a char
1156 int index = 0;
1157 String format = Preferences.get("editor.untitled.suffix");
1158 String suffix = null;
1159 if (format == null) {
1160 Calendar cal = Calendar.getInstance();
1161 int day = cal.get(Calendar.DAY_OF_MONTH); // 1..31
1162 int month = cal.get(Calendar.MONTH); // 0..11
1163 suffix = months[month] + PApplet.nf(day, 2);
1164 } else {
1165 //SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd");
1166 //SimpleDateFormat formatter = new SimpleDateFormat("MMMdd");
1167 //String purty = formatter.format(new Date()).toLowerCase();
1168 SimpleDateFormat formatter = new SimpleDateFormat(format);
1169 suffix = formatter.format(new Date());
1170 }
1171 do {
1172 if (index == 26) {
1173 // In 0159, avoid running past z by sending people outdoors.
1174 if (!breakTime) {
1175 Messages.showWarning("Time for a Break",
1176 "You've reached the limit for auto naming of new sketches\n" +
1177 "for the day. How about going for a walk instead?", null);
1178 breakTime = true;
1179 } else {
1180 Messages.showWarning("Sunshine",
1181 "No really, time for some fresh air for you.", null);
1182 }
1183 return;
1184 }
1185 newbieName = prefix + suffix + ((char) ('a' + index));
1186 // Also sanitize the name since it might do strange things on
1187 // non-English systems that don't use this sort of date format.
1188 // http://code.google.com/p/processing/issues/detail?id=283
1189 newbieName = Sketch.sanitizeName(newbieName);
1190 newbieDir = new File(newbieParentDir, newbieName);
1191 index++;
1192 // Make sure it's not in the temp folder *and* it's not in the sketchbook
1193 } while (newbieDir.exists() || new File(sketchbookFolder, newbieName).exists());
1194
1195 // Make the directory for the new sketch
1196 newbieDir.mkdirs();
1197
1198 // Add any template files from the Mode itself
1199 File newbieFile = nextMode.addTemplateFiles(newbieDir, newbieName);
1200

Callers 6

BaseMethod · 0.95
changeModeMethod · 0.95
handleOpenMethod · 0.95
runMethod · 0.80
actionPerformedMethod · 0.80
actionPerformedMethod · 0.80

Calls 12

getMethod · 0.95
nfMethod · 0.95
showWarningMethod · 0.95
sanitizeNameMethod · 0.95
getDefaultModeMethod · 0.95
saveModeSettingsMethod · 0.95
handleOpenMethod · 0.95
addTemplateFilesMethod · 0.80
getMethod · 0.65
formatMethod · 0.65
getInstanceMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected