1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

update Sketch menu, add Save hex option

* Moving Upload options from "File" menu to "Sketch" menu as those
     are sketch actions more than file actions.

Signed-off-by: Arnav Gupta <championswimmer@gmail.com>
This commit is contained in:
Arnav Gupta
2015-01-23 08:30:46 +05:30
committed by Federico Fissore
parent 11327bb3a6
commit 78936541b7
6 changed files with 154 additions and 41 deletions

View File

@ -152,6 +152,8 @@ public class Editor extends JFrame implements RunnerListener {
Runnable runHandler;
Runnable presentHandler;
Runnable runAndSaveHandler;
Runnable presentAndSaveHandler;
Runnable stopHandler;
Runnable exportHandler;
Runnable exportAppHandler;
@ -563,22 +565,6 @@ public class Editor extends JFrame implements RunnerListener {
});
fileMenu.add(saveAsMenuItem);
item = newJMenuItem(_("Upload"), 'U');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExport(false);
}
});
fileMenu.add(item);
item = newJMenuItemShift(_("Upload Using Programmer"), 'U');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExport(true);
}
});
fileMenu.add(item);
fileMenu.addSeparator();
item = newJMenuItemShift(_("Page Setup"), 'P');
@ -637,14 +623,31 @@ public class Editor extends JFrame implements RunnerListener {
}
});
sketchMenu.add(item);
item = newJMenuItem(_("Upload"), 'U');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExport(false);
}
});
sketchMenu.add(item);
// item = newJMenuItemShift("Verify / Compile (verbose)", 'R');
// item.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// handleRun(true);
// }
// });
// sketchMenu.add(item);
item = newJMenuItemShift(_("Upload Using Programmer"), 'U');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExport(true);
}
});
sketchMenu.add(item);
item = newJMenuItemAlt("Export compiled Binary", 'S');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleRunAndSave(true);
}
});
sketchMenu.add(item);
// item = new JMenuItem("Stop");
// item.addActionListener(new ActionListener() {
@ -1508,11 +1511,17 @@ public class Editor extends JFrame implements RunnerListener {
// abstract from the editor in this fashion.
public void setHandlers(Runnable runHandler, Runnable presentHandler,
public void setHandlers(Runnable runHandler,
Runnable presentHandler,
Runnable runAndSaveHandler,
Runnable presentAndSaveHandler,
Runnable stopHandler,
Runnable exportHandler, Runnable exportAppHandler) {
Runnable exportHandler,
Runnable exportAppHandler) {
this.runHandler = runHandler;
this.presentHandler = presentHandler;
this.runAndSaveHandler = runAndSaveHandler;
this.presentAndSaveHandler = presentAndSaveHandler;
this.stopHandler = stopHandler;
this.exportHandler = exportHandler;
this.exportAppHandler = exportAppHandler;
@ -1522,6 +1531,8 @@ public class Editor extends JFrame implements RunnerListener {
public void resetHandlers() {
runHandler = new BuildHandler();
presentHandler = new BuildHandler(true);
runAndSaveHandler = new BuildAndSaveHandler();
presentAndSaveHandler = new BuildAndSaveHandler(true);
stopHandler = new DefaultStopHandler();
exportHandler = new DefaultExportHandler();
exportAppHandler = new DefaultExportAppHandler();
@ -2012,6 +2023,29 @@ public class Editor extends JFrame implements RunnerListener {
// placed on the event thread and causes a hang--bad idea all around.
new Thread(verbose ? presentHandler : runHandler).start();
}
/**
* Implements Sketch &rarr; Run and Save.
* @param verbose Set true to run with verbose output.
*/
public void handleRunAndSave(final boolean verbose) {
internalCloseRunner();
running = true;
toolbar.activate(EditorToolbar.RUN);
status.progress(_("Compiling sketch..."));
// do this to advance/clear the terminal window / dos prompt / etc
for (int i = 0; i < 10; i++) System.out.println();
// clear the console on each run, unless the user doesn't want to
if (Preferences.getBoolean("console.auto_clear")) {
console.clear();
}
// Cannot use invokeLater() here, otherwise it gets
// placed on the event thread and causes a hang--bad idea all around.
new Thread(verbose ? presentAndSaveHandler : runAndSaveHandler).start();
}
class BuildHandler implements Runnable {
@ -2029,7 +2063,7 @@ public class Editor extends JFrame implements RunnerListener {
public void run() {
try {
sketch.prepare();
sketch.build(verbose);
sketch.build(verbose, false);
statusNotice(_("Done compiling."));
} catch (PreferencesMapException e) {
statusError(I18n.format(
@ -2044,6 +2078,38 @@ public class Editor extends JFrame implements RunnerListener {
toolbar.deactivate(EditorToolbar.RUN);
}
}
class BuildAndSaveHandler implements Runnable {
private final boolean verbose;
public BuildAndSaveHandler() {
this(false);
}
public BuildAndSaveHandler(boolean verbose) {
this.verbose = verbose;
}
@Override
public void run() {
try {
sketch.prepare();
sketch.build(verbose, true);
statusNotice(_("Done compiling."));
} catch (PreferencesMapException e) {
statusError(I18n.format(
_("Error while compiling: missing '{0}' configuration parameter"),
e.getMessage()));
} catch (Exception e) {
status.unprogress();
statusError(e);
}
status.unprogress();
toolbar.deactivate(EditorToolbar.RUN);
}
}
class DefaultStopHandler implements Runnable {
public void run() {

View File

@ -1133,8 +1133,8 @@ public class Sketch {
* @return null if compilation failed, main class name if not
* @throws RunnerException
*/
public String build(boolean verbose) throws RunnerException, PreferencesMapException {
return build(tempBuildFolder.getAbsolutePath(), verbose);
public String build(boolean verbose, boolean save) throws RunnerException, PreferencesMapException {
return build(tempBuildFolder.getAbsolutePath(), verbose, save);
}
/**
@ -1146,7 +1146,7 @@ public class Sketch {
*
* @return null if compilation failed, main class name if not
*/
public String build(String buildPath, boolean verbose) throws RunnerException, PreferencesMapException {
public String build(String buildPath, boolean verbose, boolean save) throws RunnerException, PreferencesMapException {
// run the preprocessor
editor.status.progressUpdate(20);
@ -1159,7 +1159,7 @@ public class Sketch {
}
};
return Compiler.build(data, buildPath, tempBuildFolder, pl, verbose);
return Compiler.build(data, buildPath, tempBuildFolder, pl, verbose, save);
}
protected boolean exportApplet(boolean usingProgrammer) throws Exception {
@ -1177,7 +1177,7 @@ public class Sketch {
// build the sketch
editor.status.progressNotice(_("Compiling sketch..."));
String foundName = build(appletPath, false);
String foundName = build(appletPath, false, false);
// (already reported) error during export, exit this function
if (foundName == null) return false;