Search in sources :

Example 1 with DuplexConsoleView

use of com.intellij.execution.console.DuplexConsoleView in project intellij-community by JetBrains.

the class DuplexConsoleActionsTest method testMergedClear.

public void testMergedClear() {
    final ConsoleViewImpl console1 = ConsoleViewImplTest.createConsole();
    final ConsoleViewImpl console2 = ConsoleViewImplTest.createConsole();
    final DuplexConsoleView<ConsoleViewImpl, ConsoleViewImpl> duplexConsoleView = new DuplexConsoleView<>(console1, console2);
    Disposer.register(myDisposable, duplexConsoleView);
    final AnAction clearAction = findAction(duplexConsoleView.createConsoleActions(), "Clear");
    assertNotNull(clearAction);
    console1.print("FooBar", ConsoleViewContentType.NORMAL_OUTPUT);
    console2.print("BazFoo", ConsoleViewContentType.NORMAL_OUTPUT);
    console1.flushDeferredText();
    console2.flushDeferredText();
    clearAction.actionPerformed(AnActionEvent.createFromAnAction(clearAction, null, ActionPlaces.EDITOR_TOOLBAR, DataContext.EMPTY_CONTEXT));
    console1.waitAllRequests();
    console2.waitAllRequests();
    assertEquals(0, console1.getContentSize());
    assertEquals(0, console2.getContentSize());
}
Also used : DuplexConsoleView(com.intellij.execution.console.DuplexConsoleView) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 2 with DuplexConsoleView

use of com.intellij.execution.console.DuplexConsoleView in project intellij-community by JetBrains.

the class GradleRunnerUtil method attachTaskExecutionView.

public static DuplexConsoleView attachTaskExecutionView(@NotNull final Project project, @NotNull final ConsoleView consoleView, final boolean isTaskConsoleEnabledByDefault, @Nullable final String stateStorageKey, @NotNull final ProcessHandler processHandler, @NotNull final ExternalSystemTaskId taskId) {
    final String tripleStateStorageKey = stateStorageKey != null ? stateStorageKey + "_str" : null;
    if (stateStorageKey != null && isTaskConsoleEnabledByDefault && !PropertiesComponent.getInstance().isValueSet(tripleStateStorageKey)) {
        PropertiesComponent.getInstance().setValue(tripleStateStorageKey, Boolean.TRUE.toString());
        PropertiesComponent.getInstance().setValue(stateStorageKey, Boolean.TRUE);
    }
    final TaskExecutionView gradleExecutionConsole = new TaskExecutionView(project);
    final Ref<DuplexConsoleView> duplexConsoleViewRef = Ref.create();
    final DuplexConsoleView duplexConsoleView = new DuplexConsoleView<ConsoleView, ConsoleView>(gradleExecutionConsole, consoleView, stateStorageKey) {

        @Override
        public void enableConsole(boolean primary) {
            super.enableConsole(primary);
            if (stateStorageKey != null) {
                PropertiesComponent.getInstance().setValue(tripleStateStorageKey, Boolean.toString(primary));
            }
        }

        @NotNull
        @Override
        public AnAction[] createConsoleActions() {
            final DefaultActionGroup textActionGroup = new DefaultActionGroup() {

                @Override
                public void update(AnActionEvent e) {
                    super.update(e);
                    if (duplexConsoleViewRef.get() != null) {
                        e.getPresentation().setVisible(!duplexConsoleViewRef.get().isPrimaryConsoleEnabled());
                    }
                }
            };
            final AnAction[] consoleActions = consoleView.createConsoleActions();
            for (AnAction anAction : consoleActions) {
                textActionGroup.add(anAction);
            }
            final List<AnAction> anActions = ContainerUtil.newArrayList(super.createConsoleActions());
            anActions.add(textActionGroup);
            return ArrayUtil.toObjectArray(anActions, AnAction.class);
        }
    };
    duplexConsoleViewRef.set(duplexConsoleView);
    duplexConsoleView.setDisableSwitchConsoleActionOnProcessEnd(false);
    duplexConsoleView.getSwitchConsoleActionPresentation().setIcon(AllIcons.Actions.ChangeView);
    duplexConsoleView.getSwitchConsoleActionPresentation().setText(GradleBundle.message("gradle.runner.toggle.tree.text.action.name"));
    final ExternalSystemProgressNotificationManager progressManager = ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
    final ExternalSystemTaskNotificationListenerAdapter taskListener = new ExternalSystemTaskNotificationListenerAdapter() {

        @Override
        public void onStatusChange(@NotNull final ExternalSystemTaskNotificationEvent event) {
            if (event instanceof ExternalSystemTaskExecutionEvent) {
                UIUtil.invokeLaterIfNeeded(() -> {
                    if (((ExternalSystemTaskExecutionEvent) event).getProgressEvent() instanceof ExternalSystemProgressEventUnsupported) {
                        duplexConsoleView.enableConsole(false);
                    }
                    gradleExecutionConsole.onStatusChange((ExternalSystemTaskExecutionEvent) event);
                });
            }
        }

        @Override
        public void onQueued(@NotNull ExternalSystemTaskId id, final String workingDir) {
            UIUtil.invokeLaterIfNeeded(() -> gradleExecutionConsole.setWorkingDir(workingDir));
        }

        @Override
        public void onFailure(@NotNull ExternalSystemTaskId id, @NotNull final Exception e) {
            UIUtil.invokeLaterIfNeeded(() -> gradleExecutionConsole.onFailure(e));
        }

        @Override
        public void onEnd(@NotNull ExternalSystemTaskId id) {
            progressManager.removeNotificationListener(this);
        }
    };
    progressManager.addNotificationListener(taskId, taskListener);
    return duplexConsoleView;
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemProgressNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager) ExternalSystemTaskNotificationEvent(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent) DuplexConsoleView(com.intellij.execution.console.DuplexConsoleView)

Aggregations

DuplexConsoleView (com.intellij.execution.console.DuplexConsoleView)2 AnAction (com.intellij.openapi.actionSystem.AnAction)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)1 ExternalSystemTaskNotificationEvent (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent)1 ExternalSystemTaskNotificationListenerAdapter (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter)1 ExternalSystemProgressNotificationManager (com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager)1 NotNull (org.jetbrains.annotations.NotNull)1