Search in sources :

Example 1 with FlutterModuleBuilder

use of io.flutter.module.FlutterModuleBuilder in project flutter-intellij by flutter.

the class FlutterProjectCreator method createModule.

public void createModule() {
    Project project = myModel.project().getValue();
    VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null) {
        // Project was deleted.
        return;
    }
    String baseDirPath = baseDir.getPath();
    String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, myModel.projectName().get(), "");
    String contentRoot = baseDirPath + "/" + moduleName;
    File location = new File(contentRoot);
    if (!location.exists() && !location.mkdirs()) {
        String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.getAbsolutePath());
        Messages.showErrorDialog(project, message, ActionsBundle.message("action.NewDirectoryProject.title"));
        return;
    }
    // ModuleBuilder mixes UI and model code too much to easily reuse. We have to override a bunch of stuff to ensure
    // that methods which expect a live UI do not get called.
    FlutterModuleBuilder builder = new FlutterModuleBuilder() {

        @NotNull
        @Override
        public FlutterCreateAdditionalSettings getAdditionalSettings() {
            return makeAdditionalSettings();
        }

        @Override
        protected FlutterSdk getFlutterSdk() {
            return FlutterSdk.forPath(myModel.flutterSdk().get());
        }

        @Override
        public boolean validate(Project current, Project dest) {
            return true;
        }

        @Override
        public ModuleWizardStep getCustomOptionsStep(final WizardContext context, final Disposable parentDisposable) {
            return null;
        }

        @Override
        public void setFlutterSdkPath(String s) {
        }

        @Override
        public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep) {
            return null;
        }
    };
    builder.setName(myModel.projectName().get());
    builder.setModuleFilePath(toSystemIndependentName(contentRoot) + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
    builder.commitModule(project, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) SettingsStep(com.intellij.ide.util.projectWizard.SettingsStep) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) FlutterModuleBuilder(io.flutter.module.FlutterModuleBuilder)

Aggregations

SettingsStep (com.intellij.ide.util.projectWizard.SettingsStep)1 WizardContext (com.intellij.ide.util.projectWizard.WizardContext)1 Disposable (com.intellij.openapi.Disposable)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FlutterModuleBuilder (io.flutter.module.FlutterModuleBuilder)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1