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

Method saveAs

app/src/processing/app/Sketch.java:843–1031  ·  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

841 * because they can cause trouble.
842 */
843 public boolean saveAs() throws IOException {
844 String newParentDir = null;
845 String newSketchName = null;
846
847 final String PROMPT = Language.text("save");
848
849 // https://github.com/processing/processing4/issues/77
850 boolean useNative = Preferences.getBoolean("chooser.files.native");
851 if (useNative) {
852 // get new name for folder
853 FileDialog fd = new FileDialog(editor, PROMPT, FileDialog.SAVE);
854 if (isReadOnly() || isUntitled()) {
855 // default to the sketchbook folder
856 fd.setDirectory(Preferences.getSketchbookPath());
857 } else {
858 // default to the parent folder of where this was
859 fd.setDirectory(folder.getParent());
860 }
861 String oldFolderName = folder.getName();
862 fd.setFile(oldFolderName);
863 fd.setVisible(true);
864 newParentDir = fd.getDirectory();
865 newSketchName = fd.getFile();
866 } else {
867 JFileChooser fc = new JFileChooser();
868 fc.setDialogTitle(PROMPT);
869 if (isReadOnly() || isUntitled()) {
870 // default to the sketchbook folder
871 fc.setCurrentDirectory(new File(Preferences.getSketchbookPath()));
872 } else {
873 // default to the parent folder of where this was
874 fc.setCurrentDirectory(folder.getParentFile());
875 }
876 // can't do this, will try to save into itself by default
877 //fc.setSelectedFile(folder);
878 int result = fc.showSaveDialog(editor);
879 if (result == JFileChooser.APPROVE_OPTION) {
880 File selection = fc.getSelectedFile();
881 newParentDir = selection.getParent();
882 newSketchName = selection.getName();
883 }
884 }
885
886 // user canceled selection
887 if (newSketchName == null) return false;
888
889 boolean sync = Preferences.getBoolean("editor.sync_folder_and_filename");
890 String newMainFileName = null; // only set with !sync
891 File newFolder;
892 if (sync) {
893 // before 4.0 beta 6
894 //String sanitaryName = Sketch.checkName(newSketchName);
895 String newMainName = sanitizeName(newSketchName);
896 newFolder = new File(newParentDir, newMainName);
897 if (!newMainName.equals(newSketchName) && newFolder.exists()) {
898 Messages.showMessage(Language.text("save_file.messages.sketch_exists"),
899 Language.interpolate("save_file.messages.sketch_exists.description",
900 newMainName));

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
sanitizeNameMethod · 0.95
showMessageMethod · 0.95
interpolateMethod · 0.95
saveMethod · 0.95
showWarningMethod · 0.95
deleteFileMethod · 0.95
updateSketchCodesMethod · 0.95

Tested by

no test coverage detected