This is called upon return from entering a new file name. (that is, from either newCode or renameCode after the prompt)
(String newName)
| 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); |
no test coverage detected