Eclipse RCP:文件关联(--launcher.openFile)
我正在开发一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这种方法对我来说是未知的,但由于您粘贴的代码中没有显式的编辑器调用,我猜您仍然依赖 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.
由于我刚刚为 RCP 应用程序完成了这项工作,因此我认为在此处记录我的操作方式并提供参考文献会很有帮助。
非常有用的参考资料是:
对于基本编码:
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.
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"