How to close Run console tab/window programmatically?

Hi,

 

my plugin is implementing AbstractConsoleRunnerWithHistory to provide a "Run"-Tab. I can open and use it programmatically with

RConsoleRunner runner = new RConsoleRunner(project, project.getBasePath());
runner.initAndRun();

and this works pretty well. But is it possible to close it as well? My guess would be to go via `runner.getConsoleView().??`. but there's no obvious `quit()` or `hide()` method (or something similar).

Best regards,
Holger

 

0
5 comments
Avatar
Permanently deleted user

Pleas try ExecutionManager.getInstance(Project).getContentManager().removeRunContent(Executor, RunContentDescriptor)

0
Avatar
Permanently deleted user

Thanks Vassiliy. I've tried as suggested and managed to find the descriptor via

ExecutionManager executionManager = ExecutionManager.getInstance(project);
RunContentDescriptor descriptor = executionManager.getContentManager().getSelectedContent();

but I don't know how to get a the executor instance given my RConsoleRunner which extends 

AbstractConsoleRunnerWithHistory

I've tried

Set<Executor> executors = ((ExecutionManagerImpl) executionManager).getExecutors(descriptor);

but this Set seems always empty. How can I obtain the executor?

 

0
Avatar
Permanently deleted user

Actually AbstractConsoleRunnerWithHistory has getExecutor() method that returns DefaultRunExecutor.getRunExecutorInstance() if it's not overriden.

0
Avatar
Permanently deleted user

That method is protected that's why I missed it in the first place, but since I did not override it I could follow your 2nd suggestion. It works now,  and the window is nicely closing. Thanks for your kind help.

In case somebody else stumbles over this thread, and wants to see the full example see https://github.com/holgerbrandl/r4intellij/blob/master/src/com/r4intellij/inspections/InstallLibraryFix.java#L91

Best,
Holger

0
Avatar
Permanently deleted user

I'm trying to unit-test the solution from above using LightPlatformCodeInsightFixtureTestCase. However in contrast to interactive use, when running the test the `executionManager.getContentManager().getSelectedContent()` as discussed above always return null. Without the descriptor I can not close the tool-window and the test stumbles over some built-in assertion:

CompositeException (3 nested):
------------------------------
[0]: Editor of class com.intellij.openapi.editor.impl.EditorImpl hasn't been released:
[1]: Editor of class com.intellij.openapi.editor.impl.EditorImpl hasn't been released:
[2]: Unreleased editors: 2
------------------------------

CompositeException (3 nested):
------------------------------
[0]: com.intellij.openapi.util.TraceableDisposable.ObjectNotDisposedException: See stack trace responsible for creation of unreleased object below
at com.intellij.openapi.editor.impl.EditorImpl.<init>(EditorImpl.java:153)
at com.intellij.openapi.editor.impl.EditorFactoryImpl.a(EditorFactoryImpl.java:203)
at com.intellij.openapi.editor.impl.EditorFactoryImpl.createEditor(EditorFactoryImpl.java:179)
at com.intellij.execution.console.LanguageConsoleImpl.<init>(LanguageConsoleImpl.java:133)
at com.intellij.execution.console.LanguageConsoleImpl.<init>(LanguageConsoleImpl.java:121)
at com.r4intellij.console.RConsoleRunner.createConsoleView(RConsoleRunner.java:30)
at com.intellij.execution.runners.AbstractConsoleRunnerWithHistory.a(AbstractConsoleRunnerWithHistory.java:79)
at com.intellij.util.ui.UIUtil.invokeLaterIfNeeded(UIUtil.java:2493)
at com.intellij.execution.runners.AbstractConsoleRunnerWithHistory.initAndRun(AbstractConsoleRunnerWithHistory.java:77)
at com.r4intellij.intentions.InstallLibraryFix.applyFix(InstallLibraryFix.java:54)
at com.r4intellij.intentions.InstallLibraryFix.applyFix(InstallLibraryFix.java:25)

How can i avoid such a CompositeException?

Intention

https://github.com/holgerbrandl/r4intellij/blob/master/src/com/r4intellij/intentions/InstallLibraryFix.java#L91

Test

https://github.com/holgerbrandl/r4intellij/blob/master/test/com/r4intellij/intentions/InstallLibraryFixTest.java#L48

 

Many thanks in advance,
Holger

0

Please sign in to leave a comment.