Skip to content

Commit 0363702

Browse files
author
Federico Fissore
committed
When exporting compiled binary of an example (readonly) sketch, users are forced to save it into their sketchbook. Fixes #3127
1 parent 9166828 commit 0363702

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

app/src/processing/app/Editor.java

+27-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import cc.arduino.packages.MonitorFactory;
2626

2727
import cc.arduino.view.StubMenuListener;
28+
import com.google.common.base.Predicate;
2829
import com.jcraft.jsch.JSchException;
2930
import jssc.SerialPortException;
3031
import processing.app.debug.*;
@@ -68,6 +69,25 @@
6869
@SuppressWarnings("serial")
6970
public class Editor extends JFrame implements RunnerListener {
7071

72+
private static class ShouldSaveIfModified implements Predicate<Sketch> {
73+
74+
@Override
75+
public boolean apply(Sketch sketch) {
76+
if (PreferencesData.getBoolean("editor.save_on_verify")) {
77+
return sketch.isModified() && !sketch.isReadOnly();
78+
}
79+
return false;
80+
}
81+
}
82+
83+
private static class ShouldSaveReadOnly implements Predicate<Sketch> {
84+
85+
@Override
86+
public boolean apply(Sketch sketch) {
87+
return sketch.isReadOnly();
88+
}
89+
}
90+
7191
private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList(new String[]{"serial", "network"});
7292
private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(new String[]{_("Serial ports"), _("Network ports")});
7393

@@ -690,7 +710,7 @@ public void actionPerformed(ActionEvent e) {
690710
item = newJMenuItemAlt(_("Export compiled Binary"), 'S');
691711
item.addActionListener(new ActionListener() {
692712
public void actionPerformed(ActionEvent e) {
693-
handleRun(false, Editor.this.presentAndSaveHandler, Editor.this.runAndSaveHandler);
713+
handleRun(false, new ShouldSaveReadOnly(), Editor.this.presentAndSaveHandler, Editor.this.runAndSaveHandler);
694714
}
695715
});
696716
sketchMenu.add(item);
@@ -2005,11 +2025,13 @@ protected void handleFindReference() {
20052025
* @param nonVerboseHandler
20062026
*/
20072027
public void handleRun(final boolean verbose, Runnable verboseHandler, Runnable nonVerboseHandler) {
2028+
handleRun(verbose, new ShouldSaveIfModified(), verboseHandler, nonVerboseHandler);
2029+
}
2030+
2031+
public void handleRun(final boolean verbose, Predicate<Sketch> shouldSavePredicate, Runnable verboseHandler, Runnable nonVerboseHandler) {
20082032
internalCloseRunner();
2009-
if (PreferencesData.getBoolean("editor.save_on_verify")) {
2010-
if (sketch.isModified() && !sketch.isReadOnly()) {
2011-
handleSave(true);
2012-
}
2033+
if (shouldSavePredicate.apply(sketch)) {
2034+
handleSave(true);
20132035
}
20142036
running = true;
20152037
toolbar.activate(EditorToolbar.RUN);

0 commit comments

Comments
 (0)