使编辑器不能关闭 [英] Make Editor Not-Closeable
问题描述
public class ProjectEditor扩展EditorPart {
/ /实施
}
注册:
< extension point =org.eclipse.ui.editors>
< editor
class =com.qualitype.gpm.project.rcp.ProjectEditor
icon =icons / obj16 / project.gif
id =com。 qualitype.gpm.project.rcp.ProjectEditor
name =%view.project>
< / editor>
< / extension>
我希望该编辑器始终打开。但是,在扩展点中缺少一些参数,如扩展点。
另外,对于视图,这可以起作用:
public class ProjectPerspective实现IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout){
final IViewLayout projectLayout = layout.getViewLayout(ProjectEditor.ID);
projectLayout.setCloseable(false);
}
}
但当然不是编辑。由于编辑器和视图在技术上是相同的(工作台部分),所以应该是可能的。
如何阻止用户关闭编辑器?
您可以通过清除 MPart
来删除编辑器选项卡上的关闭X可关闭标志您可以在编辑器的 init
方法中执行此操作:
@Override
public void init(IEditorSite site,IEditorInput editorInput)throws PartInitException
{
super.init(site,editorInput);
MPart part = getSite()。getService(MPart.class);
part.setCloseable(false);
但文件>关闭操作仍然可以关闭编辑器不检查可关闭的标志,并且没有不可编辑的编辑器的概念。
I have a standard E3 editor in the current E4 world:
public class ProjectEditor extends EditorPart {
// implement
}
Registered like that:
<extension point="org.eclipse.ui.editors">
<editor
class="com.qualitype.gpm.project.rcp.ProjectEditor"
icon="icons/obj16/project.gif"
id="com.qualitype.gpm.project.rcp.ProjectEditor"
name="%view.project" >
</editor>
</extension>
I want that editor to be always open. But a parameter like for the views is missing in the extension point.
Also, for views this would work:
public class ProjectPerspective implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
final IViewLayout projectLayout = layout.getViewLayout(ProjectEditor.ID);
projectLayout.setCloseable(false);
}
}
But of course not for editors. Since both editors and view are technically the same thing (workbench parts), it should be possible.
How do I prevent the user from closing my editor?
You can remove the close 'X' on the editor tab by clearing the MPart
closeable flag. You could do this in the editor's init
method:
@Override
public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException
{
super.init(site, editorInput);
MPart part = getSite().getService(MPart.class);
part.setCloseable(false);
But the 'File > Close' action will still be able to close the editor as it doesn't check the closeable flag and has no concept of un-closeable editors.
这篇关于使编辑器不能关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!