/*
 * Copyright 2017 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.view;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.openapi.wm.ToolWindowManager;
import org.jetbrains.annotations.NotNull;

public class FlutterViewFactory implements ToolWindowFactory {
  public static void init(@NotNull Project project) {
    //noinspection CodeBlock2Expr
    project.getMessageBus().connect().subscribe(
      FlutterViewMessages.FLUTTER_DEBUG_TOPIC, (event) -> {
        openFlutterView(project, event);
      });
  }

  private static void openFlutterView(@NotNull Project project, FlutterViewMessages.FlutterDebugEvent event) {
    ApplicationManager.getApplication().invokeLater(() -> {
      final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Flutter");
      toolWindow.show(() -> {
        final FlutterView flutterView = ServiceManager.getService(project, FlutterView.class);
        flutterView.debugActive(event);
      });
    });
  }

  @Override
  public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    //noinspection CodeBlock2Expr
    DumbService.getInstance(project).runWhenSmart(() -> {
      (ServiceManager.getService(project, FlutterView.class)).initToolWindow(toolWindow);
    });
  }
}

@@ -699,24 +699,69 @@
  project) %7B%0A
+    //TODO: re-enable after UI review (#691)%0A
     //noinsp
@@ -786,16 +786,18 @@
 xpr%0A    
+//
 project.
@@ -837,16 +837,18 @@
 be(%0A    
+//
   Flutte
@@ -895,24 +895,26 @@
 t) -%3E %7B%0A    
+//
     openFlut
@@ -934,32 +934,34 @@
 ct, event);%0A    
+//
   %7D);%0A  %7D%0A%0A  pri

Disable auto-enable of the Flutter View (#691). (#693)