Search in sources :

Example 1 with FlutterRunConfigurationType

use of io.flutter.run.FlutterRunConfigurationType in project flutter-intellij by flutter.

the class FlutterModuleUtils method ensureRunConfigSelected.

/**
 * Ensures a Flutter run configuration is selected in the run pull down.
 */
public static void ensureRunConfigSelected(@NotNull Project project) {
    if (project.isDisposed())
        return;
    final FlutterRunConfigurationType configType = FlutterRunConfigurationType.getInstance();
    final RunManager runManager = RunManager.getInstance(project);
    if (!runManager.getConfigurationsList(configType).isEmpty()) {
        if (runManager.getSelectedConfiguration() == null) {
            final List<RunnerAndConfigurationSettings> flutterConfigs = runManager.getConfigurationSettingsList(configType);
            if (!flutterConfigs.isEmpty()) {
                runManager.setSelectedConfiguration(flutterConfigs.get(0));
            }
        }
    }
}
Also used : RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RunManager(com.intellij.execution.RunManager) FlutterRunConfigurationType(io.flutter.run.FlutterRunConfigurationType)

Example 2 with FlutterRunConfigurationType

use of io.flutter.run.FlutterRunConfigurationType in project flutter-intellij by flutter.

the class FlutterModuleUtils method autoCreateRunConfig.

/**
 * Creates a Flutter run configuration if none exists.
 */
public static void autoCreateRunConfig(@NotNull Project project, @NotNull PubRoot root) {
    assert ApplicationManager.getApplication().isReadAccessAllowed();
    if (project.isDisposed())
        return;
    VirtualFile main = root.getLibMain();
    if (main == null || !main.exists()) {
        // Check for example main.dart in plugins
        main = root.getExampleLibMain();
        if (main == null || !main.exists()) {
            return;
        }
    }
    final FlutterRunConfigurationType configType = FlutterRunConfigurationType.getInstance();
    final RunManager runManager = RunManager.getInstance(project);
    if (!runManager.getConfigurationsList(configType).isEmpty()) {
        // Don't create a run config if one already exists.
        return;
    }
    final RunnerAndConfigurationSettings settings = runManager.createConfiguration(project.getName(), configType.getFactory());
    final SdkRunConfig config = (SdkRunConfig) settings.getConfiguration();
    // Set config name.
    config.setName("main.dart");
    // Set fields.
    final SdkFields fields = new SdkFields();
    fields.setFilePath(main.getPath());
    config.setFields(fields);
    runManager.addConfiguration(settings);
    runManager.setSelectedConfiguration(settings);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkRunConfig(io.flutter.run.SdkRunConfig) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) SdkFields(io.flutter.run.SdkFields) RunManager(com.intellij.execution.RunManager) FlutterRunConfigurationType(io.flutter.run.FlutterRunConfigurationType)

Aggregations

RunManager (com.intellij.execution.RunManager)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 FlutterRunConfigurationType (io.flutter.run.FlutterRunConfigurationType)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 SdkFields (io.flutter.run.SdkFields)1 SdkRunConfig (io.flutter.run.SdkRunConfig)1