How to assign new values to ActionContextParameters/DataKeys?
Question
Hello,
is it possible to assign new values to ActionContextParameters/DataKeys inside the execute(event) function of an action?
Example
1) I've created an action, that requires context parameters with the DataKeys NODE and EDITOR_COMPONENT
2) If i want to access the values of these parameters inside the execute function i can do it with the this keyword or via the event parameter:
3) Now i was wondering how i can change the values of these parameters programmatically? For instance, to execute an action inside the execute function with other ActionContextParameters.
My best attempt
I've tried it with the MPS.IDEA/com.intellij.ide.DataManager, because i found out, that this class manages the same DataContext as the event parameter. The attempt failed because the DataManager class uses Key<T> instead of DataKey<T> objects and i was not able to figure out how to resolve the proper Key<T> object.
Any suggestions?
Thank you in advance and best regards
Please sign in to leave a comment.
Hello,
Looking at your example, I guess what you are really looking for is jetbrains.mps.nodeEditor.reflectiveEditor.ReflectiveHintsManager#makeNodeReflective and jetbrains.mps.nodeEditor.reflectiveEditor.ReflectiveHintsManager#makeSubtree. But you also have to handle editor update in case of using this methods.
If managing Reflective Editor programmatically is your intention, we can provide you with more info, how to do it, if needed.
For calling action from action with different data context - there is solution, but it is not recommended:
You have to create new AnActionEvent with your custom DataContext, that return new value for specific DataKey.
So it will be smth like this:
But this is kind of hack, because you changing context, which should not be changed.
Hi Victor,
thanks for your response.
Yes, i tried to push reflective editor hints by recursively calling the ShowReflecitveEditor_Action with altered context parameters. During this adventure i was wondering how to change context parameters of actions in general, but if this is considered a hack and is not recommended, I won't do it as well.
I can't use the ReflectiveHintsManager class, because i'm currently working with MPS 2017.2.
In my current solution i partially copied the implementation of the ShowReflectiveEditor_Action, iterated over all applicable descendant nodes, pushed the editor hints and updated the editor content.