简体   繁体   English

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

[英]Eclipse RCP: File association (--launcher.openFile)

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. 我遵循了几个示例(如thisthis ),但似乎编辑器曾经收到过SWT OpenDocument事件。

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 如fileAssociation示例中所述,我创建了一个eventListener类来处理SWT.OpenDocument事件,并在调用PlatformUI.createAndRunWorkbench()方法之前将其添加到我的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));

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.. 如果我在一个新的空RCP项目中使用相同的代码,它的工作原理就像一个魅力。

I can't figured out which could be the problem.. 我不知道这可能是问题。

can you help me? 你能帮助我吗?

Thanks a lot!! 非常感谢!!

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. 当我刚刚为RCP应用程序完成这项工作时,我认为在此处记录我的操作方式并提供参考将很有帮助。

  1. I had no use for the 'context.getArguments()..', the 'OpenDocumentEventProcessor' handled everything. 我没有用'context.getArguments()..','OpenDocumentEventProcessor'处理了所有事情。
  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. 我建议这样做不起作用的原因是-name值与'org.eclipse.core.runtime.products'扩展点中'appName'属性的值不匹配。 Just to be sure, I removed the spaces from the appName property and in the -name. 可以肯定的是,我从appName属性和-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 对于基本编码: 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 有关其工作原理的说明: 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 - ie it became "%1" 最终,我意识到(瞬间!),我需要在文件关联的安装程序(InstallAware)定义中的%1参数周围加上引号-即它变成了“%1”

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. 这种方法对我来说是未知的,但是由于您粘贴的代码中没有显式的编辑器调用,我想您仍然依靠eclipse来决定必须打开哪个编辑器。 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...). 为此,请为“ org.eclipse.core.contenttype.contentTypes”扩展名添加一个“文件关联”(文件扩展名...)。 Get your editor declaration in your plugin xml and add the previously created 'contentTypeBinding' id. 在插件xml中获取编辑器声明,并添加先前创建的“ contentTypeBinding” ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM