@@ -302,7 +302,7 @@ static private void createAndShowGUI(String[] args) {
302302// t6 = System.currentTimeMillis();
303303
304304 // Prevent more than one copy of the PDE from running.
305- SingleInstance .startServer (base );
305+ new Thread (() -> { SingleInstance .startServer (base ); } ). start ( );
306306
307307 handleWelcomeScreen (base );
308308 handleCrustyDisplay ();
@@ -485,20 +485,26 @@ static public boolean isCommandLine() {
485485
486486 public Base (String [] args ) throws Exception {
487487 long t1 = System .currentTimeMillis ();
488- ContributionManager .init (this );
488+ new Thread (() -> {
489+ try {
490+ ContributionManager .init (this );
491+ } catch (Exception e ) {
492+ throw new RuntimeException (e );
493+ }
494+ }).start ();
489495
490496 long t2 = System .currentTimeMillis ();
491497 buildCoreModes ();
492498 long t2b = System .currentTimeMillis ();
493- rebuildContribModes ();
499+ new Thread ( this :: rebuildContribModes ). start ();
494500 long t2c = System .currentTimeMillis ();
495501 rebuildContribExamples ();
496502
497503 long t3 = System .currentTimeMillis ();
498504 // Needs to happen after the sketchbook folder has been located.
499505 // Also relies on the modes to be loaded, so it knows what can be
500506 // marked as an example.
501- Recent .init (this );
507+ new Thread (() -> { Recent .init (this ); }). start ( );
502508
503509 long t4 = System .currentTimeMillis ();
504510 String lastModeIdentifier = Preferences .get ("mode.last" ); //$NON-NLS-1$
@@ -523,7 +529,7 @@ public Base(String[] args) throws Exception {
523529 long t5 = System .currentTimeMillis ();
524530
525531 // Make sure ThinkDifferent has library examples too
526- nextMode .rebuildLibraryList ();
532+ // nextMode.rebuildLibraryList();
527533
528534 // Put this after loading the examples, so that building the default file
529535 // menu works on Mac OS X (since it needs examplesFolder to be set).
@@ -863,7 +869,7 @@ public List<ToolContribution> getContribTools() {
863869 return contribTools ;
864870 }
865871
866-
872+ private List < Tool > toolsToInit = new ArrayList <>();
867873 public void rebuildToolList () {
868874 // Only do these once because the list of internal tools will never change
869875 if (internalTools == null ) {
@@ -883,43 +889,12 @@ public void rebuildToolList() {
883889 // Only init() these the first time they're loaded
884890 if (coreTools == null ) {
885891 coreTools = ToolContribution .loadAll (Base .getToolsFolder ());
886- for (Tool tool : coreTools ) {
887- tool .init (this );
888- }
892+ toolsToInit .addAll (coreTools );
889893 }
890894
891895 // Reset the contributed tools and re-init() all of them.
892896 contribTools = ToolContribution .loadAll (Base .getSketchbookToolsFolder ());
893- for (Tool tool : contribTools ) {
894- try {
895- tool .init (this );
896-
897- // With the exceptions, we can't call statusError because the window
898- // isn't completely set up yet. Also not gonna pop up a warning because
899- // people may still be running different versions of Processing.
900-
901- } catch (VerifyError | AbstractMethodError ve ) {
902- System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
903- "compatible with this version of Processing" );
904- Messages .err ("Incompatible Tool found during tool.init()" , ve );
905-
906- } catch (NoSuchMethodError nsme ) {
907- System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
908- "compatible with this version of Processing" );
909- System .err .println ("The " + nsme .getMessage () + " method no longer exists." );
910- Messages .err ("Incompatible Tool found during tool.init()" , nsme );
911-
912- } catch (NoClassDefFoundError ncdfe ) {
913- System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
914- "compatible with this version of Processing" );
915- System .err .println ("The " + ncdfe .getMessage () + " class is no longer available." );
916- Messages .err ("Incompatible Tool found during tool.init()" , ncdfe );
917-
918- } catch (Error | Exception e ) {
919- System .err .println ("An error occurred inside \" " + tool .getMenuTitle () + "\" " );
920- e .printStackTrace ();
921- }
922- }
897+ toolsToInit .addAll (contribTools );
923898 }
924899
925900
@@ -928,7 +903,7 @@ protected void initInternalTool(Class<?> toolClass) {
928903 final Tool tool = (Tool )
929904 toolClass .getDeclaredConstructor ().newInstance ();
930905
931- tool . init ( this );
906+ toolsToInit . add ( tool );
932907 internalTools .add (tool );
933908
934909 } catch (Exception e ) {
@@ -976,12 +951,40 @@ public void populateToolsMenu(JMenu toolsMenu) {
976951 toolsMenu .add (manageTools );
977952 }
978953
954+ void initTool (Tool tool ) {
955+ if (!toolsToInit .contains (tool )) {return ;}
956+ try {
957+ tool .init (this );
958+ toolsToInit .remove (tool );
959+ } catch (VerifyError | AbstractMethodError ve ) {
960+ System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
961+ "compatible with this version of Processing" );
962+ Messages .err ("Incompatible Tool found during tool.init()" , ve );
963+
964+ } catch (NoSuchMethodError nsme ) {
965+ System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
966+ "compatible with this version of Processing" );
967+ System .err .println ("The " + nsme .getMessage () + " method no longer exists." );
968+ Messages .err ("Incompatible Tool found during tool.init()" , nsme );
969+
970+ } catch (NoClassDefFoundError ncdfe ) {
971+ System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
972+ "compatible with this version of Processing" );
973+ System .err .println ("The " + ncdfe .getMessage () + " class is no longer available." );
974+ Messages .err ("Incompatible Tool found during tool.init()" , ncdfe );
975+
976+ } catch (Error | Exception e ) {
977+ System .err .println ("An error occurred inside \" " + tool .getMenuTitle () + "\" " );
978+ e .printStackTrace ();
979+ }
980+ }
979981
980982 JMenuItem createToolItem (final Tool tool ) { //, Map<String, JMenuItem> toolItems) {
981983 String title = tool .getMenuTitle ();
982984 final JMenuItem item = new JMenuItem (title );
983985 item .addActionListener (e -> {
984986 try {
987+ initTool (tool );
985988 tool .run ();
986989
987990 } catch (NoSuchMethodError | NoClassDefFoundError ne ) {
0 commit comments