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 ;
@@ -57,7 +64,7 @@ public class FlutterSettingsConfigurable implements SearchableConfigurable {
57
64
private static final String FLUTTER_SETTINGS_HELP_TOPIC = "flutter.settings.help" ;
58
65
59
66
private JPanel mainPanel ;
60
- private ComboboxWithBrowseButton mySdkCombo ;
67
+ private ComboBox < String > mySdkCombo ;
61
68
private JBLabel myVersionLabel ;
62
69
private JCheckBox myHotReloadOnSaveCheckBox ;
63
70
private JCheckBox myEnableVerboseLoggingCheckBox ;
@@ -104,7 +111,7 @@ private void init() {
104
111
if (sdk != null ) {
105
112
previousSdkVersion = sdk .getVersion ();
106
113
}
107
- mySdkCombo .getComboBox (). setEditable (true );
114
+ mySdkCombo .setEditable (true );
108
115
109
116
myCopyButton .setSize (ActionToolbar .DEFAULT_MINIMUM_BUTTON_SIZE );
110
117
myCopyButton .setIcon (PlatformIcons .COPY_ICON );
@@ -114,7 +121,7 @@ private void init() {
114
121
}
115
122
});
116
123
117
- final JTextComponent sdkEditor = (JTextComponent )mySdkCombo .getComboBox (). getEditor ().getEditorComponent ();
124
+ final JTextComponent sdkEditor = (JTextComponent )mySdkCombo .getEditor ().getEditorComponent ();
118
125
sdkEditor .getDocument ().addDocumentListener (new DocumentAdapter () {
119
126
@ Override
120
127
protected void textChanged (@ NotNull final DocumentEvent e ) {
@@ -123,13 +130,7 @@ protected void textChanged(@NotNull final DocumentEvent e) {
123
130
}
124
131
}
125
132
});
126
-
127
133
workspaceCache .subscribe (this ::onVersionChanged );
128
-
129
- mySdkCombo .addBrowseFolderListener ("Select Flutter SDK Path" , null , null ,
130
- FileChooserDescriptorFactory .createSingleFolderDescriptor (),
131
- TextComponentAccessor .STRING_COMBOBOX_WHOLE_TEXT );
132
-
133
134
myFormatCodeOnSaveCheckBox .addChangeListener (
134
135
(e ) -> myOrganizeImportsOnSaveCheckBox .setEnabled (myFormatCodeOnSaveCheckBox .isSelected ()));
135
136
myShowStructuredErrors .addChangeListener (
@@ -139,7 +140,26 @@ protected void textChanged(@NotNull final DocumentEvent e) {
139
140
}
140
141
141
142
private void createUIComponents () {
142
- mySdkCombo = new ComboboxWithBrowseButton (new ComboBox <>());
143
+ ExtendableTextComponent .Extension browseExtension =
144
+ ExtendableTextComponent .Extension .create (
145
+ AllIcons .General .OpenDisk ,
146
+ AllIcons .General .OpenDiskHover ,
147
+ "Select Flutter SDK Path" ,
148
+ () -> {
149
+ FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createSingleFolderDescriptor ();
150
+ VirtualFile file = FileChooser .chooseFile (descriptor , mySdkCombo , null , null );
151
+ mySdkCombo .setItem (file .getPath ());
152
+ });
153
+ mySdkCombo = new ComboBox <>();
154
+ mySdkCombo .setEditor (new BasicComboBoxEditor () {
155
+ @ Override
156
+ protected JTextField createEditorComponent () {
157
+ ExtendableTextField ecbEditor = new ExtendableTextField ();
158
+ ecbEditor .addExtension (browseExtension );
159
+ ecbEditor .setBorder (null );
160
+ return ecbEditor ;
161
+ }
162
+ });
143
163
settingsLink = ActionsOnSaveConfigurable .createGoToActionsOnSavePageLink ();
144
164
}
145
165
@@ -293,8 +313,8 @@ public void reset() {
293
313
// (This can happen if the user changed the Dart SDK.)
294
314
try {
295
315
ignoringSdkChanges = true ;
296
- FlutterSdkUtil .addKnownSDKPathsToCombo (mySdkCombo . getComboBox () );
297
- mySdkCombo .getComboBox (). getEditor ().setItem (FileUtil .toSystemDependentName (path ));
316
+ FlutterSdkUtil .addKnownSDKPathsToCombo (mySdkCombo );
317
+ mySdkCombo .getEditor ().setItem (FileUtil .toSystemDependentName (path ));
298
318
}
299
319
finally {
300
320
ignoringSdkChanges = false ;
@@ -356,7 +376,7 @@ private void onVersionChanged() {
356
376
assert (workspace != null );
357
377
358
378
mySdkCombo .setEnabled (false );
359
- mySdkCombo .getComboBox (). getEditor ()
379
+ mySdkCombo .getEditor ()
360
380
.setItem (workspace .getRoot ().getPath () + '/' + workspace .getSdkHome () + " <set by bazel project>" );
361
381
}
362
382
}
@@ -442,7 +462,7 @@ public String getHelpTopic() {
442
462
443
463
@ NotNull
444
464
private String getSdkPathText () {
445
- return FileUtilRt .toSystemIndependentName (mySdkCombo .getComboBox (). getEditor ().getItem ().toString ().trim ());
465
+ return FileUtilRt .toSystemIndependentName (mySdkCombo .getEditor ().getItem ().toString ().trim ());
446
466
}
447
467
448
468
private void checkFontPackages (String value , String previous ) {
0 commit comments