package jetbrains.mps.testActions.util;
/*Generated by MPS */
import com.intellij.openapi.actionSystem.ActionManager;
import java.util.Set;
import java.util.HashSet;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import org.jdom.Element;
import java.util.Arrays;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.ActionGroup;
public class FlyingActionsFinder {
private ActionManager myActionManager = ActionManager.getInstance();
private Set<String> myFlyingActions = new HashSet<String>();
private FlyingActionsFinder() {
findFlyingActions();
}
/**
* Get Set of actionGroups ids which belongs to MPS Core
* Such actionGroups belongs to main menu, so we could ignore them in check
*
* @return set of actions ids
*/
private Set<String> getIdeaCoreActions() {
PluginId pluginId = PluginId.getId(PluginManager.CORE_PLUGIN_ID);
IdeaPluginDescriptor descriptor = PluginManager.getPlugin(pluginId);
Set<String> ideaCoreActions = new HashSet<String>();
if (descriptor == null) {
return ideaCoreActions;
}
for (Element element : descriptor.getActionsDescriptionElements()) {
ideaCoreActions.add(element.getAttributeValue("id"));
}
return ideaCoreActions;
}
private void findFlyingActions() {
myFlyingActions = new HashSet<String>(Arrays.asList(myActionManager.getActionIds("")));
Set<String> childrenOrShortCutActionsSet = new HashSet<String>();
AnAction anAction;
for (String id : myFlyingActions) {
anAction = myActionManager.getAction(id);
if (anAction.getShortcutSet().getShortcuts().length > 0) {
childrenOrShortCutActionsSet.add(id);
}
if (ActionGroup.class.isInstance(anAction)) {
for (AnAction child : ((ActionGroup) anAction).getChildren(null)) {
childrenOrShortCutActionsSet.add(myActionManager.getId(child));
}
}
}
myFlyingActions.removeAll(childrenOrShortCutActionsSet);
myFlyingActions.removeAll(getIdeaCoreActions());
myFlyingActions.removeAll(getMPSRootActionIds());
}
/**
* Creates list of actions/actionGroups with no parent, no shortcuts and not presented in MPS Core actions
*
* @return List of "flying" actions/actionGroups to check
*/
private Set<String> getFlyingActions() {
return myFlyingActions;
}
/**
* Hardcoded action/actionGroups ids that can have no parent, have no shortcuts
* and do not belong to main menu
*
* @return Set of actions/actionGroups ids
*/
public static Set<String> getMPSRootActionIds() {
Set<String> set = new HashSet<String>();
set.add("jetbrains.mps.ide.actions.FlyingActions_ActionGroup");
set.add("jetbrains.mps.vcs.platform.actions.ChangesStrip_ActionGroup");
set.add("jetbrains.mps.vcs.plugin.TestMergeAction_Action");
set.add("jetbrains.mps.lang.dataFlow.pluginSolution.plugin.DataFlowInternal_ActionGroup");
set.add("jetbrains.mps.samples.ActionWithProgress.plugin.ProgressActionsGroup_ActionGroup");
set.add("Git.LogContextMenu");
return set;
}
public static Set<String> getAllFlyingActions() {
FlyingActionsFinder finder = new FlyingActionsFinder();
return finder.getFlyingActions();
}
}