Remove a piece of code from the sketch and from the disk.
()
| 632 | * Remove a piece of code from the sketch and from the disk. |
| 633 | */ |
| 634 | public void handleDeleteCode() { |
| 635 | // make sure the user didn't hide the sketch folder |
| 636 | ensureExistence(); |
| 637 | |
| 638 | // if read-only, give an error |
| 639 | if (isReadOnly()) { |
| 640 | // if the files are read-only, need to first do a "save as". |
| 641 | Messages.showMessage(Language.text("delete.messages.is_read_only"), |
| 642 | Language.text("delete.messages.is_read_only.description")); |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | // don't allow if untitled |
| 647 | if (currentIndex == 0 && isUntitled()) { |
| 648 | Messages.showMessage(Language.text("delete.messages.cannot_delete"), |
| 649 | Language.text("delete.messages.cannot_delete.description")); |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | // confirm deletion with user, yes/no |
| 654 | Object[] options = { Language.text("prompt.ok"), Language.text("prompt.cancel") }; |
| 655 | String prompt = (currentIndex == 0) ? |
| 656 | Language.text("warn.delete.sketch") : |
| 657 | Language.interpolate("warn.delete.file", current.getPrettyName()); |
| 658 | int result = JOptionPane.showOptionDialog(editor, |
| 659 | prompt, |
| 660 | Language.text("warn.delete"), |
| 661 | JOptionPane.YES_NO_OPTION, |
| 662 | JOptionPane.QUESTION_MESSAGE, |
| 663 | null, |
| 664 | options, |
| 665 | options[0]); |
| 666 | if (result == JOptionPane.YES_OPTION) { |
| 667 | if (currentIndex == 0) { |
| 668 | // need to unset all the modified flags, otherwise tries |
| 669 | // to do a save on the handleNew() |
| 670 | |
| 671 | // delete the entire sketch |
| 672 | Util.removeDir(folder); |
| 673 | |
| 674 | // get the changes into the sketchbook menu |
| 675 | //sketchbook.rebuildMenus(); |
| 676 | |
| 677 | // make a new sketch and rebuild the sketch menu |
| 678 | //editor.handleNewUnchecked(); |
| 679 | //editor.handleClose2(); |
| 680 | editor.getBase().rebuildSketchbookMenus(); |
| 681 | editor.getBase().handleClose(editor, false); |
| 682 | |
| 683 | } else { |
| 684 | // delete the file |
| 685 | if (!current.deleteFile()) { |
| 686 | Messages.showMessage(Language.text("delete.messages.cannot_delete.file"), |
| 687 | Language.text("delete.messages.cannot_delete.file.description")+" \"" + |
| 688 | current.getFileName() + "\"."); |
| 689 | return; |
| 690 | } |
| 691 |
no test coverage detected