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;
}
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();
}
}
}
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);
}
}
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);
}
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));
}
Aggregations