IDEA-79908 Balloons should be displayed in a not-focused window
authorpeter <peter@jetbrains.com>
Mon, 16 Jan 2012 17:06:13 +0000 (18:06 +0100)
committerpeter <peter@jetbrains.com>
Mon, 16 Jan 2012 18:26:41 +0000 (19:26 +0100)
platform/platform-impl/src/com/intellij/notification/EventLog.java
platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java
platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java
platform/platform-impl/src/com/intellij/ui/BalloonImpl.java

index b973cbf6bbe5924303458e68dc75626d5e7d57ca..2327b0e2a56e99d92ddcc4a13e1138d1203418d5 100644 (file)
@@ -410,7 +410,7 @@ public class EventLog implements Notifications {
 
       RelativePoint target = EventLog.getProjectComponent(project).myConsole.getHyperlinkLocation(this);
       if (target != null) {
-        Balloon balloon = NotificationsManagerImpl.createBalloon(myNotification, true, true, false);
+        Balloon balloon = NotificationsManagerImpl.createBalloon(myNotification, true, true);
         Disposer.register(project, balloon);
         balloon.show(target, Balloon.Position.above);
       }
index 1ff82647280147fcc382360bcd670809f4c17a46..6870f9459f21f767fb56aedf461decc1fd08cd10 100644 (file)
@@ -148,32 +148,18 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
     }
 
     if (NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS) {
-      showWhenVisible(notification, project);
-    }
-  }
-
-  private static void showWhenVisible(final Notification notification, final Project project) {
-    FrameStateManager.getInstance().getApplicationActive().doWhenDone(new Runnable() {
-      @Override
-      public void run() {
-        if (project != null) {
-          if (project.isDisposed()) {
-            return;
-          }
-
-          if (!project.isInitialized()) {
-            StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
-              @Override
-              public void run() {
-                showWhenVisible(notification, project);
-              }
-            });
-            return;
-          }
+      final Runnable runnable = new Runnable() {
+        @Override
+        public void run() {
+          showNotification(notification, project);
         }
-        showNotification(notification, project);
+      };
+      if (project == null) {
+        runnable.run();
+      } else if (!project.isDisposed()) {
+        StartupManager.getInstance(project).runWhenProjectIsInitialized(runnable);
       }
-    });
+    }
   }
 
   private static void showNotification(final Notification notification, @Nullable final Project project) {
@@ -244,18 +230,33 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
     Window window = findWindowForBalloon(project);
     if (window instanceof IdeFrameImpl) {
       final ProjectManager projectManager = ProjectManager.getInstance();
-      boolean noProjects = projectManager.getOpenProjects().length == 0;
-      boolean sticky = NotificationDisplayType.STICKY_BALLOON == displayType || noProjects;
-      final Balloon balloon = createBalloon(notification, false, false, !sticky);
+      final boolean noProjects = projectManager.getOpenProjects().length == 0;
+      final boolean sticky = NotificationDisplayType.STICKY_BALLOON == displayType || noProjects;
+      final Balloon balloon = createBalloon(notification, false, false);
       Disposer.register(project != null ? project : ApplicationManager.getApplication(), balloon);
       ((IdeFrameImpl)window).getBalloonLayout().add(balloon);
-      if (noProjects && NotificationDisplayType.BALLOON == displayType) {
-        projectManager.addProjectManagerListener(new ProjectManagerAdapter() {
+      if (NotificationDisplayType.BALLOON == displayType) {
+        FrameStateManager.getInstance().getApplicationActive().doWhenDone(new Runnable() {
           @Override
-          public void projectOpened(Project project) {
-            projectManager.removeProjectManagerListener(this);
-            if (!balloon.isDisposed()) {
-              ((BalloonImpl)balloon).startFadeoutTimer(300);
+          public void run() {
+            if (balloon.isDisposed()) {
+              return;
+            }
+
+            if (!sticky) {
+              ((BalloonImpl)balloon).startFadeoutTimer(3000);
+            }
+            else //noinspection ConstantConditions
+              if (noProjects) {
+              projectManager.addProjectManagerListener(new ProjectManagerAdapter() {
+                @Override
+                public void projectOpened(Project project) {
+                  projectManager.removeProjectManagerListener(this);
+                  if (!balloon.isDisposed()) {
+                    ((BalloonImpl)balloon).startFadeoutTimer(300);
+                  }
+                }
+              });
             }
           }
         });
@@ -274,7 +275,7 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
     return frame;
   }
 
-  public static Balloon createBalloon(final Notification notification, final boolean showCallout, final boolean hideOnClickOutside, final boolean fadeOut) {
+  public static Balloon createBalloon(final Notification notification, final boolean showCallout, final boolean hideOnClickOutside) {
     final JEditorPane text = new JEditorPane();
     text.setEditorKit(UIUtil.getHTMLEditorKit());
 
@@ -312,10 +313,6 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
       .setHideOnAction(hideOnClickOutside)
       .setHideOnKeyOutside(hideOnClickOutside).setHideOnFrameResize(false);
 
-    if (fadeOut) {
-      builder.setFadeoutTime(3000);
-    }
-
     final Balloon balloon = builder.createBalloon();
     balloon.addListener(new JBPopupAdapter() {
       @Override
index 78e2c793e24989f4e48d7742ae1ac84ba4aba0b8..2b4c5217936f944ab2d21a557e84388fb415a82f 100644 (file)
@@ -16,6 +16,7 @@
 package com.intellij.openapi.wm.impl;
 
 import com.intellij.Patches;
+import com.intellij.ide.FrameStateManager;
 import com.intellij.ide.IdeEventQueue;
 import com.intellij.ide.ui.LafManager;
 import com.intellij.ide.ui.LafManagerListener;
@@ -47,6 +48,7 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.*;
 import com.intellij.openapi.wm.ex.*;
 import com.intellij.openapi.wm.impl.commands.*;
+import com.intellij.ui.BalloonImpl;
 import com.intellij.ui.awt.RelativePoint;
 import com.intellij.ui.switcher.QuickAccessSettings;
 import com.intellij.ui.switcher.SwitchManager;
@@ -1326,7 +1328,13 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements
     final BalloonHyperlinkListener listenerWrapper = new BalloonHyperlinkListener(listener);
     final Balloon balloon =
       JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text.replace("\n", "<br>"), actualIcon, type.getPopupBackground(), listenerWrapper)
-        .setHideOnClickOutside(true).setHideOnFrameResize(false).createBalloon();
+        .setHideOnClickOutside(false).setHideOnFrameResize(false).createBalloon();
+    FrameStateManager.getInstance().getApplicationActive().doWhenDone(new Runnable() {
+      @Override
+      public void run() {
+        ((BalloonImpl)balloon).setHideOnClickOutside(true);
+      }
+    });
     listenerWrapper.myBalloon = balloon;
     myWindow2Balloon.put(toolWindowId, balloon);
     Disposer.register(balloon, new Disposable() {
index 5d42a065f1414156250cea99a7f79496ce5f5804..fa78cb10442a682c446dd4f6c1793a9e49b9d43c 100644 (file)
@@ -17,7 +17,6 @@ package com.intellij.ui;
 
 import com.intellij.ide.IdeEventQueue;
 import com.intellij.ide.IdeTooltip;
-import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.ActionManager;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -28,7 +27,6 @@ import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.impl.ShadowBorderPainter;
 import com.intellij.openapi.ui.popup.Balloon;
 import com.intellij.openapi.ui.popup.JBPopupListener;
-import com.intellij.openapi.ui.popup.LightweightWindow;
 import com.intellij.openapi.ui.popup.LightweightWindowEvent;
 import com.intellij.openapi.util.*;
 import com.intellij.openapi.util.registry.Registry;
@@ -178,7 +176,7 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui {
 
   private boolean myDisposed;
   private final JComponent myContent;
-  private final boolean myHideOnMouse;
+  private boolean myHideOnMouse;
   private final boolean myHideOnKey;
   private boolean myHideOnAction;
   private final boolean myEnableCloseButton;
@@ -713,6 +711,10 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui {
     return myVisible;
   }
 
+  public void setHideOnClickOutside(boolean hideOnMouse) {
+    myHideOnMouse = hideOnMouse;
+  }
+
   public void setShowPointer(final boolean show) {
     myShowPointer = show;
   }