Parse file to make sections non-editable

I am using a tool that generates code with "guarded blocks" and "free blocks". Anything that is not inside a
//[FREE_BLOCK]

//[/FREE_BLOCK]
should not be editable. Is it possible, using the OpenAPI, to enforce this by parsing the generated code; or at least give some visual cue to the blocks (i.e., background-color, margin icons)?

Thanks,
Joe

8 comments
Comment actions Permalink

Hi,
short answer is: yes. I'd have to look up the details, but basically you could either use
the undocumented PSI (parse tree), or merely scan the editor contents for the comments.
You can intercept any editing action using com.intellij.openapi.editor.Document.addDocumentListener, and possibly call fireReadOnlyModificationAttempt to stop it, but I've never actually tried it.
Coloring can be done, I believe using the MarkupModel you can get from the Editor.
But others have played with this more than I. Check out any plugins that do
coloring and that provide source code.

Joe Parks wrote:

I am using a tool that generates code with "guarded blocks" and "free blocks". Anything that is not inside a
//[FREE_BLOCK]

//[/FREE_BLOCK]
should not be editable. Is it possible, using the OpenAPI, to enforce this by parsing the generated code; or at least give some visual cue to the blocks (i.e., background-color, margin icons)?

Thanks,
Joe



--

Erb

==============================================================
"Most of you are familiar with the virtues of a programmer.
There are three, of course: laziness, impatience, and hubris."
- Larry Wall
==============================================================

0
Comment actions Permalink

no, firing the event won't do it. Seems you have to register an EditorActionHandler
for each editor action. But there may be a more general way...


Erb wrote:

Hi,
short answer is: yes. I'd have to look up the details, but basically
you could either use
the undocumented PSI (parse tree), or merely scan the editor contents
for the comments.
You can intercept any editing action using
com.intellij.openapi.editor.Document.addDocumentListener, and possibly
call fireReadOnlyModificationAttempt to stop it, but I've never actually
tried it.
Coloring can be done, I believe using the MarkupModel you can get from
the Editor.
But others have played with this more than I. Check out any plugins
that do
coloring and that provide source code.

Joe Parks wrote:

>> I am using a tool that generates code with "guarded blocks" and "free
>> blocks". Anything that is not inside a
>> //[FREE_BLOCK]
>>
>> //[/FREE_BLOCK]
>> should not be editable. Is it possible, using the OpenAPI, to enforce
>> this by parsing the generated code; or at least give some visual cue
>> to the blocks (i.e., background-color, margin icons)?
>>
>> Thanks,
>> Joe




--

Erb

==============================================================
"Most of you are familiar with the virtues of a programmer.
There are three, of course: laziness, impatience, and hubris."
- Larry Wall
==============================================================

0
Comment actions Permalink

I think it's quite easy to make the coloring in the editor but very
difficult to prohibit editing.

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"

"Joe Parks" <itnadmin@jetbrains.com> wrote in message
news:31385968.1055784736764.JavaMail.itn@is.intellij.net...

I am using a tool that generates code with "guarded blocks" and "free

blocks". Anything that is not inside a

//[FREE_BLOCK]

>

//[/FREE_BLOCK]
should not be editable. Is it possible, using the OpenAPI, to enforce

this by parsing the generated code; or at least give some visual cue to the
blocks (i.e., background-color, margin icons)?
>

Thanks,
Joe



0
Comment actions Permalink

That's too bad. Of course, the added step would be to integrate with intellij's engine(s). That is, to make sure that added import statements are only added within free blocks, and to prevent refactorings such as rename when the target is within a guarded block.
I guess that's out.

0
Comment actions Permalink

I think it's quite easy to make the coloring in the
editor


Any hints as to how to do this?

For example, an ApplicationComponent or ProjectComponent?
What class(es) deal with the coloring of editor sections?

Thanks,
Joe

0
Comment actions Permalink

Editor.getMarkupModel()

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Joe Parks" <no_mail@jetbrains.com> wrote in message
news:21579221.1064335969772.JavaMail.itn@is.intellij.net...

I think it's quite easy to make the coloring in the
editor

>

Any hints as to how to do this?

>

For example, an ApplicationComponent or ProjectComponent?
What class(es) deal with the coloring of editor sections?

>

Thanks,
Joe



0
Comment actions Permalink

Thanks for the incredibly quick response.

The only example I could find (with source) is the FunkySearchPlugin. That plugin's action, though, is triggered by a keyboard shortcut or click of a button.

How do I register a listener for a document opening/refreshing?

-Joe

0
Comment actions Permalink

How do I register a listener for a document opening/refreshing?

EditorFactory.addEditorFactoryListener() for openening. Refreshing is
quite a different thing. You may add documentListener to a particular
document for to all documents via EditorEventMulticaster thing.

Some highlighting stuff is used in PsiViewerPlugin AFAIK.

Luck!
--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Joe Parks" <no_mail@jetbrains.com> wrote in message
news:6551065.1064337790238.JavaMail.itn@is.intellij.net...

Thanks for the incredibly quick response.

>

The only example I could find (with source) is the FunkySearchPlugin.

That plugin's action, though, is triggered by a keyboard shortcut or click
of a button.
>

How do I register a listener for a document opening/refreshing?

>

-Joe



0

Please sign in to leave a comment.