Eclipse 插件 - 与文件扩展名和透视图关联的编辑器
我正在开发两个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
(抱歉,这是“不要这样做!”的非答案之一。:))
正如评论中提到的,我建议不要根据当前的观点打开不同的编辑器。我认为这违背了用户的期望,并且会产生一些不直观的后果,例如当我创建自己的观点时。
例如,我建议采用 Eclipse 的 XML/插件清单编辑器的路径。底部的选项卡允许用户在不同的视图之间进行选择,而与任何视角选择或配置无关。
(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.
虽然我同意基于开放视角对同一文件使用不同的默认编辑器似乎有点奇怪,但您可以这样做。
更新#1添加了一些示例
有一些在线 教程 。但这里有一些示例代码,可以让您更轻松地了解需要做什么。以下是声明内容类型的方法(您需要其中两个)
然后在Describer 类中执行匹配逻辑。然后在编辑器扩展点中引用内容类型而不是文件名或扩展名,如下所示:
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.
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)
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:
我建议重新考虑您的方法,并从 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.
其他选项可以以编程方式更改文件类型与
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.