|
| 1 | +/* |
| 2 | + * Copyright 2017 The Chromium Authors. All rights reserved. |
| 3 | + * Use of this source code is governed by a BSD-style license that can be |
| 4 | + * found in the LICENSE file. |
| 5 | + */ |
| 6 | +package io.flutter.actions |
| 7 | + |
| 8 | +import com.intellij.ide.impl.createNewProjectAsync |
| 9 | +import com.intellij.ide.projectWizard.NewProjectWizard |
| 10 | +import com.intellij.openapi.actionSystem.ActionUpdateThread |
| 11 | +import com.intellij.openapi.actionSystem.AnAction |
| 12 | +import com.intellij.openapi.actionSystem.AnActionEvent |
| 13 | +import com.intellij.openapi.application.EDT |
| 14 | +import com.intellij.openapi.project.DumbAware |
| 15 | +import com.intellij.openapi.roots.ui.configuration.ModulesProvider |
| 16 | +import com.intellij.openapi.wm.impl.welcomeScreen.NewWelcomeScreen |
| 17 | +import io.flutter.FlutterBundle |
| 18 | +import io.flutter.FlutterUtils |
| 19 | +import kotlinx.coroutines.DelicateCoroutinesApi |
| 20 | +import kotlinx.coroutines.Dispatchers |
| 21 | +import kotlinx.coroutines.GlobalScope |
| 22 | +import kotlinx.coroutines.launch |
| 23 | +import kotlinx.coroutines.withContext |
| 24 | + |
| 25 | +/** |
| 26 | + * This classes was re-implemented with Kotlin from FlutterNewProjectAction.java to resolve the New Flutter Project action from hanging, |
| 27 | + * https://github.com/flutter/flutter-intellij/issues/8310. |
| 28 | + * |
| 29 | + * See https://github.com/JetBrains/intellij-community/blob/master/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.kt |
| 30 | + */ |
| 31 | +class FlutterNewProjectAction : AnAction(FlutterBundle.message("action.new.project.title")), DumbAware { |
| 32 | + override fun update(e: AnActionEvent) { |
| 33 | + if (NewWelcomeScreen.isNewWelcomeScreen(e)) { |
| 34 | + e.presentation.setText(FlutterBundle.message("welcome.new.project.compact")) |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + @OptIn(DelicateCoroutinesApi::class) |
| 39 | + override fun actionPerformed(e: AnActionEvent) { |
| 40 | + if (FlutterUtils.isAndroidStudio()) { |
| 41 | + System.setProperty("studio.projectview", "true") |
| 42 | + } |
| 43 | + |
| 44 | + GlobalScope.launch { |
| 45 | + val wizard = withContext(Dispatchers.EDT) { |
| 46 | + NewProjectWizard(null, ModulesProvider.EMPTY_MODULES_PROVIDER, null) |
| 47 | + } |
| 48 | + createNewProjectAsync(wizard) |
| 49 | + } |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + override fun getActionUpdateThread() = ActionUpdateThread.BGT |
| 54 | +} |
0 commit comments