Eclipse 插件 - 与文件扩展名和透视图关联的编辑器

发布于 2024-11-28 18:19:42 字数 221 浏览 2 评论 0原文

我正在开发两个 Eclipse 插件,我有下一个问题:

我有两个管理相同文件的视角。我想在文件扩展名-编辑器-透视图之间建立关联。

我的意思是,如果我在透视图 1 中打开文件扩展名 .XXX,它会使用编辑器 A,但是如果我在透视图 2 中打开相同的文件扩展名 .XXX,它会使用编辑器 B。

这可能吗?从现在开始,我使用了启动器,但现在我需要更多的差异化。

谢谢。

I'm developing tow eclipse plugin, I have the next problem:

I have two perspective that manages the same files. I would like to make an association between file extension - editor - perspective.

I mean if I open the file extension .XXX in perspective 1 it uses the editor A, but if I open the same file extension .XXX in perspective 2, it uses the editor B.

is it possible? Since now, I used the launcher but now I need more differentiation.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最偏执的依靠 2024-12-05 18:19:42

(抱歉,这是“不要这样做!”的非答案之一。:))

正如评论中提到的,我建议不要根据当前的观点打开不同的编辑器。我认为这违背了用户的期望,并且会产生一些不直观的后果,例如当我创建自己的观点时。

例如,我建议采用 Eclipse 的 XML/插件清单编辑器的路径。底部的选项卡允许用户在不同的视图之间进行选择,而与任何视角选择或配置无关。

Eclipse 插件清单编辑器

(Sorry, this is one of those "don't do that!" non-answers. :))

As mentioned in the comments, I'd recommend against opening a different editor depending on the current perspective. I think that goes against the expectations of the user, and has some unintuitive consequences, e.g. when I create my own perspectives.

I'd recommend going the path of Eclipse' XML/Plug-in manifest editors, for example. Tabs at the bottom allow the user to choose between the different views, independent of any perspective choice or configuration.

Eclipse plugin-in manifest editor

谁把谁当真 2024-12-05 18:19:42

虽然我同意基于开放视角对同一文件使用不同的默认编辑器似乎有点奇怪,但您可以这样做。

  1. 创建两个新的内容类型扩展
  2. 将您的第一个编辑器注册为第一个新内容类型的默认编辑器
  3. 将第二个编辑器注册为第二个新内容类型的默认编辑器
  4. 对于每种内容类型,您都有一个“内容类型描述器”。在这些描述器类中,让它检查活动工作台页面中的当前透视 ID,如果它与预期值匹配,则为“有效”,如果透视 ID 不匹配,则返回“无效”。
  5. 对于这两个编辑器,您需要将这些编辑器与内容类型关联,而不是文件扩展名或文件名。
  6. 现在,一次只有一种内容类型匹配,具体取决于打开的透视图。确保其中一种内容类型是“默认”,以便在用户打开其他透视图时它始终匹配。

更新#1添加了一些示例

有一些在线 教程 。但这里有一些示例代码,可以让您更轻松地了解需要做什么。以下是声明内容类型的方法(您需要其中两个)

<plugin>
   <extension
         point="org.eclipse.core.contenttype.contentTypes">
      <content-type
            base-type="org.eclipse.core.runtime.xml"
            describer="com.liferay.ide.core.FirstContentTypeDescriber"
            id="com.liferay.ide.core.contentType1"
            name="First Content Type"
            priority="normal">
      </content-type>
   </extension>
</plugin>

然后在Describer 类中执行匹配逻辑。然后在编辑器扩展点中引用内容类型而不是文件名或扩展名,如下所示:

   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="com.liferay.ide.ui.FirstEditor"
            default="false"
            id="com.liferay.ide.ui.editor1"
            name="My First Editor">
         <contentTypeBinding
               contentTypeId="com.liferay.ide.core.firstContentType">
         </contentTypeBinding>
      </editor>
   </extension>

While I agree that this seems a little strange to have the default editor be different for the same file based on the open perspective, here is how you could do it.

  1. Create two new Content Type extensions
  2. Register your first editor as default editor for 1st new Content Type
  3. Register your 2nd editor as the default editor for the 2nd new Content Type
  4. For each content type, you have a 'content type describer'. In these describer classes, have it check the active workbench page for the current perspective ID and if it matches the expected value, then VALID, if perspective id doesn't match, return INVALID.
  5. For both editors you need to associate those editors with a content-type instead of a file-extension or filename
  6. Now only one content type will match at a time depending on which perspective is open. Make sure that one of the content types is the 'default' so that it will always match if the user has some other perspective open.

Update #1 added some examples

There are some online tutorials for this. But here is some example code to make it easier to see what work is required. Here is how you declare your content types (you would need two of them)

<plugin>
   <extension
         point="org.eclipse.core.contenttype.contentTypes">
      <content-type
            base-type="org.eclipse.core.runtime.xml"
            describer="com.liferay.ide.core.FirstContentTypeDescriber"
            id="com.liferay.ide.core.contentType1"
            name="First Content Type"
            priority="normal">
      </content-type>
   </extension>
</plugin>

Then in the Describer class you would do your matching logic. Then in the editor extension point you reference a content type instead of a file-name or extension like this:

   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="com.liferay.ide.ui.FirstEditor"
            default="false"
            id="com.liferay.ide.ui.editor1"
            name="My First Editor">
         <contentTypeBinding
               contentTypeId="com.liferay.ide.core.firstContentType">
         </contentTypeBinding>
      </editor>
   </extension>
少年亿悲伤 2024-12-05 18:19:42

我建议重新考虑您的方法,并从 WindowBuilder 中获取一些提示:拥有一个与打开选项卡式编辑器的文件类型相关联的编辑器;如果添加了第二个插件,请让它在同一编辑器上创建一个单独的选项卡。

I would recommend to rethink your approach, and take some cues from WindowBuilder: have one editor associated with the file type which opens a tabbed editor; if a second plugin is added, have it create a separate tab on the same editor.

东北女汉子 2024-12-05 18:19:42

其他选项可以以编程方式更改文件类型与

Eclipse RCP 中所示的 Java 代码关联:以编程方式将文件类型与编辑器关联起来?

那么只有一个问题:如何在透视更改事件上执行该代码。

Other option may be programmatically change file type association with Java code shown in

Eclipse RCP: programmatically associate file type with Editor?

Then there is only a question how to execute that code on perspective change event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文