Intellj Idea开发使用Run ToolWindow来展示我的流程如下

时间:2021-01-23 13:19:44

标签: intellij-idea plugins window

最近我一直在开发一个intellij插件。我设计了一个按钮,希望当这个按钮被双击时,一个进程可以被执行并显示在Run ToolWindow中。

比如在Maven的IDEA插件中,当我们双击'clean'按钮时,就会执行mvn clean,并在运行窗口中显示执行过程。我希望能达到同样的效果。

那么我怎样才能达到这个效果呢?我试过问题 Intellij plugin development print in console window 显示:

ConsoleView cslView = TextConsoleBuilderFactory.getInstance().createBuilder(project).
                                    getConsole();


GeneralCommandLine commandLine = new GeneralCommandLine("C:\\Works\\ojworks\\hello.exe");
OSProcessHandler processHandler = ProcessHandlerFactory.getInstance().createColoredProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
cslView.attachToProcess(processHandler);
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Run");
Content content = toolWindow.getContentManager().getFactory().createContent(cslView.getComponent(), "Console", true);

但是有两个问题:

  1. 如果Run ToolWindow没有被激活,getToolWindow函数会返回null,那么我如何主动激活Run ToolWindow?
  2. 控制台已打开但没有显示。函数attachToProcess是真的生效了还是我需要做其他事情?

谢谢你的建议。

0 个答案:

没有答案