@@ -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 ();
@@ -1124,7 +1158,7 @@ public void onBoardOrPortChange() {
1124
1158
}
1125
1159
1126
1160
public void rebuildBoardsMenu (JMenu toolsMenu , final Editor editor ) {
1127
- JMenu boardsMenu = makeOrGetBoardMenu (toolsMenu , "Board" );
1161
+ JMenu boardsMenu = makeOrGetBoardMenu (toolsMenu , _ ( "Board" ) );
1128
1162
1129
1163
String selPackage = Preferences .get ("target_package" );
1130
1164
String selPlatform = Preferences .get ("target_platform" );
@@ -1161,37 +1195,22 @@ public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) {
1161
1195
1162
1196
// For every platform cycle through all boards
1163
1197
for (final String boardID : targetPlatform .getBoards ().keySet ()) {
1164
-
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 );
1198
+ // Setup a menu item for the current board
1199
+ String boardName = boards .get (boardID ).get ("name" );
1200
+ @ SuppressWarnings ("serial" )
1201
+ Action action = new AbstractAction (boardName ) {
1202
+ public void actionPerformed (ActionEvent actionevent ) {
1203
+ selectBoard ((String ) getValue ("b" ), editor );
1181
1204
}
1182
-
1183
1205
};
1184
- action .putValue ("properties" , boardAttributes );
1185
- action .putValue ("board" , boardID );
1186
- action .putValue ("package" , packageName );
1187
- action .putValue ("platform" , platformName );
1206
+ action .putValue ("b" , packageName + ":" + platformName + ":" + boardID );
1188
1207
1189
1208
JRadioButtonMenuItem item = new JRadioButtonMenuItem (action );
1190
1209
boardsMenu .add (item );
1191
1210
boardsButtonGroup .add (item );
1192
1211
1193
- if (selBoard .equals (action . getValue ( "board" )) && selPackage .equals (action . getValue ( "package" ) )
1194
- && selPlatform .equals (action . getValue ( "platform" ) )) {
1212
+ if (selBoard .equals (boardID ) && selPackage .equals (packageName )
1213
+ && selPlatform .equals (platformName )) {
1195
1214
menuItemsToClickAfterStartup .add (item );
1196
1215
}
1197
1216
@@ -1205,34 +1224,33 @@ public void actionPerformed(ActionEvent e) {
1205
1224
MapWithSubkeys boardCustomMenu = customMenu .get (boardID );
1206
1225
final int currentIndex = i + 1 + 1 ; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one
1207
1226
for (final String customMenuOption : boardCustomMenu .getKeys ()) {
1208
- action = new AbstractAction ( _ ( boardCustomMenu . getValueOf ( customMenuOption ))) {
1209
-
1227
+ @ SuppressWarnings ( "serial" )
1228
+ Action subAction = new AbstractAction ( _ ( boardCustomMenu . getValueOf ( customMenuOption ))) {
1210
1229
@ Override
1211
1230
public void actionPerformed (ActionEvent e ) {
1212
1231
Preferences .set ("target_package" , (String ) getValue ("package" ));
1213
1232
Preferences .set ("target_platform" , (String ) getValue ("platform" ));
1214
1233
Preferences .set ("board" , (String ) getValue ("board" ));
1215
1234
Preferences .set ("custom_" + customMenuID , boardID + "_" + (String ) getValue ("custom_menu_option" ));
1216
1235
1217
- filterVisibilityOfSubsequentBoardMenus ((String ) getValue ("board" ), currentIndex , e );
1236
+ filterVisibilityOfSubsequentBoardMenus ((String ) getValue ("board" ), currentIndex );
1218
1237
1219
1238
onBoardOrPortChange ();
1220
1239
Sketch .buildSettingChanged ();
1221
1240
rebuildImportMenu (Editor .importMenu , editor );
1222
1241
rebuildExamplesMenu (Editor .examplesMenu );
1223
1242
}
1224
1243
};
1225
- action .putValue ("properties" , boardCustomMenu .getValues ());
1226
- action .putValue ("board" , boardID );
1227
- action .putValue ("custom_menu_option" , customMenuOption );
1228
- action .putValue ("package" , packageName );
1229
- action .putValue ("platform" , platformName );
1244
+ subAction .putValue ("board" , boardID );
1245
+ subAction .putValue ("custom_menu_option" , customMenuOption );
1246
+ subAction .putValue ("package" , packageName );
1247
+ subAction .putValue ("platform" , platformName );
1230
1248
1231
1249
if (!buttonGroupsMap .containsKey (customMenuID )) {
1232
1250
buttonGroupsMap .put (customMenuID , new ButtonGroup ());
1233
1251
}
1234
1252
1235
- item = new JRadioButtonMenuItem (action );
1253
+ item = new JRadioButtonMenuItem (subAction );
1236
1254
menu .add (item );
1237
1255
buttonGroupsMap .get (customMenuID ).add (item );
1238
1256
@@ -1258,7 +1276,7 @@ public void actionPerformed(ActionEvent e) {
1258
1276
}
1259
1277
}
1260
1278
1261
- private static void filterVisibilityOfSubsequentBoardMenus (String boardID , int fromIndex , ActionEvent originatingEvent ) {
1279
+ private static void filterVisibilityOfSubsequentBoardMenus (String boardID , int fromIndex ) {
1262
1280
for (int i = fromIndex ; i < Editor .boardsMenus .size (); i ++) {
1263
1281
JMenu menu = Editor .boardsMenus .get (i );
1264
1282
for (int m = 0 ; m < menu .getItemCount (); m ++) {
@@ -1271,7 +1289,7 @@ private static void filterVisibilityOfSubsequentBoardMenus(String boardID, int f
1271
1289
JMenuItem visibleSelectedOrFirstMenuItem = selectVisibleSelectedOrFirstMenuItem (menu );
1272
1290
if (!visibleSelectedOrFirstMenuItem .isSelected ()) {
1273
1291
visibleSelectedOrFirstMenuItem .setSelected (true );
1274
- visibleSelectedOrFirstMenuItem .getAction ().actionPerformed (originatingEvent );
1292
+ visibleSelectedOrFirstMenuItem .getAction ().actionPerformed (null );
1275
1293
}
1276
1294
}
1277
1295
}
@@ -1287,13 +1305,12 @@ private static boolean ifThereAreVisibleItemsOn(JMenu menu) {
1287
1305
}
1288
1306
1289
1307
private JMenu makeOrGetBoardMenu (JMenu toolsMenu , String label ) {
1290
- String i18nLabel = _ (label );
1291
1308
for (JMenu menu : Editor .boardsMenus ) {
1292
- if (i18nLabel .equals (menu .getText ())) {
1309
+ if (label .equals (menu .getText ())) {
1293
1310
return menu ;
1294
1311
}
1295
1312
}
1296
- JMenu menu = new JMenu (i18nLabel );
1313
+ JMenu menu = new JMenu (label );
1297
1314
Editor .boardsMenus .add (menu );
1298
1315
toolsMenu .add (menu );
1299
1316
return menu ;
@@ -1329,7 +1346,23 @@ private static JMenuItem selectFirstEnabledMenuItem(JMenu menu) {
1329
1346
}
1330
1347
throw new IllegalStateException ("Menu has no enabled items" );
1331
1348
}
1332
-
1349
+
1350
+
1351
+ private void selectBoard (String selectBoard , Editor editor ) {
1352
+ String [] split = selectBoard .split (":" );
1353
+ Preferences .set ("target_package" , split [0 ]);
1354
+ Preferences .set ("target_platform" , split [1 ]);
1355
+ Preferences .set ("board" , split [2 ]);
1356
+
1357
+ filterVisibilityOfSubsequentBoardMenus (split [2 ], 1 );
1358
+
1359
+ onBoardOrPortChange ();
1360
+ Sketch .buildSettingChanged ();
1361
+ rebuildImportMenu (Editor .importMenu , editor );
1362
+ rebuildExamplesMenu (Editor .examplesMenu );
1363
+ }
1364
+
1365
+
1333
1366
public void rebuildProgrammerMenu (JMenu menu ) {
1334
1367
menu .removeAll ();
1335
1368
ButtonGroup group = new ButtonGroup ();
0 commit comments