How do I open an editor on a file outside the workspace?

本文介绍如何使用EFS支持在工作空间之外打开文本编辑器编辑文件,以及如何在现有项目中创建指向文件系统的外部文件的链接资源,允许平台以读写模式在标准编辑器中打开这些文件。

Since 3.3 you can use the new EFS support to open an text editor on a file outside the workspace:

Stringname=newFileDialog(aShell,SWT.OPEN).open();
if(name==null)
return;
IFileStorefileStore
=EFS.getLocalFileSystem().getStore(newPath(filterPath));
fileStore
=fileStore.getChild(names[i]);
if(!fileStore.fetchInfo().isDirectory()&&fileStore.fetchInfo().exists())...{
IWorkbenchPagepage
=window.getActivePage();
try...{
IDE.openEditorOnFileStore(page,fileStore);
}
catch(PartInitExceptione)...{
/**//*somecode*/
}



Alternatively, you can create a linked resource in an existing project, which points to a file elsewhere in the file system. This example snippet creates a project called “External Files,” and then prompts the user to select any file in the file system. The code then creates a linked resource in the project to that external file, allowing the platform to open the file in read/write mode in one of the standard editors:

IWorkspacews=ResourcesPlugin.getWorkspace();
IProjectproject
=ws.getRoot().getProject("ExternalFiles");
if(!project.exists())
project.create(
null);
if(!project.isOpen())
project.open(
null);
Shellshell
=window.getShell();
Stringname
=newFileDialog(shell,SWT.OPEN).open();
if(name==null)
return;
IPathlocation
=newPath(name);
IFilefile
=project.getFile(location.lastSegment());
file.createLink(location,IResource.NONE,
null);
IWorkbenchPagepage
=window.getActivePage();
if(page!=null)
page.openEditor(file);


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值