Skip to content

Commit 43fa225

Browse files
committed
Dialog and preference about renaming .pde to .ino files on save.
The new extension (.ino) is used by default for all new sketches (whether created with new or save as). It's possible, however, to control the behavior on save. The first time you save a sketch with a .pde file, you're prompted to rename it or cancel the save. There's a preference that allow selecting whether or not .pde files are renamed on save. http://code.google.com/p/arduino/issues/detail?id=644
1 parent a398aaf commit 43fa225

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

app/src/processing/app/Preferences.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public class Preferences {
121121
JTextField memoryField;
122122
JCheckBox checkUpdatesBox;
123123
JTextField fontSizeField;
124+
JCheckBox updateExtensionBox;
124125
JCheckBox autoAssociateBox;
125126

126127

@@ -325,7 +326,15 @@ public void actionPerformed(ActionEvent e) {
325326
checkUpdatesBox.setBounds(left, top, d.width + 10, d.height);
326327
right = Math.max(right, left + d.width);
327328
top += d.height + GUI_BETWEEN;
328-
329+
330+
// [ ] Update sketch files to new extension on save (.pde -> .ino)
331+
332+
updateExtensionBox = new JCheckBox("Update sketch files to new extension on save (.pde -> .ino)");
333+
pain.add(updateExtensionBox);
334+
d = updateExtensionBox.getPreferredSize();
335+
updateExtensionBox.setBounds(left, top, d.width + 10, d.height);
336+
right = Math.max(right, left + d.width);
337+
top += d.height + GUI_BETWEEN;
329338

330339
// [ ] Automatically associate .pde files with Processing
331340

@@ -526,6 +535,8 @@ protected void applyFrame() {
526535
setBoolean("platform.auto_file_type_associations",
527536
autoAssociateBox.isSelected());
528537
}
538+
539+
setBoolean("editor.update_extension", updateExtensionBox.isSelected());
529540

530541
editor.applyPreferences();
531542
}
@@ -558,6 +569,9 @@ protected void showFrame(Editor editor) {
558569
autoAssociateBox.
559570
setSelected(getBoolean("platform.auto_file_type_associations"));
560571
}
572+
573+
updateExtensionBox.setSelected(get("editor.update_extension") == null ||
574+
getBoolean("editor.update_extension"));
561575

562576
dialog.setVisible(true);
563577
}

app/src/processing/app/Sketch.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,33 @@ public boolean accept(File dir, String name) {
718718
});
719719

720720
if (pdeFiles != null && pdeFiles.length > 0) {
721-
// Do rename of all .pde files to new .ino extension
722-
for (File pdeFile : pdeFiles)
723-
renameCodeToInoExtension(pdeFile);
721+
if (Preferences.get("editor.update_extension") == null) {
722+
Object[] options = { "OK", "Cancel" };
723+
int result = JOptionPane.showOptionDialog(editor,
724+
"In Arduino 1.0, the default file extension has changed\n" +
725+
"from .pde to .ino. New sketches (including those created\n" +
726+
"by \"Save-As\" will use the new extension. The extension\n" +
727+
"of existing sketches will be updated on save, but you can\n" +
728+
"disable this in the Preferences dialog.\n" +
729+
"\n" +
730+
"Save sketch and update its extension?",
731+
".pde -> .ino",
732+
JOptionPane.OK_CANCEL_OPTION,
733+
JOptionPane.QUESTION_MESSAGE,
734+
null,
735+
options,
736+
options[0]);
737+
738+
if (result != JOptionPane.OK_OPTION) return false; // save cancelled
739+
740+
Preferences.setBoolean("editor.update_extension", true);
741+
}
742+
743+
if (Preferences.getBoolean("editor.update_extension")) {
744+
// Do rename of all .pde files to new .ino extension
745+
for (File pdeFile : pdeFiles)
746+
renameCodeToInoExtension(pdeFile);
747+
}
724748
}
725749
}
726750

0 commit comments

Comments
 (0)