Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Property Editor] Add Property Editor as a side panel #7958

Merged
merged 1 commit into from
Mar 5, 2025
Merged
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
1 change: 1 addition & 0 deletions flutter-idea/src/icons/FlutterIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private static Icon load(String path) {
public static final Icon DevTools = load("/icons/expui/devTools.svg");
public static final Icon DevToolsExtensions = load("/icons/expui/extensions.svg");
public static final Icon DevToolsInspector = load("icons/expui/inspector.svg");
public static final Icon PropertyEditor = load("/icons/expui/propertyEditor.svg");

public static final Icon Flutter_13_2x = load("/icons/[email protected]");
public static final Icon Flutter_64 = load("/icons/flutter_64.png");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2025 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package io.flutter.propertyeditor;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import io.flutter.FlutterUtils;
import io.flutter.actions.RefreshToolWindowAction;
import io.flutter.bazel.WorkspaceCache;
import io.flutter.devtools.DevToolsIdeFeature;
import io.flutter.devtools.DevToolsUrl;
import io.flutter.run.daemon.DevToolsService;
import io.flutter.sdk.FlutterSdk;
import io.flutter.sdk.FlutterSdkVersion;
import io.flutter.utils.AsyncUtils;
import kotlin.coroutines.Continuation;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;

public class PropertyEditorViewFactory implements ToolWindowFactory {
@NotNull private static String TOOL_WINDOW_ID = "Flutter Property Editor";

@Override
public Object isApplicableAsync(@NotNull Project project, @NotNull Continuation<? super Boolean> $completion) {
FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
FlutterSdkVersion sdkVersion = sdk == null ? null : sdk.getVersion();
return sdkVersion != null && sdkVersion.canUsePropertyEditor();
}

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
FlutterSdkVersion sdkVersion = sdk == null ? null : sdk.getVersion();

AsyncUtils.whenCompleteUiThread(
DevToolsService.getInstance(project).getDevToolsInstance(),
(instance, error) -> {
// Skip displaying if the project has been closed.
if (!project.isOpen()) {
return;
}

if (error != null) {
return;
}

if (instance == null) {
return;
}

final DevToolsUrl devToolsUrl = new DevToolsUrl.Builder()
.setDevToolsHost(instance.host())
.setDevToolsPort(instance.port())
.setPage("propertyEditor")
.setEmbed(true)
.setFlutterSdkVersion(sdkVersion)
.setWorkspaceCache(WorkspaceCache.getInstance(project))
.setIdeFeature(DevToolsIdeFeature.TOOL_WINDOW)
.build();

ApplicationManager.getApplication().invokeLater(() -> {
Optional.ofNullable(
FlutterUtils.embeddedBrowser(project))
.ifPresent(embeddedBrowser -> embeddedBrowser.openPanel(toolWindow, "Property Editor", devToolsUrl, System.out::println));
});
}
);

toolWindow.setTitleActions(List.of(new RefreshToolWindowAction(TOOL_WINDOW_ID)));
}
}
7 changes: 7 additions & 0 deletions flutter-idea/src/io/flutter/sdk/FlutterSdkVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public final class FlutterSdkVersion implements Comparable<FlutterSdkVersion> {
@NotNull
private static final FlutterSdkVersion MIN_SUPPORTS_DTD = new FlutterSdkVersion("3.22.0");

@NotNull
private static final FlutterSdkVersion MIN_SUPPORTS_PROPERTY_EDITOR = new FlutterSdkVersion("3.29.0");

@Nullable
private final Version version;
@Nullable
Expand Down Expand Up @@ -127,6 +130,10 @@ public boolean canUseDeepLinksTool() {
return supportsVersion(MIN_SUPPORTS_DEEP_LINKS_TOOL);
}

public boolean canUsePropertyEditor() {
return supportsVersion(MIN_SUPPORTS_PROPERTY_EDITOR);
}

public boolean canUseDevToolsMultiEmbed() {
return supportsVersion(MIN_SUPPORTS_DEVTOOLS_MULTI_EMBED);
}
Expand Down
2 changes: 2 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@
<toolWindow id="Flutter Inspector" anchor="right" icon="FlutterIcons.DevToolsInspector"
factoryClass="io.flutter.view.FlutterViewFactory"/>
<projectService serviceImplementation="io.flutter.view.FlutterView" overrides="false"/>
<!-- Do not uncomment until ready to release the Property Editor. -->
<!-- <toolWindow id="Flutter Property Editor" anchor="right" icon="FlutterIcons.PropertyEditor" factoryClass="io.flutter.propertyeditor.PropertyEditorViewFactory" /> -->
<toolWindow id="Flutter Deep Links" anchor="right" icon="FlutterIcons.DevToolsDeepLinks" factoryClass="io.flutter.deeplinks.DeepLinksViewFactory" />
<toolWindow id="Flutter DevTools" anchor="right" icon="FlutterIcons.DevTools" factoryClass="io.flutter.devtools.RemainingDevToolsViewFactory" />
<toolWindow id="Flutter DevTools Extensions" anchor="right" icon="FlutterIcons.DevToolsExtensions" factoryClass="io.flutter.devtools.DevToolsExtensionsViewFactory" />
Expand Down
2 changes: 2 additions & 0 deletions resources/META-INF/plugin_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@
<toolWindow id="Flutter Inspector" anchor="right" icon="FlutterIcons.DevToolsInspector"
factoryClass="io.flutter.view.FlutterViewFactory"/>
<projectService serviceImplementation="io.flutter.view.FlutterView" overrides="false"/>
<!-- Do not uncomment until ready to release the Property Editor. -->
<!-- <toolWindow id="Flutter Property Editor" anchor="right" icon="FlutterIcons.PropertyEditor" factoryClass="io.flutter.propertyeditor.PropertyEditorViewFactory" /> -->
<toolWindow id="Flutter Deep Links" anchor="right" icon="FlutterIcons.DevToolsDeepLinks" factoryClass="io.flutter.deeplinks.DeepLinksViewFactory" />
<toolWindow id="Flutter DevTools" anchor="right" icon="FlutterIcons.DevTools" factoryClass="io.flutter.devtools.RemainingDevToolsViewFactory" />
<toolWindow id="Flutter DevTools Extensions" anchor="right" icon="FlutterIcons.DevToolsExtensions" factoryClass="io.flutter.devtools.DevToolsExtensionsViewFactory" />
Expand Down
6 changes: 6 additions & 0 deletions resources/icons/expui/propertyEditor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions resources/icons/expui/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions resources/icons/expui/propertyEditor@20x20_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions resources/icons/expui/propertyEditor_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.