Search in sources :

Example 11 with InputEvent

use of java.awt.event.InputEvent 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)

Example 12 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class PotemkinProgress method dispatchAwtEventsWithoutModelAccess.

private void dispatchAwtEventsWithoutModelAccess(int timeoutMs) {
    SunToolkit.flushPendingEvents();
    try {
        while (true) {
            InputEvent event = myEventQueue.poll(timeoutMs, TimeUnit.MILLISECONDS);
            if (event == null)
                return;
            dispatchInputEvent(event);
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : InputEvent(java.awt.event.InputEvent)

Example 13 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class WelcomePopupAction method showPopup.

private void showPopup(final AnActionEvent e) {
    final DefaultActionGroup group = new DefaultActionGroup();
    fillActions(group);
    if (group.getChildrenCount() == 1 && isSilentlyChooseSingleOption()) {
        final AnAction[] children = group.getChildren(null);
        children[0].actionPerformed(e);
        return;
    }
    if (group.getChildrenCount() == 0) {
        group.add(new AnAction(getTextForEmpty()) {

            public void actionPerformed(AnActionEvent e) {
                group.setPopup(false);
            }
        });
    }
    final DataContext context = e.getDataContext();
    final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(getCaption(), group, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true);
    JComponent contextComponent = null;
    InputEvent inputEvent = e.getInputEvent();
    if (inputEvent instanceof MouseEvent) {
        if (inputEvent.getSource() instanceof JComponent) {
            contextComponent = (JComponent) inputEvent.getSource();
        }
    }
    showPopup(context, popup, contextComponent);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) InputEvent(java.awt.event.InputEvent)

Example 14 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class ActivateToolWindowAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    Project project = getEventProject(e);
    if (project == null)
        return;
    ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
    final ToolWindow window = windowManager.getToolWindow(myToolWindowId);
    InputEvent event = e.getInputEvent();
    Runnable run = null;
    if (event instanceof KeyEvent && event.isShiftDown()) {
        final Content[] contents = window.getContentManager().getContents();
        if (contents.length > 0 && window.getContentManager().getSelectedContent() != contents[0]) {
            run = () -> window.getContentManager().setSelectedContent(contents[0], true, true);
        }
    }
    if (windowManager.isEditorComponentActive() || !myToolWindowId.equals(windowManager.getActiveToolWindowId()) || run != null) {
        if (run != null && window.isActive()) {
            run.run();
        } else {
            window.activate(run);
        }
    } else {
        windowManager.getToolWindow(myToolWindowId).hide(null);
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) ToolWindow(com.intellij.openapi.wm.ToolWindow) Content(com.intellij.ui.content.Content) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) InputEvent(java.awt.event.InputEvent)

Example 15 with InputEvent

use of java.awt.event.InputEvent in project intellij-community by JetBrains.

the class PasteFromX11Action method update.

@Override
public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    DataContext dataContext = e.getDataContext();
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (editor == null || !SystemInfo.isXWindow) {
        presentation.setEnabled(false);
    } else {
        boolean rightPlace = true;
        final InputEvent inputEvent = e.getInputEvent();
        if (inputEvent instanceof MouseEvent) {
            rightPlace = false;
            final MouseEvent me = (MouseEvent) inputEvent;
            if (editor.getMouseEventArea(me) == EditorMouseEventArea.EDITING_AREA) {
                final Component component = SwingUtilities.getDeepestComponentAt(me.getComponent(), me.getX(), me.getY());
                rightPlace = !(component instanceof JScrollBar);
            }
        }
        presentation.setEnabled(rightPlace);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) MouseEvent(java.awt.event.MouseEvent) InputEvent(java.awt.event.InputEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) Editor(com.intellij.openapi.editor.Editor)

Aggregations

InputEvent (java.awt.event.InputEvent)21 MouseEvent (java.awt.event.MouseEvent)7 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 NotNull (org.jetbrains.annotations.NotNull)4 ListPopup (com.intellij.openapi.ui.popup.ListPopup)3 AWTEvent (java.awt.AWTEvent)3 ActionEvent (java.awt.event.ActionEvent)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 ActionCallback (com.intellij.openapi.util.ActionCallback)2 Pair (com.intellij.openapi.util.Pair)2 JBList (com.intellij.ui.components.JBList)2 Nullable (org.jetbrains.annotations.Nullable)2 ExecutionBundle (com.intellij.execution.ExecutionBundle)1 ExecutionManager (com.intellij.execution.ExecutionManager)1 Executor (com.intellij.execution.Executor)1 KillableProcess (com.intellij.execution.KillableProcess)1 Location (com.intellij.execution.Location)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1