Save all code in the current sketch.
()
| 300 | * Save all code in the current sketch. |
| 301 | */ |
| 302 | public boolean save() throws IOException { |
| 303 | // make sure the user didn't hide the sketch folder |
| 304 | ensureExistence(); |
| 305 | |
| 306 | if (isReadOnly()) { |
| 307 | Base.showMessage(tr("Sketch is read-only"), |
| 308 | tr("Some files are marked \"read-only\", so you'll\n" + |
| 309 | "need to re-save this sketch to another location.")); |
| 310 | return saveAs(); |
| 311 | } |
| 312 | |
| 313 | // rename .pde files to .ino |
| 314 | List<SketchFile> oldFiles = new ArrayList<>(); |
| 315 | for (SketchFile file : sketch.getFiles()) { |
| 316 | if (file.isExtension(Sketch.OLD_SKETCH_EXTENSIONS)) |
| 317 | oldFiles.add(file); |
| 318 | } |
| 319 | |
| 320 | if (oldFiles.size() > 0) { |
| 321 | if (PreferencesData.get("editor.update_extension") == null) { |
| 322 | Object[] options = {tr("OK"), tr("Cancel")}; |
| 323 | int result = JOptionPane.showOptionDialog(editor, |
| 324 | tr("In Arduino 1.0, the default file extension has changed\n" + |
| 325 | "from .pde to .ino. New sketches (including those created\n" + |
| 326 | "by \"Save-As\") will use the new extension. The extension\n" + |
| 327 | "of existing sketches will be updated on save, but you can\n" + |
| 328 | "disable this in the Preferences dialog.\n" + |
| 329 | "\n" + |
| 330 | "Save sketch and update its extension?"), |
| 331 | tr(".pde -> .ino"), |
| 332 | JOptionPane.OK_CANCEL_OPTION, |
| 333 | JOptionPane.QUESTION_MESSAGE, |
| 334 | null, |
| 335 | options, |
| 336 | options[0]); |
| 337 | |
| 338 | if (result != JOptionPane.OK_OPTION) return false; // save cancelled |
| 339 | |
| 340 | PreferencesData.setBoolean("editor.update_extension", true); |
| 341 | } |
| 342 | |
| 343 | if (PreferencesData.getBoolean("editor.update_extension")) { |
| 344 | // Do rename of all .pde files to new .ino extension |
| 345 | for (SketchFile file : oldFiles) { |
| 346 | File newName = FileUtils.replaceExtension(file.getFile(), Sketch.DEFAULT_SKETCH_EXTENSION); |
| 347 | file.renameTo(newName.getName()); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | sketch.save(); |
| 353 | return true; |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Handles 'Save As' for a sketch. |
no test coverage detected