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

Method nameCode

app/src/processing/app/Sketch.java:446–628  ·  view source on GitHub ↗

This is called upon return from entering a new file name. (that is, from either newCode or renameCode after the prompt)

(String newName)

Source from the content-addressed store, hash-verified

444 * (that is, from either newCode or renameCode after the prompt)
445 */
446 protected void nameCode(String newName) {
447 newName = newName.trim();
448 if (newName.length() == 0) {
449 return;
450 }
451
452 // make sure the user didn't hide the sketch folder
453 ensureExistence();
454
455 // Add the extension here, this simplifies some of the logic below.
456 if (newName.indexOf('.') == -1) {
457 newName += "." + (renamingCode ? mode.getDefaultExtension() : mode.getModuleExtension());
458 }
459
460 // if renaming to the same thing as before, just ignore.
461 // also ignoring case here, because i don't want to write
462 // a bunch of special stuff for each platform
463 // (osx is case insensitive but preserving, windows insensitive,
464 // *nix is sensitive and preserving.. argh)
465 if (renamingCode) {
466 if (newName.equalsIgnoreCase(current.getFileName())) {
467 // exit quietly for the 'rename' case.
468 // if it's a 'new' then an error will occur down below
469 return;
470 }
471 }
472
473 if (newName.startsWith(".")) {
474 Messages.showWarning(Language.text("name.messages.problem_renaming"),
475 Language.text("name.messages.starts_with_dot.description"));
476 return;
477 }
478
479 int dot = newName.lastIndexOf('.');
480 String newExtension = newName.substring(dot+1).toLowerCase();
481 if (!mode.validExtension(newExtension)) {
482 Messages.showWarning(Language.text("name.messages.problem_renaming"),
483 Language.interpolate("name.messages.invalid_extension.description",
484 newExtension));
485 return;
486 }
487
488 // Don't let the user create the main tab as a .java file instead of .pde
489 if (!mode.isDefaultExtension(newExtension)) {
490 if (renamingCode) { // If creating a new tab, don't show this error
491 if (current == code[0]) { // If this is the main tab, disallow
492 Messages.showWarning(Language.text("name.messages.problem_renaming"),
493 Language.interpolate("name.messages.main_java_extension.description",
494 newExtension));
495 return;
496 }
497 }
498 }
499
500 // dots are allowed for the .pde and .java, but not in the name
501 // make sure the user didn't name things poo.time.pde
502 // or something like that (nothing against poo time)
503 String shortName = newName.substring(0, dot);

Callers 1

promptForTabNameMethod · 0.95

Calls 15

ensureExistenceMethod · 0.95
showWarningMethod · 0.95
textMethod · 0.95
interpolateMethod · 0.95
sanitizeNameMethod · 0.95
showMessageMethod · 0.95
updateInternalMethod · 0.95
insertCodeMethod · 0.95
sortCodeMethod · 0.95
setCurrentCodeMethod · 0.95
getModuleExtensionMethod · 0.80
startsWithMethod · 0.80

Tested by

no test coverage detected