From 076dc9b29d794dd5f0e098c9600a5317a0741f09 Mon Sep 17 00:00:00 2001 From: irengrig Date: Thu, 25 Oct 2012 16:49:53 +0400 Subject: [PATCH] vcs balloon: show balloon for any modal component --- .../vcs/ui/VcsBalloonProblemNotifier.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java index e9d5c2e90bd7..00c7b67f916d 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java @@ -22,12 +22,15 @@ import com.intellij.notification.NotificationType; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.BalloonBuilder; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.NamedRunnable; import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager; +import com.intellij.openapi.wm.IdeFocusManager; +import com.intellij.openapi.wm.IdeFrame; import com.intellij.ui.awt.RelativePoint; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,7 +38,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.HyperlinkEvent; import java.awt.*; -import java.util.concurrent.TimeUnit; /** * Shows a notification balloon over one of version control related tool windows: Changes View or Version Control View. @@ -127,7 +129,35 @@ public class VcsBalloonProblemNotifier implements Runnable { notification.notify(myProject.isDefault() ? null : myProject); } - public static void showBalloonForComponent(@NotNull JComponent component, @NotNull final String message, final MessageType type, + public static void showBalloonForActiveComponent(@NotNull final String message, final MessageType type) { + Window[] windows = Window.getWindows(); + Window targetWindow = null; + for (Window each : windows) { + if (each.isActive()) { + targetWindow = each; + break; + } + } + + if (targetWindow == null) { + targetWindow = JOptionPane.getRootFrame(); + } + + if (targetWindow == null) { + final IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame(); + if (frame == null) { + final Project[] projects = ProjectManager.getInstance().getOpenProjects(); + showOverChangesView(projects == null || projects.length == 0 ? ProjectManager.getInstance().getDefaultProject() : projects[0], + message, type); + return; + } + showBalloonForComponent(frame.getComponent(), message, type, true); + } else { + showBalloonForComponent(targetWindow, message, type, true); + } + } + + public static void showBalloonForComponent(@NotNull Component component, @NotNull final String message, final MessageType type, final boolean atTop) { BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, type, null); Balloon balloon = balloonBuilder.createBalloon();