Search in sources :

Example 21 with IdeFocusManager

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

the class FocusTracesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
    if (!(manager instanceof FocusManagerImpl))
        return;
    final FocusManagerImpl focusManager = (FocusManagerImpl) manager;
    myActive = !myActive;
    if (myActive) {
        myFocusTracker = new AWTEventListener() {

            @Override
            public void eventDispatched(AWTEvent event) {
                if (event instanceof FocusEvent && event.getID() == FocusEvent.FOCUS_GAINED) {
                    focusManager.recordFocusRequest(((FocusEvent) event).getComponent(), false);
                }
            }
        };
        Toolkit.getDefaultToolkit().addAWTEventListener(myFocusTracker, AWTEvent.FOCUS_EVENT_MASK);
    }
    if (!myActive) {
        final List<FocusRequestInfo> requests = focusManager.getRequests();
        new FocusTracesDialog(project, new ArrayList<>(requests)).show();
        Toolkit.getDefaultToolkit().removeAWTEventListener(myFocusTracker);
        myFocusTracker = null;
        requests.clear();
    }
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) Project(com.intellij.openapi.project.Project) AWTEventListener(java.awt.event.AWTEventListener) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) ArrayList(java.util.ArrayList) FocusEvent(java.awt.event.FocusEvent) FocusRequestInfo(com.intellij.openapi.wm.impl.FocusRequestInfo)

Example 22 with IdeFocusManager

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

the class DataManagerImpl method getFocusedComponent.

@Nullable
private Component getFocusedComponent() {
    if (myWindowManager == null) {
        return null;
    }
    Window activeWindow = myWindowManager.getMostRecentFocusedWindow();
    if (activeWindow == null) {
        activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
        if (activeWindow == null) {
            activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
            if (activeWindow == null)
                return null;
        }
    }
    if (Registry.is("actionSystem.noContextComponentWhileFocusTransfer")) {
        IdeFocusManager fm = IdeFocusManager.findInstanceByComponent(activeWindow);
        if (fm.isFocusBeingTransferred()) {
            return null;
        }
    }
    // whereas we want to be able to type in other frames as well.
    if (activeWindow instanceof FloatingDecorator) {
        IdeFocusManager ideFocusManager = IdeFocusManager.findInstanceByComponent(activeWindow);
        IdeFrame lastFocusedFrame = ideFocusManager.getLastFocusedFrame();
        JComponent frameComponent = lastFocusedFrame != null ? lastFocusedFrame.getComponent() : null;
        Window lastFocusedWindow = frameComponent != null ? SwingUtilities.getWindowAncestor(frameComponent) : null;
        boolean toolWindowIsNotFocused = myWindowManager.getFocusedComponent(activeWindow) == null;
        if (toolWindowIsNotFocused && lastFocusedWindow != null) {
            activeWindow = lastFocusedWindow;
        }
    }
    // try to find first parent window that has focus
    Window window = activeWindow;
    Component focusedComponent = null;
    while (window != null) {
        focusedComponent = myWindowManager.getFocusedComponent(window);
        if (focusedComponent != null) {
            break;
        }
        window = window.getOwner();
    }
    if (focusedComponent == null) {
        focusedComponent = activeWindow;
    }
    return focusedComponent;
}
Also used : FloatingDecorator(com.intellij.openapi.wm.impl.FloatingDecorator) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) IdeFrame(com.intellij.openapi.wm.IdeFrame) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with IdeFocusManager

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

the class DirDiffPanel method focusTable.

public void focusTable() {
    final Project project = myModel.getProject();
    final IdeFocusManager focusManager = project == null || project.isDefault() ? IdeFocusManager.getGlobalInstance() : IdeFocusManager.getInstance(project);
    focusManager.requestFocus(myTable, true);
}
Also used : Project(com.intellij.openapi.project.Project) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager)

Example 24 with IdeFocusManager

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

the class ChooseByNameBase method showTextFieldPanel.

protected void showTextFieldPanel() {
    final JLayeredPane layeredPane = getLayeredPane();
    final Dimension preferredTextFieldPanelSize = myTextFieldPanel.getPreferredSize();
    final int x = (layeredPane.getWidth() - preferredTextFieldPanelSize.width) / 2;
    final int paneHeight = layeredPane.getHeight();
    final int y = paneHeight / 3 - preferredTextFieldPanelSize.height / 2;
    VISIBLE_LIST_SIZE_LIMIT = Math.max(10, (paneHeight - (y + preferredTextFieldPanelSize.height)) / (preferredTextFieldPanelSize.height / 2) - 1);
    ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myTextFieldPanel, myTextField);
    builder.setLocateWithinScreenBounds(false);
    builder.setKeyEventHandler(event -> {
        if (myTextPopup == null || !AbstractPopup.isCloseRequest(event) || !myTextPopup.isCancelKeyEnabled()) {
            return false;
        }
        IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject);
        if (isDescendingFromTemporarilyFocusableToolWindow(focusManager.getFocusOwner())) {
            focusManager.requestFocus(myTextField, true);
            return false;
        } else {
            myTextPopup.cancel(event);
            return true;
        }
    }).setCancelCallback(() -> {
        myTextPopup = null;
        close(false);
        return Boolean.TRUE;
    }).setFocusable(true).setRequestFocus(true).setModalContext(false).setCancelOnClickOutside(false);
    Point point = new Point(x, y);
    SwingUtilities.convertPointToScreen(point, layeredPane);
    Rectangle bounds = new Rectangle(point, new Dimension(preferredTextFieldPanelSize.width + 20, preferredTextFieldPanelSize.height));
    myTextPopup = builder.createPopup();
    myTextPopup.setSize(bounds.getSize());
    myTextPopup.setLocation(bounds.getLocation());
    MnemonicHelper.init(myTextFieldPanel);
    if (myProject != null && !myProject.isDefault()) {
        DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(myTextPopup);
    }
    Disposer.register(myTextPopup, new Disposable() {

        @Override
        public void dispose() {
            cancelListUpdater();
        }
    });
    myTextPopup.show(layeredPane);
}
Also used : ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) AllIcons(com.intellij.icons.AllIcons) ReadTask(com.intellij.openapi.progress.util.ReadTask) ModalityState(com.intellij.openapi.application.ModalityState) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) Task(com.intellij.openapi.progress.Task) TooManyUsagesStatus(com.intellij.openapi.progress.util.TooManyUsagesStatus) Disposer(com.intellij.openapi.util.Disposer) Matcher(com.intellij.util.text.Matcher) Logger(com.intellij.openapi.diagnostic.Logger) ListSelectionEvent(javax.swing.event.ListSelectionEvent) AttributeSet(javax.swing.text.AttributeSet) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) ToolWindow(com.intellij.openapi.wm.ToolWindow) StatisticsInfo(com.intellij.psi.statistics.StatisticsInfo) WindowManager(com.intellij.openapi.wm.WindowManager) PopupOwner(com.intellij.ui.popup.PopupOwner) MacIntelliJTextFieldUI(com.intellij.ide.ui.laf.intellij.MacIntelliJTextFieldUI) AbstractPopup(com.intellij.ui.popup.AbstractPopup) BadLocationException(javax.swing.text.BadLocationException) com.intellij.openapi.ui.popup(com.intellij.openapi.ui.popup) PlainDocument(javax.swing.text.PlainDocument) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) com.intellij.ui(com.intellij.ui) UsageViewManagerImpl(com.intellij.usages.impl.UsageViewManagerImpl) UnknownFileType(com.intellij.openapi.fileTypes.UnknownFileType) IdeBundle(com.intellij.ide.IdeBundle) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) CopyReferenceAction(com.intellij.ide.actions.CopyReferenceAction) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) com.intellij.util.ui(com.intellij.util.ui) java.awt.event(java.awt.event) ApplicationManager(com.intellij.openapi.application.ApplicationManager) EmptyBorder(javax.swing.border.EmptyBorder) Registry(com.intellij.openapi.util.registry.Registry) WindowManagerEx(com.intellij.openapi.wm.ex.WindowManagerEx) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) KeymapManager(com.intellij.openapi.keymap.KeymapManager) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) MatcherHolder(com.intellij.util.text.MatcherHolder) NonNls(org.jetbrains.annotations.NonNls) UsageInfo(com.intellij.usageView.UsageInfo) MacIntelliJTextBorder(com.intellij.ide.ui.laf.intellij.MacIntelliJTextBorder) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) ContainerUtil(com.intellij.util.containers.ContainerUtil) NameUtil(com.intellij.psi.codeStyle.NameUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) StatisticsManager(com.intellij.psi.statistics.StatisticsManager) PopupUpdateProcessor(com.intellij.ui.popup.PopupUpdateProcessor) DarculaTextFieldUI(com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PopupPositionManager(com.intellij.ui.popup.PopupPositionManager) DocumentEvent(javax.swing.event.DocumentEvent) DataManager(com.intellij.ide.DataManager) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) JBList(com.intellij.ui.components.JBList) Patches(com.intellij.Patches) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.usages(com.intellij.usages) GotoFileAction(com.intellij.ide.actions.GotoFileAction) FileTypeManagerEx(com.intellij.openapi.fileTypes.ex.FileTypeManagerEx) Disposable(com.intellij.openapi.Disposable) SystemInfo(com.intellij.openapi.util.SystemInfo) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Pair(com.intellij.openapi.util.Pair) MnemonicHelper(com.intellij.openapi.MnemonicHelper) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ListSelectionListener(javax.swing.event.ListSelectionListener) DarculaTextBorder(com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) Disposable(com.intellij.openapi.Disposable) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager)

Example 25 with IdeFocusManager

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

the class FileEditorManagerImpl method notifyPublisher.

@NotNull
@Override
public ActionCallback notifyPublisher(@NotNull final Runnable runnable) {
    final IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject);
    final ActionCallback done = new ActionCallback();
    return myBusyObject.execute(new ActiveRunnable() {

        @NotNull
        @Override
        public ActionCallback run() {
            focusManager.doWhenFocusSettlesDown(new ExpirableRunnable.ForProject(myProject) {

                @Override
                public void run() {
                    runnable.run();
                    done.setDone();
                }
            });
            return done;
        }
    });
}
Also used : IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

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