Search in sources :

Example 6 with IdeFocusManager

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

the class IdeaHelpBroker method setDisplayed.

/**
   * Displays the presentation to the user.
   */
public void setDisplayed(boolean visible) {
    createHelpWindow();
    if (myModallyActivated) {
        myDialog.setVisible(visible);
        if (visible) {
            myDialog.setLocationRelativeTo(myDialog.getOwner());
        }
    } else {
        //myFrame.setLocationRelativeTo(null);
        myFrame.setVisible(visible);
        myFrame.setState(JFrame.NORMAL);
        IdeFocusManager focusManager = IdeFocusManager.findInstance();
        JComponent target = focusManager.getFocusTargetFor(myFrame.getRootPane());
        focusManager.requestFocus(target != null ? target : myFrame, true);
    }
}
Also used : IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager)

Example 7 with IdeFocusManager

use of com.intellij.openapi.wm.IdeFocusManager 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 8 with IdeFocusManager

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

the class FileEditorManagerImpl method getActiveSplittersAsync.

@NotNull
private AsyncResult<EditorsSplitters> getActiveSplittersAsync() {
    final AsyncResult<EditorsSplitters> result = new AsyncResult<>();
    final IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
    fm.doWhenFocusSettlesDown(() -> {
        if (myProject.isDisposed()) {
            result.setRejected();
            return;
        }
        Component focusOwner = fm.getFocusOwner();
        DockContainer container = myDockManager.getContainerFor(focusOwner);
        if (container instanceof DockableEditorTabbedContainer) {
            result.setDone(((DockableEditorTabbedContainer) container).getSplitters());
        } else {
            result.setDone(getMainSplitters());
        }
    });
    return result;
}
Also used : DockContainer(com.intellij.ui.docking.DockContainer) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with IdeFocusManager

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

the class WindowSystemPlaybackCall method findProject.

public static AsyncResult<Project> findProject() {
    final AsyncResult<Project> project = new AsyncResult<>();
    final IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
    fm.doWhenFocusSettlesDown(() -> {
        Component parent = UIUtil.findUltimateParent(fm.getFocusOwner());
        if (parent instanceof IdeFrame) {
            IdeFrame frame = (IdeFrame) parent;
            if (frame.getProject() != null) {
                project.setDone(frame.getProject());
                return;
            }
        }
        project.setRejected();
    });
    return project;
}
Also used : Project(com.intellij.openapi.project.Project) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) AsyncResult(com.intellij.openapi.util.AsyncResult) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 10 with IdeFocusManager

use of com.intellij.openapi.wm.IdeFocusManager 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)

Aggregations

IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)27 Project (com.intellij.openapi.project.Project)6 IdeFrame (com.intellij.openapi.wm.IdeFrame)5 NotNull (org.jetbrains.annotations.NotNull)4 FocusManagerImpl (com.intellij.openapi.wm.impl.FocusManagerImpl)3 DataManager (com.intellij.ide.DataManager)2 Disposable (com.intellij.openapi.Disposable)2 PersistentStateComponent (com.intellij.openapi.components.PersistentStateComponent)2 AsyncResult (com.intellij.openapi.util.AsyncResult)2 Nullable (org.jetbrains.annotations.Nullable)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Patches (com.intellij.Patches)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 AllIcons (com.intellij.icons.AllIcons)1 IdeBundle (com.intellij.ide.IdeBundle)1 CopyReferenceAction (com.intellij.ide.actions.CopyReferenceAction)1 GotoFileAction (com.intellij.ide.actions.GotoFileAction)1 DarculaTextBorder (com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder)1 DarculaTextFieldUI (com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI)1