@@ -86,6 +86,11 @@ public class Base {
86
86
List <Editor > editors = Collections .synchronizedList (new ArrayList <Editor >());
87
87
Editor activeEditor ;
88
88
89
+ // these menus are shared so that the board and serial port selections
90
+ // are the same for all windows (since the board and serial port that are
91
+ // actually used are determined by the preferences, which are shared)
92
+ static List <JMenu > boardsCustomMenus ;
93
+
89
94
static public void main (String args []) throws Exception {
90
95
System .setProperty ("awt.useSystemAAFontSettings" , "on" );
91
96
System .setProperty ("swing.aatext" , "true" );
@@ -238,7 +243,8 @@ public Base(String[] args) throws Exception {
238
243
splashScreenHelper .splashText (_ ("Initializing packages..." ));
239
244
BaseNoGui .initPackages ();
240
245
splashScreenHelper .splashText (_ ("Preparing boards..." ));
241
-
246
+ rebuildBoardsMenu ();
247
+
242
248
// Setup board-dependent variables.
243
249
onBoardOrPortChange ();
244
250
@@ -1114,78 +1120,95 @@ private void openInstallBoardDialog() {
1114
1120
ContributionManagerUI managerUI = new ContributionManagerUI (activeEditor ) {
1115
1121
@ Override
1116
1122
protected void onIndexesUpdated () throws Exception {
1117
- BaseNoGui .reloadAllHardware ();
1123
+ BaseNoGui .initPackages ();
1124
+ rebuildBoardsMenu ();
1118
1125
setIndexer (BaseNoGui .indexer );
1119
1126
}
1120
1127
};
1121
1128
managerUI .setIndexer (BaseNoGui .indexer );
1122
1129
managerUI .setVisible (true );
1130
+ // Installer dialog is modal, waits here until closed
1131
+
1132
+ // Reload all boards (that may have been installed/updated/removed)
1133
+ try {
1134
+ BaseNoGui .initPackages ();
1135
+ rebuildBoardsMenu ();
1136
+ onBoardOrPortChange ();
1137
+ } catch (Exception e ) {
1138
+ // TODO Auto-generated catch block
1139
+ e .printStackTrace ();
1140
+ }
1123
1141
}
1124
1142
1125
- public void rebuildBoardsMenu (JMenu toolsMenu , Editor editor ) throws Exception {
1126
- JMenu boardsMenu = getBoardCustomMenu ();
1143
+ public void rebuildBoardsMenu () throws Exception {
1144
+ boardsCustomMenus = new LinkedList < JMenu > ();
1127
1145
1146
+ // The first custom menu is the "Board" selection submenu
1147
+ JMenu boardMenu = new JMenu (_ ("Board" ));
1148
+ MenuScroller .setScrollerFor (boardMenu );
1128
1149
@ SuppressWarnings ("serial" )
1129
1150
Action runInstaller = new AbstractAction ("Install boards..." ) {
1130
1151
public void actionPerformed (ActionEvent actionevent ) {
1131
1152
openInstallBoardDialog ();
1132
1153
}
1133
1154
};
1134
- boardsMenu .add (new JMenuItem (runInstaller ));
1155
+ boardMenu .add (new JMenuItem (runInstaller ));
1156
+ boardsCustomMenus .add (boardMenu );
1135
1157
1136
- // If there are no platforms installed skip menu creation
1158
+ // If there are no platforms installed we are done
1137
1159
if (BaseNoGui .packages .size () == 0 )
1138
1160
return ;
1139
-
1140
- boardsMenu .add (new JSeparator ());
1141
1161
1142
- boolean first = true ;
1143
-
1144
- List <JMenuItem > menuItemsToClickAfterStartup = new LinkedList <JMenuItem >();
1145
-
1146
- ButtonGroup boardsButtonGroup = new ButtonGroup ();
1147
- Map <String , ButtonGroup > buttonGroupsMap = new HashMap <String , ButtonGroup >();
1162
+ // Separate "Install boards..." command from installed boards
1163
+ boardMenu .add (new JSeparator ());
1148
1164
1149
1165
// Generate custom menus for all platforms
1150
1166
Set <String > titles = new HashSet <String >();
1151
1167
for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
1152
1168
for (TargetPlatform targetPlatform : targetPackage .platforms ())
1153
1169
titles .addAll (targetPlatform .getCustomMenus ().values ());
1154
1170
}
1155
- for (String title : titles )
1156
- makeBoardCustomMenu (toolsMenu , _ (title ));
1157
-
1171
+ for (String title : titles ) {
1172
+ boardsCustomMenus .add (new JMenu (_ (title )));
1173
+ }
1174
+
1175
+ List <JMenuItem > menuItemsToClickAfterStartup = new LinkedList <JMenuItem >();
1176
+
1177
+ ButtonGroup boardsButtonGroup = new ButtonGroup ();
1178
+ Map <String , ButtonGroup > buttonGroupsMap = new HashMap <String , ButtonGroup >();
1179
+
1158
1180
// Cycle through all packages
1181
+ boolean first = true ;
1159
1182
for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
1160
1183
// For every package cycle through all platform
1161
1184
for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
1162
1185
1163
1186
// Add a separator from the previous platform
1164
1187
if (!first )
1165
- boardsMenu .add (new JSeparator ());
1188
+ boardMenu .add (new JSeparator ());
1166
1189
first = false ;
1167
1190
1168
1191
// Add a title for each platform
1169
- String platformLabel = targetPlatform .getPreferences ().get ("name" );
1192
+ String platformLabel = targetPlatform .getPreferences ().get ("name" );
1170
1193
if (platformLabel != null && !targetPlatform .getBoards ().isEmpty ()) {
1171
1194
JMenuItem menuLabel = new JMenuItem (_ (platformLabel ));
1172
1195
menuLabel .setEnabled (false );
1173
- boardsMenu .add (menuLabel );
1196
+ boardMenu .add (menuLabel );
1174
1197
}
1175
1198
1176
1199
// Cycle through all boards of this platform
1177
1200
for (TargetBoard board : targetPlatform .getBoards ().values ()) {
1178
1201
JMenuItem item = createBoardMenusAndCustomMenus (menuItemsToClickAfterStartup ,
1179
1202
buttonGroupsMap ,
1180
1203
board , targetPlatform , targetPackage );
1181
- boardsMenu .add (item );
1204
+ boardMenu .add (item );
1182
1205
boardsButtonGroup .add (item );
1183
1206
}
1184
1207
}
1185
1208
}
1186
1209
1187
1210
if (menuItemsToClickAfterStartup .isEmpty ()) {
1188
- menuItemsToClickAfterStartup .add (selectFirstEnabledMenuItem (boardsMenu ));
1211
+ menuItemsToClickAfterStartup .add (selectFirstEnabledMenuItem (boardMenu ));
1189
1212
}
1190
1213
1191
1214
for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup ) {
@@ -1265,9 +1288,10 @@ public void actionPerformed(ActionEvent e) {
1265
1288
return item ;
1266
1289
}
1267
1290
1268
- private static void filterVisibilityOfSubsequentBoardMenus (TargetBoard board , int fromIndex ) {
1269
- for (int i = fromIndex ; i < Editor .boardsMenus .size (); i ++) {
1270
- JMenu menu = Editor .boardsMenus .get (i );
1291
+ private static void filterVisibilityOfSubsequentBoardMenus (TargetBoard board ,
1292
+ int fromIndex ) {
1293
+ for (int i = fromIndex ; i < boardsCustomMenus .size (); i ++) {
1294
+ JMenu menu = boardsCustomMenus .get (i );
1271
1295
for (int m = 0 ; m < menu .getItemCount (); m ++) {
1272
1296
JMenuItem menuItem = menu .getItem (m );
1273
1297
menuItem .setVisible (menuItem .getAction ().getValue ("board" ).equals (board ));
@@ -1293,19 +1317,8 @@ private static boolean ifThereAreVisibleItemsOn(JMenu menu) {
1293
1317
return false ;
1294
1318
}
1295
1319
1296
- private JMenu makeBoardCustomMenu (JMenu toolsMenu , String label ) {
1297
- JMenu menu = new JMenu (label );
1298
- Editor .boardsMenus .add (menu );
1299
- toolsMenu .add (menu );
1300
- return menu ;
1301
- }
1302
-
1303
- private JMenu getBoardCustomMenu () throws Exception {
1304
- return getBoardCustomMenu (_ ("Board" ));
1305
- }
1306
-
1307
1320
private JMenu getBoardCustomMenu (String label ) throws Exception {
1308
- for (JMenu menu : Editor . boardsMenus )
1321
+ for (JMenu menu : boardsCustomMenus )
1309
1322
if (label .equals (menu .getText ()))
1310
1323
return menu ;
1311
1324
throw new Exception ("Custom menu not found!" );
@@ -1760,6 +1773,10 @@ static public PreferencesMap getBoardPreferences() {
1760
1773
return BaseNoGui .getBoardPreferences ();
1761
1774
}
1762
1775
1776
+ public static List <JMenu > getBoardsCustomMenus () {
1777
+ return boardsCustomMenus ;
1778
+ }
1779
+
1763
1780
static public File getPortableFolder () {
1764
1781
return BaseNoGui .getPortableFolder ();
1765
1782
}
0 commit comments