Read only mode for document
Hey, m beginner! Is there any other way to make a document read only except document.setReadOnly(true). If there is any other way that is better than this, Please let me know asap. Thanks in advance.
When I am using document.setReadOnly(true) then i am getting this error.
ERROR - llij.ide.plugins.PluginManager - Attempt to modify read-only document
com.intellij.openapi.editor.ReadOnlyModificationException: Attempt to modify read-only document
Please sign in to leave a comment.
Could you clarify, why do you need read-only Document?
If you need it to show read-only Editor, you can use EditorFactory.createViewer() instead of EditorFactory.createEditor().
If this document should be modified exclusively by some specific code, you can temporally make it writable there (document.setReadOnly(false); document.setText("New content"); document.setReadOnly(false) ).
Thank you. Now i'll use EditorFactory.createViewer().
Hey is there anything for DiffContentFactory that is editable and not editable,like this EditorFactory.createEditor(Document,Project,FileType,isViewer)
I'm not sure if I got your question right, but you might want to pass DiffUserDataKeys.FORCE_READ_ONLY or DiffUserDataKeys.FORCE_READ_ONLY_CONTENTS key to the request.
Example: https://github.com/JetBrains/intellij-community/blob/master/platform/diff-impl/src/com/intellij/diff/actions/CompareClipboardWithSelectionAction.java#L97
Does an editor created with createViewer() support carets? I have a situation (REPL output) where I would like to be able to allow the user to have a caret in a read-only document so that they can copy text from it. Is this possible?
Yes. This is regular Editor with disabled editing actions.
Hey Aleksey, You got my question correct like i need for editor and DocumentContent both. for editor i found
I can't reproduce the issue, could you attach sample code snippet ?
Note, that in the example above "makes read only to content2 only not content 1" is a desired behaviour. You need FORCE_READ_ONLY to mark all contents as read only (or pass {true, true} for two-content case).