【发布时间】:2015-06-24 17:29:57
【问题描述】:
我有一个修改多个文件的 Eclipse 编辑器。当这些文件中的任何一个出现错误时,我希望它打开 MyEditor 而不是它可能会打开的标准文本编辑器。
我通过设置marker属性强制marker打开MyEditor:
marker.setAttribute(IDE.EDITOR_ID_ATTR, "com.example.xyz.MyEditorID");
现在,在MyEditor.setInput() 中,我有以下代码将输入从传入文件切换到主文件:
protected void setInput(final IEditorInput input) {
FileEditorInput fileEditorInput = (FileEditorInput) input;
final IFile file = (IFile) input.getAdapter(IFile.class);
if( file.getName().endsWith(mySuffix) ) {
// this is a coded values type file. It needs to be opened with the default profile
fileEditorInput = new FileEditorInput(theCorrectFileName);
}
...
super.setInput(fileEditorInput);
...
}
我更改了编辑器的 equals 方法,如果输入相等则返回 true
public boolean equals(final Object obj) {
if(obj == null) {
return false;
}
if(this == obj) {
return true;
}
if( !getClass().isInstance(obj) ) {
return false;
}
final MyEdior otherEditor = (MyEditor) obj;
return getEditorInput().equals( otherEditor.getEditorInput() );
}
但是当我点击我的错误标记时,它仍然每次都会打开一个新的编辑器。我做错了什么?
【问题讨论】:
标签: eclipse eclipse-plugin editor