use of com.intellij.openapi.keymap.impl.ui.MouseShortcutPanel in project intellij-community by JetBrains.
the class IdeMouseEventDispatcher method dispatchMouseEvent.
/**
* @return {@code true} if and only if the passed event is already dispatched by the
* {@code IdeMouseEventDispatcher} and there is no need for any other processing of the event.
* If the method returns {@code false} then it means that the event should be delivered
* to normal event dispatching.
*/
public boolean dispatchMouseEvent(MouseEvent e) {
Component c = e.getComponent();
//frame activation by mouse click
if (e.getID() == MOUSE_PRESSED && c instanceof IdeFrame && !c.hasFocus()) {
IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
if (focusManager instanceof FocusManagerImpl) {
Component at = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());
if (at != null && at.isFocusable()) {
((FocusManagerImpl) focusManager).setLastFocusedAtDeactivation((IdeFrame) c, at);
}
}
}
if (e.isPopupTrigger()) {
if (BUTTON3 == e.getButton()) {
if (Registry.is("ide.mouse.popup.trigger.modifiers.disabled") && (~BUTTON3_DOWN_MASK & e.getModifiersEx()) != 0) {
// it allows to use our mouse shortcuts for Ctrl+Button3, for example
resetPopupTrigger(e);
}
} else if (SystemInfo.isXWindow) {
// we can do better than silly triggering popup on everything but left click
resetPopupTrigger(e);
}
}
boolean ignore = false;
if (!(e.getID() == MOUSE_PRESSED || e.getID() == MOUSE_RELEASED || e.getID() == MOUSE_WHEEL && 0 < e.getModifiersEx() || e.getID() == MOUSE_CLICKED)) {
ignore = true;
}
patchClickCount(e);
int clickCount = e.getClickCount();
int button = MouseShortcut.getButton(e);
if (button == MouseShortcut.BUTTON_WHEEL_UP || button == MouseShortcut.BUTTON_WHEEL_DOWN) {
clickCount = 1;
}
if (e.isConsumed() || e.isPopupTrigger() || (button > 3 ? e.getID() != MOUSE_PRESSED && e.getID() != MOUSE_WHEEL : e.getID() != MOUSE_RELEASED) || clickCount < 1 || button == NOBUTTON) {
// See #16995. It did happen
ignore = true;
}
@JdkConstants.InputEventMask int modifiers = e.getModifiers();
@JdkConstants.InputEventMask int modifiersEx = e.getModifiersEx();
if (e.getID() == MOUSE_PRESSED) {
myPressedModifiersStored = true;
myModifiers = modifiers;
myModifiersEx = modifiersEx;
} else if (e.getID() == MOUSE_RELEASED) {
myForceTouchIsAllowed = true;
if (myPressedModifiersStored) {
myPressedModifiersStored = false;
modifiers = myModifiers;
modifiersEx = myModifiersEx;
}
}
final JRootPane root = findRoot(e);
if (root != null) {
BlockState blockState = myRootPane2BlockedId.get(root);
if (blockState != null) {
if (SWING_EVENTS_PRIORITY.indexOf(blockState.currentEventId) < SWING_EVENTS_PRIORITY.indexOf(e.getID())) {
blockState.currentEventId = e.getID();
if (blockState.blockMode == IdeEventQueue.BlockMode.COMPLETE) {
return true;
} else {
ignore = true;
}
} else {
myRootPane2BlockedId.remove(root);
}
}
}
if (c == null) {
throw new IllegalStateException("component cannot be null");
}
c = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());
if (c instanceof IdeGlassPaneImpl) {
c = ((IdeGlassPaneImpl) c).getTargetComponentFor(e);
}
if (c == null) {
// do nothing if component doesn't contains specified point
return false;
}
if (c instanceof MouseShortcutPanel || c.getParent() instanceof MouseShortcutPanel) {
// forward mouse processing to the special shortcut panel
return false;
}
if (isHorizontalScrolling(c, e)) {
boolean done = doHorizontalScrolling(c, (MouseWheelEvent) e);
if (done)
return true;
}
if (ignore)
return false;
// avoid "cyclic component initialization error" in case of dialogs shown because of component initialization failure
if (!KeymapManagerImpl.ourKeymapManagerInitialized) {
return false;
}
final MouseShortcut shortcut = new MouseShortcut(button, modifiersEx, clickCount);
fillActionsList(c, shortcut, IdeKeyEventDispatcher.isModalContext(c));
ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
if (actionManager != null) {
AnAction[] actions = myActions.toArray(new AnAction[myActions.size()]);
for (AnAction action : actions) {
DataContext dataContext = DataManager.getInstance().getDataContext(c);
Presentation presentation = myPresentationFactory.getPresentation(action);
AnActionEvent actionEvent = new AnActionEvent(e, dataContext, ActionPlaces.MAIN_MENU, presentation, ActionManager.getInstance(), modifiers);
if (ActionUtil.lastUpdateAndCheckDumb(action, actionEvent, false)) {
actionManager.fireBeforeActionPerformed(action, dataContext, actionEvent);
final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
if (context != null && !context.isShowing())
continue;
ActionUtil.performActionDumbAware(action, actionEvent);
actionManager.fireAfterActionPerformed(action, dataContext, actionEvent);
e.consume();
}
}
}
return e.getButton() > 3;
}
Aggregations