Search in sources :

Example 1 with DnDManagerImpl

use of com.intellij.ide.dnd.DnDManagerImpl in project intellij-community by JetBrains.

the class IdeEventQueue method _dispatchEvent.

public void _dispatchEvent(@NotNull AWTEvent e, boolean typeAheadFlushing) {
    if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
        DnDManagerImpl dndManager = (DnDManagerImpl) DnDManager.getInstance();
        if (dndManager != null) {
            dndManager.setLastDropHandler(null);
        }
    }
    myEventCount++;
    if (processAppActivationEvents(e))
        return;
    if (!typeAheadFlushing) {
        fixStickyFocusedComponents(e);
    }
    if (!myPopupManager.isPopupActive()) {
        enterSuspendModeIfNeeded(e);
    }
    myKeyboardBusy = e instanceof KeyEvent || myKeyboardEventsPosted.get() > myKeyboardEventsDispatched.get();
    if (e instanceof KeyEvent) {
        if (e.getID() == KeyEvent.KEY_RELEASED && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_SHIFT) {
            myMouseEventDispatcher.resetHorScrollingTracker();
        }
    }
    if (!typeAheadFlushing && typeAheadDispatchToFocusManager(e)) {
        LOG.debug("Typeahead dispatch for event ", e);
        return;
    }
    if (e instanceof WindowEvent) {
        ActivityTracker.getInstance().inc();
    }
    if (e instanceof MouseWheelEvent) {
        final MenuElement[] selectedPath = MenuSelectionManager.defaultManager().getSelectedPath();
        if (selectedPath.length > 0 && !(selectedPath[0] instanceof ComboPopup)) {
            ((MouseWheelEvent) e).consume();
            Component component = selectedPath[0].getComponent();
            if (component instanceof JBPopupMenu) {
                ((JBPopupMenu) component).processMouseWheelEvent((MouseWheelEvent) e);
            }
            return;
        }
    }
    // Process "idle" and "activity" listeners
    if (e instanceof KeyEvent || e instanceof MouseEvent) {
        ActivityTracker.getInstance().inc();
        synchronized (myLock) {
            myIdleRequestsAlarm.cancelAllRequests();
            for (Runnable idleListener : myIdleListeners) {
                final MyFireIdleRequest request = myListener2Request.get(idleListener);
                if (request == null) {
                    LOG.error("There is no request for " + idleListener);
                } else {
                    myIdleRequestsAlarm.addRequest(request, request.getTimeout(), ModalityState.NON_MODAL);
                }
            }
            if (KeyEvent.KEY_PRESSED == e.getID() || KeyEvent.KEY_TYPED == e.getID() || MouseEvent.MOUSE_PRESSED == e.getID() || MouseEvent.MOUSE_RELEASED == e.getID() || MouseEvent.MOUSE_CLICKED == e.getID()) {
                addIdleTimeCounterRequest();
                for (Runnable activityListener : myActivityListeners) {
                    activityListener.run();
                }
            }
        }
    }
    if (myPopupManager.isPopupActive() && myPopupManager.dispatch(e)) {
        if (myKeyEventDispatcher.isWaitingForSecondKeyStroke()) {
            myKeyEventDispatcher.setState(KeyState.STATE_INIT);
        }
        return;
    }
    if (dispatchByCustomDispatchers(e))
        return;
    if (e instanceof InputMethodEvent) {
        if (SystemInfo.isMac && myKeyEventDispatcher.isWaitingForSecondKeyStroke()) {
            return;
        }
    }
    if (e instanceof ComponentEvent && myWindowManager != null) {
        myWindowManager.dispatchComponentEvent((ComponentEvent) e);
    }
    if (e instanceof KeyEvent) {
        if (mySuspendMode || !myKeyEventDispatcher.dispatchKeyEvent((KeyEvent) e)) {
            defaultDispatchEvent(e);
        } else {
            ((KeyEvent) e).consume();
            defaultDispatchEvent(e);
        }
    } else if (e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) e;
        if (IdeMouseEventDispatcher.patchClickCount(me) && me.getID() == MouseEvent.MOUSE_CLICKED) {
            final MouseEvent toDispatch = new MouseEvent(me.getComponent(), me.getID(), System.currentTimeMillis(), me.getModifiers(), me.getX(), me.getY(), 1, me.isPopupTrigger(), me.getButton());
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(() -> dispatchEvent(toDispatch));
        }
        if (!myMouseEventDispatcher.dispatchMouseEvent(me)) {
            defaultDispatchEvent(e);
        }
    } else {
        defaultDispatchEvent(e);
    }
}
Also used : JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) DnDManagerImpl(com.intellij.ide.dnd.DnDManagerImpl) ComboPopup(javax.swing.plaf.basic.ComboPopup)

Aggregations

DnDManagerImpl (com.intellij.ide.dnd.DnDManagerImpl)1 JBPopupMenu (com.intellij.openapi.ui.JBPopupMenu)1 ComboPopup (javax.swing.plaf.basic.ComboPopup)1