use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.
the class AttachDebuggerAction method update.
@Override
public void update(AnActionEvent e) {
final Project project = e.getProject();
if (project == null || project.isDefault()) {
super.update(e);
return;
}
if (!FlutterSdkUtil.hasFlutterModules(project)) {
// Hide this button in Android projects.
e.getPresentation().setVisible(false);
return;
}
RunConfiguration configuration = findRunConfig(project);
boolean enabled;
if (configuration == null) {
final RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project).getSelectedConfiguration();
if (settings == null) {
enabled = false;
} else {
configuration = settings.getConfiguration();
enabled = configuration instanceof SdkRunConfig;
}
} else {
enabled = true;
}
if (enabled && (project.getUserData(ATTACH_IS_ACTIVE) != null)) {
enabled = false;
}
e.getPresentation().setVisible(true);
e.getPresentation().setEnabled(enabled);
}
use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.
the class AttachDebuggerAction method findRunConfig.
@Nullable
public static RunConfiguration findRunConfig(Project project) {
// Look for a Flutter run config. If exactly one is found then return it otherwise return null.
final RunManagerEx mgr = RunManagerEx.getInstanceEx(project);
final List<RunConfiguration> configs = mgr.getAllConfigurationsList();
int count = 0;
RunConfiguration sdkConfig = null;
for (RunConfiguration config : configs) {
if (config instanceof SdkRunConfig) {
count += 1;
sdkConfig = config;
}
}
return count == 1 ? sdkConfig : null;
}
use of io.flutter.run.SdkRunConfig 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);
}
use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.
the class AttachDebuggerAction method startCommand.
@Override
public void startCommand(@NotNull Project project, @NotNull FlutterSdk sdk, @Nullable PubRoot root, @NotNull DataContext context) {
// NOTE: When making changes here, consider making similar changes to RunFlutterAction.
FlutterInitializer.sendAnalyticsAction(this);
RunConfiguration configuration = findRunConfig(project);
if (configuration == null) {
final RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project).getSelectedConfiguration();
if (settings == null) {
showSelectConfigDialog();
return;
}
configuration = settings.getConfiguration();
if (!(configuration instanceof SdkRunConfig)) {
if (project.isDefault() || !FlutterSdkUtil.hasFlutterModules(project)) {
return;
}
showSelectConfigDialog();
return;
}
}
final SdkAttachConfig sdkRunConfig = new SdkAttachConfig((SdkRunConfig) configuration);
final Executor executor = RunFlutterAction.getExecutor(ToolWindowId.DEBUG);
if (executor == null) {
return;
}
final ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(executor, sdkRunConfig);
final ExecutionEnvironment env = builder.activeTarget().dataContext(context).build();
FlutterLaunchMode.addToEnvironment(env, FlutterLaunchMode.DEBUG);
if (project.getUserData(ATTACH_IS_ACTIVE) == null) {
project.putUserData(ATTACH_IS_ACTIVE, ThreeState.fromBoolean(false));
onAttachTermination(project, (p) -> p.putUserData(ATTACH_IS_ACTIVE, null));
}
ProgramRunnerUtil.executeConfiguration(env, false, true);
}
use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.
the class RunFlutterAction method shouldEnable.
private static boolean shouldEnable(@Nullable AnActionEvent e) {
final RunnerAndConfigurationSettings settings = getRunConfigSettings(e);
final RunConfiguration config = settings == null ? null : settings.getConfiguration();
// TODO(pq): add support for Bazel.
return config instanceof SdkRunConfig && LaunchState.getRunningAppProcess((SdkRunConfig) config) == null;
}
Aggregations