show notification if breakpoint is reached in another thread
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Fri, 10 Jul 2015 15:34:37 +0000 (18:34 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Fri, 10 Jul 2015 15:38:09 +0000 (18:38 +0300)
java/debugger/impl/src/com/intellij/debugger/impl/DebuggerSession.java
resources-en/src/messages/DebuggerBundle.properties

index eb0867dbf7da358870ef6e8d37b1da68b7de9383..bccc7caa8f51125a1140c31fc098ea576a86aee4 100644 (file)
@@ -38,6 +38,9 @@ import com.intellij.execution.configurations.RunProfileState;
 import com.intellij.execution.process.ProcessHandler;
 import com.intellij.execution.process.ProcessOutputTypes;
 import com.intellij.idea.ActionsBundle;
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationListener;
+import com.intellij.notification.NotificationType;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.diagnostic.Logger;
@@ -60,6 +63,7 @@ import com.intellij.util.ui.UIUtil;
 import com.intellij.xdebugger.AbstractDebuggerSession;
 import com.intellij.xdebugger.XDebugSession;
 import com.intellij.xdebugger.XSourcePosition;
+import com.intellij.xdebugger.impl.XDebugSessionImpl;
 import com.intellij.xdebugger.impl.actions.XDebuggerActions;
 import com.intellij.xdebugger.impl.evaluate.quick.common.ValueLookupManager;
 import com.sun.jdi.ObjectCollectedException;
@@ -70,6 +74,7 @@ import com.sun.jdi.request.StepRequest;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import javax.swing.event.HyperlinkEvent;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -451,6 +456,37 @@ public class DebuggerSession implements AbstractDebuggerSession {
             getContextManager().fireStateChanged(getContextManager().getContext(), EVENT_THREADS_REFRESH);
           }
         });
+        final ThreadReferenceProxyImpl thread = suspendContext.getThread();
+        if (thread != null) {
+          List<Pair<Breakpoint, Event>> descriptors = DebuggerUtilsEx.getEventDescriptors(suspendContext);
+          if (!descriptors.isEmpty()) {
+            XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(
+              DebuggerBundle.message("status.breakpoint.reached.in.thread", thread.name()),
+              DebuggerBundle.message("status.breakpoint.reached.in.thread.switch"),
+              NotificationType.INFORMATION, new NotificationListener() {
+                @Override
+                public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+                  if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+                    notification.expire();
+                    getProcess().getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {
+                      @Override
+                      public void contextAction() throws Exception {
+                        final DebuggerContextImpl debuggerContext =
+                          DebuggerContextImpl.createDebuggerContext(DebuggerSession.this, suspendContext, thread, null);
+
+                        DebuggerInvocationUtil.invokeLater(getProject(), new Runnable() {
+                          @Override
+                          public void run() {
+                            getContextManager().setState(debuggerContext, STATE_PAUSED, EVENT_PAUSE, null);
+                          }
+                        });
+                      }
+                    });
+                  }
+                }
+              }).notify(getProject());
+          }
+        }
         return;
       }
 
index 27a21049be9316859c5b8d782f3a4cbae87cff11..4e8f16a937b57b46d9e401704594b007c2129c20 100644 (file)
@@ -49,6 +49,8 @@ status.line.breakpoint.reached=Breakpoint reached at {0}({1}:{2,number,#})
 status.line.breakpoint.reached.full.trace=Breakpoint reached at {0}
 export.threads.stackframe.format=at {0}({1}:{2,number,#})
 status.generic.breakpoint.reached=Breakpoint reached
+status.breakpoint.reached.in.thread=Breakpoint reached in thread {0}
+status.breakpoint.reached.in.thread.switch=<a href="#">Switch thread</a>
 status.method.entry.breakpoint.reached=Method ''{0}'' entered at {1}({2}:{3,number,#})
 status.method.exit.breakpoint.reached=Method breakpoint reached. Method ''{0}'' is about to exit at {1}({2}:{3,number,#})
 status.exception.breakpoint.reached=Exception breakpoint reached