@@ -96,26 +96,39 @@ private static void updateKnownPaths(@SuppressWarnings("SameParameterValue") @No
96
96
* Adds the current path and other known paths to the combo, most recently used first.
97
97
*/
98
98
public static void addKnownSDKPathsToCombo (@ NotNull JComboBox combo ) {
99
- final Set <String > pathsToShow = new LinkedHashSet <>();
100
-
99
+ // First, get the current path from the combo box on the EDT.
101
100
final String currentPath = combo .getEditor ().getItem ().toString ().trim ();
101
+ final Set <String > pathsToShow = new LinkedHashSet <>();
102
102
if (!currentPath .isEmpty ()) {
103
103
pathsToShow .add (currentPath );
104
104
}
105
105
106
- final String [] knownPaths = getKnownFlutterSdkPaths ();
107
- for (String path : knownPaths ) {
108
- if (FlutterSdk .forPath (path ) != null ) {
109
- pathsToShow .add (FileUtil .toSystemDependentName (path ));
106
+ // Now, run the slow operation (finding valid SDK paths) on a background thread.
107
+ ApplicationManager .getApplication ().executeOnPooledThread (() -> {
108
+ final String [] knownPaths = getKnownFlutterSdkPaths ();
109
+ final Set <String > validPaths = new LinkedHashSet <>();
110
+ for (String path : knownPaths ) {
111
+ // The call to forPath() is on a background thread.
112
+ if (FlutterSdk .forPath (path ) != null ) {
113
+ validPaths .add (FileUtil .toSystemDependentName (path ));
114
+ }
110
115
}
111
- }
112
116
113
- //noinspection unchecked
114
- combo .setModel (new DefaultComboBoxModel (ArrayUtil .toStringArray (pathsToShow )));
117
+ // After the slow operation is complete, switch back to the EDT to update the UI.
118
+ ApplicationManager .getApplication ().invokeLater (() -> {
119
+ // This code runs on the EDT.
120
+ pathsToShow .addAll (validPaths );
115
121
116
- if (combo .getSelectedIndex () == -1 && combo .getItemCount () > 0 ) {
117
- combo .setSelectedIndex (0 );
118
- }
122
+ // Update the combo box model with the new paths.
123
+ //noinspection unchecked
124
+ combo .setModel (new DefaultComboBoxModel <>(ArrayUtil .toStringArray (pathsToShow )));
125
+
126
+ // Select the first item if none is selected.
127
+ if (combo .getSelectedIndex () == -1 && combo .getItemCount () > 0 ) {
128
+ combo .setSelectedIndex (0 );
129
+ }
130
+ });
131
+ });
119
132
}
120
133
121
134
@ NotNull
@@ -365,7 +378,6 @@ public static String parseFlutterSdkPath(String packagesFileContent) {
365
378
return path ;
366
379
}
367
380
}
368
-
369
381
return null ;
370
382
}
371
383
0 commit comments