How to define two or more “text-like” editors for the same concept

Is there a way to define two or more “text-like” editors for the same concept?

For example, if I want my scripting language syntax to be more C-like in one kind of view and more Python-like in another one.

12 comments
Official comment

Yes, you can do that, this capability is actually one of the key advantages of projectional editing over plain text - https://confluence.jetbrains.com/display/MPSD33/Editor+cookbook#Editorcookbook-Howtodefinemultipleeditorsforthesameconcept

 

Thank you!

The ConceptEditorContextHints concept is what I was looking for. Sorry for the inconvenience.

0

I have another question in this context. Is there a way to "bind" an alternative editor to a specific projectview?

I have implemented an alternative to the logical view (projectview) and I'd like to open alternative editors when navigating in that view. It is clear to me how to create alternative editors and employ them using editor hints. However, I don't know the underlying mechanism that could be triggered from my alternative view. In addition, I don't know how to override the double click in the alternative view.

0

Solved the double click problem. Any ideas how to trigger editor hints?

 

 

0

Benjamin, the way to provide editor hints to editor component is method setInitialHints

setInitialEditorHints(@Nullable String[] hints)

from the Updater class. It takes the array of initial hints fq names.

FQ name of hint depends on the language where it is defined. It is <language FQ name>.editor.<root name>.<hint name>

E.g. fq name of the hint "VisibleExpressionBoundaries" defined in "BLHints" root in baseLanguage is 

"jetbrains.mps.baseLanguage.editor.BLHints.VisibleExpressionBoundaries"

 

You can retrieve the updater form the editor component via 

Updater getUpdater();

 

After resetting the initial editor hints you should call

void rebuildEditorContent();

from the editor component.

 

0

Semen, thanks for the detailed explanation! I managed to open the alternative editor. However, now I can neither control the editor hints using "Preferences->Editor hints" nor can I open the default editor using the logical view anymore. Any ideas?

I basically did the following in my action, where currentEditor comes from NavigationSupport.getInstance().openNode(...):

string[] editorHint = {"test.editor.Hints.myHint"}; 
currentEditor.getCurrentEditorComponent().getUpdater().setInitialEditorHints(editorHint);
currentEditor.getCurrentEditorComponent().rebuildEditorContent();
0

Okay, I managed to open the default editor again via push editor hints in the popup menu. So it seems to override the global settings in the preferences menu. Do you have an idea how to open the default editor from the logical view? Or do I have to provide a "clone" of the logical view in order to make it work?

0

Benjamin, with that method call (setInitialEditorHints(editorHint)) you've set the individual hints for the editor.

If the individual initial hints are set for the editor, then common hints from the Preferences->Editor hints are ignored.

You can change individual editor hints settings via right-click on the editor -> "Push editor hints".

(You may take a look at the document section: "Pushing hints from IDE")

Alternatively you can create your own IDE action (E.g "show default editor") which will set initial hints to null

editorComponent.getUpdater().setInitialEditorHints(null);

editorComponent.rebuildEditorContent()

That will show the default editor.

You can find document describing creating your own actions in MPS you here

0

That explanation helps. I just missed the "Push editor hints" entry. Checked the documentation again, but couldn't find a way to have the logical view always open the default editor. Is there any solution?

0

Benjamin, MPS native logical pane just opens the current editor (with it's initial hints) for the node by the double click.

You cannot override that behaviour.

So the only way now is to provide another project pane ("clone" as you said) which will always open the default editor.

Also as I mentioned before, you can provide the custom action. But it will work only by the "right-click->choose" action on the project tree node, or the keystroke, not by the double click

0

Okay, I'll stick with "clone" solution. Really appreciate your help! Thanks!

0

Please sign in to leave a comment.