Is it possible to detect when the Console window is closed / minimized

IntelliJ 13.x - Is it possible to be notified and/or detect when the run/debug console window is closed and/or minimized? If so, how?

Regards

Nick

5 comments
Comment actions Permalink

I found something to detect closure:

          Disposer.register(console, new Disposable() {                @Override                public void dispose() {                                     }           });

0
Comment actions Permalink

I have a related question, how to open a tool window with the right console, when you have only a reference to the console?

0
Comment actions Permalink

Found it:

private void activate(ConsoleViewImpl consoleViewImpl) {      final Project project = consoleViewImpl.getProject();      final RunContentManager runContentManager = ExecutionManager.getInstance(project).getContentManager();      for (RunContentDescriptor descriptor : runContentManager.getAllDescriptors()) {           final ExecutionConsole executionConsole = descriptor.getExecutionConsole();           if (executionConsole == consoleViewImpl) {                final ToolWindow toolWindowByDescriptor = runContentManager.getToolWindowByDescriptor(descriptor);                if (toolWindowByDescriptor != null) {                     final ContentManager contentManager = toolWindowByDescriptor.getContentManager();                     toolWindowByDescriptor.activate(null);                     contentManager.setSelectedContent(descriptor.getAttachedContent(), true);                     return;                }           }      } }

0
Comment actions Permalink

Of course it will not work for JUnit and other types of executions, I need to find out where to get ExecutionId so I can match it to RunContentDescriptor#getExecutionId...

0
Comment actions Permalink

Found it again :D

          final MessageBusConnection conn = project.getMessageBus().connect();           conn.subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionAdapter() {                @Override                public void processStarting(String executorId, @NotNull ExecutionEnvironment env) {                     long executionId = env.getExecutionId();                }           });


Then I can bring the right tool window with the right tab on the foreground:

     private void activate(Project project, long executionId) {           final RunContentManager runContentManager = ExecutionManager.getInstance(project).getContentManager();           for (RunContentDescriptor descriptor : runContentManager.getAllDescriptors()) {                if (descriptor.getExecutionId() == executionId) {                     final ToolWindow toolWindowByDescriptor = runContentManager.getToolWindowByDescriptor(descriptor);                     if (toolWindowByDescriptor != null) {                          final ContentManager contentManager = toolWindowByDescriptor.getContentManager();                          toolWindowByDescriptor.activate(null);                          contentManager.setSelectedContent(descriptor.getAttachedContent(), true);                          return;                     }                }           }      }

0

Please sign in to leave a comment.