Eclipse RCP:文件关联(--launcher.openFile)

发布于 2024-12-11 07:03:06 字数 1345 浏览 0 评论 0原文

我正在开发一个 Eclipse 产品,我需要将文件扩展名关联到我的编辑器。 我遵循了几个示例(例如 this和 this),但编辑器似乎曾经收到过 SWT OpenDocument 事件。

如 fileAssociation 示例中所述,我创建了一个 eventListener 类来处理 SWT.OpenDocument 事件,并在我的 Application 类中将其添加到显示中,然后

public Object start(IApplicationContext context) throws Exception {
Object args = context.getArguments().get(IApplicationContext.APPLICATION_ARGS); 
OpenDocumentEventProcessor eProc = new OpenDocumentEventProcessor();
Display display = PlatformUI.createDisplay();
display.addListener(SWT.OpenDocument, eProc);
try{
    if(!handleWorkspace(display)){
        System.exit(0);
        return IApplication.EXIT_OK;
    }
int returnCode = PlatformUI.createAndRunWorkbench(display, new XVRWorkbenchAdvisor(args, eProc));

在产品文件中 调用 PlatformUI.createAndRunWorkbench() 方法我添加了以下程序参数:

--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-name
XVR Studio Developer

如果我在一个新的空 RCP 项目中使用相同的代码,它就像一个魅力..

我不知道哪个可能是问题..

你能帮助我吗?

多谢!!

I'm developing an eclipse product and i need to associate a file extension to my editor.
I followed several examples (as like as this and
this) but it seems that the editor ever receives the SWT OpenDocument event.

As described in the fileAssociation example i created an eventListener class to process SWT.OpenDocument events and i added this in my Application class to the display before that the PlatformUI.createAndRunWorkbench() method gets called

public Object start(IApplicationContext context) throws Exception {
Object args = context.getArguments().get(IApplicationContext.APPLICATION_ARGS); 
OpenDocumentEventProcessor eProc = new OpenDocumentEventProcessor();
Display display = PlatformUI.createDisplay();
display.addListener(SWT.OpenDocument, eProc);
try{
    if(!handleWorkspace(display)){
        System.exit(0);
        return IApplication.EXIT_OK;
    }
int returnCode = PlatformUI.createAndRunWorkbench(display, new XVRWorkbenchAdvisor(args, eProc));

In the product file i added the following program arguments:

--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-name
XVR Studio Developer

If I use the same code in a new empty RCP project it works like a charm..

I can't figured out which could be the problem..

can you help me?

Thanks a lot!!

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

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

发布评论

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

评论(2

哑剧 2024-12-18 07:03:06

这种方法对我来说是未知的,但由于您粘贴的代码中没有显式的编辑器调用,我猜您仍然依赖 eclipse 来决定必须打开哪个编辑器。所以我想你仍然必须以声明方式定义内容类型和文件关联。要为“org.eclipse.core.contenttype.contentTypes”扩展做出贡献,请添加“文件关联”(文件扩展名...)。在插件 xml 中获取编辑器声明并添加之前创建的“contentTypeBinding”id。

This approach is unknown for me, but since there is no explicit editor call in your pasted code I guess you still rely on eclipse to decide which editor has to be opened. So I guess you still have to define contentypes and file associations declaratively. To do that contribute to "org.eclipse.core.contenttype.contentTypes" extension, add a 'file-association' (file extension...). Get your editor declaration in your plugin xml and add the previously created 'contentTypeBinding' id.

神魇的王 2024-12-18 07:03:06

由于我刚刚为 RCP 应用程序完成了这项工作,因此我认为在此处记录我的操作方式并提供参考文献会很有帮助。

  1. 我没有使用“context.getArguments()..”,“OpenDocumentEventProcessor”处理了一切。
  2. 我认为这不起作用的原因是 -name 值与“org.eclipse.core.runtime.products”扩展点中“appName”属性的值不匹配。为了确定起见,我删除了 appName 属性和 -name 中的空格。然后就成功了。

非常有用的参考资料是:

对于基本编码:
http:// help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fproduct_open_file.htm

有关如何进行的说明这有效:
http://aniefer.blogspot.co .uk/2010/05/opening-files-in-eclipse-from-command.html

有一个小问题让我困惑了一段时间,那就是在几个步骤中获取文件的路径名称中有空格的地方出现块。最终我意识到(在“呃!”时刻)我需要在安装程序 (InstallAware) 文件关联定义中的 %1 参数上加上引号 - 即它变成 "% 1"

As I have just made this work for an RCP app, I thought it would be helpful to document how I did it here, and provide refs.

  1. I had no use for the 'context.getArguments()..', the 'OpenDocumentEventProcessor' handled everything.
  2. I would suggest that the reason this did not work was that the -name value did not match the value of the 'appName' property in the 'org.eclipse.core.runtime.products' extension point. Just to be sure, I removed the spaces from the appName property and in the -name. Then it worked.

Very useful references are:

For the basic coding:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fproduct_open_file.htm

For an explanation of how this works:
http://aniefer.blogspot.co.uk/2010/05/opening-files-in-eclipse-from-command.html

One small point that eluded me for some time, was getting the path for the file in several chunks at the place where there was a space in the name. Eventually I realised (in a 'duh!' moment) that I needed to put quotes round the %1 parameter in the installer's (InstallAware) definition for the file association - i.e it became "%1"

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