Menus (Ctrl+Space)
Hi.
I'm a newbie and it seems that I'm a bit confused :)
I have a concept A with child concept B.
Concept B in its turn has an optional reference to concept A (i.e. [0..1]).
I'd like to create an editor for concept B with menu (Ctrl+Space) with list of all instances of concept A. If I have not optional reference, such a menu is generated automatically if I specify primary replace child menu.
But I don't get how to create it in case of optional reference.
Not sure if such description of my problem is clear :)
I'm a newbie and it seems that I'm a bit confused :)
I have a concept A with child concept B.
Concept B in its turn has an optional reference to concept A (i.e. [0..1]).
I'd like to create an editor for concept B with menu (Ctrl+Space) with list of all instances of concept A. If I have not optional reference, such a menu is generated automatically if I specify primary replace child menu.
But I don't get how to create it in case of optional reference.
Not sure if such description of my problem is clear :)
Please sign in to leave a comment.
Here's the component definition I'm using for B:
editor component compForB overrides: <no EditorComponent> applicable concept: B component cell layout: [- ref: ( % a % -> { name } ) -]Here's A's editor:
<default> editor for concept A node cell layout: [- A { name } with ( % b % -> # compForB # ) -] inspected cell layout: <choose cell model>Vaclav
Concepts…
The important part is that B has [0..1] reference to A, not [1].
Also I have such component
editor component compForB overrides: <no EditorComponent> applicable concept: B component cell layout: ( % a % -> { name } )And finally the editor, where I use it:
<default> editor for concept A node cell layout: [/ { name } <constant> [> ( % b % -> # compForB # ) and its body: ( % b % -> { body } ) <] /] inspected cell layout: <choose cell model>And the result in sandbox solution:
In first case it just shows B node in autocompletion list (and it seems that nothing changes if I choose it)
If I change the reference in B from [0..1] to [1], i.e. from "B may have a reference to A" to "B must have a reference to A", then we have the following:
My question is: how can I make such a menu but with optional reference to A? Or I just simply don't get something?
Sorry for a long post :) I hope, the definition of my problem is clear. I can create a full project with this example if it's needed.
In such case this is standard and correct behaviour - you first need to create a B child, so you could make it refer to an A in a second step. I expect that after you select the B in the menu, you get a second completion menu with the correct (A) items.
If you make the cardinality of B in A [1], MPS will create an instance of B for each created A automatically and so you avoid the first completion menu.
If instead, as you tried, make the cardinality of A in B [1], MPS will treat B as a "Smart reference" and thus populate the completion menu with possible As, even if there's no B in your current A. B becomes somewhat invisible.
No, the cardinality of B in A is [1]. So each A always has B-child. I've put my declarations of concepts A and B in my previous message under the {cut}. Please, take a look on it.
Unfortunately, no. Selecting of B changes nothing.
If I use concept editor instead of editor component, everything is OK. I can make a repo with example.
You can find my whole project here: https://bitbucket.org/gooroo/mps_playground
I've commited all the stuff (source_gen, caches etc.)
When pressing "Control + Space" on the cell MPS prefers to offer substitutions for B (replacing the B instance with a new one) instead of showing the completion menu for the "parent" reference inside B. This is one of heuristics that MPS uses to be more in-line with typical usages.
A solution for your case would be to wrap the cell in a collection cell and prepend it with a transparent constant cell:
[- <constant> ( % parent % -> { name } ) -]where the constant cell has the following properties to become invisible:
Style: <no base style> { selectable : false punctuation-left : true punctuation-right : true }Vaclav