66package io .flutter .sdk ;
77
88import com .intellij .execution .process .ProcessOutput ;
9+ import com .intellij .icons .AllIcons ;
910import com .intellij .ide .actions .ShowSettingsUtilImpl ;
1011import com .intellij .ide .actionsOnSave .ActionsOnSaveConfigurable ;
1112import com .intellij .notification .Notification ;
1415import com .intellij .openapi .actionSystem .ActionToolbar ;
1516import com .intellij .openapi .application .ApplicationManager ;
1617import com .intellij .openapi .application .ModalityState ;
18+ import com .intellij .openapi .fileChooser .FileChooser ;
19+ import com .intellij .openapi .fileChooser .FileChooserDescriptor ;
1720import com .intellij .openapi .fileChooser .FileChooserDescriptorFactory ;
1821import com .intellij .openapi .ide .CopyPasteManager ;
1922import com .intellij .openapi .options .ConfigurationException ;
2023import com .intellij .openapi .options .SearchableConfigurable ;
2124import com .intellij .openapi .project .Project ;
2225import com .intellij .openapi .ui .ComboBox ;
2326import com .intellij .openapi .ui .FixedSizeButton ;
24- import com .intellij .openapi .ui .TextComponentAccessor ;
2527import com .intellij .openapi .util .io .FileUtil ;
2628import com .intellij .openapi .util .io .FileUtilRt ;
2729import com .intellij .openapi .util .text .StringUtil ;
28- import com .intellij .ui . ComboboxWithBrowseButton ;
30+ import com .intellij .openapi . vfs . VirtualFile ;
2931import com .intellij .ui .DocumentAdapter ;
3032import com .intellij .ui .components .ActionLink ;
3133import com .intellij .ui .components .JBLabel ;
34+ import com .intellij .ui .components .fields .ExtendableTextComponent ;
35+ import com .intellij .ui .components .fields .ExtendableTextField ;
3236import com .intellij .util .PlatformIcons ;
3337import icons .FlutterIcons ;
34- import io .flutter .*;
38+ import io .flutter .FlutterBundle ;
39+ import io .flutter .FlutterConstants ;
40+ import io .flutter .FlutterMessages ;
3541import io .flutter .bazel .Workspace ;
3642import io .flutter .bazel .WorkspaceCache ;
3743import io .flutter .font .FontPreviewProcessor ;
4450
4551import javax .swing .*;
4652import javax .swing .event .DocumentEvent ;
53+ import javax .swing .plaf .basic .BasicComboBoxEditor ;
4754import javax .swing .text .JTextComponent ;
4855import java .awt .datatransfer .StringSelection ;
4956import java .util .List ;
@@ -58,7 +65,7 @@ public class FlutterSettingsConfigurable implements SearchableConfigurable {
5865 private static final String FLUTTER_SETTINGS_HELP_TOPIC = "flutter.settings.help" ;
5966
6067 private JPanel mainPanel ;
61- private ComboboxWithBrowseButton mySdkCombo ;
68+ private ComboBox < String > mySdkCombo ;
6269 private JBLabel myVersionLabel ;
6370 private JCheckBox myHotReloadOnSaveCheckBox ;
6471 private JCheckBox myEnableVerboseLoggingCheckBox ;
@@ -105,7 +112,7 @@ private void init() {
105112 if (sdk != null ) {
106113 previousSdkVersion = sdk .getVersion ();
107114 }
108- mySdkCombo .getComboBox (). setEditable (true );
115+ mySdkCombo .setEditable (true );
109116
110117 myCopyButton .setSize (ActionToolbar .DEFAULT_MINIMUM_BUTTON_SIZE );
111118 myCopyButton .setIcon (PlatformIcons .COPY_ICON );
@@ -115,7 +122,7 @@ private void init() {
115122 }
116123 });
117124
118- final JTextComponent sdkEditor = (JTextComponent )mySdkCombo .getComboBox (). getEditor ().getEditorComponent ();
125+ final JTextComponent sdkEditor = (JTextComponent )mySdkCombo .getEditor ().getEditorComponent ();
119126 sdkEditor .getDocument ().addDocumentListener (new DocumentAdapter () {
120127 @ Override
121128 protected void textChanged (@ NotNull final DocumentEvent e ) {
@@ -124,13 +131,7 @@ protected void textChanged(@NotNull final DocumentEvent e) {
124131 }
125132 }
126133 });
127-
128134 workspaceCache .subscribe (this ::onVersionChanged );
129-
130- mySdkCombo .addBrowseFolderListener ("Select Flutter SDK Path" , null , null ,
131- FileChooserDescriptorFactory .createSingleFolderDescriptor (),
132- TextComponentAccessor .STRING_COMBOBOX_WHOLE_TEXT );
133-
134135 myFormatCodeOnSaveCheckBox .addChangeListener (
135136 (e ) -> myOrganizeImportsOnSaveCheckBox .setEnabled (myFormatCodeOnSaveCheckBox .isSelected ()));
136137 myShowStructuredErrors .addChangeListener (
@@ -140,7 +141,26 @@ protected void textChanged(@NotNull final DocumentEvent e) {
140141 }
141142
142143 private void createUIComponents () {
143- mySdkCombo = new ComboboxWithBrowseButton (new ComboBox <>());
144+ ExtendableTextComponent .Extension browseExtension =
145+ ExtendableTextComponent .Extension .create (
146+ AllIcons .General .OpenDisk ,
147+ AllIcons .General .OpenDiskHover ,
148+ "Select Flutter SDK Path" ,
149+ () -> {
150+ FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createSingleFolderDescriptor ();
151+ VirtualFile file = FileChooser .chooseFile (descriptor , mySdkCombo , null , null );
152+ mySdkCombo .setItem (file .getPath ());
153+ });
154+ mySdkCombo = new ComboBox <>();
155+ mySdkCombo .setEditor (new BasicComboBoxEditor () {
156+ @ Override
157+ protected JTextField createEditorComponent () {
158+ ExtendableTextField ecbEditor = new ExtendableTextField ();
159+ ecbEditor .addExtension (browseExtension );
160+ ecbEditor .setBorder (null );
161+ return ecbEditor ;
162+ }
163+ });
144164 settingsLink = ActionsOnSaveConfigurable .createGoToActionsOnSavePageLink ();
145165 }
146166
@@ -294,8 +314,8 @@ public void reset() {
294314 // (This can happen if the user changed the Dart SDK.)
295315 try {
296316 ignoringSdkChanges = true ;
297- FlutterSdkUtil .addKnownSDKPathsToCombo (mySdkCombo . getComboBox () );
298- mySdkCombo .getComboBox (). getEditor ().setItem (FileUtil .toSystemDependentName (path ));
317+ FlutterSdkUtil .addKnownSDKPathsToCombo (mySdkCombo );
318+ mySdkCombo .getEditor ().setItem (FileUtil .toSystemDependentName (path ));
299319 }
300320 finally {
301321 ignoringSdkChanges = false ;
@@ -357,7 +377,7 @@ private void onVersionChanged() {
357377 assert (workspace != null );
358378
359379 mySdkCombo .setEnabled (false );
360- mySdkCombo .getComboBox (). getEditor ()
380+ mySdkCombo .getEditor ()
361381 .setItem (workspace .getRoot ().getPath () + '/' + workspace .getSdkHome () + " <set by bazel project>" );
362382 }
363383 }
@@ -443,7 +463,7 @@ public String getHelpTopic() {
443463
444464 @ NotNull
445465 private String getSdkPathText () {
446- return FileUtilRt .toSystemIndependentName (mySdkCombo .getComboBox (). getEditor ().getItem ().toString ().trim ());
466+ return FileUtilRt .toSystemIndependentName (mySdkCombo .getEditor ().getItem ().toString ().trim ());
447467 }
448468
449469 private void checkFontPackages (String value , String previous ) {
0 commit comments