Using locked regions


Is there way to override what happens when a modification is attempted in/on
a locked region?
I'd like to override the default popup/messagebox.

Taras


14 comments
Comment actions Permalink

Hello Taras,

Is there way to override what happens when a modification is attempted
in/on a locked region?
I'd like to override the default popup/messagebox.


Have a look at
com.intellij.openapi.editor.actionSystem.EditorActionManager#setReadonlyFragmentModificationHandler

Its default-implementation seems to be the one that shows the message box.

Sascha

0
Comment actions Permalink

Hello Sascha,

Have a look at
com.intellij.openapi.editor.actionSystem.EditorActionManager#setReadon
lyFragmentModificationHandler


Did you use that successfully?
I'll try again, but IIRC I tried that one before, without any visible effect.

-tt


0
Comment actions Permalink

Hello Taras,

>> Have a look at
>> com.intellij.openapi.editor.actionSystem.EditorActionManager#setReadon
>> lyFragmentModificationHandler


Did you use that successfully?
I'll try again, but IIRC I tried that one before, without any visible
effect.


Nope I haven't used this myself, it is just the result of a rather quick search.

Sascha

0
Comment actions Permalink

Hey, it works :)
I think I was trying similar methods on DocumentEx before.

So, setting this behavior is application-wide, correct? That seems fine for a dialog, but what if I only want to customize this for a Project (or just a Document)?

In addition, is there any special trick to get EditorTextField to work in multi-line mode? :)

0
Comment actions Permalink

Hello Taras,

So, setting this behavior is application-wide, correct?


Yes, EAM is an application component.

That seems fine for a dialog, but what if I only want to customize this for a Project (or just a Document)?


You should be able to get the Document from the parameter passed to
ReadonlyFragmentModificationHandler#handle and either show your dialog or delegate to the original
handler.

However, since Documents are application-wide as well, I'm not sure how to accomplish something
purely project-specific.

In addition, is there any special trick to get EditorTextField to work in multi-line mode? :)


Yes: By subclassing it and overriding createEditor(). Then call "editor.setOneLineMode(false);"

Sascha

0
Comment actions Permalink

Hello Sascha,

>> In addition, is there any special trick to get EditorTextField to
>> work in multi-line mode? :)
>>

Yes: By subclassing it and overriding createEditor(). Then call
"editor.setOneLineMode(false);"


Thanks again. More quick questions:
-I assume I should set EditorEx#setEmbeddedIntoDialogWrapper() if applicable.
What does it do?
-I'd like to have a (left) gutter. I see getGutter()/getGutterComponentEx().
Is there simple way to add it?
-(related to previous): Line numbers in gutter would be nice - if possible.
-To get a more editor-line font I just query it from Colors&Fonts and set
it in my subclass?
-I'd like to provide a different color/style for the locked regions. Possible?

Taras


0
Comment actions Permalink

Taras Tielkes wrote:

Hello Sascha,

>>> In addition, is there any special trick to get EditorTextField to
>>> work in multi-line mode? :)
>>>
>> Yes: By subclassing it and overriding createEditor(). Then call
>> "editor.setOneLineMode(false);"


Thanks again. More quick questions:
-I assume I should set EditorEx#setEmbeddedIntoDialogWrapper() if
applicable. What does it do?

Tab / Shift + Tab actions are not working

--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Maxim Mossienko (JetBrains) wrote:
>> -I assume I should set EditorEx#setEmbeddedIntoDialogWrapper() if
>> applicable. What does it do?


Tab / Shift + Tab actions are not working


I would have sworn that Shift-Tab doesn't work even when setting this to true. However I
just saw that it works in the DOM-controls. So why isn't this used in all the other IDEA
dialogs (introduce variable, etc.)?

Sascha

0
Comment actions Permalink

Hello Taras,

-I'd like to have a (left) gutter. I see
getGutter()/getGutterComponentEx(). Is there simple way to add it?


Not sure. It should already be part of Editor.getComponent() - says the javadoc. I'm also
pretty sure that I've already seen the gutter in an ETF.

-(related to previous): Line numbers in gutter would be nice - if possible.


See com.intellij.openapi.editor.EditorSettings#isLineNumbersShown - although this probably
requires the gutter to be shown (or causes it to be shown?).

-To get a more editor-line font I just query it from Colors&Fonts and
set it in my subclass?


Could work. ;)

-I'd like to provide a different color/style for the locked regions.
Possible?


See com.intellij.openapi.editor.colors.EditorColors#READONLY_FRAGMENT_BACKGROUND_COLOR
You should be able to change it with
com.intellij.openapi.editor.colors.EditorColorsScheme#setColor

Sascha

0
Comment actions Permalink

I would have sworn that Shift-Tab doesn't work even when setting this to
true. However I just saw that it works in the DOM-controls.


Update: Shift-Tab indeed kinda works, but as it seems only inside the same container/panel. It also
doesn't even matter if setEmbeddedIntoDialogWrapper() has been called or not (at least for one-line
textfields). Is this intended or should it be put into a JIRA request?

BTW: The best way to make Shift-Tab work still seems to be
org.intellij.plugins.intelliLang.util.ShiftTabAction ;)

Sascha

0
Comment actions Permalink

Hello Sascha,

Thanks for the help, basic editor textfield configuration looks OK now.
Here are a couple of more advanced features I'd like to add/customize:

1) Expand/Collapse folded regions
My textfield content contains some folds (created using editor.getFoldingModel()).
Is there a way to make the common fold actions work? (Ctrl+/Ctrl-)

2) Column mode toggle
Similar to (1): I'd like the default shortcut for Column mode toggle the
setting for the textfield.
Can I somehow reuse the default actions, or should I implement this myself?

3) Ctrl-W / Ctrl-Shift-W support
The default Ctrl-W for plain text stops at word level.
Is there a way to customize this? What I'm after:
word -> line (w/o leading/trailing whitespace) -> line -> all

Btw, I don't have a PSI at all - I'm simply using EditorFactory#createDocument().

4) Status bar
Is there a reusable editor status bar component in OpenApi by any chance?
I'm looking for basic (row:col) and "Insert/Overwrite" indicators.

5) Highlight occurrences / right gutter
I'd like to add "old-style" Ctrl-Shift-F7 support.
Is the "right gutter" / "stripe bar" component available for reuse, or is
it hidded deep inside idea.jar?

Thanks,
Taras


0
Comment actions Permalink

Hello Taras,

1) Expand/Collapse folded regions
My textfield content contains some folds (created using
editor.getFoldingModel()).
Is there a way to make the common fold actions work? (Ctrl+/Ctrl-)

2) Column mode toggle
Similar to (1): I'd like the default shortcut for Column mode toggle the
setting for the textfield.
Can I somehow reuse the default actions, or should I implement this myself?


Those actions seem to only work in non-modal context. See
com.intellij.openapi.actionSystem.DataConstants#IS_MODAL_CONTEXT

You can try to enable them with code like this:
ActionManager.getInstance().getAction(["CollapseRegion", "ExpandRegion",
"EditorToggleColumnMode"]).setEnabledInModalContext(true);

If you think they are generally useful in dialogs, you can try to file a JIRA request to make this
standard.

3) Ctrl-W / Ctrl-Shift-W support
The default Ctrl-W for plain text stops at word level.
Is there a way to customize this? What I'm after:
word -> line (w/o leading/trailing whitespace) -> line -> all

Btw, I don't have a PSI at all - I'm simply using
EditorFactory#createDocument().


Not sure if this is customizable for non-PSI Documents. Probably not.

4) Status bar
Is there a reusable editor status bar component in OpenApi by any chance?
I'm looking for basic (row:col) and "Insert/Overwrite" indicators.


Have a look at
com.intellij.openapi.wm.impl.status.PositionPanel
com.intellij.openapi.wm.impl.status.TextPanel

5) Highlight occurrences / right gutter
I'd like to add "old-style" Ctrl-Shift-F7 support.
Is the "right gutter" / "stripe bar" component available for reuse, or
is it hidded deep inside idea.jar?


It doesn't look like this is a reusable component.

Sascha

0
Comment actions Permalink

Hello Sascha,

Hello Taras,

>> 1) Expand/Collapse folded regions
>> My textfield content contains some folds (created using
>> editor.getFoldingModel()).
>> Is there a way to make the common fold actions work? (Ctrl+/Ctrl-)
>> 2) Column mode toggle
>> Similar to (1): I'd like the default shortcut for Column mode toggle
>> the
>> setting for the textfield.
>> Can I somehow reuse the default actions, or should I implement this
>> myself?

Those actions seem to only work in non-modal context. See
com.intellij.openapi.actionSystem.DataConstants#IS_MODAL_CONTEXT

You can try to enable them with code like this:
ActionManager.getInstance().getAction(["CollapseRegion",
"ExpandRegion",
"EditorToggleColumnMode"]).setEnabledInModalContext(true);


I see. This works for "EditorToggleColumnMode" (which extends ToggleAction),
but not for the others (which extend BaseCodeInsightAction): CodeInsightAction#actionPerformedImpl()
bails out early if there's no psiFile.

To work around this I upgraded from "editorFactory.createDocument()" to:
---
PsiFile myFile = elementFactory.createFileFromText("temp.txt", StdFileTypes.PLAIN_TEXT,
rootText, System.currentTimeMillis(), false);
Document document = PsiDocumentManager.getInstance(project).getDocument(myFile);
---
Now the expand/collapse actions work :)

One thing I don't understand is why I get a null Document returned when I
create the psiFile as non-physical. Any ideas?

>> 3) Ctrl-W / Ctrl-Shift-W support
>> The default Ctrl-W for plain text stops at word level.
>> Is there a way to customize this? What I'm after:
>> word -> line (w/o leading/trailing whitespace) -> line -> all
>> Btw, I don't have a PSI at all - I'm simply using
>> EditorFactory#createDocument().

Not sure if this is customizable for non-PSI Documents. Probably not.


Well, now I have one (see above). :)
Is there some place I can (try to) plug my custom Ctrl-W selection logic?

Taras


0
Comment actions Permalink

Hello Taras,

One thing I don't understand is why I get a null Document returned when
I create the psiFile as non-physical. Any ideas?


Not sure. Probably an optimization to reduce syncing-overhead when it's not needed.

>>> 3) Ctrl-W / Ctrl-Shift-W support
>>> The default Ctrl-W for plain text stops at word level.
>>> Is there a way to customize this? What I'm after:
>>> word -> line (w/o leading/trailing whitespace) -> line -> all
>>> Btw, I don't have a PSI at all - I'm simply using
>>> EditorFactory#createDocument().
>>
>> Not sure if this is customizable for non-PSI Documents. Probably not.


Well, now I have one (see above). :)
Is there some place I can (try to) plug my custom Ctrl-W selection logic?


There's SelectWordUtil#registerSelectioner although adding something at the end that
triggers on PsiPlainText probably won't work. If you're bold enough, try
replacing/wrapping the SelectWordUtil.PlainTextLineSelectioner instance using reflection.
You've been warned ;)

Sascha

0

Please sign in to leave a comment.