Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<text resource-bundle="messages/DartBundle" key="remote.debug.search.sources.in"/>
</properties>
</component>
<component id="e3762" class="com.intellij.ui.ComboboxWithBrowseButton" binding="myDartProjectCombo">
<component id="e3762" class="com.intellij.openapi.ui.ComboBox" binding="myDartProjectCombo" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="100" height="-1"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.lang.dart.ide.runner.server.ui;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.TextComponentAccessor;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.GlobalSearchScopesCore;
import com.intellij.ui.ComboboxWithBrowseButton;
import com.intellij.ui.SimpleListCellRenderer;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.fields.ExtendableTextField;
import com.jetbrains.lang.dart.DartBundle;
import com.jetbrains.lang.dart.DartFileType;
import com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugConfiguration;
import com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugParameters;
Expand All @@ -24,6 +27,7 @@
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.plaf.basic.BasicComboBoxEditor;
import java.util.SortedSet;
import java.util.TreeSet;

Expand All @@ -32,18 +36,21 @@
public class DartRemoteDebugConfigurationEditor extends SettingsEditor<DartRemoteDebugConfiguration> {

private JPanel myMainPanel;
private ComboboxWithBrowseButton myDartProjectCombo;
private ComboBox<NameAndPath> myDartProjectCombo;
private JBLabel myHintLabel;

private final Project myProject;
private final SortedSet<NameAndPath> myComboItems = new TreeSet<>();

public DartRemoteDebugConfigurationEditor(final @NotNull Project project) {
myProject = project;
installBrowseExtension();
initDartProjectsCombo(project);
myHintLabel.setCopyable(true);
}

private void initDartProjectsCombo(final @NotNull Project project) {
myDartProjectCombo.getComboBox().setRenderer(SimpleListCellRenderer.create("", NameAndPath::getPresentableText));
myDartProjectCombo.setRenderer(SimpleListCellRenderer.create("", NameAndPath::getPresentableText));

if (!project.isDefault()) {
for (VirtualFile pubspecFile : FilenameIndex.getVirtualFilesByName(PUBSPEC_YAML, GlobalSearchScope.projectScope(project))) {
Expand All @@ -59,23 +66,7 @@ private void initDartProjectsCombo(final @NotNull Project project) {
}
}

myDartProjectCombo.getComboBox().setModel(new DefaultComboBoxModel<>(myComboItems.toArray()));

myDartProjectCombo.addBrowseFolderListener(
project,
FileChooserDescriptorFactory.createSingleFolderDescriptor(),
new TextComponentAccessor<>() {
@Override
public String getText(final JComboBox combo) {
final Object item = combo.getSelectedItem();
return item instanceof NameAndPath ? ((NameAndPath)item).myPath : "";
}

@Override
public void setText(final JComboBox combo, final @NotNull String path) {
setSelectedProjectPath(FileUtil.toSystemIndependentName(path));
}
});
myDartProjectCombo.setModel(new DefaultComboBoxModel<>(myComboItems.toArray(NameAndPath[]::new)));
}

@Override
Expand All @@ -98,17 +89,46 @@ private void setSelectedProjectPath(final @NotNull String projectPath) {

if (!myComboItems.contains(item)) {
myComboItems.add(item);
myDartProjectCombo.getComboBox().setModel(new DefaultComboBoxModel(myComboItems.toArray()));
myDartProjectCombo.setModel(new DefaultComboBoxModel<>(myComboItems.toArray(NameAndPath[]::new)));
}

myDartProjectCombo.getComboBox().setSelectedItem(item);
myDartProjectCombo.setSelectedItem(item);
}

@Override
protected void applyEditorTo(final @NotNull DartRemoteDebugConfiguration config) {
final DartRemoteDebugParameters params = config.getParameters();
final Object selectedItem = myDartProjectCombo.getComboBox().getSelectedItem();
params.setDartProjectPath(selectedItem instanceof NameAndPath ? ((NameAndPath)selectedItem).myPath : "");
final Object selectedItem = myDartProjectCombo.getSelectedItem();
params.setDartProjectPath(selectedItem instanceof NameAndPath ? ((NameAndPath)selectedItem).myPath : selectedItem == null ? "" : selectedItem.toString().trim());
}

private void createUIComponents() {
myDartProjectCombo = new ComboBox<>();
}

private void installBrowseExtension() {
ExtendableTextField editor = new ExtendableTextField();
editor.addExtension(
ExtendableTextField.Extension.create(
AllIcons.General.OpenDisk,
AllIcons.General.OpenDiskHover,
DartBundle.message("button.browse.dialog.title.select.dart.project.path"),
() -> {
var descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()
.withTitle(DartBundle.message("button.browse.dialog.title.select.dart.project.path"));
VirtualFile file = FileChooser.chooseFile(descriptor, myDartProjectCombo, myProject, null);
if (file != null) {
setSelectedProjectPath(FileUtil.toSystemIndependentName(file.getPath()));
}
}));
editor.setBorder(null);
myDartProjectCombo.setEditable(true);
myDartProjectCombo.setEditor(new BasicComboBoxEditor() {
@Override
protected JTextField createEditorComponent() {
return editor;
}
});
}

private static class NameAndPath implements Comparable<NameAndPath> {
Expand All @@ -126,7 +146,7 @@ public String getPresentableText() {

@Override
public String toString() {
return getPresentableText();
return myPath;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<text resource-bundle="messages/DartBundle" key="dart.sdk.path.label"/>
</properties>
</component>
<component id="b09db" class="com.intellij.ui.ComboboxWithBrowseButton" binding="mySdkPathComboWithBrowse" custom-create="true">
<component id="b09db" class="com.intellij.openapi.ui.ComboBox" binding="mySdkPathComboWithBrowse" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.intellij.platform.ProjectGeneratorPeer;
import com.intellij.platform.WebProjectGenerator;
import com.intellij.ui.ColorUtil;
import com.intellij.ui.ComboboxWithBrowseButton;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.JBColor;
import com.intellij.ui.components.JBCheckBox;
Expand All @@ -41,7 +40,7 @@ public class DartGeneratorPeer implements ProjectGeneratorPeer<DartProjectWizard
private static final String CREATE_SAMPLE_UNCHECKED = "CREATE_SAMPLE_UNCHECKED";

private JPanel myMainPanel;
private ComboboxWithBrowseButton mySdkPathComboWithBrowse;
private ComboBox<String> mySdkPathComboWithBrowse;
private JBLabel myVersionLabel;

private JPanel myTemplatesPanel;
Expand All @@ -60,8 +59,8 @@ public class DartGeneratorPeer implements ProjectGeneratorPeer<DartProjectWizard

public DartGeneratorPeer() {
// set initial values before initDartSdkControls() because listeners should not be triggered on initialization
mySdkPathComboWithBrowse.getComboBox().setEditable(true);
//mySdkPathComboWithBrowse.getComboBox().getEditor().setItem(...); initial sdk path will be correctly taken from known paths history
mySdkPathComboWithBrowse.setEditable(true);
//mySdkPathComboWithBrowse.getEditor().setItem(...); initial sdk path will be correctly taken from known paths history

// now setup controls
DartSdkUtil.initDartSdkControls(null, mySdkPathComboWithBrowse, myVersionLabel);
Expand Down Expand Up @@ -92,7 +91,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
myCreateSampleProjectCheckBox.setEnabled(false);
myTemplatesList.setEnabled(false);

final JTextComponent editorComponent = (JTextComponent)mySdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
final JTextComponent editorComponent = (JTextComponent)mySdkPathComboWithBrowse.getEditor().getEditorComponent();
editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final @NotNull DocumentEvent e) {
Expand All @@ -106,7 +105,7 @@ protected void textChanged(final @NotNull DocumentEvent e) {
}

private void onSdkPathChanged() {
String sdkPath = mySdkPathComboWithBrowse.getComboBox().getEditor().getItem().toString().trim();
String sdkPath = mySdkPathComboWithBrowse.getEditor().getItem().toString().trim();
// If the sdk path has changed, recalculate the create template options
if (myDartCreateTemplatesSdkPath != null && !myDartCreateTemplatesSdkPath.equals(sdkPath)) {
clearTemplates();
Expand Down Expand Up @@ -159,7 +158,7 @@ private void startLoadingTemplates() {
asyncProcessIcon.resume();

ApplicationManager.getApplication().executeOnPooledThread(() -> {
final String comboSdkPath = mySdkPathComboWithBrowse.getComboBox().getEditor().getItem().toString().trim();
final String comboSdkPath = mySdkPathComboWithBrowse.getEditor().getItem().toString().trim();
final String sdkPath =
FileUtil.toSystemIndependentName(comboSdkPath);
DartProjectTemplate.loadTemplatesAsync(sdkPath, templates -> {
Expand Down Expand Up @@ -236,7 +235,7 @@ public void buildUI(final @NotNull SettingsStep settingsStep) {

@Override
public @NotNull DartProjectWizardData getSettings() {
final String sdkPath = FileUtil.toSystemIndependentName(mySdkPathComboWithBrowse.getComboBox().getEditor().getItem().toString().trim());
final String sdkPath = FileUtil.toSystemIndependentName(mySdkPathComboWithBrowse.getEditor().getItem().toString().trim());
final DartProjectTemplate template = myCreateSampleProjectCheckBox.isSelected() ? myTemplatesList.getSelectedValue() : null;
PropertiesComponent.getInstance().setValue(DART_PROJECT_TEMPLATE, template == null ? CREATE_SAMPLE_UNCHECKED : template.getName());

Expand All @@ -245,7 +244,7 @@ public void buildUI(final @NotNull SettingsStep settingsStep) {

@Override
public @Nullable ValidationInfo validate() {
final String sdkPath = mySdkPathComboWithBrowse.getComboBox().getEditor().getItem().toString().trim();
final String sdkPath = mySdkPathComboWithBrowse.getEditor().getItem().toString().trim();
final String message = DartSdkUtil.getErrorMessageIfWrongSdkRootPath(sdkPath);
if (message != null) {
return new ValidationInfo(message, mySdkPathComboWithBrowse);
Expand Down Expand Up @@ -284,7 +283,7 @@ public boolean validateInIntelliJ() {
}

private void enableIntellijLiveValidation() {
final JTextComponent editorComponent = (JTextComponent)mySdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
final JTextComponent editorComponent = (JTextComponent)mySdkPathComboWithBrowse.getEditor().getEditorComponent();
editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final @NotNull DocumentEvent e) {
Expand All @@ -304,7 +303,7 @@ public boolean isBackgroundJobRunning() {

@Override
public void addSettingsStateListener(final @NotNull WebProjectGenerator.SettingsStateListener stateListener) {
final JTextComponent editorComponent = (JTextComponent)mySdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
final JTextComponent editorComponent = (JTextComponent)mySdkPathComboWithBrowse.getEditor().getEditorComponent();
editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final @NotNull DocumentEvent e) {
Expand All @@ -318,6 +317,6 @@ protected void textChanged(final @NotNull DocumentEvent e) {
}

private void createUIComponents() {
mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
mySdkPathComboWithBrowse = new ComboBox<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<properties/>
<border type="none"/>
<children>
<component id="80a7b" class="com.intellij.ui.ComboboxWithBrowseButton" binding="mySdkPathComboWithBrowse" custom-create="true">
<component id="80a7b" class="com.intellij.openapi.ui.ComboBox" binding="mySdkPathComboWithBrowse" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class DartConfigurable implements SearchableConfigurable, NoScroll
private JBCheckBox myEnableDartSupportCheckBox;

private JPanel mySettingsPanel;
private ComboboxWithBrowseButton mySdkPathComboWithBrowse;
private ComboBox<String> mySdkPathComboWithBrowse;
private JBLabel myVersionLabel;
private JBCheckBox myCheckSdkUpdateCheckBox;
// disabled and unchecked, shown in UI instead of myCheckSdkUpdateCheckBox if selected Dart SDK is a part of a Flutter SDK
Expand Down Expand Up @@ -102,7 +102,7 @@ private void initEnableDartSupportCheckBox() {
private void initDartSdkControls() {
DartSdkUtil.initDartSdkControls(myProject, mySdkPathComboWithBrowse, myVersionLabel);

final JTextComponent sdkEditor = (JTextComponent)mySdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
final JTextComponent sdkEditor = (JTextComponent)mySdkPathComboWithBrowse.getEditor().getEditorComponent();
sdkEditor.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final @NotNull DocumentEvent e) {
Expand Down Expand Up @@ -249,8 +249,8 @@ public boolean isModified() {
return false;
}

private static @NotNull String getTextFromCombo(final @NotNull ComboboxWithBrowseButton combo) {
return FileUtilRt.toSystemIndependentName(combo.getComboBox().getEditor().getItem().toString().trim());
private static @NotNull String getTextFromCombo(final @NotNull ComboBox<?> combo) {
return FileUtilRt.toSystemIndependentName(combo.getEditor().getItem().toString().trim());
}

@Override
Expand All @@ -268,9 +268,9 @@ public void reset() {
// reset UI
myEnableDartSupportCheckBox.setSelected(myDartSupportEnabledInitial);
@NlsSafe String sdkInitialPath = mySdkInitial == null ? "" : FileUtilRt.toSystemDependentName(mySdkInitial.getHomePath());
mySdkPathComboWithBrowse.getComboBox().getEditor().setItem(sdkInitialPath);
mySdkPathComboWithBrowse.getEditor().setItem(sdkInitialPath);
if (!sdkInitialPath.isEmpty()) {
ensureComboModelContainsCurrentItem(mySdkPathComboWithBrowse.getComboBox());
ensureComboModelContainsCurrentItem(mySdkPathComboWithBrowse);
}

final DartSdkUpdateOption sdkUpdateOption = DartSdkUpdateOption.getDartSdkUpdateOption();
Expand Down Expand Up @@ -409,7 +409,7 @@ private void updateErrorLabel() {
}

private void createUIComponents() {
mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
mySdkPathComboWithBrowse = new ComboBox<>();

final CheckboxTree.CheckboxTreeCellRenderer checkboxTreeCellRenderer = new CheckboxTree.CheckboxTreeCellRenderer() {
@Override
Expand Down
Loading
Loading