40
40
import cc .arduino .packages .DiscoveryManager ;
41
41
import cc .arduino .packages .Uploader ;
42
42
import cc .arduino .view .Event ;
43
+ import cc .arduino .view .JMenuLazy ;
43
44
import cc .arduino .view .JMenuUtils ;
44
45
import cc .arduino .view .SplashScreenHelper ;
45
46
import com .github .zafarkhaja .semver .Version ;
71
72
import java .util .List ;
72
73
import java .util .Timer ;
73
74
import java .util .concurrent .Executor ;
75
+ import java .util .concurrent .ExecutorService ;
74
76
import java .util .concurrent .Executors ;
75
77
import java .util .*;
76
78
import java .util .logging .Handler ;
90
92
* files and images, etc) that comes from that.
91
93
*/
92
94
public class Base {
95
+
96
+ private Logger logger ;
93
97
94
98
private static final int RECENT_SKETCHES_MAX_SIZE = 10 ;
95
99
@@ -130,7 +134,7 @@ public class Base {
130
134
private final List <JMenuItem > recentSketchesMenuItems = new LinkedList <>();
131
135
132
136
// Executor to load / reload menus in backgroud.
133
- private Executor menuExecutor = Executors .newCachedThreadPool ();
137
+ private ExecutorService menuExecutor = Executors .newCachedThreadPool ();
134
138
135
139
static public void main (String args []) throws Exception {
136
140
if (!OSUtils .isWindows ()) {
@@ -1176,12 +1180,17 @@ public void actionPerformed(ActionEvent e) {
1176
1180
1177
1181
}
1178
1182
1179
-
1180
- protected void rebuildSketchbookMenu (JMenu menu ) {
1183
+ protected void rebuildSketchbookMenu (JMenuLazy menu ) {
1184
+
1185
+ // Avoid call twice from "Editor.buildMenuBar"
1186
+ if (menu .isLoading ()) return ;
1187
+
1188
+ menu .setLoading (true ); // mark as not enabled
1189
+
1181
1190
menu .removeAll ();
1182
-
1191
+
1183
1192
// Execute in backgroud thread, no need UI thread becouse no rendering needed
1184
- menuExecutor .execute (() -> {
1193
+ menuExecutor .submit (() -> {
1185
1194
1186
1195
addSketches (menu , BaseNoGui .getSketchbookFolder ());
1187
1196
@@ -1193,6 +1202,8 @@ protected void rebuildSketchbookMenu(JMenu menu) {
1193
1202
if (hardwareMenu != null ) {
1194
1203
menu .remove (hardwareMenu );
1195
1204
}
1205
+
1206
+ SwingUtilities .invokeLater (() -> menu .setLoading (false ));
1196
1207
});
1197
1208
1198
1209
}
@@ -1268,15 +1279,28 @@ public void actionPerformed(ActionEvent event) {
1268
1279
}
1269
1280
}
1270
1281
1271
- public void rebuildExamplesMenu (JMenu menu ) {
1282
+ public void rebuildExamplesMenu (JMenuLazy menu ) {
1272
1283
if (menu == null ) {
1273
1284
return ;
1274
1285
}
1275
-
1286
+
1287
+ new Throwable ().printStackTrace ();
1288
+
1289
+ boolean showDialog = PreferencesData .getBoolean ("menu.examples.dialog" , true );
1290
+ if (showDialog ) {
1291
+ return ;
1292
+ }
1293
+
1294
+ // Avoid call twice from "Editor.buildMenuBar"
1295
+ if (menu .isLoading ()) return ;
1296
+
1297
+ menu .setLoading (true );
1298
+
1276
1299
menu .removeAll ();
1277
1300
1278
1301
// Execute in backgroud thread, no need UI thread becouse no rendering needed
1279
1302
menuExecutor .execute (() -> {
1303
+
1280
1304
// Add examples from distribution "example" folder
1281
1305
JMenuItem label = new JMenuItem (tr ("Built-in Examples" ));
1282
1306
label .setEnabled (false );
@@ -1438,8 +1462,12 @@ public void rebuildExamplesMenu(JMenu menu) {
1438
1462
addSketchesSubmenu (menu , lib );
1439
1463
}
1440
1464
}
1465
+
1466
+ SwingUtilities .invokeLater (() -> {
1467
+ menu .setLoading (false );
1468
+ });
1441
1469
});
1442
-
1470
+
1443
1471
}
1444
1472
1445
1473
private static String priorPlatformFolder ;
@@ -1537,7 +1565,7 @@ protected void onIndexesUpdated() throws Exception {
1537
1565
public void rebuildBoardsMenu () throws Exception {
1538
1566
boardsCustomMenus = new LinkedList <>();
1539
1567
1540
- // Execute in backgroud thread, no need UI thread becouse no rendering needed
1568
+ // Execute in backgroud thread, no need UI thread because no rendering needed
1541
1569
menuExecutor .execute (() -> {
1542
1570
// The first custom menu is the "Board" selection submenu
1543
1571
JMenu boardMenu = new JMenu (tr ("Board" ));
@@ -1660,6 +1688,7 @@ public void actionPerformed(ActionEvent actionevent) {
1660
1688
menuItemToClick .setSelected (true );
1661
1689
menuItemToClick .getAction ().actionPerformed (new ActionEvent (this , -1 , "" ));
1662
1690
}
1691
+
1663
1692
});
1664
1693
1665
1694
}
0 commit comments