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

Method nameCode

app/src/processing/app/Sketch.java:452–578  ·  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

450 * (that is, from either newCode or renameCode after the prompt)
451 */
452 protected void nameCode(String newName) {
453 newName = newName.trim();
454 if (newName.length() == 0) {
455 return;
456 }
457
458 // Make sure the sketch folder is still available and exists.
459 ensureExistence();
460
461 // Add the extension here, this simplifies some logic below.
462 if (newName.indexOf('.') == -1) {
463 newName += "." + (renamingCode ? mode.getDefaultExtension() : mode.getModuleExtension());
464 }
465
466 // If renaming to the same thing as before, just ignore.
467 // Also ignoring case here, because I don't want to write/maintain/debug
468 // a bunch of platform-specific quirks: macOS is case-insensitive but
469 // preserving, Windows is insensitive, *nix is sensitive and preserving,
470 // and someday we're all gonna die, and I'm comfortable that writing the
471 // necessary code is not essential to the story of my life on Earth.
472 if (renamingCode) {
473 if (newName.equalsIgnoreCase(current.getFileName())) {
474 // exit quietly for the 'rename' case.
475 // if it's a 'new' then an error will occur down below
476 return;
477 }
478 }
479
480 if (newName.startsWith(".")) {
481 Messages.showWarning(Language.text("name.messages.problem_renaming"),
482 Language.text("name.messages.starts_with_dot.description"));
483 return;
484 }
485
486 int dot = newName.lastIndexOf('.');
487 String newExtension = newName.substring(dot+1).toLowerCase();
488 if (!mode.validExtension(newExtension)) {
489 Messages.showWarning(Language.text("name.messages.problem_renaming"),
490 Language.interpolate("name.messages.invalid_extension.description",
491 newExtension));
492 return;
493 }
494
495 // Don't let the user create the main tab as a .java file instead of .pde
496 if (!mode.isDefaultExtension(newExtension)) {
497 if (renamingCode) { // If creating a new tab, don't show this error
498 if (current == code[0]) { // If this is the main tab, disallow
499 Messages.showWarning(Language.text("name.messages.problem_renaming"),
500 Language.interpolate("name.messages.main_java_extension.description",
501 newExtension));
502 return;
503 }
504 }
505 }
506
507 // Dots are allowed for the .pde and .java, but not in the name.
508 // Make sure the user didn't name the file poo.time.pde or anything
509 // else with a dot inside it (nothing against poo time).

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
getBooleanMethod · 0.95
renameSketchMethod · 0.95
updateNamePropertiesMethod · 0.95
insertCodeMethod · 0.95
sortCodeMethod · 0.95
setCurrentCodeMethod · 0.95

Tested by

no test coverage detected