MCPcopy Index your code
hub / github.com/processing/processing / saveAs

Method saveAs

app/src/processing/app/Sketch.java:836–1008  ·  view source on GitHub ↗

Handles 'Save As' for a sketch. This basically just duplicates the current sketch folder to a new location, and then calls 'Save'. (needs to take the current state of the open files and save them to the new folder.. but not save over the old versions for the old sketch..) Also removes the pr

()

Source from the content-addressed store, hash-verified

834 * because they can cause trouble.
835 */
836 public boolean saveAs() throws IOException {
837 String newParentDir = null;
838 String newName = null;
839 String oldName = folder.getName();
840
841 // TODO rewrite this to use shared version from PApplet (But because that
842 // specifies a callback function, this needs to wait until the refactoring)
843 final String PROMPT = Language.text("save");
844 if (Preferences.getBoolean("chooser.files.native")) {
845 // get new name for folder
846 FileDialog fd = new FileDialog(editor, PROMPT, FileDialog.SAVE);
847 if (isReadOnly() || isUntitled()) {
848 // default to the sketchbook folder
849 fd.setDirectory(Preferences.getSketchbookPath());
850 } else {
851 // default to the parent folder of where this was
852 fd.setDirectory(folder.getParent());
853 }
854 String oldFolderName = folder.getName();
855 fd.setFile(oldFolderName);
856 fd.setVisible(true);
857 newParentDir = fd.getDirectory();
858 newName = fd.getFile();
859 } else {
860 JFileChooser fc = new JFileChooser();
861 fc.setDialogTitle(PROMPT);
862 if (isReadOnly() || isUntitled()) {
863 // default to the sketchbook folder
864 fc.setCurrentDirectory(new File(Preferences.getSketchbookPath()));
865 } else {
866 // default to the parent folder of where this was
867 fc.setCurrentDirectory(folder.getParentFile());
868 }
869 // can't do this, will try to save into itself by default
870 //fc.setSelectedFile(folder);
871 int result = fc.showSaveDialog(editor);
872 if (result == JFileChooser.APPROVE_OPTION) {
873 File selection = fc.getSelectedFile();
874 newParentDir = selection.getParent();
875 newName = selection.getName();
876 }
877 }
878
879 // user canceled selection
880 if (newName == null) return false;
881
882 // check on the sanity of the name
883 String sanitaryName = Sketch.checkName(newName);
884 File newFolder = new File(newParentDir, sanitaryName);
885 if (!sanitaryName.equals(newName) && newFolder.exists()) {
886 Messages.showMessage(Language.text("save_file.messages.sketch_exists"),
887 Language.interpolate("save_file.messages.sketch_exists.description",
888 sanitaryName));
889 return false;
890 }
891 newName = sanitaryName;
892
893// String newPath = newFolder.getAbsolutePath();

Callers 2

saveMethod · 0.95
handleSaveAsMethod · 0.45

Calls 15

textMethod · 0.95
getBooleanMethod · 0.95
isReadOnlyMethod · 0.95
isUntitledMethod · 0.95
getSketchbookPathMethod · 0.95
checkNameMethod · 0.95
showMessageMethod · 0.95
interpolateMethod · 0.95
saveMethod · 0.95
showWarningMethod · 0.95
removeDirMethod · 0.95
updateSketchCodesMethod · 0.95

Tested by

no test coverage detected