In our last post working on the importer, we created an action to invoke our importer. The action worked but wasn’t included in any menu. Today we will fix this.

Each menu in MPS shows a particular action group. Action groups are extensible, dynamic lists of actions whose contents can be modified by plugins such as our importer plugin. They are also recursive: you can add an action group to another action group.

In fact, you cannot add a single action directly to an action group but have to wrap it in an action group of its own first.

Finding the right group

The biggest stumbling block here is finding the right group to add the action to. Although the documentation states that the predefined MPS groups are stored in the jetbrains.mps.ide.actions model, it is not really helpful in this instance.

First, the documentation is incomplete. For example, the EditorPopup group that represents the context menu in an editor is defined in jetbrains.mps.ide.editor.actions (note the .editor. in the name).

Second, jetbrains.mps.ide.actions model contains dozens of actions, and the documentation does not specify which group corresponds to which menu.

We can try guessing the name or looking through the completion menu. In our case we look for the context menu related to a model so we could try typing Model and see what comes up.

If that fails, we can look up an action that is already present in the menu, and use Find Usages to find which groups contain it. Ideally the action should be something distinct that would be easy to track, as opposed to a generic action like New or Build Model.

Let’s say we look through the menu and find an action called Analyze Model Dependencies. This is the action’s title but we need to find the actual action node whose name is going to be a Java identifier. So we need to guess again.

In this case, AnalyzeModelDependencies doesn’t bring up any results but searching for just Analyze finds AnalyzeDependencies which turns out to be the action group we are looking for.

The next step is to search for usages of AnalyzeDependencies, globally. To do that we bring up the Find Usages Settings dialog by pressing Ctrl+Alt+Shift+F7, change the Scope to Global and confirm.

This brings us to ModelActions group that is the group we are looking for. It mostly consists of anchors (items with an arrow in front of their names) that represent sections that other action groups can add actions to, to keep related actions together.

Adding the action to the group

After we have figured out the action group, adding the action is fairly straightforward. I have recorded a screencast of the necessary steps:

Next: invoking importer from an editor

In the next post we will implement an alternative way of invoking importers: from an editor. Meanwhile, the latest code is on GitHub.