Mark Document Readonly (and make it stick)

Documents are ephemeral- changing its status to readonly has no effect.  Is there a way to keep a view/document from being updated.  NOTE: I'm not talking about the file on disk being writable.

2 comments
Comment actions Permalink

I found an unpleasnt hack by using beforeDocumentChange and setting the docs readonly there.  This throws a ReadOnlyModificationException in the log. Setting the virtualfile to readonly changes the on disk perms.  I coud rewind the change, but that is equally stupid.  Surely there is some sane way of ding this?

0
Comment actions Permalink

The current solution is to undo the current change and the mark the document readonly (which spams the console).

        final Document document = event.getDocument();
        final String text = document.getText();

        context.setTimeout(0, new Runnable() {
            @Override
            public void run() {
                ThreadSafe.write(context, new Runnable() {
                    @Override
                    public void run() {
                        isListening.set(false);
                        document.setReadOnly(false);
                        document.setText(text);
                        document.setReadOnly(true);
                        isListening.set(true);
                    }
                });
            }
        });
        document.setReadOnly(true);

0

Please sign in to leave a comment.