use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.
the class LabelInput method addInspectorViewContent.
private void addInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) {
final ContentManager contentManager = toolWindow.getContentManager();
final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
// TODO: Don't switch to JBRunnerTabs(Project, Disposable) until 2020.1.
final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.getInstance(myProject), this);
runnerTabs.setSelectionChangeHandler(this::onTabSelectionChange);
final JPanel tabContainer = new JPanel(new BorderLayout());
final String tabName;
final FlutterDevice device = app.device();
if (device == null) {
tabName = app.getProject().getName();
} else {
final List<FlutterDevice> existingDevices = new ArrayList<>();
for (FlutterApp otherApp : perAppViewState.keySet()) {
existingDevices.add(otherApp.device());
}
tabName = device.getUniqueName(existingDevices);
}
final Content content = contentManager.getFactory().createContent(null, tabName, false);
tabContainer.add(runnerTabs.getComponent(), BorderLayout.CENTER);
content.setComponent(tabContainer);
content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
content.setIcon(FlutterIcons.Phone);
contentManager.addContent(content);
if (emptyContent != null) {
contentManager.removeContent(emptyContent, true);
emptyContent = null;
}
contentManager.setSelectedContent(content);
final PerAppState state = getOrCreateStateForApp(app);
assert (state.content == null);
state.content = content;
final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, inspectorService);
toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent());
toolbarGroup.add(new OverflowAction(getOrCreateStateForApp(app), this, app));
final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("InspectorToolbar", toolbarGroup, true);
final JComponent toolbarComponent = toolbar.getComponent();
toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
tabContainer.add(toolbarComponent, BorderLayout.NORTH);
final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection();
final boolean hasInspectorService = inspectorService != null;
// If the inspector is available (non-release mode), then show it.
if (debugConnectionAvailable) {
if (hasInspectorService) {
final boolean detailsSummaryViewSupported = inspectorService.isDetailsSummaryViewSupported();
addInspectorPanel(WIDGET_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow, toolbarGroup, true, detailsSummaryViewSupported);
addInspectorPanel(RENDER_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService, toolWindow, toolbarGroup, false, false);
} else {
// If in profile mode, add disabled tabs for the inspector.
addDisabledTab(WIDGET_TAB_LABEL, runnerTabs, toolbarGroup);
addDisabledTab(RENDER_TAB_LABEL, runnerTabs, toolbarGroup);
}
} else {
// Add a message about the inspector not being available in release mode.
final JBLabel label = new JBLabel("Inspector not available in release mode", SwingConstants.CENTER);
label.setForeground(UIUtil.getLabelDisabledForeground());
tabContainer.add(label, BorderLayout.CENTER);
}
}
use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.
the class DeviceSelectorAction method update.
@Override
public void update(final AnActionEvent e) {
// Suppress device actions in all but the toolbars.
final String place = e.getPlace();
if (!Objects.equals(place, ActionPlaces.NAVIGATION_BAR_TOOLBAR) && !Objects.equals(place, ActionPlaces.MAIN_TOOLBAR)) {
e.getPresentation().setVisible(false);
return;
}
// Only show device menu when the device daemon process is running.
final Project project = e.getProject();
if (!isSelectorVisible(project)) {
e.getPresentation().setVisible(false);
return;
}
super.update(e);
final Presentation presentation = e.getPresentation();
if (!knownProjects.contains(project)) {
knownProjects.add(project);
final Application application = ApplicationManager.getApplication();
application.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
@Override
public void projectClosed(@NotNull Project closedProject) {
knownProjects.remove(closedProject);
}
});
deviceListener = () -> queueUpdate(project, e.getPresentation());
DeviceService.getInstance(project).addListener(deviceListener);
// Listen for android device changes, and rebuild the menu if necessary.
emulatorListener = () -> queueUpdate(project, e.getPresentation());
AndroidEmulatorManager.getInstance(project).addListener(emulatorListener);
ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerListener() {
public void projectClosing(@NotNull Project project) {
DeviceService.getInstance(project).removeListener(deviceListener);
AndroidEmulatorManager.getInstance(project).removeListener(emulatorListener);
}
});
update(project, presentation);
}
final DeviceService deviceService = DeviceService.getInstance(project);
final FlutterDevice selectedDevice = deviceService.getSelectedDevice();
final Collection<FlutterDevice> devices = deviceService.getConnectedDevices();
if (devices.isEmpty()) {
final boolean isLoading = deviceService.getStatus() == DeviceService.State.LOADING;
if (isLoading) {
presentation.setText(FlutterBundle.message("devicelist.loading"));
} else {
presentation.setText("<no devices>");
}
} else if (selectedDevice == null) {
presentation.setText("<no device selected>");
} else if (selectedDeviceAction != null) {
final Presentation template = selectedDeviceAction.getTemplatePresentation();
presentation.setIcon(template.getIcon());
presentation.setText(selectedDevice.presentationName());
presentation.setEnabled(true);
}
}
use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.
the class DeviceSelection method withDevices.
/**
* Returns a new snapshot with the devices changed and the selection updated appropriately.
*/
@NotNull
DeviceSelection withDevices(@NotNull List<FlutterDevice> newDevices) {
final String selectedId = selection == null ? null : selection.deviceId();
final Optional<FlutterDevice> selectedDevice = findById(newDevices, selectedId);
// If there's no selected device, default the first ephemoral one in the list.
final FlutterDevice firstEphemoral = newDevices.stream().filter(FlutterDevice::ephemeral).findFirst().orElse(null);
return new DeviceSelection(ImmutableList.copyOf(newDevices), selectedDevice.orElse(firstEphemoral));
}
use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.
the class BazelRunConfig method getState.
@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
final BazelFields launchFields = fields.copy();
try {
launchFields.checkRunnable(env.getProject());
} catch (RuntimeConfigurationError e) {
throw new ExecutionException(e);
}
final Workspace workspace = fields.getWorkspace(getProject());
final VirtualFile workspaceRoot = workspace.getRoot();
final RunMode mode = RunMode.fromEnv(env);
final Module module = ModuleUtil.findModuleForFile(workspaceRoot, env.getProject());
final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> {
if (device == null)
return null;
final GeneralCommandLine command = getCommand(env, device);
return FlutterApp.start(env, env.getProject(), module, mode, device, command, StringUtil.capitalize(mode.mode()) + "BazelApp", "StopBazelApp");
};
return new LaunchState(env, workspaceRoot, workspaceRoot, this, createAppCallback);
}
use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.
the class LaunchCommandsTest method producesCorrectCommandLineWithAdditionalArgs.
@Test
public void producesCorrectCommandLineWithAdditionalArgs() throws ExecutionException {
final BazelFields fields = setupBazelFields("bazel_target", null, "additional_args", false);
final FlutterDevice device = FlutterDevice.getTester();
final GeneralCommandLine launchCommand = fields.getLaunchCommand(projectFixture.getProject(), device, RunMode.RUN);
final List<String> expectedCommandLine = new ArrayList<>();
expectedCommandLine.add(platformize("/workspace/scripts/flutter-run.sh"));
expectedCommandLine.add("--machine");
expectedCommandLine.add("additional_args");
expectedCommandLine.add("-d");
expectedCommandLine.add("flutter-tester");
expectedCommandLine.add("--devtools-server-address=http://http://localhost:1234");
expectedCommandLine.add("bazel_target");
assertThat(launchCommand.getCommandLineList(null), equalTo(expectedCommandLine));
}
Aggregations