【发布时间】:2019-12-06 07:30:30
【问题描述】:
我正在开发一个 Eclipse 插件,我需要应用程序的每个编辑器都是只读的,具体取决于所包含文件的 路径(相对于项目)。
我已经创建了自己的编辑器类,并且能够重写一些方法来获得我想要的:
public class MyTextEditor extends TextEditor {
/**
* Overridden to inhibit the replace action in find&replace dialog.
*/
@Override
public boolean isEditorInputModifiable() {
if (!super.isEditorInputModifiable()) {
return false;
}
return Utils.checkEditorInputModifiable(getEditorInput());
}
/**
* Overridden to inhibit any user edit in the editor input.
*/
@Override
public boolean isEditable() {
if (!super.isEditable()) {
return false;
}
return Utils.checkEditorInputModifiable(getEditorInput());
}
How to make read only editor in Eclipse (Eclipse Plugin Development)
但问题是:如何在比较编辑器上做到这一点?
eclipse 在每个比较对话框中使用的编辑器是不同的编辑器,我可以使用我的内容 ContentMergeViewer 并将 compareConfiguration 设置为只读(在一侧或两侧)但这还不够。每边的 compareInput 应该是只读的!
或者有没有其他更方便的方法来实现我想要的??
谢谢!
【问题讨论】:
-
“不够”怎么办?在 CompareConfiguration 上调用 setLeftEditable(false) 和 setRightEditable(false) 看起来会停止编辑。
-
这还不够......比较中间的两个小箭头将消失在只读的一侧......所以没关系。但是顶部栏上用于将差异从一侧复制到另一侧的按钮仍然启用!您必须在比较输入对象上实现
IEditableContent接口,即 isEditable() 方法。我在自定义比较对话框上做了,但在这种情况下,Eclipse 使用它自己的对话框并比较基础结构..所以我现在不知道该怎么做..
标签: eclipse eclipse-rcp