Search in sources :

Example 1 with AnActionListener

use of com.intellij.openapi.actionSystem.ex.AnActionListener in project intellij-community by JetBrains.

the class StudyProjectComponent method initComponent.

@Override
public void initComponent() {
    EditorFactory.getInstance().addEditorFactoryListener(new StudyEditorFactoryListener(), myProject);
    ActionManager.getInstance().addAnActionListener(new AnActionListener() {

        @Override
        public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
            AnAction[] newGroupActions = ((ActionGroup) ActionManager.getInstance().getAction("NewGroup")).getChildren(null);
            for (AnAction newAction : newGroupActions) {
                if (newAction == action) {
                    myListener = new FileCreatedByUserListener();
                    VirtualFileManager.getInstance().addVirtualFileListener(myListener);
                    break;
                }
            }
        }

        @Override
        public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
            AnAction[] newGroupActions = ((ActionGroup) ActionManager.getInstance().getAction("NewGroup")).getChildren(null);
            for (AnAction newAction : newGroupActions) {
                if (newAction == action) {
                    VirtualFileManager.getInstance().removeVirtualFileListener(myListener);
                }
            }
        }

        @Override
        public void beforeEditorTyping(char c, DataContext dataContext) {
        }
    });
}
Also used : StudyEditorFactoryListener(com.jetbrains.edu.learning.editor.StudyEditorFactoryListener) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener)

Example 2 with AnActionListener

use of com.intellij.openapi.actionSystem.ex.AnActionListener in project intellij-community by JetBrains.

the class AutoPopupController method setupListeners.

private void setupListeners() {
    ActionManagerEx.getInstanceEx().addAnActionListener(new AnActionListener() {

        @Override
        public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
            cancelAllRequest();
        }

        @Override
        public void beforeEditorTyping(char c, DataContext dataContext) {
            cancelAllRequest();
        }

        @Override
        public void afterActionPerformed(final AnAction action, final DataContext dataContext, AnActionEvent event) {
        }
    }, this);
    IdeEventQueue.getInstance().addActivityListener(() -> cancelAllRequest(), this);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 3 with AnActionListener

use of com.intellij.openapi.actionSystem.ex.AnActionListener in project intellij-community by JetBrains.

the class ActionManagerImpl method fireAfterActionPerformed.

@Override
public void fireAfterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
    if (action != null) {
        myPrevPerformedActionId = myLastPreformedActionId;
        myLastPreformedActionId = getId(action);
        //noinspection AssignmentToStaticFieldFromInstanceMethod
        IdeaLogger.ourLastActionId = myLastPreformedActionId;
    }
    for (AnActionListener listener : myActionListeners) {
        try {
            listener.afterActionPerformed(action, dataContext, event);
        } catch (AbstractMethodError ignored) {
        }
    }
}
Also used : AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener)

Example 4 with AnActionListener

use of com.intellij.openapi.actionSystem.ex.AnActionListener in project intellij-community by JetBrains.

the class ActionManagerImpl method fireBeforeActionPerformed.

@Override
public void fireBeforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
    if (action != null) {
        myPrevPerformedActionId = myLastPreformedActionId;
        myLastPreformedActionId = getId(action);
        //noinspection AssignmentToStaticFieldFromInstanceMethod
        IdeaLogger.ourLastActionId = myLastPreformedActionId;
    }
    for (AnActionListener listener : myActionListeners) {
        listener.beforeActionPerformed(action, dataContext, event);
    }
}
Also used : AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener)

Example 5 with AnActionListener

use of com.intellij.openapi.actionSystem.ex.AnActionListener in project intellij-community by JetBrains.

the class ActionCommand method _execute.

protected ActionCallback _execute(final PlaybackContext context) {
    final String actionName = getText().substring(PREFIX.length()).trim();
    final ActionManager am = ActionManager.getInstance();
    final AnAction targetAction = am.getAction(actionName);
    if (targetAction == null) {
        dumpError(context, "Unknown action: " + actionName);
        return ActionCallback.REJECTED;
    }
    if (!context.isUseDirectActionCall()) {
        final Shortcut[] sc = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionName);
        KeyStroke stroke = null;
        for (Shortcut each : sc) {
            if (each instanceof KeyboardShortcut) {
                final KeyboardShortcut ks = (KeyboardShortcut) each;
                final KeyStroke first = ks.getFirstKeyStroke();
                final KeyStroke second = ks.getSecondKeyStroke();
                if (second == null) {
                    stroke = KeyStroke.getKeyStroke(first.getKeyCode(), first.getModifiers(), false);
                    break;
                }
            }
        }
        if (stroke != null) {
            final ActionCallback result = new TimedOutCallback(Registry.intValue("actionSystem.commandProcessingTimeout"), "Timed out calling action id=" + actionName, new Throwable(), true) {

                @Override
                protected void dumpError() {
                    context.error(getMessage(), getLine());
                }
            };
            context.message("Invoking action via shortcut: " + stroke.toString(), getLine());
            final KeyStroke finalStroke = stroke;
            inWriteSafeContext(() -> {
                final Ref<AnActionListener> listener = new Ref<>();
                listener.set(new AnActionListener.Adapter() {

                    @Override
                    public void beforeActionPerformed(final AnAction action, DataContext dataContext, AnActionEvent event) {
                        ApplicationManager.getApplication().invokeLater(() -> {
                            if (context.isDisposed()) {
                                am.removeAnActionListener(listener.get());
                                return;
                            }
                            if (targetAction.equals(action)) {
                                context.message("Performed action: " + actionName, context.getCurrentLine());
                                am.removeAnActionListener(listener.get());
                                result.setDone();
                            }
                        }, ModalityState.any());
                    }
                });
                am.addAnActionListener(listener.get());
                context.runPooledThread(() -> type(context.getRobot(), finalStroke));
            });
            return result;
        }
    }
    final InputEvent input = getInputEvent(actionName);
    final ActionCallback result = new ActionCallback();
    context.getRobot().delay(Registry.intValue("actionSystem.playback.delay"));
    ApplicationManager.getApplication().invokeLater(() -> am.tryToExecute(targetAction, input, null, null, false).doWhenProcessed(result.createSetDoneRunnable()), ModalityState.any());
    return result;
}
Also used : TimedOutCallback(com.intellij.openapi.util.TimedOutCallback) ActionCallback(com.intellij.openapi.util.ActionCallback) Ref(com.intellij.openapi.util.Ref) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) InputEvent(java.awt.event.InputEvent)

Aggregations

AnActionListener (com.intellij.openapi.actionSystem.ex.AnActionListener)5 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 Ref (com.intellij.openapi.util.Ref)1 TimedOutCallback (com.intellij.openapi.util.TimedOutCallback)1 StudyEditorFactoryListener (com.jetbrains.edu.learning.editor.StudyEditorFactoryListener)1 InputEvent (java.awt.event.InputEvent)1