Search in sources :

Example 16 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame 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;
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) IdeGlassPaneImpl(com.intellij.openapi.wm.impl.IdeGlassPaneImpl) MouseShortcutPanel(com.intellij.openapi.keymap.impl.ui.MouseShortcutPanel) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) IdeFrame(com.intellij.openapi.wm.IdeFrame) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Example 17 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class WindowManagerImpl method tryToFindTheOnlyFrame.

private static IdeFrame tryToFindTheOnlyFrame() {
    IdeFrame candidate = null;
    final Frame[] all = Frame.getFrames();
    for (Frame each : all) {
        if (each instanceof IdeFrame) {
            if (candidate == null) {
                candidate = (IdeFrame) each;
            } else {
                candidate = null;
                break;
            }
        }
    }
    return candidate;
}
Also used : WelcomeFrame(com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame) IdeFrame(com.intellij.openapi.wm.IdeFrame) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 18 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class WindowManagerImpl method getIdeFrame.

@Override
public IdeFrame getIdeFrame(@Nullable final Project project) {
    if (project != null) {
        return getFrame(project);
    }
    final Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    final Component parent = UIUtil.findUltimateParent(window);
    if (parent instanceof IdeFrame)
        return (IdeFrame) parent;
    final Frame[] frames = Frame.getFrames();
    for (Frame each : frames) {
        if (each instanceof IdeFrame) {
            return (IdeFrame) each;
        }
    }
    return null;
}
Also used : WelcomeFrame(com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame) IdeFrame(com.intellij.openapi.wm.IdeFrame) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 19 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class ToolWindowContentUi method initMouseListeners.

public static void initMouseListeners(final JComponent c, final ToolWindowContentUi ui) {
    if (c.getClientProperty(ui) != null)
        return;
    final Point[] myLastPoint = new Point[1];
    c.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseDragged(final MouseEvent e) {
            if (myLastPoint[0] == null)
                return;
            final Window window = SwingUtilities.windowForComponent(c);
            if (window instanceof IdeFrame)
                return;
            final Point windowLocation = window.getLocationOnScreen();
            PointerInfo info = MouseInfo.getPointerInfo();
            if (info == null)
                return;
            final Point newPoint = info.getLocation();
            Point p = myLastPoint[0];
            windowLocation.translate(newPoint.x - p.x, newPoint.y - p.y);
            window.setLocation(windowLocation);
            myLastPoint[0] = newPoint;
        }
    });
    c.addMouseListener(new MouseAdapter() {

        public void mousePressed(final MouseEvent e) {
            PointerInfo info = MouseInfo.getPointerInfo();
            myLastPoint[0] = info != null ? info.getLocation() : e.getLocationOnScreen();
            if (!e.isPopupTrigger()) {
                if (!UIUtil.isCloseClick(e)) {
                    ui.myWindow.fireActivated();
                }
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (!e.isPopupTrigger()) {
                if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) {
                    ui.processHide(e);
                }
            }
        }
    });
    c.addMouseListener(new PopupHandler() {

        public void invokePopup(final Component comp, final int x, final int y) {
            final Content content = c instanceof BaseLabel ? ((BaseLabel) c).getContent() : null;
            ui.showContextMenu(comp, x, y, ui.myWindow.getPopupGroup(), content);
        }
    });
    c.putClientProperty(ui, Boolean.TRUE);
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) IdeFrame(com.intellij.openapi.wm.IdeFrame) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 20 with IdeFrame

use of com.intellij.openapi.wm.IdeFrame in project intellij-community by JetBrains.

the class GuiTestUtil method waitForIdeToStart.

// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
    GuiActionRunner.executeInEDT(false);
    Robot robot = null;
    try {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
        final MyProjectManagerListener listener = new MyProjectManagerListener();
        //[ACCEPT IntelliJ IDEA Privacy Policy Agreement]
        acceptAgreementIfNeeded(robot);
        findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

            @Override
            protected boolean isMatching(@NotNull Frame frame) {
                if (frame instanceof IdeFrame) {
                    if (frame instanceof IdeFrameImpl) {
                        listener.myActive = true;
                        ProjectManager.getInstance().addProjectManagerListener(listener);
                    }
                    return true;
                }
                return false;
            }
        }).withTimeout(LONG_TIMEOUT.duration()).using(robot);
        if (listener.myActive) {
            Pause.pause(new Condition("Project to be opened") {

                @Override
                public boolean test() {
                    boolean notified = listener.myNotified;
                    if (notified) {
                        ProgressManager progressManager = ProgressManager.getInstance();
                        boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
                        if (isIdle) {
                            ProjectManager.getInstance().removeProjectManagerListener(listener);
                        }
                        return isIdle;
                    }
                    return false;
                }
            }, LONG_TIMEOUT);
        }
    } finally {
        GuiActionRunner.executeInEDT(true);
        if (robot != null) {
            robot.cleanUpWithoutDisposingWindows();
        }
    }
}
Also used : Condition(org.fest.swing.timing.Condition) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeFrame(com.intellij.openapi.wm.IdeFrame) WindowFinder.findFrame(org.fest.swing.finder.WindowFinder.findFrame) ProgressManager(com.intellij.openapi.progress.ProgressManager) Robot(org.fest.swing.core.Robot) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Aggregations

IdeFrame (com.intellij.openapi.wm.IdeFrame)49 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)7 Balloon (com.intellij.openapi.ui.popup.Balloon)5 IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)5 NotNull (org.jetbrains.annotations.NotNull)5 ProgressManager (com.intellij.openapi.progress.ProgressManager)4 MessageType (com.intellij.openapi.ui.MessageType)3 StatusBarEx (com.intellij.openapi.wm.ex.StatusBarEx)3 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 HyperlinkEvent (javax.swing.event.HyperlinkEvent)3 Application (com.intellij.openapi.application.Application)2 ApplicationActivationListener (com.intellij.openapi.application.ApplicationActivationListener)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 ModalityState (com.intellij.openapi.application.ModalityState)2 Extensions (com.intellij.openapi.extensions.Extensions)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Ref (com.intellij.openapi.util.Ref)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2