MCPcopy
hub / github.com/arduino/Arduino / saveAs

Method saveAs

app/src/processing/app/SketchController.java:367–447  ·  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

365 * because they can cause trouble.
366 */
367 protected boolean saveAs() throws IOException {
368 // get new name for folder
369 FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
370 if (isReadOnly() || isUntitled()) {
371 // default to the sketchbook folder
372 fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
373 } else {
374 // default to the parent folder of where this was
375 // on macs a .getParentFile() method is required
376
377 fd.setDirectory(sketch.getFolder().getParentFile().getAbsolutePath());
378 }
379 String oldName = sketch.getName();
380 fd.setFile(oldName);
381
382 fd.setVisible(true);
383 String newParentDir = fd.getDirectory();
384 String newName = fd.getFile();
385
386 // user canceled selection
387 if (newName == null) return false;
388 newName = SketchController.checkName(newName);
389
390 File newFolder;
391 // User may want to overwrite a .ino
392 // check if the parent folder name ends with the sketch name
393 if (newName.endsWith(".ino") && newParentDir.endsWith(newName.substring(0, newName.lastIndexOf('.'))+ File.separator)) {
394 newFolder = new File(newParentDir);
395 } else {
396 newFolder = new File(newParentDir, newName);
397 }
398
399 // check if the paths are identical
400 if (newFolder.equals(sketch.getFolder())) {
401 // just use "save" here instead, because the user will have received a
402 // message (from the operating system) about "do you want to replace?"
403 return save();
404 }
405
406 // check to see if the user is trying to save this sketch inside itself
407 try {
408 String newPath = newFolder.getCanonicalPath() + File.separator;
409 String oldPath = sketch.getFolder().getCanonicalPath() + File.separator;
410
411 if (newPath.indexOf(oldPath) == 0) {
412 Base.showWarning(tr("How very Borges of you"),
413 tr("You cannot save the sketch into a folder\n" +
414 "inside itself. This would go on forever."), null);
415 return false;
416 }
417 } catch (IOException e) {
418 //ignore
419 }
420
421 // if the new folder already exists, then need to remove
422 // its contents before copying everything over
423 // (user will have already been warned)
424 if (newFolder.exists()) {

Callers 2

saveMethod · 0.95
handleSaveAsMethod · 0.45

Calls 15

isReadOnlyMethod · 0.95
isUntitledMethod · 0.95
getSketchbookFolderMethod · 0.95
checkNameMethod · 0.95
saveMethod · 0.95
showWarningMethod · 0.95
recursiveDeleteMethod · 0.95
setUntitledMethod · 0.95
trMethod · 0.80
setVisibleMethod · 0.80
rebuildMethod · 0.80

Tested by

no test coverage detected