Copy-Action in MPS (Ctrl+C)

Hello there.

I'm currently working on a project, that among other things validates constraints outside of MPS. Therefore I created a language similar to the Alloy.

Now I'm at the point that I need the textual representation of my constraints. In other words: I need something like Ctrl+C in my Editor for any kind of node.
Basically the same problem this (https://mps-support.jetbrains.com/hc/en-us/community/posts/206613685-Code-generation-Why-so-many-steps-) post started with. But unfortunately that post went off-topic.

I found out that MPS gives me two actions for Ctrl+C, both named "Copy": 

Both of them have a different functionality.

1 (not what I need):

[facts] Fact null[8154441716430517392] in SandboxSolution.A1

2 (exactly what I need):

fact { 
all p : person | p not in p.friend
}

I tried to figure out how they work with the help of my cloned MPS from GitHub. There I found the class jetbrains.mps.ide.actions.CopyNode_Action. This is doing the first Copy-Variant with the help of getDebugText(SNode node) in jetbrains.mps.util.SNodeOperations. But this (as mentioned above) not what I need. I was searching for some hours for the implementation of the second one, but wasn't able to find anything that gives me the String-representation of a node from the editor.
Does anyone here can help me?

Would be glad to hear from you.

Regards
JanK411

4 comments
Comment actions Permalink

You need the `EditorCell.renderText().getText()`.

0
Comment actions Permalink

Thank you for your quick reply! It sounds very promising, but now I'm struggling to get my EditorCell from the Behavior-Aspect.

new EditorCellFactoryImpl(<context?>).createEditorCell(this, false).renderText().getText();

If this is a proper way to do it? And if yes, how can I acquire the EditorContext that is needed for the EditorCellFactory?

Or is there maybe another way to access the EditorCell of a Node from its Behavior?

0
Comment actions Permalink

You can't do it from Behavior directly. I see two solutions:

1. Call this from somewhere where you have an editor open: either an intention or an action with the context parameter EDITOR_CELL.

2. Look into creating a HeadlessEditorComponent and opening your node in it and use it to get hold of the cell.

0
Comment actions Permalink

Wow! Thank you so much, it's working!
Solved it this way now:

new HeadlessEditorComponent(this, this.model/.getRepository()).findNodeCell(this).renderText().getText()

Best regards

JanK411

 

0

Please sign in to leave a comment.