// TODO use in PluginUtil because EditorActions needs special support
public class ActionWrapper {
private static final Logger LOG = Logger.getInstance(ActionWrapper.class);
public static AnAction wrapAction(String actionId, final Listener listener) {
ActionManager actionManager = ActionManager.getInstance();
final AnAction action = actionManager.getAction(actionId);
if (action == null) {
LOG.warn("Couldn't wrap action " + actionId + " because it was not found");
return null;
}
AnAction newAction;
if (action instanceof EditorAction) {
newAction = new WrappedEditorAction(listener, (EditorAction) action);
} else if (action instanceof DumbAware) {
newAction = new WrappedAction(listener, action);
} else {
newAction = new WrappedDumbUnawareAction(listener, action);
}
newAction.getTemplatePresentation().setText(action.getTemplatePresentation().getText());
newAction.getTemplatePresentation().setIcon(action.getTemplatePresentation().getIcon());
newAction.getTemplatePresentation().setHoveredIcon(action.getTemplatePresentation().getHoveredIcon());
newAction.getTemplatePresentation().setDescription(action.getTemplatePresentation().getDescription());
newAction.copyShortcutFrom(action);
actionManager.unregisterAction(actionId);
actionManager.registerAction(actionId, newAction);
LOG.info("Wrapped action " + actionId);
return newAction;
}