![](/img/trans.png)
[英]How to make a editor just output part of datas(eclipse plugin development)
[英]How to make read only editor in Eclipse (Eclipse Plugin Development)
我想知道如何制作一個真正只讀的 eclipse 編輯器。我的編輯器擴展了TextEditor ,所以當我重新實現方法isEditable時總是返回false 。
這是最簡單的方法,它可以防止用戶在編輯器中打開的文檔中鍵入或刪除任何內容。 但是您仍然可以更改文檔的內容,例如使用查找/替換。 這是不希望的..
有沒有其他簡單的方法可以實現這個目標?
我想使用編輯器而不是查看器,因為編輯器已經制作完成,所以我只使用了第 3 方插件。
我找到了我的解決方案 - maybe 不是很干凈但是完成了工作並且非常簡單所以它贏了
我已經覆蓋了這些方法:
@Override
public boolean isEditable() {
return false;
}
@Override
public boolean isEditorInputModifiable() {
return false;
}
@Override
public boolean isEditorInputReadOnly() {
return true;
}
@Override
public boolean isDirty() {
return false;
}
您是否嘗試過創建自己的 SourceViewer? 像這樣的東西。 我自己還沒有嘗試過代碼。
class ReadOnlyViewer extends SourceViewer
{
protected StyledText createTextWidget(Composite parent, int styles)
{
return new StyledText(parent, styles | SWT.READ_ONLY);
}
}
class MyEditor extends TextEditor
{
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles)
{
fAnnotationAccess= getAnnotationAccess();
fOverviewRuler= createOverviewRuler(getSharedColors());
ISourceViewer viewer= new ReadOnlyViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
// ensure decoration support has been created and configured.
getSourceViewerDecorationSupport(viewer);
return viewer;
}
}
在 SWT styles 中,指定SWT.READ_ONLY 。 這應該拒絕所有修改文檔的 API(我希望 setText() 除外......)
如果沒有,請提交錯誤。
為什么您使用 TextEditor 而不是使用TextViewer ?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.