From 2469bb7be08f861bf04892ba69b6123136467bcf Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 21 Jul 2015 19:28:15 +0300 Subject: [PATCH] fixing IDEA-142798 Debugger does not activate correct session on breakpoint --- .../xdebugger/impl/XDebuggerManagerImpl.java | 6 ++ .../impl/ui/DebuggerSessionTabBase.java | 67 ++++++++++++------- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java index 20ebb141f1ad..d4e3cf7f23eb 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java @@ -263,6 +263,12 @@ public class XDebuggerManagerImpl extends XDebuggerManager public void setActiveSession(@Nullable XDebugSessionImpl session, @Nullable XSourcePosition position, boolean useSelection, final @Nullable GutterIconRenderer gutterIconRenderer) { boolean sessionChanged = myActiveSession.getAndSet(session) != session; + if (sessionChanged && session != null) { + XDebugSessionTab tab = session.getSessionTab(); + if (tab != null) { + tab.select(); + } + } updateExecutionPoint(position, useSelection, gutterIconRenderer); if (sessionChanged) { onActiveSessionChanged(); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java index da75913cda93..df0dcd9a16e4 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java @@ -37,6 +37,7 @@ import com.intellij.openapi.wm.ToolWindow; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.ui.AppIcon; import com.intellij.ui.content.Content; +import com.intellij.util.ui.UIUtil; import com.intellij.xdebugger.XDebuggerBundle; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -91,37 +92,55 @@ public abstract class DebuggerSessionTabBase extends RunTab { } + public void select() { + if (ApplicationManager.getApplication().isUnitTestMode()) return; + + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + if (myRunContentDescriptor != null) { + ToolWindow toolWindow = ExecutionManager.getInstance(myProject).getContentManager() + .getToolWindowByDescriptor(myRunContentDescriptor); + Content content = myRunContentDescriptor.getAttachedContent(); + if (toolWindow != null && content != null && !toolWindow.getContentManager().isSelected(content)) { + toolWindow.getContentManager().setSelectedContent(content); + } + } + } + }); + } + public void toFront(boolean focus, @Nullable final Runnable onShowCallback) { - if (!ApplicationManager.getApplication().isUnitTestMode()) { + if (ApplicationManager.getApplication().isUnitTestMode()) return; + + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + if (myRunContentDescriptor != null) { + ToolWindow toolWindow = ExecutionManager.getInstance(myProject).getContentManager() + .getToolWindowByDescriptor(myRunContentDescriptor); + if (toolWindow != null) { + if (!toolWindow.isVisible()) { + toolWindow.show(onShowCallback); + } + //noinspection ConstantConditions + toolWindow.getContentManager().setSelectedContent(myRunContentDescriptor.getAttachedContent()); + } + } + } + }); + + if (focus) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { - if (myRunContentDescriptor != null) { - ToolWindow toolWindow = ExecutionManager.getInstance(myProject).getContentManager() - .getToolWindowByDescriptor(myRunContentDescriptor); - if (toolWindow != null) { - if (!toolWindow.isVisible()) { - toolWindow.show(onShowCallback); - } - //noinspection ConstantConditions - toolWindow.getContentManager().setSelectedContent(myRunContentDescriptor.getAttachedContent()); - } + boolean focusWnd = Registry.is("debugger.mayBringFrameToFrontOnBreakpoint"); + ProjectUtil.focusProjectWindow(myProject, focusWnd); + if (!focusWnd) { + AppIcon.getInstance().requestAttention(myProject, true); } } }); - - if (focus) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - boolean focusWnd = Registry.is("debugger.mayBringFrameToFrontOnBreakpoint"); - ProjectUtil.focusProjectWindow(myProject, focusWnd); - if (!focusWnd) { - AppIcon.getInstance().requestAttention(myProject, true); - } - } - }); - } } } }