Search in sources :

Example 11 with ConsoleViewImpl

use of com.intellij.execution.impl.ConsoleViewImpl in project intellij-community by JetBrains.

the class GroovyConsole method createConsole.

@Nullable
public static GroovyConsole createConsole(@NotNull final Project project, @NotNull final VirtualFile contentFile, @NotNull Module module) {
    final ProcessHandler processHandler = createProcessHandler(module);
    if (processHandler == null)
        return null;
    final GroovyConsoleStateService consoleStateService = GroovyConsoleStateService.getInstance(project);
    consoleStateService.setFileModule(contentFile, module);
    final String title = consoleStateService.getSelectedModuleTitle(contentFile);
    final ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true);
    final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, processHandler, new JPanel(new BorderLayout()), title);
    final GroovyConsole console = new GroovyConsole(project, descriptor, consoleView, processHandler);
    // must call getComponent before createConsoleActions()
    final JComponent consoleViewComponent = consoleView.getComponent();
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    actionGroup.add(new BuildAndRestartConsoleAction(module, project, defaultExecutor, descriptor, restarter(project, contentFile)));
    actionGroup.addSeparator();
    actionGroup.addAll(consoleView.createConsoleActions());
    actionGroup.add(new CloseAction(defaultExecutor, descriptor, project) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            // use force
            processHandler.destroyProcess();
            super.actionPerformed(e);
        }
    });
    final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, false);
    toolbar.setTargetComponent(consoleViewComponent);
    final JComponent ui = descriptor.getComponent();
    ui.add(consoleViewComponent, BorderLayout.CENTER);
    ui.add(toolbar.getComponent(), BorderLayout.WEST);
    project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (file.equals(contentFile)) {
                // if file was closed then kill process and hide console content
                console.stop();
            }
        }
    });
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(ProcessEvent event) {
            if (contentFile.getUserData(GROOVY_CONSOLE) == console) {
                // process terminated either by closing file or by close action
                contentFile.putUserData(GROOVY_CONSOLE, null);
            }
        }
    });
    contentFile.putUserData(GROOVY_CONSOLE, console);
    consoleView.attachToProcess(processHandler);
    processHandler.startNotify();
    ExecutionManager.getInstance(project).getContentManager().showRunContent(defaultExecutor, descriptor);
    return console;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) CloseAction(com.intellij.execution.ui.actions.CloseAction) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with ConsoleViewImpl

use of com.intellij.execution.impl.ConsoleViewImpl in project intellij-community by JetBrains.

the class PyUnitTestTask method getHighlightedStrings.

/**
   * Gets highlighted information from test console. Some parts of output (like file links) may be highlighted, and you need to check them.
   *
   * @return pair of [[ranges], [texts]] where range is [from,to] in doc. for each region, and "text" is text extracted from this region.
   * For example assume that in document "spam eggs ham" words "ham" and "spam" are highlighted.
   * You should have 2 ranges (0, 4) and (10, 13) and 2 strings (spam and ham)
   */
@NotNull
public final Pair<List<Pair<Integer, Integer>>, List<String>> getHighlightedStrings() {
    final ConsoleView console = myConsoleView.getConsole();
    assert console instanceof ConsoleViewImpl : "Console has no editor!";
    final ConsoleViewImpl consoleView = (ConsoleViewImpl) console;
    final Editor editor = consoleView.getEditor();
    final List<String> resultStrings = new ArrayList<>();
    final List<Pair<Integer, Integer>> resultRanges = new ArrayList<>();
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            /**
         * To fetch data from console we need to flush it first.
         * It works locally, but does not work on TC (reasons are not clear yet and need to be investigated).
         * So, we flush it explicitly to make test run on TC.
         */
            consoleView.flushDeferredText();
            for (final RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
                if (highlighter instanceof RangeHighlighterEx) {
                    final int start = ((RangeHighlighterEx) highlighter).getAffectedAreaStartOffset();
                    final int end = ((RangeHighlighterEx) highlighter).getAffectedAreaEndOffset();
                    resultRanges.add(Pair.create(start, end));
                    resultStrings.add(editor.getDocument().getText().substring(start, end));
                }
            }
        }
    });
    final String message = String.format("Following output is searched for hightlighed strings: %s \n", editor.getDocument().getText());
    Logger.getInstance(getClass()).warn(message);
    return Pair.create(resultRanges, resultStrings);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) ConsoleView(com.intellij.execution.ui.ConsoleView) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ConsoleViewImpl (com.intellij.execution.impl.ConsoleViewImpl)12 ConsoleView (com.intellij.execution.ui.ConsoleView)5 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)4 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)3 Executor (com.intellij.execution.Executor)2 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)2 CloseAction (com.intellij.execution.ui.actions.CloseAction)2 Editor (com.intellij.openapi.editor.Editor)2 NotNull (org.jetbrains.annotations.NotNull)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 RemoteDebugProcessHandler (com.intellij.debugger.engine.RemoteDebugProcessHandler)1 GenericDebuggerRunner (com.intellij.debugger.impl.GenericDebuggerRunner)1 GenericDebuggerRunnerSettings (com.intellij.debugger.impl.GenericDebuggerRunnerSettings)1 ExecutionException (com.intellij.execution.ExecutionException)1 ExecutionManager (com.intellij.execution.ExecutionManager)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 com.intellij.execution.configurations (com.intellij.execution.configurations)1 TextConsoleBuilder (com.intellij.execution.filters.TextConsoleBuilder)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1