@@ -96,26 +96,39 @@ private static void updateKnownPaths(@SuppressWarnings("SameParameterValue") @No
9696 * Adds the current path and other known paths to the combo, most recently used first.
9797 */
9898 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.
101100 final String currentPath = combo.getEditor().getItem().toString().trim();
101+ final Set<String> pathsToShow = new LinkedHashSet<>();
102102 if (!currentPath.isEmpty()) {
103103 pathsToShow.add(currentPath);
104104 }
105105
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+ }
110115 }
111- }
112116
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);
115121
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+ });
119132 }
120133
121134 @NotNull
@@ -365,7 +378,6 @@ public static String parseFlutterSdkPath(String packagesFileContent) {
365378 return path;
366379 }
367380 }
368-
369381 return null;
370382 }
371383
0 commit comments