mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
When exporting compiled binary of an example (readonly) sketch, users are forced to save it into their sketchbook. Fixes #3127
This commit is contained in:
@ -25,6 +25,7 @@ package processing.app;
|
|||||||
import cc.arduino.packages.MonitorFactory;
|
import cc.arduino.packages.MonitorFactory;
|
||||||
|
|
||||||
import cc.arduino.view.StubMenuListener;
|
import cc.arduino.view.StubMenuListener;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.jcraft.jsch.JSchException;
|
import com.jcraft.jsch.JSchException;
|
||||||
import jssc.SerialPortException;
|
import jssc.SerialPortException;
|
||||||
import processing.app.debug.*;
|
import processing.app.debug.*;
|
||||||
@ -68,6 +69,25 @@ import cc.arduino.packages.uploaders.SerialUploader;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class Editor extends JFrame implements RunnerListener {
|
public class Editor extends JFrame implements RunnerListener {
|
||||||
|
|
||||||
|
private static class ShouldSaveIfModified implements Predicate<Sketch> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Sketch sketch) {
|
||||||
|
if (PreferencesData.getBoolean("editor.save_on_verify")) {
|
||||||
|
return sketch.isModified() && !sketch.isReadOnly();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ShouldSaveReadOnly implements Predicate<Sketch> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Sketch sketch) {
|
||||||
|
return sketch.isReadOnly();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList(new String[]{"serial", "network"});
|
private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList(new String[]{"serial", "network"});
|
||||||
private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(new String[]{_("Serial ports"), _("Network ports")});
|
private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(new String[]{_("Serial ports"), _("Network ports")});
|
||||||
|
|
||||||
@ -690,7 +710,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
item = newJMenuItemAlt(_("Export compiled Binary"), 'S');
|
item = newJMenuItemAlt(_("Export compiled Binary"), 'S');
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
handleRun(false, Editor.this.presentAndSaveHandler, Editor.this.runAndSaveHandler);
|
handleRun(false, new ShouldSaveReadOnly(), Editor.this.presentAndSaveHandler, Editor.this.runAndSaveHandler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sketchMenu.add(item);
|
sketchMenu.add(item);
|
||||||
@ -2005,11 +2025,13 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
* @param nonVerboseHandler
|
* @param nonVerboseHandler
|
||||||
*/
|
*/
|
||||||
public void handleRun(final boolean verbose, Runnable verboseHandler, Runnable nonVerboseHandler) {
|
public void handleRun(final boolean verbose, Runnable verboseHandler, Runnable nonVerboseHandler) {
|
||||||
|
handleRun(verbose, new ShouldSaveIfModified(), verboseHandler, nonVerboseHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleRun(final boolean verbose, Predicate<Sketch> shouldSavePredicate, Runnable verboseHandler, Runnable nonVerboseHandler) {
|
||||||
internalCloseRunner();
|
internalCloseRunner();
|
||||||
if (PreferencesData.getBoolean("editor.save_on_verify")) {
|
if (shouldSavePredicate.apply(sketch)) {
|
||||||
if (sketch.isModified() && !sketch.isReadOnly()) {
|
handleSave(true);
|
||||||
handleSave(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
running = true;
|
running = true;
|
||||||
toolbar.activate(EditorToolbar.RUN);
|
toolbar.activate(EditorToolbar.RUN);
|
||||||
|
Reference in New Issue
Block a user