gpt4 book ai didi

intellij-idea - Intellij 插件开发 : toolWindow extension is blank when opened in different project windows

转载 作者:行者123 更新时间:2023-12-04 06:17:25 27 4
gpt4 key购买 nike

当我在不同的 intellij 窗口中打开多个 (3-4) 项目时,我的 JSON 插件工具窗口显示为空白。这是我的 plugin.xml

<idea-plugin>
<id>com.xxxxx.json.Editor</id>
<name>JSON Editor</name>
<version>1.5</version>
<vendor email="xxxxxxxxxx" url="xxxxxxx">xxxxxx</vendor>

<description><![CDATA[
JetBrains IntelliJ IDE plugin for easy viewing and editing of currently opened JSON file in IDE using Tree Structure.
]]></description>

<change-notes><![CDATA[
Feature: Indentation changes - adding space after ':' char.
]]>
</change-notes>

<idea-version since-build="192.6"/>
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="JSON Editor" anchor="right" factoryClass="JsonEditor" />
</extensions>

<actions>
</actions>

</idea-plugin>

这是插件 JSON 编辑器工具窗口的内容(按钮和 TreeView )的屏幕截图。

enter image description here

这是同一工具窗口内容完全空白的屏幕截图(如果在不同窗口中打开多个 (3-4) 项目,就会发生这种情况。)

enter image description here

这是 createToolWindowContent 方法的代码 -

public class JsonEditor implements ToolWindowFactory {

private JPanel mainContent;
....
....

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
this.project = project;
ContentFactory contentFactory =
ContentFactory.SERVICE.getInstance();
Content content = contentFactory.createContent(mainContent, "", false);
toolWindow.getContentManager().addContent(content);
}
}

我该如何解决这个问题?我还能以不同的方式打开插件扩展实例的不同状态吗?

最佳答案

每次调用 createToolWindowContent 方法时,您都需要创建一个不同的 mainContent 实例,因为 AWT 小部件只能有一个父级。

每个 IDE 窗口都会调用此方法,因此一个窗口将“获胜”。

因此,不要编写 mainContent,而是编写 createMainContentInstance()。然后,您可以通过使用当前窗口的 Project 对象来访问全局所需的详细信息,这两个窗口之间是不同的。

关于intellij-idea - Intellij 插件开发 : toolWindow extension is blank when opened in different project windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59534505/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com