6
6
package io .flutter .sdk ;
7
7
8
8
import com .intellij .execution .process .ProcessOutput ;
9
+ import com .intellij .icons .AllIcons ;
9
10
import com .intellij .ide .actions .ShowSettingsUtilImpl ;
10
11
import com .intellij .ide .actionsOnSave .ActionsOnSaveConfigurable ;
11
12
import com .intellij .notification .Notification ;
14
15
import com .intellij .openapi .actionSystem .ActionToolbar ;
15
16
import com .intellij .openapi .application .ApplicationManager ;
16
17
import com .intellij .openapi .application .ModalityState ;
18
+ import com .intellij .openapi .fileChooser .FileChooser ;
19
+ import com .intellij .openapi .fileChooser .FileChooserDescriptor ;
17
20
import com .intellij .openapi .fileChooser .FileChooserDescriptorFactory ;
18
21
import com .intellij .openapi .ide .CopyPasteManager ;
19
22
import com .intellij .openapi .options .ConfigurationException ;
20
23
import com .intellij .openapi .options .SearchableConfigurable ;
21
24
import com .intellij .openapi .project .Project ;
22
25
import com .intellij .openapi .ui .ComboBox ;
23
26
import com .intellij .openapi .ui .FixedSizeButton ;
24
- import com .intellij .openapi .ui .TextComponentAccessor ;
25
27
import com .intellij .openapi .util .io .FileUtil ;
26
28
import com .intellij .openapi .util .io .FileUtilRt ;
27
29
import com .intellij .openapi .util .text .StringUtil ;
28
- import com .intellij .ui . ComboboxWithBrowseButton ;
30
+ import com .intellij .openapi . vfs . VirtualFile ;
29
31
import com .intellij .ui .DocumentAdapter ;
30
32
import com .intellij .ui .components .ActionLink ;
31
33
import com .intellij .ui .components .JBLabel ;
34
+ import com .intellij .ui .components .fields .ExtendableTextComponent ;
35
+ import com .intellij .ui .components .fields .ExtendableTextField ;
32
36
import com .intellij .util .PlatformIcons ;
33
37
import icons .FlutterIcons ;
34
- import io .flutter .*;
38
+ import io .flutter .FlutterBundle ;
39
+ import io .flutter .FlutterConstants ;
40
+ import io .flutter .FlutterMessages ;
35
41
import io .flutter .bazel .Workspace ;
36
42
import io .flutter .bazel .WorkspaceCache ;
37
43
import io .flutter .font .FontPreviewProcessor ;
44
50
45
51
import javax .swing .*;
46
52
import javax .swing .event .DocumentEvent ;
53
+ import javax .swing .plaf .basic .BasicComboBoxEditor ;
47
54
import javax .swing .text .JTextComponent ;
48
55
import java .awt .datatransfer .StringSelection ;
49
56
import java .util .List ;
@@ -58,7 +65,7 @@ public class FlutterSettingsConfigurable implements SearchableConfigurable {
58
65
private static final String FLUTTER_SETTINGS_HELP_TOPIC = "flutter.settings.help" ;
59
66
60
67
private JPanel mainPanel ;
61
- private ComboboxWithBrowseButton mySdkCombo ;
68
+ private ComboBox < String > mySdkCombo ;
62
69
private JBLabel myVersionLabel ;
63
70
private JCheckBox myHotReloadOnSaveCheckBox ;
64
71
private JCheckBox myEnableVerboseLoggingCheckBox ;
@@ -105,7 +112,7 @@ private void init() {
105
112
if (sdk != null ) {
106
113
previousSdkVersion = sdk .getVersion ();
107
114
}
108
- mySdkCombo .getComboBox (). setEditable (true );
115
+ mySdkCombo .setEditable (true );
109
116
110
117
myCopyButton .setSize (ActionToolbar .DEFAULT_MINIMUM_BUTTON_SIZE );
111
118
myCopyButton .setIcon (PlatformIcons .COPY_ICON );
@@ -115,7 +122,7 @@ private void init() {
115
122
}
116
123
});
117
124
118
- final JTextComponent sdkEditor = (JTextComponent )mySdkCombo .getComboBox (). getEditor ().getEditorComponent ();
125
+ final JTextComponent sdkEditor = (JTextComponent )mySdkCombo .getEditor ().getEditorComponent ();
119
126
sdkEditor .getDocument ().addDocumentListener (new DocumentAdapter () {
120
127
@ Override
121
128
protected void textChanged (@ NotNull final DocumentEvent e ) {
@@ -124,13 +131,7 @@ protected void textChanged(@NotNull final DocumentEvent e) {
124
131
}
125
132
}
126
133
});
127
-
128
134
workspaceCache .subscribe (this ::onVersionChanged );
129
-
130
- mySdkCombo .addBrowseFolderListener ("Select Flutter SDK Path" , null , null ,
131
- FileChooserDescriptorFactory .createSingleFolderDescriptor (),
132
- TextComponentAccessor .STRING_COMBOBOX_WHOLE_TEXT );
133
-
134
135
myFormatCodeOnSaveCheckBox .addChangeListener (
135
136
(e ) -> myOrganizeImportsOnSaveCheckBox .setEnabled (myFormatCodeOnSaveCheckBox .isSelected ()));
136
137
myShowStructuredErrors .addChangeListener (
@@ -140,7 +141,26 @@ protected void textChanged(@NotNull final DocumentEvent e) {
140
141
}
141
142
142
143
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
+ });
144
164
settingsLink = ActionsOnSaveConfigurable .createGoToActionsOnSavePageLink ();
145
165
}
146
166
@@ -294,8 +314,8 @@ public void reset() {
294
314
// (This can happen if the user changed the Dart SDK.)
295
315
try {
296
316
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 ));
299
319
}
300
320
finally {
301
321
ignoringSdkChanges = false ;
@@ -357,7 +377,7 @@ private void onVersionChanged() {
357
377
assert (workspace != null );
358
378
359
379
mySdkCombo .setEnabled (false );
360
- mySdkCombo .getComboBox (). getEditor ()
380
+ mySdkCombo .getEditor ()
361
381
.setItem (workspace .getRoot ().getPath () + '/' + workspace .getSdkHome () + " <set by bazel project>" );
362
382
}
363
383
}
@@ -443,7 +463,7 @@ public String getHelpTopic() {
443
463
444
464
@ NotNull
445
465
private String getSdkPathText () {
446
- return FileUtilRt .toSystemIndependentName (mySdkCombo .getComboBox (). getEditor ().getItem ().toString ().trim ());
466
+ return FileUtilRt .toSystemIndependentName (mySdkCombo .getEditor ().getItem ().toString ().trim ());
447
467
}
448
468
449
469
private void checkFontPackages (String value , String previous ) {
0 commit comments