diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index dc5fc5b0f9..0365d8cc8a 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -1565,6 +1565,14 @@
topic="com.intellij.openapi.project.ProjectManagerListener"/>
+
+
+
+
+
+
diff --git a/resources/META-INF/plugin_template.xml b/resources/META-INF/plugin_template.xml
index 0e89a2897d..eaf1b8f8a6 100644
--- a/resources/META-INF/plugin_template.xml
+++ b/resources/META-INF/plugin_template.xml
@@ -246,6 +246,14 @@
topic="com.intellij.openapi.project.ProjectManagerListener"/>
+
+
+
+
+
+
diff --git a/src/io/flutter/performance/FlutterPerformanceViewFactory.java b/src/io/flutter/performance/FlutterPerformanceViewFactory.java
index fd488b01d5..41c77d1b42 100644
--- a/src/io/flutter/performance/FlutterPerformanceViewFactory.java
+++ b/src/io/flutter/performance/FlutterPerformanceViewFactory.java
@@ -5,6 +5,7 @@
*/
package io.flutter.performance;
+import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.DumbAware;
@@ -13,10 +14,13 @@
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.openapi.wm.ToolWindowManager;
+import io.flutter.utils.ViewListener;
import io.flutter.view.FlutterViewMessages;
import org.jetbrains.annotations.NotNull;
public class FlutterPerformanceViewFactory implements ToolWindowFactory, DumbAware {
+ private static final String TOOL_WINDOW_VISIBLE_PROPERTY = "flutter.performance.tool.window.visible";
+
public static void init(@NotNull Project project) {
project.getMessageBus().connect().subscribe(
FlutterViewMessages.FLUTTER_DEBUG_TOPIC, (event) -> initPerfView(project, event)
@@ -24,6 +28,10 @@ public static void init(@NotNull Project project) {
final ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(FlutterPerformanceView.TOOL_WINDOW_ID);
if (window != null) {
window.setAvailable(true);
+
+ if (PropertiesComponent.getInstance(project).getBoolean(TOOL_WINDOW_VISIBLE_PROPERTY, false)) {
+ window.activate(null, false);
+ }
}
}
@@ -47,4 +55,10 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
public boolean shouldBeAvailable(@NotNull Project project) {
return false;
}
+
+ public static class FlutterPerformanceViewListener extends ViewListener {
+ public FlutterPerformanceViewListener(@NotNull Project project) {
+ super(project, FlutterPerformanceView.TOOL_WINDOW_ID, TOOL_WINDOW_VISIBLE_PROPERTY);
+ }
+ }
}
diff --git a/src/io/flutter/preview/PreviewViewFactory.java b/src/io/flutter/preview/PreviewViewFactory.java
index 1a8e591487..7777c916bb 100644
--- a/src/io/flutter/preview/PreviewViewFactory.java
+++ b/src/io/flutter/preview/PreviewViewFactory.java
@@ -5,6 +5,7 @@
*/
package io.flutter.preview;
+import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.DumbService;
@@ -12,13 +13,22 @@
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.openapi.wm.ToolWindowManager;
+import com.intellij.openapi.wm.ex.ToolWindowManagerListener;
+import io.flutter.performance.FlutterPerformanceView;
+import io.flutter.utils.ViewListener;
import org.jetbrains.annotations.NotNull;
public class PreviewViewFactory implements ToolWindowFactory, DumbAware {
+ private static final String TOOL_WINDOW_VISIBLE_PROPERTY = "flutter.preview.tool.window.visible";
+
public static void init(@NotNull Project project) {
final ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(PreviewView.TOOL_WINDOW_ID);
if (window != null) {
window.setAvailable(true);
+
+ if (PropertiesComponent.getInstance(project).getBoolean(TOOL_WINDOW_VISIBLE_PROPERTY, false)) {
+ window.activate(null, false);
+ }
}
}
@@ -34,4 +44,10 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
public boolean shouldBeAvailable(@NotNull Project project) {
return false;
}
+
+ public static class PreviewViewListener extends ViewListener {
+ public PreviewViewListener(@NotNull Project project) {
+ super(project, PreviewView.TOOL_WINDOW_ID, TOOL_WINDOW_VISIBLE_PROPERTY);
+ }
+ }
}
diff --git a/src/io/flutter/utils/ViewListener.java b/src/io/flutter/utils/ViewListener.java
new file mode 100644
index 0000000000..a286d37781
--- /dev/null
+++ b/src/io/flutter/utils/ViewListener.java
@@ -0,0 +1,32 @@
+package io.flutter.utils;
+
+import com.intellij.ide.util.PropertiesComponent;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.wm.ToolWindow;
+import com.intellij.openapi.wm.ToolWindowManager;
+import com.intellij.openapi.wm.ex.ToolWindowManagerListener;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Helps to initialize a tool window with the same visibility state as when the project was previously closed.
+ */
+public abstract class ViewListener implements ToolWindowManagerListener {
+ private final @NotNull Project project;
+ private final String toolWindowId;
+ private final String toolWindowVisibleProperty;
+
+ public ViewListener(@NotNull Project project, String toolWindowId, String toolWindowVisibleProperty) {
+ this.project = project;
+ this.toolWindowId = toolWindowId;
+ this.toolWindowVisibleProperty = toolWindowVisibleProperty;
+ }
+
+ @Override
+ public void stateChanged(@NotNull ToolWindowManager toolWindowManager) {
+ ToolWindow toolWindow = toolWindowManager.getToolWindow(toolWindowId);
+ // We only make tool windows available once we've found a Flutter project, so we want to avoid setting the visible property until then.
+ if (toolWindow != null && toolWindow.isAvailable()) {
+ PropertiesComponent.getInstance(project).setValue(toolWindowVisibleProperty, toolWindow.isVisible(), false);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/io/flutter/view/FlutterViewFactory.java b/src/io/flutter/view/FlutterViewFactory.java
index 0710d9ef83..b2cf114aed 100644
--- a/src/io/flutter/view/FlutterViewFactory.java
+++ b/src/io/flutter/view/FlutterViewFactory.java
@@ -5,6 +5,7 @@
*/
package io.flutter.view;
+import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.DumbAware;
@@ -13,9 +14,12 @@
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.openapi.wm.ToolWindowManager;
+import io.flutter.utils.ViewListener;
import org.jetbrains.annotations.NotNull;
public class FlutterViewFactory implements ToolWindowFactory, DumbAware {
+ private static final String TOOL_WINDOW_VISIBLE_PROPERTY = "flutter.view.tool.window.visible";
+
public static void init(@NotNull Project project) {
project.getMessageBus().connect().subscribe(
FlutterViewMessages.FLUTTER_DEBUG_TOPIC, (event) -> initFlutterView(project, event)
@@ -24,6 +28,10 @@ public static void init(@NotNull Project project) {
final ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(FlutterView.TOOL_WINDOW_ID);
if (window != null) {
window.setAvailable(true);
+
+ if (PropertiesComponent.getInstance(project).getBoolean(TOOL_WINDOW_VISIBLE_PROPERTY, false)) {
+ window.activate(null, false);
+ }
}
}
@@ -46,4 +54,10 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
(ServiceManager.getService(project, FlutterView.class)).initToolWindow(toolWindow);
});
}
+
+ public static class FlutterViewListener extends ViewListener {
+ public FlutterViewListener(@NotNull Project project) {
+ super(project, FlutterView.TOOL_WINDOW_ID, TOOL_WINDOW_VISIBLE_PROPERTY);
+ }
+ }
}