|
25 | 25 | import cc.arduino.packages.MonitorFactory; |
26 | 26 |
|
27 | 27 | import cc.arduino.view.StubMenuListener; |
| 28 | +import com.google.common.base.Predicate; |
28 | 29 | import com.jcraft.jsch.JSchException; |
29 | 30 | import jssc.SerialPortException; |
30 | 31 | import processing.app.debug.*; |
|
68 | 69 | @SuppressWarnings("serial") |
69 | 70 | public class Editor extends JFrame implements RunnerListener { |
70 | 71 |
|
| 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 | + |
71 | 91 | private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList(new String[]{"serial", "network"}); |
72 | 92 | private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(new String[]{_("Serial ports"), _("Network ports")}); |
73 | 93 |
|
@@ -690,7 +710,7 @@ public void actionPerformed(ActionEvent e) { |
690 | 710 | item = newJMenuItemAlt(_("Export compiled Binary"), 'S'); |
691 | 711 | item.addActionListener(new ActionListener() { |
692 | 712 | 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); |
694 | 714 | } |
695 | 715 | }); |
696 | 716 | sketchMenu.add(item); |
@@ -2005,11 +2025,13 @@ protected void handleFindReference() { |
2005 | 2025 | * @param nonVerboseHandler |
2006 | 2026 | */ |
2007 | 2027 | 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) { |
2008 | 2032 | 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); |
2013 | 2035 | } |
2014 | 2036 | running = true; |
2015 | 2037 | toolbar.activate(EditorToolbar.RUN); |
|
0 commit comments