Search in sources :

Example 1 with FlutterDevice

use of io.flutter.run.daemon.FlutterDevice in project flutter-intellij by flutter.

the class ObservatoryActionGroup method addInspector.

private void addInspector(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) {
    final ContentManager contentManager = toolWindow.getContentManager();
    final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
    final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), null, this);
    final List<FlutterDevice> existingDevices = new ArrayList<>();
    for (FlutterApp otherApp : perAppViewState.keySet()) {
        existingDevices.add(otherApp.device());
    }
    final JPanel tabContainer = new JPanel(new BorderLayout());
    final Content content = contentManager.getFactory().createContent(null, app.device().getUniqueName(existingDevices), 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);
    final PerAppState state = getOrCreateStateForApp(app);
    assert (state.content == null);
    state.content = content;
    final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, runnerTabs);
    toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent());
    // If the inspector is available (non-profile mode), then show it.
    if (inspectorService != null) {
        addInspectorPanel("Widgets", runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow, toolbarGroup, true);
        addInspectorPanel("Render Tree", runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService, toolWindow, toolbarGroup, false);
    } else {
        toolbarGroup.add(new OverflowAction(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);
        // Add a message about the inspector not being available in profile mode.
        final JBLabel label = new JBLabel("Widget info not available in profile mode", SwingConstants.CENTER);
        label.setForeground(UIUtil.getLabelDisabledForeground());
        tabContainer.add(label, BorderLayout.CENTER);
    }
    final boolean isVertical = !toolWindow.getAnchor().isHorizontal();
    if (isVertical) {
        final JPanel dashboardsPanel = new JPanel(new BorderLayout());
        tabContainer.add(dashboardsPanel, BorderLayout.SOUTH);
        if (FlutterSettings.getInstance().isShowHeapDisplay()) {
            dashboardsPanel.add(FPSDisplay.createJPanelView(runnerTabs, app), BorderLayout.NORTH);
            dashboardsPanel.add(HeapDisplay.createJPanelView(runnerTabs, app), BorderLayout.SOUTH);
        }
    }
}
Also used : FlutterApp(io.flutter.run.daemon.FlutterApp) ContentManager(com.intellij.ui.content.ContentManager) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) FlutterDevice(io.flutter.run.daemon.FlutterDevice) JBRunnerTabs(com.intellij.execution.ui.layout.impl.JBRunnerTabs) JBLabel(com.intellij.ui.components.JBLabel) Content(com.intellij.ui.content.Content)

Example 2 with FlutterDevice

use of io.flutter.run.daemon.FlutterDevice in project flutter-intellij by flutter.

the class DeviceSelectorAction method updateActions.

private void updateActions(@NotNull Project project, Presentation presentation) {
    actions.clear();
    final DeviceService service = DeviceService.getInstance(project);
    final Collection<FlutterDevice> devices = service.getConnectedDevices();
    for (FlutterDevice device : devices) {
        actions.add(new SelectDeviceAction(device, devices));
    }
    if (actions.isEmpty()) {
        final boolean isLoading = service.getStatus() == DeviceService.State.LOADING;
        final String message = isLoading ? FlutterBundle.message("devicelist.loading") : FlutterBundle.message("devicelist.empty");
        actions.add(new NoDevicesAction(message));
    }
    // Show the 'Open iOS Simulator' action.
    if (SystemInfo.isMac) {
        boolean simulatorOpen = false;
        for (AnAction action : actions) {
            if (action instanceof SelectDeviceAction) {
                final SelectDeviceAction deviceAction = (SelectDeviceAction) action;
                final FlutterDevice device = deviceAction.device;
                if (device.isIOS() && device.emulator()) {
                    simulatorOpen = true;
                }
            }
        }
        actions.add(new Separator());
        actions.add(new OpenSimulatorAction(!simulatorOpen));
    }
    // Add Open Android emulators actions.
    final List<OpenEmulatorAction> emulatorActions = OpenEmulatorAction.getEmulatorActions(project);
    if (!emulatorActions.isEmpty()) {
        actions.add(new Separator());
        actions.addAll(emulatorActions);
    }
    selectedDeviceAction = null;
    final FlutterDevice selectedDevice = service.getSelectedDevice();
    for (AnAction action : actions) {
        if (action instanceof SelectDeviceAction) {
            final SelectDeviceAction deviceAction = (SelectDeviceAction) action;
            if (Objects.equals(deviceAction.device, selectedDevice)) {
                selectedDeviceAction = deviceAction;
                final Presentation template = action.getTemplatePresentation();
                presentation.setIcon(template.getIcon());
                presentation.setText(deviceAction.deviceName());
                presentation.setEnabled(true);
                return;
            }
        }
    }
    if (devices.isEmpty()) {
        presentation.setText("<no devices>");
    } else {
        presentation.setText(null);
    }
}
Also used : DeviceService(io.flutter.run.daemon.DeviceService) FlutterDevice(io.flutter.run.daemon.FlutterDevice)

Example 3 with FlutterDevice

use of io.flutter.run.daemon.FlutterDevice in project flutter-intellij by flutter.

the class FlutterReloadManager method saveAllAndRestart.

public void saveAllAndRestart(@NotNull FlutterApp app) {
    if (app.isStarted()) {
        FileDocumentManager.getInstance().saveAllDocuments();
        app.performRestartApp().thenAccept(result -> {
            if (!result.ok()) {
                showRunNotification(app, "Full Restart", result.getMessage(), true);
            }
        });
        final FlutterDevice device = DeviceService.getInstance(myProject).getSelectedDevice();
        if (device != null) {
            device.bringToFront();
        }
    }
}
Also used : FlutterDevice(io.flutter.run.daemon.FlutterDevice)

Aggregations

FlutterDevice (io.flutter.run.daemon.FlutterDevice)3 JBRunnerTabs (com.intellij.execution.ui.layout.impl.JBRunnerTabs)1 SimpleToolWindowPanel (com.intellij.openapi.ui.SimpleToolWindowPanel)1 JBLabel (com.intellij.ui.components.JBLabel)1 Content (com.intellij.ui.content.Content)1 ContentManager (com.intellij.ui.content.ContentManager)1 DeviceService (io.flutter.run.daemon.DeviceService)1 FlutterApp (io.flutter.run.daemon.FlutterApp)1