From a6f73c0cb5e3ce07f38dff43d4479635c0b2703f Mon Sep 17 00:00:00 2001 From: Vassiliy Kudryashov Date: Wed, 20 Feb 2013 17:26:51 +0400 Subject: [PATCH] IDEA-100922 Messages, Run & Debug tool windows pop up unexpectedly and disturb one from the current work --- .../intellij/compiler/progress/CompilerTask.java | 16 ++++++++++++++-- .../execution/ui/RunContentManagerImpl.java | 2 +- .../src/com/intellij/openapi/wm/ToolWindow.java | 7 +++++++ .../wm/impl/ToolWindowHeadlessManagerImpl.java | 5 +++++ .../intellij/openapi/wm/impl/ToolWindowImpl.java | 13 ++++++++++++- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java index 9c430d8a3ad9..c4000e1ebb45 100644 --- a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java +++ b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java @@ -41,6 +41,7 @@ import com.intellij.openapi.project.DumbModeAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerListener; +import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.TextRange; @@ -209,6 +210,18 @@ public class CompilerTask extends Task.Backgroundable { closeUI(); } stopAppIconProgress(); + + Runnable runnable = new Runnable() { + public void run() { + NotificationInfo notificationInfo = getNotificationInfo(); + if (notificationInfo != null && !myMessagesAutoActivated && (myErrorCount > 0 || (myWarningCount > 0 && !ErrorTreeViewConfiguration.getInstance(myProject).isHideWarnings()))) { + MessageType messageType = myErrorCount > 0 ? MessageType.ERROR : myWarningCount > 0 ? MessageType.WARNING : MessageType.INFO; + ToolWindowManager.getInstance(myProject).notifyByBalloon(ToolWindowId.MESSAGES_WINDOW, messageType, + getNotificationInfo().getNotificationText(), null, null); + } + } + }; + ApplicationManager.getApplication().invokeLater(runnable); } private void stopAppIconProgress() { @@ -319,7 +332,6 @@ public class CompilerTask extends Task.Backgroundable { (CompilerMessageCategory.WARNING.equals(category) && !ErrorTreeViewConfiguration.getInstance(myProject).isHideWarnings()) ); if (shouldAutoActivate) { - myMessagesAutoActivated = true; activateMessageView(); } } @@ -444,7 +456,7 @@ public class CompilerTask extends Task.Backgroundable { if (myErrorTreeView != null) { final ToolWindow tw = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.MESSAGES_WINDOW); if (tw != null) { - tw.activate(null, false); + myMessagesAutoActivated = tw.activate(null, false, false, false); } } } diff --git a/platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java index c044e5b8c97b..c3018d5fe9f9 100644 --- a/platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java @@ -342,7 +342,7 @@ public class RunContentManagerImpl implements RunContentManager, Disposable { // mark the window as "last activated" windows and thus // some action like navigation up/down in stactrace wont // work correctly - window.activate(null, false, false); + window.activate(null, false, false, false); } }); } diff --git a/platform/platform-api/src/com/intellij/openapi/wm/ToolWindow.java b/platform/platform-api/src/com/intellij/openapi/wm/ToolWindow.java index 93870283c6ce..b73abbab69a3 100644 --- a/platform/platform-api/src/com/intellij/openapi/wm/ToolWindow.java +++ b/platform/platform-api/src/com/intellij/openapi/wm/ToolWindow.java @@ -46,6 +46,13 @@ public interface ToolWindow extends BusyObject { void activate(@Nullable Runnable runnable, boolean autoFocusContents, boolean forced); + /** + * @param ignoreActiveWindowWithSameAnchor is true by default. + * If it's false and current active window has same anchor, activation will be cancelled + * @return false if activation was cancelled, otherwise true + */ + boolean activate(@Nullable Runnable runnable, boolean autoFocusContents, boolean forced, boolean ignoreActiveWindowWIthSameAnchor); + /** * @return whether the tool window is visible or not. * @exception IllegalStateException if tool window isn't installed. diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeadlessManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeadlessManagerImpl.java index 1f54b2bb341a..15e7a60c52d5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeadlessManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeadlessManagerImpl.java @@ -212,6 +212,11 @@ public class ToolWindowHeadlessManagerImpl extends ToolWindowManagerEx { public void activate(@Nullable Runnable runnable, boolean autoFocusContents, boolean forced) { } + @Override + public boolean activate(@Nullable Runnable runnable, boolean autoFocusContents, boolean forced, boolean ignoreActiveWindowWIthSameAnchor) { + return true; + } + @Override public void showContentPopup(InputEvent inputEvent) { } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java index 96458475d254..61c49e0657ad 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java @@ -126,8 +126,18 @@ public final class ToolWindowImpl implements ToolWindowEx { } public void activate(@Nullable final Runnable runnable, boolean autoFocusContents, boolean forced) { - ApplicationManager.getApplication().assertIsDispatchThread(); + activate(runnable, autoFocusContents, forced, true); + } + @Override + public boolean activate(@Nullable final Runnable runnable, boolean autoFocusContents, boolean forced, boolean ignoreActiveWindowWithSameAnchor) { + ApplicationManager.getApplication().assertIsDispatchThread(); + if (!ignoreActiveWindowWithSameAnchor) { + String windowId = myToolWindowManager.getActiveToolWindowId(); + if (windowId != null && windowId != myId && myToolWindowManager.getToolWindowAnchor(windowId) == getAnchor()) { + return false; + } + } final UiActivity activity = new UiActivity.Focus("toolWindow:" + myId); UiActivityMonitor.getInstance().addActivity(myToolWindowManager.getProject(), activity, ModalityState.NON_MODAL); @@ -146,6 +156,7 @@ public final class ToolWindowImpl implements ToolWindowEx { }); } }); + return true; } public final boolean isActive() {