Pre-4.0b6 style rename where the sketch name must be identical to the name of the first (main) tab with the extension removed.
(String newName, String newExtension)
| 583 | * to the name of the first (main) tab with the extension removed. |
| 584 | */ |
| 585 | protected boolean renameSketch(String newName, String newExtension) { |
| 586 | // get the new folder name/location |
| 587 | String folderName = newName.substring(0, newName.indexOf('.')); |
| 588 | File newFolder = new File(folder.getParentFile(), folderName); |
| 589 | if (newFolder.exists()) { |
| 590 | Messages.showWarning(Language.text("name.messages.new_folder_exists"), |
| 591 | Language.interpolate("name.messages.new_folder_exists.description", newName)); |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | // renaming the containing sketch folder |
| 596 | boolean success = folder.renameTo(newFolder); |
| 597 | if (!success) { |
| 598 | Messages.showWarning(Language.text("name.messages.error"), |
| 599 | Language.text("name.messages.no_rename_folder.description")); |
| 600 | return false; |
| 601 | } |
| 602 | // let this guy know where he's living (at least for a split second) |
| 603 | current.setFolder(newFolder); |
| 604 | // folder will be set to newFolder by updateInternal() |
| 605 | |
| 606 | // unfortunately this can't be a "save as" because that |
| 607 | // only copies the sketch files and the data folder |
| 608 | // however this *will* first save the sketch, then rename |
| 609 | |
| 610 | // This isn't changing folders, just changes the name |
| 611 | File newFile = new File(newFolder, newName); |
| 612 | if (!current.renameTo(newFile, newExtension)) { |
| 613 | Messages.showWarning(Language.text("name.messages.error"), |
| 614 | Language.interpolate("name.messages.no_rename_file.description", |
| 615 | current.getFileName(), newFile.getName())); |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | // Tell each code file the good news about their new home. |
| 620 | // current.renameTo() above already took care of the main tab. |
| 621 | for (int i = 1; i < codeCount; i++) { |
| 622 | code[i].setFolder(newFolder); |
| 623 | } |
| 624 | // Save the path in case we need to remove it from the Recent menu |
| 625 | String oldPath = getMainPath(); |
| 626 | |
| 627 | // Update internal state to reflect the new location |
| 628 | updateInternal(newFolder); |
| 629 | |
| 630 | if (renamingCode) { |
| 631 | // Update the Recent menu if a Rename event (but not Save As) |
| 632 | // https://github.com/processing/processing/issues/5902 |
| 633 | Recent.rename(editor, oldPath); |
| 634 | } |
| 635 | |
| 636 | return true; |
| 637 | } |
| 638 | |
| 639 | |
| 640 | /** |
no test coverage detected