xdebugger: added option to show 'debug' tool window only when debug process is suspended

This commit is contained in:
nik
2011-01-25 16:45:00 +03:00
parent 9e239e6d76
commit cd2f20719a
3 changed files with 67 additions and 23 deletions
@@ -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;
}
@@ -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<XDebugSessionListener> 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 <B extends XBreakpoint<?>> XBreakpointType<?, ?> getBreakpointTypeClass(final XBreakpointHandler<B> 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();
}
});
@@ -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);