How to make read only editor in Eclipse (Eclipse Plugin Development)
Asked Answered
A

3

5

I'm wondering how to make a really read only eclipse editor.. My editor extends TextEditor, so when I reimplement method isEditable to always return false.

It's the easiest way, which prevents user from typing or deleting anything in the document opened in the editor. But you can still change content of the document for example by using find/replace. And this is not desired..

Is there any other aesy way how to arhieve this goal?

Adan answered 16/6, 2009 at 12:58 Comment(1)
Nice oxymoron- "read only editor"Manolete
A
10

I wanted to use editor instead of viewer because the editor was already made, so I just used a 3rd party plugin..

I found my solution - maybee not very clean but does the job and is pretty easy so it wins

I've overriden theese methods:

@Override
public boolean isEditable() {
    return false;
}

@Override
public boolean isEditorInputModifiable() {
    return false;
}

@Override
public boolean isEditorInputReadOnly() {
    return true;
}

@Override
public boolean isDirty() {
    return false;
}
Adan answered 17/6, 2009 at 6:23 Comment(0)
M
0

Have you tried to create your own SourceViewer? Something like this. I haven't tried the code myself.

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;
    }
}
Micrometer answered 16/6, 2009 at 21:26 Comment(0)
O
-1

In the SWT styles, specify SWT.READ_ONLY. This should reject all APIs which modify the document (with the exception of setText(), I hope ...)

If not, please file a bug.

Outwash answered 16/6, 2009 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.