Search in sources :

Example 1 with InputEvent

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

the class ToggleActionCommand method _execute.

@Override
protected ActionCallback _execute(PlaybackContext context) {
    String[] args = getText().substring(PREFIX.length()).trim().split(" ");
    String syntaxText = "Syntax error, expected: " + PREFIX + " " + ON + "|" + OFF + " actionName";
    if (args.length != 2) {
        context.error(syntaxText, getLine());
        return ActionCallback.REJECTED;
    }
    final boolean on;
    if (ON.equalsIgnoreCase(args[0])) {
        on = true;
    } else if (OFF.equalsIgnoreCase(args[0])) {
        on = false;
    } else {
        context.error(syntaxText, getLine());
        return ActionCallback.REJECTED;
    }
    String actionId = args[1];
    final AnAction action = ActionManager.getInstance().getAction(actionId);
    if (action == null) {
        context.error("Unknown action id=" + actionId, getLine());
        return ActionCallback.REJECTED;
    }
    if (!(action instanceof ToggleAction)) {
        context.error("Action is not a toggle action id=" + actionId, getLine());
        return ActionCallback.REJECTED;
    }
    final InputEvent inputEvent = ActionCommand.getInputEvent(actionId);
    final ActionCallback result = new ActionCallback();
    context.getRobot().delay(Registry.intValue("actionSystem.playback.delay"));
    IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
    fm.doWhenFocusSettlesDown(() -> {
        final Presentation presentation = (Presentation) action.getTemplatePresentation().clone();
        AnActionEvent event = new AnActionEvent(inputEvent, DataManager.getInstance().getDataContext(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()), ActionPlaces.UNKNOWN, presentation, ActionManager.getInstance(), 0);
        ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, event, false);
        Boolean state = (Boolean) event.getPresentation().getClientProperty(ToggleAction.SELECTED_PROPERTY);
        if (state.booleanValue() != on) {
            ActionManager.getInstance().tryToExecute(action, inputEvent, null, ActionPlaces.UNKNOWN, true).doWhenProcessed(result.createSetDoneRunnable());
        } else {
            result.setDone();
        }
    });
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) InputEvent(java.awt.event.InputEvent)

Example 2 with InputEvent

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

the class ShortcutPromoterManager method beforeActionPerformed.

@Override
public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
    final InputEvent input = event.getInputEvent();
    if (input instanceof MouseEvent) {
        final String id = ActionManager.getInstance().getId(action);
        final ShortcutPromoterEP ep = myExtensions.get(id);
        if (ep != null) {
            PromoterState state = myState.get(id);
            if (state == null) {
                state = new PromoterState();
                myState.put(id, state);
            }
            state.incClicks();
        }
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) InputEvent(java.awt.event.InputEvent)

Example 3 with InputEvent

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

the class GotoClassAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project == null)
        return;
    if (!DumbService.getInstance(project).isDumb()) {
        super.actionPerformed(e);
    } else {
        DumbService.getInstance(project).showDumbModeNotification(IdeBundle.message("go.to.class.dumb.mode.message"));
        AnAction action = ActionManager.getInstance().getAction(GotoFileAction.ID);
        InputEvent event = ActionCommand.getInputEvent(GotoFileAction.ID);
        Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
        ActionManager.getInstance().tryToExecute(action, event, component, e.getPlace(), true);
    }
}
Also used : Project(com.intellij.openapi.project.Project) InputEvent(java.awt.event.InputEvent)

Example 4 with InputEvent

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

the class BaseRunConfigurationAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    final RunnerAndConfigurationSettings existing = context.findExisting();
    if (existing == null) {
        final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
        if (producers.isEmpty())
            return;
        if (producers.size() > 1) {
            final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
            Collections.sort(producers, ConfigurationFromContext.NAME_COMPARATOR);
            final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationFromContext>(ExecutionBundle.message("configuration.action.chooser.title"), producers) {

                @Override
                @NotNull
                public String getTextFor(final ConfigurationFromContext producer) {
                    return childActionName(producer.getConfigurationType(), producer.getConfiguration());
                }

                @Override
                public Icon getIconFor(final ConfigurationFromContext producer) {
                    return producer.getConfigurationType().getIcon();
                }

                @Override
                public PopupStep onChosen(final ConfigurationFromContext producer, final boolean finalChoice) {
                    perform(producer, context);
                    return FINAL_CHOICE;
                }
            });
            final InputEvent event = e.getInputEvent();
            if (event instanceof MouseEvent) {
                popup.show(new RelativePoint((MouseEvent) event));
            } else if (editor != null) {
                popup.showInBestPositionFor(editor);
            } else {
                popup.showInBestPositionFor(dataContext);
            }
        } else {
            perform(producers.get(0), context);
        }
        return;
    }
    perform(context);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) InputEvent(java.awt.event.InputEvent) Editor(com.intellij.openapi.editor.Editor)

Example 5 with InputEvent

use of java.awt.event.InputEvent in project jgnash by ccavanaugh.

the class IndeterminateCheckBox method iterateState.

// Mostly delegates to model
private void iterateState() {
    //Maybe do nothing at all?
    if (!getModel().isEnabled()) {
        return;
    }
    grabFocus();
    // Iterate state
    ((ButtonModelEx) getModel()).iterateState();
    // Fire ActionEvent
    int modifiers = 0;
    AWTEvent currentEvent = EventQueue.getCurrentEvent();
    if (currentEvent instanceof InputEvent) {
        modifiers = ((InputEvent) currentEvent).getModifiers();
    } else if (currentEvent instanceof ActionEvent) {
        modifiers = ((ActionEvent) currentEvent).getModifiers();
    }
    fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getText(), System.currentTimeMillis(), modifiers));
}
Also used : ActionEvent(java.awt.event.ActionEvent) AWTEvent(java.awt.AWTEvent) InputEvent(java.awt.event.InputEvent)

Aggregations

InputEvent (java.awt.event.InputEvent)23 MouseEvent (java.awt.event.MouseEvent)8 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 AWTEvent (java.awt.AWTEvent)4 ActionEvent (java.awt.event.ActionEvent)4 NotNull (org.jetbrains.annotations.NotNull)4 ListPopup (com.intellij.openapi.ui.popup.ListPopup)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 Pair (com.intellij.openapi.util.Pair)2 JBList (com.intellij.ui.components.JBList)2 KeyEvent (java.awt.event.KeyEvent)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