From ddcb5a75478a5de12a34885c73f7fd4368e6b2aa Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Fri, 5 Feb 2010 18:37:46 +0300 Subject: [PATCH] linux focus stealing: toFront() is done vie IdeFocusManager --- .../intellij/debugger/ui/DebuggerSessionTab.java | 3 +- .../src/com/intellij/ide/impl/ProjectUtil.java | 19 +++++-- .../commands/RequestFocusInEditorComponentCmd.java | 35 ++++++------ .../impl/commands/RequestFocusInToolWindowCmd.java | 66 +++++++++++++--------- .../xdebugger/impl/ui/XDebugSessionTab.java | 3 +- 5 files changed, 78 insertions(+), 48 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java index 1e155c2326..3317938fb7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java @@ -46,6 +46,7 @@ import com.intellij.execution.ui.layout.LayoutViewOptions; import com.intellij.execution.ui.layout.PlaceInGrid; import com.intellij.ide.CommonActionsManager; import com.intellij.ide.actions.ContextHelpAction; +import com.intellij.ide.impl.ProjectUtil; import com.intellij.idea.ActionsBundle; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; @@ -422,8 +423,8 @@ public class DebuggerSessionTab extends DebuggerLogConsoleManagerBase implements protected void toFront() { if (!ApplicationManager.getApplication().isUnitTestMode()) { - ((WindowManagerImpl)WindowManager.getInstance()).getFrame(getProject()).toFront(); ExecutionManager.getInstance(getProject()).getContentManager().toFrontRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), myRunContentDescriptor); + ProjectUtil.focusProjectWindow(getProject()); } } diff --git a/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java b/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java index 196eb20205..2467e49e9c 100644 --- a/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java @@ -31,11 +31,14 @@ import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ex.ProjectEx; import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.wm.FocusCommand; +import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.WindowManager; import com.intellij.projectImport.ProjectOpenProcessor; import org.jdom.JDOMException; @@ -203,10 +206,18 @@ public class ProjectUtil { return FileUtil.pathsEqual(toOpen, existing); } - private static void focusProjectWindow(Project p) { - JFrame f = WindowManager.getInstance().getFrame(p); - f.toFront(); - f.requestFocus(); + public static void focusProjectWindow(final Project p) { + IdeFocusManager.getInstance(p).requestFocus(new FocusCommand() { + @Override + public ActionCallback run() { + JFrame f = WindowManager.getInstance().getFrame(p); + if (f != null) { + f.toFront(); + f.requestFocus(); + } + return new ActionCallback.Done(); + } + }, false); } public static boolean isProjectOrWorkspaceFile(final VirtualFile file) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/commands/RequestFocusInEditorComponentCmd.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/commands/RequestFocusInEditorComponentCmd.java index c416a67519..abda1b13f2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/commands/RequestFocusInEditorComponentCmd.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/commands/RequestFocusInEditorComponentCmd.java @@ -74,24 +74,27 @@ public final class RequestFocusInEditorComponentCmd extends FinalizableCommand{ if(owner==null){ return; } - // if owner is active window or it has active child window which isn't floating decorator then - // don't bring owner window to font. If we will make toFront every time then it's possible - // the following situation: - // 1. user prform refactoring - // 2. "Do not show preview" dialog is popping up. - // 3. At that time "preview" tool window is being activated and modal "don't show..." dialog - // isn't active. - if(!owner.isActive()){ - final Window activeWindow=getActiveWindow(owner.getOwnedWindows()); - if(activeWindow == null || (activeWindow instanceof FloatingDecorator)){ - //Thread.dumpStack(); - //System.out.println("------------------------------------------------------"); - owner.toFront(); - } - } if(myComponent != null){ - myFocusManager.requestFocus(myComponent, myForced).notifyWhenDone(myDoneCallback); + myFocusManager.requestFocus(myComponent, myForced).notifyWhenDone(myDoneCallback).doWhenDone(new Runnable() { + public void run() { + // if owner is active window or it has active child window which isn't floating decorator then + // don't bring owner window to font. If we will make toFront every time then it's possible + // the following situation: + // 1. user prform refactoring + // 2. "Do not show preview" dialog is popping up. + // 3. At that time "preview" tool window is being activated and modal "don't show..." dialog + // isn't active. + if(!owner.isActive()){ + final Window activeWindow=getActiveWindow(owner.getOwnedWindows()); + if(activeWindow == null || (activeWindow instanceof FloatingDecorator)){ + //Thread.dumpStack(); + //System.out.println("------------------------------------------------------"); + owner.toFront(); + } + } + } + }); } else { myDoneCallback.setRejected(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/commands/RequestFocusInToolWindowCmd.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/commands/RequestFocusInToolWindowCmd.java index 116318fd73..6528fd5bf1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/commands/RequestFocusInToolWindowCmd.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/commands/RequestFocusInToolWindowCmd.java @@ -98,35 +98,22 @@ public final class RequestFocusInToolWindowCmd extends FinalizableCommand { preferredFocusedComponent = IdeFocusTraversalPolicy.getPreferredFocusedComponent(component); } - final Window owner = SwingUtilities.getWindowAncestor(myToolWindow.getComponent()); - //if (owner == null) { - // System.out.println("owner = " + owner); - // return; - //} - // if owner is active window or it has active child window which isn't floating decorator then - // don't bring owner window to font. If we will make toFront every time then it's possible - // the following situation: - // 1. user prform refactoring - // 2. "Do not show preview" dialog is popping up. - // 3. At that time "preview" tool window is being activated and modal "don't show..." dialog - // isn't active. - if (owner != null && owner.getFocusOwner() == null) { - final Window activeWindow = getActiveWindow(owner.getOwnedWindows()); - if (activeWindow == null || (activeWindow instanceof FloatingDecorator)) { - LOG.debug("owner.toFront()"); - //Thread.dumpStack(); - //System.out.println("------------------------------------------------------"); - owner.toFront(); - } - } // Try to focus component which is preferred one for the tool window if (preferredFocusedComponent != null) { - requestFocus(preferredFocusedComponent); + requestFocus(preferredFocusedComponent).doWhenDone(new Runnable() { + public void run() { + bringOwnerToFront(); + } + }); } else { // If there is no preferred component then try to focus tool window itself final JComponent componentToFocus = myToolWindow.getComponent(); - requestFocus(componentToFocus); + requestFocus(componentToFocus).doWhenDone(new Runnable() { + public void run() { + bringOwnerToFront(); + } + }); } } finally { @@ -134,8 +121,33 @@ public final class RequestFocusInToolWindowCmd extends FinalizableCommand { } } + private void bringOwnerToFront() { + final Window owner = SwingUtilities.getWindowAncestor(myToolWindow.getComponent()); + //if (owner == null) { + // System.out.println("owner = " + owner); + // return; + //} + // if owner is active window or it has active child window which isn't floating decorator then + // don't bring owner window to font. If we will make toFront every time then it's possible + // the following situation: + // 1. user prform refactoring + // 2. "Do not show preview" dialog is popping up. + // 3. At that time "preview" tool window is being activated and modal "don't show..." dialog + // isn't active. + if (owner != null && owner.getFocusOwner() == null) { + final Window activeWindow = getActiveWindow(owner.getOwnedWindows()); + if (activeWindow == null || (activeWindow instanceof FloatingDecorator)) { + LOG.debug("owner.toFront()"); + //Thread.dumpStack(); + //System.out.println("------------------------------------------------------"); + owner.toFront(); + } + } + } + - private void requestFocus(final Component c) { + private ActionCallback requestFocus(final Component c) { + ActionCallback result = new ActionCallback(); final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); if (owner != null && owner == c) { myManager.getFocusManager().requestFocus(new FocusCommand() { @@ -146,15 +158,17 @@ public final class RequestFocusInToolWindowCmd extends FinalizableCommand { public void run() { updateToolWindow(c); } - }); + }).notify(result); } else { myManager.getFocusManager().requestFocus(new FocusCommand.ByComponent(c, myToolWindow.getComponent()), myForced).doWhenProcessed(new Runnable() { public void run() { updateToolWindow(c); } - }); + }).notify(result); } + + return result; } private void updateToolWindow(Component c) { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java index 810455fc36..0622a5ca77 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java @@ -33,6 +33,7 @@ import com.intellij.execution.ui.actions.CloseAction; import com.intellij.execution.ui.layout.PlaceInGrid; import com.intellij.ide.CommonActionsManager; import com.intellij.ide.actions.ContextHelpAction; +import com.intellij.ide.impl.ProjectUtil; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; @@ -258,7 +259,7 @@ public class XDebugSessionTab extends DebuggerLogConsoleManagerBase { public void toFront() { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - WindowManagerEx.getInstanceEx().getFrame(getProject()).toFront(); + ProjectUtil.focusProjectWindow(getProject()); ExecutionManager.getInstance(getProject()).getContentManager().toFrontRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), myRunContentDescriptor); } }); -- 2.11.4.GIT