Example usage for com.intellij.openapi.editor.actionSystem EditorAction getHandler

List of usage examples for com.intellij.openapi.editor.actionSystem EditorAction getHandler

Introduction

In this page you can find the example usage for com.intellij.openapi.editor.actionSystem EditorAction getHandler.

Prototype

public synchronized EditorActionHandler getHandler() 

Source Link

Usage

From source file:com.maddyhome.idea.vim.command.Command.java

License:Open Source License

/**
 * Creates a command that doesn't require an argument
 *
 * @param count  The number entered prior to the command (zero if no specific number)
 * @param action The action to be executed when the command is run
 * @param type   The type of the command
 * @param flags  Any custom flags specific to this command
 *//* w w  w .j  av a 2 s . c  o m*/
public Command(int count, String actionId, AnAction action, @NotNull Type type, int flags) {
    this.count = count;
    this.action = action;
    this.type = type;
    this.flags = flags;
    this.argument = null;

    if (action instanceof EditorAction) {
        EditorAction eaction = (EditorAction) action;
        EditorActionHandler handler = eaction.getHandler();
        if (handler instanceof EditorActionHandlerBase) {
            ((EditorActionHandlerBase) handler).process(this);
        }
    }
}

From source file:com.maddyhome.idea.vim.key.KeyParser.java

License:Open Source License

public void setupActionHandler(String ideaActName, String vimActName, KeyStroke stroke, boolean special) {
    if (logger.isDebugEnabled())
        logger.debug("setupActionHandler for " + ideaActName + " and " + vimActName + " for " + stroke);
    ActionManager amgr = ActionManager.getInstance();
    AnAction action = amgr.getAction(ideaActName);
    if (action instanceof EditorAction) {
        if (logger.isDebugEnabled())
            logger.debug(ideaActName + " is an EditorAction");
        EditorAction iaction = (EditorAction) action;
        EditorActionHandler handler = iaction.getHandler();
        if (vimActName != null) {
            EditorAction vaction = (EditorAction) amgr.getAction(vimActName);
            vaction.setupHandler(handler);
        }//from  w ww .j a  v  a 2 s.  co m

        iaction.setupHandler(new EditorKeyHandler(handler, stroke, special));
    }

    //removePossibleConflict(stroke);
}

From source file:com.maddyhome.idea.vim.key.KeyParser.java

License:Open Source License

public void registerAction(int mapping, String actName, int cmdType, int cmdFlags) {
    String ideaName = actName.substring(3);
    ActionManager amgr = ActionManager.getInstance();
    if (amgr.getAction(ideaName) == null) {
        logger.info("No registered action " + ideaName);
        return;/*from   www  .  j a  v a 2  s . com*/
    }

    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    com.intellij.openapi.actionSystem.Shortcut[] cuts = keymap.getShortcuts(ideaName);
    ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>();
    for (com.intellij.openapi.actionSystem.Shortcut cut : cuts) {
        if (cut instanceof KeyboardShortcut) {
            KeyStroke keyStroke = ((KeyboardShortcut) cut).getFirstKeyStroke();
            Shortcut shortcut = new Shortcut(keyStroke);
            shortcuts.add(shortcut);
        }
    }

    registerAction(mapping, actName, cmdType, cmdFlags, shortcuts.toArray(new Shortcut[] {}));
    KeyStroke firstStroke = null;
    for (int i = 0; i < shortcuts.size(); i++) {
        Shortcut cut = shortcuts.get(i);
        //removePossibleConflict(cut.getKeys()[0]);
        if (i == 0) {
            firstStroke = cut.getKeys()[0];
        }
    }

    AnAction iaction = amgr.getAction(ideaName);
    AnAction vaction = amgr.getAction(actName);
    if (vaction instanceof DelegateAction) {
        DelegateAction daction = (DelegateAction) vaction;
        daction.setOrigAction(iaction);
    }

    if (iaction instanceof EditorAction) {
        EditorAction ea = (EditorAction) iaction;
        setupActionHandler(ideaName, new PassThruDelegateEditorAction(firstStroke, ea.getHandler()));
    } else {
        setupActionHandler(ideaName, new PassThruDelegateAction(firstStroke));
    }
}