From cd2f20719a516ce622225847feb11842b49df48c Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 25 Jan 2011 16:43:36 +0300 Subject: [PATCH] xdebugger: added option to show 'debug' tool window only when debug process is suspended --- .../intellij/xdebugger/XDebuggerManager.java | 11 +++- .../xdebugger/impl/XDebugSessionImpl.java | 56 ++++++++++++++----- .../xdebugger/impl/XDebuggerManagerImpl.java | 23 +++++--- 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerManager.java b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerManager.java index bb9e8432e9e0..53336a09bb64 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerManager.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerManager.java @@ -21,7 +21,6 @@ import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.runners.ProgramRunner; import com.intellij.execution.ui.ExecutionConsole; import com.intellij.execution.ui.RunContentDescriptor; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.xdebugger.breakpoints.XBreakpointManager; import org.jetbrains.annotations.NotNull; @@ -71,4 +70,14 @@ public abstract class XDebuggerManager { @NotNull public abstract XDebugSession startSessionAndShowTab(@NotNull String sessionName, @Nullable RunContentDescriptor contentToReuse, @NotNull XDebugProcessStarter starter) throws ExecutionException; + + /** + * Start a new debugging session and open 'Debug' tool window + * @param sessionName title of 'Debug' tool window + * @param showToolWindowOnSuspendOnly if {@code true} 'Debug' tool window won't be shown until debug process is suspended on a breakpoint + */ + @NotNull + public abstract XDebugSession startSessionAndShowTab(@NotNull String sessionName, @Nullable RunContentDescriptor contentToReuse, + boolean showToolWindowOnSuspendOnly, + @NotNull XDebugProcessStarter starter) throws ExecutionException; } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java index b9124eb339f1..147c26d606b9 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java @@ -15,7 +15,9 @@ */ package com.intellij.xdebugger.impl; +import com.intellij.execution.ExecutionManager; import com.intellij.execution.configurations.RunProfile; +import com.intellij.execution.executors.DefaultDebugExecutor; import com.intellij.execution.filters.HyperlinkInfo; import com.intellij.execution.filters.OpenFileHyperlinkInfo; import com.intellij.execution.process.ProcessHandler; @@ -74,27 +76,30 @@ public class XDebugSessionImpl implements XDebugSession { private MyDependentBreakpointListener myDependentBreakpointListener; private String mySessionName; private XDebugSessionTab mySessionTab; + private XDebugSessionData mySessionData; private final EventDispatcher myDispatcher = EventDispatcher.create(XDebugSessionListener.class); private Project myProject; private @Nullable ExecutionEnvironment myEnvironment; private ProgramRunner myRunner; private boolean myStopped; private boolean myPauseActionSupported; + private boolean myShowTabOnSuspend; public XDebugSessionImpl(final @NotNull ExecutionEnvironment env, final @NotNull ProgramRunner runner, XDebuggerManagerImpl debuggerManager) { - this(env, runner, debuggerManager, env.getRunProfile().getName()); + this(env, runner, debuggerManager, env.getRunProfile().getName(), false); } public XDebugSessionImpl(final @Nullable ExecutionEnvironment env, final @Nullable ProgramRunner runner, XDebuggerManagerImpl debuggerManager, - final @NotNull String sessionName) { + final @NotNull String sessionName, final boolean showTabOnSuspend) { myEnvironment = env; myRunner = runner; mySessionName = sessionName; myDebuggerManager = debuggerManager; + myShowTabOnSuspend = showTabOnSuspend; myProject = debuggerManager.getProject(); ValueLookupManager.getInstance(myProject).startListening(); } @@ -106,16 +111,27 @@ public class XDebugSessionImpl implements XDebugSession { @NotNull public RunContentDescriptor getRunContentDescriptor() { - LOG.assertTrue(mySessionTab != null, "Call init() first!"); + assertSessionTabInitialized(); return mySessionTab.getRunContentDescriptor(); } + private void assertSessionTabInitialized() { + if (myShowTabOnSuspend) { + LOG.error("Debug tool window isn't shown yet because debug process isn't suspended"); + } + else { + LOG.assertTrue(mySessionTab != null, "Debug tool window not initialized yet!"); + } + } + public void setPauseActionSupported(final boolean isSupported) { myPauseActionSupported = isSupported; } public void rebuildViews() { - mySessionTab.rebuildViews(); + if (!myShowTabOnSuspend) { + mySessionTab.rebuildViews(); + } } @Nullable @@ -162,6 +178,7 @@ public class XDebugSessionImpl implements XDebugSession { public XDebugSessionTab init(final XDebugProcess process, @NotNull final XDebugSessionData sessionData) { LOG.assertTrue(myDebugProcess == null); myDebugProcess = process; + mySessionData = sessionData; XBreakpointManagerImpl breakpointManager = myDebuggerManager.getBreakpointManager(); XDependentBreakpointManager dependentBreakpointManager = breakpointManager.getDependentBreakpointManager(); @@ -173,8 +190,9 @@ public class XDebugSessionImpl implements XDebugSession { myDependentBreakpointListener = new MyDependentBreakpointListener(); dependentBreakpointManager.addListener(myDependentBreakpointListener); - initSessionTab(sessionData); - process.sessionInitialized(); + if (!myShowTabOnSuspend) { + initSessionTab(); + } return mySessionTab; } @@ -183,13 +201,14 @@ public class XDebugSessionImpl implements XDebugSession { return mySessionTab; } - private void initSessionTab(@NotNull XDebugSessionData sessionData) { + private void initSessionTab() { mySessionTab = new XDebugSessionTab(myProject, mySessionName); if (myEnvironment != null) { mySessionTab.setEnvironment(myEnvironment); } Disposer.register(myProject, mySessionTab); - mySessionTab.attachToSession(this, myRunner, myEnvironment, sessionData); + mySessionTab.attachToSession(this, myRunner, myEnvironment, mySessionData); + myDebugProcess.sessionInitialized(); } private void disableSlaveBreakpoints(final XDependentBreakpointManager dependentBreakpointManager) { @@ -205,6 +224,15 @@ public class XDebugSessionImpl implements XDebugSession { } } + public void showSessionTab() { + RunContentDescriptor descriptor = getRunContentDescriptor(); + ExecutionManager.getInstance(getProject()).getContentManager().showRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), descriptor); + ProcessHandler handler = descriptor.getProcessHandler(); + if (handler != null) { + handler.startNotify(); + } + } + private static > XBreakpointType getBreakpointTypeClass(final XBreakpointHandler handler) { return XDebuggerUtil.getInstance().findBreakpointType(handler.getBreakpointTypeClass()); } @@ -483,9 +511,10 @@ public class XDebugSessionImpl implements XDebugSession { } private void printMessage(final String message, final String hyperLinkText, @Nullable final HyperlinkInfo info) { + assertSessionTabInitialized(); DebuggerUIUtil.invokeOnEventDispatch(new Runnable() { public void run() { - final ConsoleView consoleView = getConsoleView(); + final ConsoleView consoleView = (ConsoleView)mySessionTab.getConsole(); consoleView.print(message, ConsoleViewContentType.SYSTEM_OUTPUT); if (info != null) { consoleView.printHyperlink(hyperLinkText, info); @@ -498,10 +527,6 @@ public class XDebugSessionImpl implements XDebugSession { }); } - private ConsoleView getConsoleView() { - return (ConsoleView)mySessionTab.getConsole(); - } - public void positionReached(@NotNull final XSuspendContext suspendContext) { enableBreakpoints(); mySuspendContext = suspendContext; @@ -515,6 +540,11 @@ public class XDebugSessionImpl implements XDebugSession { } UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { + if (myShowTabOnSuspend) { + myShowTabOnSuspend = false; + initSessionTab(); + showSessionTab(); + } mySessionTab.toFront(); } }); 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 6375eb31cb68..f07b6d15291c 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java @@ -16,7 +16,6 @@ package com.intellij.xdebugger.impl; import com.intellij.execution.ExecutionException; -import com.intellij.execution.ExecutionManager; import com.intellij.execution.Executor; import com.intellij.execution.executors.DefaultDebugExecutor; import com.intellij.execution.process.ProcessHandler; @@ -150,18 +149,24 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom @NotNull public XDebugSession startSessionAndShowTab(@NotNull String sessionName, @Nullable RunContentDescriptor contentToReuse, - @NotNull XDebugProcessStarter starter) throws ExecutionException { - XDebugSession session = startSession(contentToReuse, starter, new XDebugSessionImpl(null, null, this, sessionName)); - RunContentDescriptor descriptor = session.getRunContentDescriptor(); - ExecutionManager.getInstance(myProject).getContentManager().showRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), descriptor); - ProcessHandler handler = descriptor.getProcessHandler(); - if (handler != null) { - handler.startNotify(); + @NotNull XDebugProcessStarter starter) throws ExecutionException { + return startSessionAndShowTab(sessionName, contentToReuse, false, starter); + } + + @NotNull + @Override + public XDebugSession startSessionAndShowTab(@NotNull String sessionName, @Nullable RunContentDescriptor contentToReuse, + boolean showToolWindowOnSuspendOnly, + @NotNull XDebugProcessStarter starter) throws ExecutionException { + XDebugSessionImpl session = startSession(contentToReuse, starter, new XDebugSessionImpl(null, null, this, sessionName, + showToolWindowOnSuspendOnly)); + if (!showToolWindowOnSuspendOnly) { + session.showSessionTab(); } return session; } - private XDebugSession startSession(final RunContentDescriptor contentToReuse, final XDebugProcessStarter processStarter, + private XDebugSessionImpl startSession(final RunContentDescriptor contentToReuse, final XDebugProcessStarter processStarter, final XDebugSessionImpl session) throws ExecutionException { XDebugProcess process = processStarter.start(session);