@@ -113,7 +113,7 @@ public class Base {
113
113
Editor activeEditor ;
114
114
115
115
116
- static public void main (String args []) {
116
+ static public void main (String args []) throws Exception {
117
117
try {
118
118
File versionFile = getContentFile ("lib/version.txt" );
119
119
if (versionFile .exists ()) {
@@ -244,7 +244,7 @@ static protected void initRequirements() {
244
244
}
245
245
246
246
247
- public Base (String [] args ) {
247
+ public Base (String [] args ) throws Exception {
248
248
platform .init (this );
249
249
250
250
// Get the sketchbook path, and make sure it's set properly
@@ -280,11 +280,28 @@ public Base(String[] args) {
280
280
// Setup board-dependent variables.
281
281
onBoardOrPortChange ();
282
282
283
- // Check if there were previously opened sketches to be restored
284
- boolean opened = restoreSketches ();
285
-
283
+ boolean opened = false ;
284
+ boolean doUpload = false ;
285
+ String selectBoard = null ;
286
+ String selectPort = null ;
286
287
// Check if any files were passed in on the command line
287
288
for (int i = 0 ; i < args .length ; i ++) {
289
+ if (args [i ].equals ("--upload" )) {
290
+ doUpload = true ;
291
+ continue ;
292
+ }
293
+ if (args [i ].equals ("--board" )) {
294
+ i ++;
295
+ if (i < args .length )
296
+ selectBoard = args [i ];
297
+ continue ;
298
+ }
299
+ if (args [i ].equals ("--port" )) {
300
+ i ++;
301
+ if (i < args .length )
302
+ selectPort = args [i ];
303
+ continue ;
304
+ }
288
305
String path = args [i ];
289
306
// Fix a problem with systems that use a non-ASCII languages. Paths are
290
307
// being passed in with 8.3 syntax, which makes the sketch loader code
@@ -303,6 +320,23 @@ public Base(String[] args) {
303
320
}
304
321
}
305
322
323
+ if (doUpload ) {
324
+ if (!opened )
325
+ throw new Exception (_ ("Can't open source sketch!" ));
326
+ Thread .sleep (2000 );
327
+ Editor editor = editors .get (0 );
328
+ if (selectPort != null )
329
+ editor .selectSerialPort (selectPort );
330
+ if (selectBoard != null )
331
+ selectBoard (selectBoard , editor );
332
+ editor .exportHandler .run ();
333
+ System .exit (0 );
334
+ }
335
+
336
+ // Check if there were previously opened sketches to be restored
337
+ if (restoreSketches ())
338
+ opened = true ;
339
+
306
340
// Create a new empty window (will be replaced with any files to be opened)
307
341
if (!opened ) {
308
342
handleNew ();
@@ -1162,36 +1196,39 @@ public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) {
1162
1196
// For every platform cycle through all boards
1163
1197
for (final String boardID : targetPlatform .getBoards ().keySet ()) {
1164
1198
1165
- PreferencesMap boardAttributes = boards .get (boardID );
1166
-
1167
- AbstractAction action = new AbstractAction (boardAttributes .get ("name" )) {
1168
-
1169
- @ Override
1170
- public void actionPerformed (ActionEvent e ) {
1171
- Preferences .set ("target_package" , (String ) getValue ("package" ));
1172
- Preferences .set ("target_platform" , (String ) getValue ("platform" ));
1173
- Preferences .set ("board" , (String ) getValue ("board" ));
1174
-
1175
- filterVisibilityOfSubsequentBoardMenus ((String ) getValue ("board" ), 1 , e );
1176
-
1177
- onBoardOrPortChange ();
1178
- Sketch .buildSettingChanged ();
1179
- rebuildImportMenu (Editor .importMenu , editor );
1180
- rebuildExamplesMenu (Editor .examplesMenu );
1199
+ // PreferencesMap boardAttributes = boards.get(boardID);
1200
+ // AbstractAction action = new AbstractAction(boardAttributes.get("name")) {
1201
+ //
1202
+ // @Override
1203
+ // public void actionPerformed(ActionEvent e) {
1204
+ // Preferences.set("target_package", (String) getValue("package"));
1205
+ // Preferences.set("target_platform", (String) getValue("platform"));
1206
+ // Preferences.set("board", (String) getValue("board"));
1207
+ //
1208
+ // filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), 1);
1209
+ //
1210
+ // onBoardOrPortChange();
1211
+ // Sketch.buildSettingChanged();
1212
+ // rebuildImportMenu(Editor.importMenu, editor);
1213
+ // rebuildExamplesMenu(Editor.examplesMenu);
1214
+ //=======
1215
+ // Setup a menu item for the current board
1216
+ String boardName = boards .get (boardID ).get ("name" );
1217
+ @ SuppressWarnings ("serial" )
1218
+ AbstractAction action = new AbstractAction (boardName ) {
1219
+ public void actionPerformed (ActionEvent actionevent ) {
1220
+ selectBoard ((String ) getValue ("b" ), editor );
1181
1221
}
1182
1222
1183
1223
};
1184
- action .putValue ("properties" , boardAttributes );
1185
- action .putValue ("board" , boardID );
1186
- action .putValue ("package" , packageName );
1187
- action .putValue ("platform" , platformName );
1224
+ action .putValue ("b" , packageName + ":" + platformName + ":" + boardID );
1188
1225
1189
1226
JRadioButtonMenuItem item = new JRadioButtonMenuItem (action );
1190
1227
boardsMenu .add (item );
1191
1228
boardsButtonGroup .add (item );
1192
1229
1193
- if (selBoard .equals (action . getValue ( "board" )) && selPackage .equals (action . getValue ( "package" ) )
1194
- && selPlatform .equals (action . getValue ( "platform" ) )) {
1230
+ if (selBoard .equals (boardID ) && selPackage .equals (packageName )
1231
+ && selPlatform .equals (platformName )) {
1195
1232
menuItemsToClickAfterStartup .add (item );
1196
1233
}
1197
1234
@@ -1214,7 +1251,7 @@ public void actionPerformed(ActionEvent e) {
1214
1251
Preferences .set ("board" , (String ) getValue ("board" ));
1215
1252
Preferences .set ("custom_" + customMenuID , boardID + "_" + (String ) getValue ("custom_menu_option" ));
1216
1253
1217
- filterVisibilityOfSubsequentBoardMenus ((String ) getValue ("board" ), currentIndex , e );
1254
+ filterVisibilityOfSubsequentBoardMenus ((String ) getValue ("board" ), currentIndex );
1218
1255
1219
1256
onBoardOrPortChange ();
1220
1257
Sketch .buildSettingChanged ();
@@ -1258,7 +1295,7 @@ public void actionPerformed(ActionEvent e) {
1258
1295
}
1259
1296
}
1260
1297
1261
- private static void filterVisibilityOfSubsequentBoardMenus (String boardID , int fromIndex , ActionEvent originatingEvent ) {
1298
+ private static void filterVisibilityOfSubsequentBoardMenus (String boardID , int fromIndex ) {
1262
1299
for (int i = fromIndex ; i < Editor .boardsMenus .size (); i ++) {
1263
1300
JMenu menu = Editor .boardsMenus .get (i );
1264
1301
for (int m = 0 ; m < menu .getItemCount (); m ++) {
@@ -1271,7 +1308,7 @@ private static void filterVisibilityOfSubsequentBoardMenus(String boardID, int f
1271
1308
JMenuItem visibleSelectedOrFirstMenuItem = selectVisibleSelectedOrFirstMenuItem (menu );
1272
1309
if (!visibleSelectedOrFirstMenuItem .isSelected ()) {
1273
1310
visibleSelectedOrFirstMenuItem .setSelected (true );
1274
- visibleSelectedOrFirstMenuItem .getAction ().actionPerformed (originatingEvent );
1311
+ visibleSelectedOrFirstMenuItem .getAction ().actionPerformed (null );
1275
1312
}
1276
1313
}
1277
1314
}
@@ -1329,7 +1366,23 @@ private static JMenuItem selectFirstEnabledMenuItem(JMenu menu) {
1329
1366
}
1330
1367
throw new IllegalStateException ("Menu has no enabled items" );
1331
1368
}
1332
-
1369
+
1370
+
1371
+ private void selectBoard (String selectBoard , Editor editor ) {
1372
+ String [] split = selectBoard .split (":" );
1373
+ Preferences .set ("target_package" , split [0 ]);
1374
+ Preferences .set ("target_platform" , split [1 ]);
1375
+ Preferences .set ("board" , split [2 ]);
1376
+
1377
+ filterVisibilityOfSubsequentBoardMenus (split [2 ], 1 );
1378
+
1379
+ onBoardOrPortChange ();
1380
+ Sketch .buildSettingChanged ();
1381
+ rebuildImportMenu (Editor .importMenu , editor );
1382
+ rebuildExamplesMenu (Editor .examplesMenu );
1383
+ }
1384
+
1385
+
1333
1386
public void rebuildProgrammerMenu (JMenu menu ) {
1334
1387
menu .removeAll ();
1335
1388
ButtonGroup group = new ButtonGroup ();
0 commit comments