Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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
164 changes: 82 additions & 82 deletions third_party/gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.jetbrains.lang.dart.ui.BasicComboBoxWithBrowseButton" 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,24 +1,28 @@
// 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.openapi.application.ModalityState;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.TextComponentAccessor;
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.util.concurrency.AppExecutorUtil;
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;
import com.jetbrains.lang.dart.ui.BasicComboBoxWithBrowseButton;
import com.jetbrains.lang.dart.util.PubspecYamlUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -32,50 +36,55 @@
public class DartRemoteDebugConfigurationEditor extends SettingsEditor<DartRemoteDebugConfiguration> {

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

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

public DartRemoteDebugConfigurationEditor(final @NotNull Project project) {
myProject = project;
myDartProjectCombo.addBrowseFolderListener(DartBundle.message("button.browse.dialog.title.select.dart.project.path"),
myProject,
FileChooserDescriptorFactory.createSingleFolderDescriptor()
.withTitle(DartBundle.message("button.browse.dialog.title.select.dart.project.path")),
this::resolveNameAndPath,
this::applySelectedProjectPath);
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()) {
if (project.isDefault()) return;

ReadAction.nonBlocking(() -> {
SortedSet<NameAndPath> items = new TreeSet<>();
for (VirtualFile pubspecFile : FilenameIndex.getVirtualFilesByName(PUBSPEC_YAML, GlobalSearchScope.projectScope(project))) {
myComboItems.add(new NameAndPath(PubspecYamlUtil.getDartProjectName(pubspecFile), pubspecFile.getParent().getPath()));
ProgressManager.checkCanceled();
items.add(new NameAndPath(PubspecYamlUtil.getDartProjectName(pubspecFile), pubspecFile.getParent().getPath()));
}

if (myComboItems.isEmpty()) {
if (items.isEmpty()) {
for (VirtualFile contentRoot : ProjectRootManager.getInstance(project).getContentRoots()) {
ProgressManager.checkCanceled();
if (FileTypeIndex.containsFileOfType(DartFileType.INSTANCE, GlobalSearchScopesCore.directoryScope(project, contentRoot, true))) {
myComboItems.add(new NameAndPath(null, contentRoot.getPath()));
items.add(new NameAndPath(null, contentRoot.getPath()));
}
}
}
}

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));
return items;
})
.finishOnUiThread(ModalityState.any(), items -> {
final Object selectedItem = myDartProjectCombo.getSelectedItem();
myComboItems.addAll(items);
myDartProjectCombo.setModel(new DefaultComboBoxModel<>(myComboItems.toArray(NameAndPath[]::new)));
if (selectedItem != null) {
myDartProjectCombo.setSelectedItem(selectedItem);
}
});
})
.submit(AppExecutorUtil.getAppExecutorService());
}

@Override
Expand All @@ -92,23 +101,34 @@ protected void resetEditorFrom(final @NotNull DartRemoteDebugConfiguration confi
private void setSelectedProjectPath(final @NotNull String projectPath) {
if (projectPath.isEmpty()) return;

ReadAction.nonBlocking(() -> resolveNameAndPath(projectPath))
.finishOnUiThread(ModalityState.any(), this::applySelectedProjectPath)
.submit(AppExecutorUtil.getAppExecutorService());
}

private @NotNull NameAndPath resolveNameAndPath(final @NotNull String projectPath) {
final VirtualFile pubspecFile = LocalFileSystem.getInstance().findFileByPath(projectPath + "/" + PUBSPEC_YAML);
final String projectName = pubspecFile == null ? null : PubspecYamlUtil.getDartProjectName(pubspecFile);
final NameAndPath item = new NameAndPath(projectName, projectPath);
return new NameAndPath(projectName, projectPath);
}

private void applySelectedProjectPath(final @NotNull NameAndPath item) {
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 == null ? "" : selectedItem.toString().trim());
}

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

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.jetbrains.lang.dart.ui.BasicComboBoxWithBrowseButton" 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
Loading
Loading