From 2b76ea0ea2f114ac7cced414a98c49de40d644d6 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Thu, 10 Sep 2009 10:21:52 +0400 Subject: [PATCH] focus tranfer on inactive application fix --- .../wm/impl/ToolWindowManagerImpl.java | 36 +++++++++++-------- .../src/misc/registry.properties | 1 + 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index cb00558ddf61..2a0e173b91bd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -2047,7 +2047,9 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements return true; } - if (!myApp.isActive() && !canExecuteOnInactiveApplication(cmd)) { + boolean doNotExecuteBecauseAppIsInactive = !myApp.isActive() + && (!canExecuteOnInactiveApplication(cmd) && Registry.is("actionSystem.suspendFocusTransferIfApplicationInactive")); + if (doNotExecuteBecauseAppIsInactive) { if (myCallbackOnActivation != null) { myCallbackOnActivation.setRejected(); } @@ -2138,26 +2140,32 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements } @Override - public void applicationActivated(IdeFrame ideFrame) { + public void applicationActivated(final IdeFrame ideFrame) { final FocusCommand cmd = myFocusCommandOnAppActivation; ActionCallback callback = myCallbackOnActivation; myFocusCommandOnAppActivation = null; myCallbackOnActivation = null; - if (cmd != null && !cmd.isExpired()) { - requestFocus(cmd, true).notifyWhenDone(callback); - } - else { - final KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager(); - if (ideFrame == myWindowManager.getFrame(myProject)) { - final Component owner = mgr.getFocusOwner(); - Component old = myFocusedComponentOnDeactivation != null ? myFocusedComponentOnDeactivation.get() : null; - - if (owner == null && old != null && old.isShowing()) { - requestFocus(old, false); + if (cmd != null) { + requestFocus(cmd, true).notify(callback).doWhenRejected(new Runnable() { + public void run() { + focusLastFocusedComponent(ideFrame); } - myFocusedComponentOnDeactivation = null; + }); + } else { + focusLastFocusedComponent(ideFrame); + } + } + + private void focusLastFocusedComponent(IdeFrame ideFrame) { + final KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + if (ideFrame == myWindowManager.getFrame(myProject)) { + final Component owner = mgr.getFocusOwner(); + Component old = myFocusedComponentOnDeactivation != null ? myFocusedComponentOnDeactivation.get() : null; + if (owner == null && old != null && old.isShowing()) { + requestFocus(old, false); } + myFocusedComponentOnDeactivation = null; } } } diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 4e4aeb6dfd0e..5693cb7faa51 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -19,6 +19,7 @@ actionSystem.playback.description=Delay between events generated by the playback actionSystem.focusIdleTimeout=20 actionSystem.mac.screenMenuNotUpdatedFix=true actionSystem.keyGestures.enabled=false +actionSystem.suspendFocusTransferIfApplicationInactive=true ide.debugMode=true ide.debugMode.description=Record additonal information to make bug reports more informative