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

Method handleDeleteCode

app/src/processing/app/Sketch.java:643–710  ·  view source on GitHub ↗

Remove a piece of code from the sketch and from the disk.

()

Source from the content-addressed store, hash-verified

641 * Remove a piece of code from the sketch and from the disk.
642 */
643 public void handleDeleteCode() {
644 // make sure the user didn't hide the sketch folder
645 ensureExistence();
646
647 // if read-only, give an error
648 if (isReadOnly()) {
649 // if the files are read-only, need to first do a "save as".
650 Messages.showMessage(Language.text("delete.messages.is_read_only"),
651 Language.text("delete.messages.is_read_only.description"));
652 return;
653 }
654
655 // don't allow if untitled
656 if (currentIndex == 0 && isUntitled()) {
657 Messages.showMessage(Language.text("delete.messages.cannot_delete"),
658 Language.text("delete.messages.cannot_delete.description"));
659 return;
660 }
661
662 // confirm deletion with user, yes/no
663 Object[] options = { Language.text("prompt.ok"), Language.text("prompt.cancel") };
664 String prompt = (currentIndex == 0) ?
665 Language.interpolate("warn.delete.sketch_folder", getName()) :
666 Language.interpolate("warn.delete.sketch_file", current.getPrettyName());
667 int result = JOptionPane.showOptionDialog(editor,
668 prompt,
669 Language.text("warn.delete"),
670 JOptionPane.YES_NO_OPTION,
671 JOptionPane.QUESTION_MESSAGE,
672 null,
673 options,
674 options[0]);
675 if (result == JOptionPane.YES_OPTION) {
676 if (currentIndex == 0) { // delete the entire sketch
677 // need to unset all the modified flags, otherwise tries
678 // to do a save on the handleNew()
679
680 // Attempt to move to the trash (falls back to removeDir)
681 try {
682 Platform.deleteFile(folder);
683 } catch (IOException e) {
684 e.printStackTrace();
685 }
686
687 // make a new sketch and rebuild the sketch menu
688 editor.getBase().rebuildSketchbook();
689 editor.getBase().handleClose(editor, false);
690
691 } else { // delete a single tab
692 if (!current.deleteFile()) {
693 Messages.showMessage(Language.text("delete.messages.cannot_delete.file"),
694 Language.text("delete.messages.cannot_delete.file.description")+" \"" +
695 current.getFileName() + "\".");
696 return;
697 }
698
699 // remove code from the list
700 removeCode(current);

Callers 1

actionPerformedMethod · 0.80

Calls 15

ensureExistenceMethod · 0.95
isReadOnlyMethod · 0.95
showMessageMethod · 0.95
textMethod · 0.95
isUntitledMethod · 0.95
interpolateMethod · 0.95
getNameMethod · 0.95
deleteFileMethod · 0.95
removeCodeMethod · 0.95
setCurrentCodeMethod · 0.95
rebuildSketchbookMethod · 0.80
getBaseMethod · 0.80

Tested by

no test coverage detected