From f0bf0224f987fcb056f2f0d7974645e2188e1515 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 16 Mar 2011 14:33:06 +0300 Subject: [PATCH] allow to change watches when debugging is finished (IDEA-62216, WI-1691, WI-3255) --- .../xdebugger/impl/XDebugSessionImpl.java | 4 ++++ .../xdebugger/impl/XDebuggerManagerImpl.java | 12 ++++++------ .../xdebugger/impl/frame/XWatchesView.java | 9 +++++++-- .../impl/frame/actions/XEditWatchAction.java | 6 +----- .../impl/frame/actions/XNewWatchAction.java | 4 ---- .../impl/frame/actions/XRemoveWatchAction.java | 7 +++---- .../frame/actions/XWatchesTreeActionBase.java | 12 ++++-------- .../xdebugger/impl/ui/XDebugSessionData.java | 4 ++++ .../xdebugger/impl/ui/XDebugSessionTab.java | 16 +++------------- 9 files changed, 32 insertions(+), 42 deletions(-) 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 ccc2a479ee71..370a5b2d54ab 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java @@ -226,6 +226,10 @@ public class XDebugSessionImpl implements XDebugSession { myDebugProcess.sessionInitialized(); } + public XDebugSessionData getSessionData() { + return mySessionData; + } + private void disableSlaveBreakpoints(final XDependentBreakpointManager dependentBreakpointManager) { Set> slaveBreakpoints = dependentBreakpointManager.getAllSlaveBreakpoints(); Set> breakpointTypes = new HashSet>(); 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 ceb0cf688dfd..464cf1ea52a6 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java @@ -62,7 +62,7 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom @NonNls public static final String COMPONENT_NAME = "XDebuggerManager"; private final Project myProject; private final XBreakpointManagerImpl myBreakpointManager; - private final Map mySessionData; + private final Map mySessionData; private final Map mySessions; private final ExecutionPointHighlighter myExecutionPointHighlighter; private XDebugSessionImpl myActiveSession; @@ -70,7 +70,7 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom public XDebuggerManagerImpl(final Project project, final StartupManager startupManager, MessageBus messageBus) { myProject = project; myBreakpointManager = new XBreakpointManagerImpl(project, this, startupManager); - mySessionData = new LinkedHashMap(); + mySessionData = new HashMap(); mySessions = new LinkedHashMap(); myExecutionPointHighlighter = new ExecutionPointHighlighter(project); messageBus.connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @@ -99,6 +99,7 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom @Override public void contentRemoved(RunContentDescriptor descriptor, @NotNull Executor executor) { if (executor.equals(DefaultDebugExecutor.getDebugExecutorInstance())) { + mySessionData.remove(descriptor); XDebugSessionImpl session = mySessions.remove(descriptor.getProcessHandler()); if (session != null) { Disposer.dispose(session.getSessionTab()); @@ -172,7 +173,7 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom final XDebugSessionImpl session) throws ExecutionException { XDebugProcess process = processStarter.start(session); - XDebugSessionData oldSessionData = contentToReuse != null ? mySessionData.remove(contentToReuse.getProcessHandler()) : null; + XDebugSessionData oldSessionData = contentToReuse != null ? mySessionData.get(contentToReuse) : null; if (oldSessionData == null) { oldSessionData = new XDebugSessionData(); } @@ -184,10 +185,9 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom public void removeSession(@NotNull XDebugSessionImpl session) { XDebugSessionTab sessionTab = session.getSessionTab(); - mySessions.remove(session); + mySessions.remove(session.getDebugProcess().getProcessHandler()); if (sessionTab != null) { - XDebugSessionData data = sessionTab.saveData(); - mySessionData.put(session.getDebugProcess().getProcessHandler(), data); + mySessionData.put(sessionTab.getRunContentDescriptor(), session.getSessionData()); } if (myActiveSession == session) { myActiveSession = null; diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesView.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesView.java index e3f4a1295fd6..9248410ccd36 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesView.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesView.java @@ -21,6 +21,7 @@ import com.intellij.ide.dnd.DnDNativeTarget; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.CustomShortcutSet; +import com.intellij.util.ArrayUtil; import com.intellij.util.ui.tree.TreeUtil; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XDebuggerBundle; @@ -53,9 +54,11 @@ public class XWatchesView extends XDebugViewBase implements DnDNativeTarget { private XDebuggerTreeState myTreeState; private XDebuggerTreeRestorer myTreeRestorer; private final WatchesRootNode myRootNode; + private final XDebugSessionData mySessionData; public XWatchesView(final XDebugSession session, final Disposable parentDisposable, final XDebugSessionData sessionData) { super(session, parentDisposable); + mySessionData = sessionData; myTreePanel = new XDebuggerTreePanel(session, session.getDebugProcess().getEditorsProvider(), this, null, XDebuggerActions.WATCHES_TREE_POPUP_GROUP); @@ -86,6 +89,7 @@ public class XWatchesView extends XDebugViewBase implements DnDNativeTarget { evaluator = stackFrame.getEvaluator(); } myRootNode.addWatchExpression(evaluator, expression, index); + updateSessionData(); } protected void rebuildView(final SessionEvent event) { @@ -147,9 +151,10 @@ public class XWatchesView extends XDebugViewBase implements DnDNativeTarget { WatchNode node = minIndex < newChildren.size() ? newChildren.get(minIndex) : newChildren.get(newChildren.size() - 1); TreeUtil.selectNode(myTreePanel.getTree(), node); } + updateSessionData(); } - public List getWatchExpressions() { + private void updateSessionData() { List watchExpressions = new ArrayList(); final List children = myRootNode.getAllChildren(); if (children != null) { @@ -157,7 +162,7 @@ public class XWatchesView extends XDebugViewBase implements DnDNativeTarget { watchExpressions.add(child.getExpression()); } } - return watchExpressions; + mySessionData.setWatchExpressions(ArrayUtil.toStringArray(watchExpressions)); } public boolean update(final DnDEvent aEvent) { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XEditWatchAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XEditWatchAction.java index 91fc8fc3716f..b4afff520a7d 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XEditWatchAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XEditWatchAction.java @@ -18,8 +18,8 @@ package com.intellij.xdebugger.impl.frame.actions; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree; import com.intellij.xdebugger.impl.ui.tree.nodes.WatchNode; -import com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode; import com.intellij.xdebugger.impl.ui.tree.nodes.WatchesRootNode; +import com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode; import java.util.List; @@ -34,10 +34,6 @@ public class XEditWatchAction extends XWatchesTreeActionBase { super.update(e); } - protected boolean isEnabled(final AnActionEvent e) { - return true; - } - public void actionPerformed(final AnActionEvent e) { XDebuggerTree tree = XDebuggerTree.getTree(e); if (tree == null) return; diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XNewWatchAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XNewWatchAction.java index 2f13de6745bc..34b01977497d 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XNewWatchAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XNewWatchAction.java @@ -34,8 +34,4 @@ public class XNewWatchAction extends XWatchesTreeActionBase { watchesRoot.addNewWatch(); } } - - protected boolean isEnabled(final AnActionEvent e) { - return XDebuggerTree.getTree(e) != null; - } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XRemoveWatchAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XRemoveWatchAction.java index 3698e4cdae99..179f558cf5cb 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XRemoveWatchAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XRemoveWatchAction.java @@ -20,6 +20,7 @@ import com.intellij.xdebugger.impl.XDebugSessionImpl; import com.intellij.xdebugger.impl.ui.XDebugSessionTab; import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree; import com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -27,10 +28,8 @@ import java.util.List; * @author nik */ public class XRemoveWatchAction extends XWatchesTreeActionBase { - - protected boolean isEnabled(final AnActionEvent e) { - XDebuggerTree tree = XDebuggerTree.getTree(e); - return tree != null && !getSelectedNodes(tree, XDebuggerTreeNode.class).isEmpty(); + protected boolean isEnabled(final AnActionEvent e, @NotNull XDebuggerTree tree) { + return !getSelectedNodes(tree, XDebuggerTreeNode.class).isEmpty(); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XWatchesTreeActionBase.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XWatchesTreeActionBase.java index ff54dc104876..0c1d4b6f39c8 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XWatchesTreeActionBase.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XWatchesTreeActionBase.java @@ -45,15 +45,11 @@ public abstract class XWatchesTreeActionBase extends AnAction { public void update(final AnActionEvent e) { final XDebuggerTree tree = XDebuggerTree.getTree(e); - boolean enabled; - if (tree == null || tree.getSession().isStopped()) { - enabled = false; - } - else { - enabled = isEnabled(e); - } + boolean enabled = tree != null && isEnabled(e, tree); e.getPresentation().setEnabled(enabled); } - protected abstract boolean isEnabled(AnActionEvent e); + protected boolean isEnabled(AnActionEvent e, @NotNull XDebuggerTree tree) { + return true; + } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionData.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionData.java index ae4f0df5b65c..8f7fa3e23391 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionData.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionData.java @@ -31,6 +31,10 @@ public class XDebugSessionData { this(ArrayUtil.EMPTY_STRING_ARRAY); } + public void setWatchExpressions(String[] watchExpressions) { + myWatchExpressions = watchExpressions; + } + public String[] getWatchExpressions() { return myWatchExpressions; } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java index d0c99debc27d..036c065207b8 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java @@ -40,7 +40,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.ui.content.Content; import com.intellij.ui.content.tabs.PinToolwindowTabAction; -import com.intellij.util.ArrayUtil; import com.intellij.xdebugger.XDebugProcess; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XDebuggerBundle; @@ -115,19 +114,10 @@ public class XDebugSessionTab extends DebuggerSessionTabBase { return framesContent; } - public XDebugSessionData saveData() { - final List watchExpressions = myWatchesView.getWatchExpressions(); - return new XDebugSessionData(ArrayUtil.toStringArray(watchExpressions)); - } - public ExecutionConsole getConsole() { return myConsole; } - public String getSessionName() { - return mySessionName; - } - public void rebuildViews() { for (XDebugViewBase view : myViews) { view.rebuildView(); @@ -144,7 +134,7 @@ public class XDebugSessionTab extends DebuggerSessionTabBase { final XDebugProcess debugProcess = session.getDebugProcess(); ProcessHandler processHandler = debugProcess.getProcessHandler(); myConsole = consoleView; - myRunContentDescriptor = new RunContentDescriptor(myConsole, processHandler, myUi.getComponent(), getSessionName()); + myRunContentDescriptor = new RunContentDescriptor(myConsole, processHandler, myUi.getComponent(), mySessionName); myUi.addContent(createFramesContent(session), 0, PlaceInGrid.left, false); myUi.addContent(createVariablesContent(session), 0, PlaceInGrid.center, false); @@ -153,7 +143,7 @@ public class XDebugSessionTab extends DebuggerSessionTabBase { myUi.addContent(consoleContent, 1, PlaceInGrid.bottom, false); attachNotificationTo(consoleContent); - session.getDebugProcess().registerAdditionalContent(myUi); + debugProcess.registerAdditionalContent(myUi); RunContentBuilder.addAdditionalConsoleEditorActions(myConsole, consoleContent); myUi.addContent(consoleContent, 0, PlaceInGrid.bottom, false); @@ -209,7 +199,7 @@ public class XDebugSessionTab extends DebuggerSessionTabBase { final XDebugProcess debugProcess = session.getDebugProcess(); ProcessHandler processHandler = debugProcess.getProcessHandler(); myConsole = consoleView; - myRunContentDescriptor = new RunContentDescriptor(myConsole, processHandler, myUi.getComponent(), getSessionName()); + myRunContentDescriptor = new RunContentDescriptor(myConsole, processHandler, myUi.getComponent(), mySessionName); myUi.addContent(createFramesContent(session), 0, PlaceInGrid.left, false); myUi.addContent(createVariablesContent(session), 0, PlaceInGrid.center, false);