From d7fa98e3f8d227a22b6df9b1e29cfd0ca7df6f73 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 23 Nov 2010 15:49:32 +0300 Subject: [PATCH 1/2] fixed problems with multiple debug sessions (IDEA-26446, WI-1766, IDEA-50339) --- .../xdebugger/impl/XDebugSessionImpl.java | 25 ++++++---- .../xdebugger/impl/XDebuggerManagerImpl.java | 49 ++++++++++--------- 2 files changed, 42 insertions(+), 32 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 50a8228f81eb..b4765e42e86e 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebugSessionImpl.java @@ -336,7 +336,7 @@ public class XDebugSessionImpl implements XDebugSession { private void doResume() { myDispatcher.getMulticaster().beforeSessionResume(); - myDebuggerManager.updateExecutionPosition(this, null, false); + myDebuggerManager.setActiveSession(this, null, false); mySuspendContext = null; myCurrentStackFrame = null; myCurrentPosition = null; @@ -362,18 +362,25 @@ public class XDebugSessionImpl implements XDebugSession { boolean frameChanged = myCurrentStackFrame != frame; myCurrentStackFrame = frame; - XSourcePosition position = frame.getSourcePosition(); - if (position != null) { - XExecutionStack activeExecutionStack = mySuspendContext.getActiveExecutionStack(); - boolean isTopFrame = activeExecutionStack != null && activeExecutionStack.getTopFrame() == frame; - myDebuggerManager.updateExecutionPosition(this, position, !isTopFrame); - } + activateSession(); if (frameChanged) { myDispatcher.getMulticaster().stackFrameChanged(); } } + public void activateSession() { + XSourcePosition position = myCurrentStackFrame != null ? myCurrentStackFrame.getSourcePosition() : null; + if (position != null) { + XExecutionStack activeExecutionStack = mySuspendContext.getActiveExecutionStack(); + boolean isTopFrame = activeExecutionStack != null && activeExecutionStack.getTopFrame() == myCurrentStackFrame; + myDebuggerManager.setActiveSession(this, position, !isTopFrame); + } + else { + myDebuggerManager.setActiveSession(this, null, false); + } + } + public void updateBreakpointPresentation(@NotNull final XLineBreakpoint breakpoint, @Nullable final Icon icon, @Nullable final String errorMessage) { CustomizedBreakpointPresentation presentation; synchronized (myRegisteredBreakpoints) { @@ -484,7 +491,7 @@ public class XDebugSessionImpl implements XDebugSession { myPaused = true; if (myCurrentPosition != null) { - myDebuggerManager.updateExecutionPosition(this, myCurrentPosition, false); + myDebuggerManager.setActiveSession(this, myCurrentPosition, false); } UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { @@ -516,7 +523,7 @@ public class XDebugSessionImpl implements XDebugSession { myCurrentPosition = null; myCurrentStackFrame = null; mySuspendContext = null; - myDebuggerManager.updateExecutionPosition(this, null, false); + myDebuggerManager.setActiveSession(this, null, false); XBreakpointManagerImpl breakpointManager = myDebuggerManager.getBreakpointManager(); breakpointManager.removeBreakpointListener(myBreakpointListener); breakpointManager.getDependentBreakpointManager().removeListener(myDependentBreakpointListener); 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 08e80cc97d3a..3dc3c8af5c73 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java @@ -38,7 +38,6 @@ import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; -import com.intellij.util.containers.HashMap; import com.intellij.util.messages.MessageBus; import com.intellij.util.xmlb.annotations.Property; import com.intellij.xdebugger.*; @@ -65,19 +64,17 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom private final Project myProject; private final XBreakpointManagerImpl myBreakpointManager; private final Map mySessionData; - private final Map mySessionTabs; - private final List mySessions; + private final Map mySessions; private final ExecutionPointHighlighter myExecutionPointHighlighter; - private XDebugSessionImpl myLastActiveSession; + private XDebugSessionImpl myActiveSession; public XDebuggerManagerImpl(final Project project, final StartupManager startupManager, MessageBus messageBus) { myProject = project; myBreakpointManager = new XBreakpointManagerImpl(project, this, startupManager); mySessionData = new LinkedHashMap(); - mySessions = new ArrayList(); + mySessions = new LinkedHashMap(); myExecutionPointHighlighter = new ExecutionPointHighlighter(project); - mySessionTabs = new HashMap(); messageBus.connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void fileOpened(final FileEditorManager source, final VirtualFile file) { @@ -90,14 +87,23 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom messageBus.connect().subscribe(RunContentManagerImpl.RUN_CONTENT_TOPIC, new RunContentWithExecutorListener() { @Override public void contentSelected(RunContentDescriptor descriptor, @NotNull Executor executor) { + if (executor.equals(DefaultDebugExecutor.getDebugExecutorInstance())) { + final XDebugSessionImpl session = mySessions.get(descriptor.getProcessHandler()); + if (session != null) { + session.activateSession(); + } + else { + setActiveSession(null, null, false); + } + } } @Override public void contentRemoved(RunContentDescriptor descriptor, @NotNull Executor executor) { if (executor.equals(DefaultDebugExecutor.getDebugExecutorInstance())) { - XDebugSessionTab sessionTab = mySessionTabs.remove(descriptor.getProcessHandler()); - if (sessionTab != null) { - Disposer.dispose(sessionTab); + XDebugSessionImpl session = mySessions.remove(descriptor.getProcessHandler()); + if (session != null) { + Disposer.dispose(session.getSessionTab()); } } } @@ -164,9 +170,8 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom if (oldSessionData == null) { oldSessionData = new XDebugSessionData(); } - final XDebugSessionTab sessionTab = session.init(process, oldSessionData); - mySessions.add(session); - mySessionTabs.put(session.getDebugProcess().getProcessHandler(), sessionTab); + session.init(process, oldSessionData); + mySessions.put(session.getDebugProcess().getProcessHandler(), session); return session; } @@ -176,15 +181,15 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom XDebugSessionData data = sessionTab.saveData(); mySessions.remove(session); mySessionData.put(session.getDebugProcess().getProcessHandler(), data); - if (myLastActiveSession == session) { - myLastActiveSession = null; + if (myActiveSession == session) { + myActiveSession = null; onActiveSessionChanged(); } } - public void updateExecutionPosition(@NotNull XDebugSessionImpl session, @Nullable XSourcePosition position, boolean useSelection) { - boolean sessionChanged = myLastActiveSession != session; - myLastActiveSession = session; + public void setActiveSession(@Nullable XDebugSessionImpl session, @Nullable XSourcePosition position, boolean useSelection) { + boolean sessionChanged = myActiveSession != session; + myActiveSession = session; if (position != null) { myExecutionPointHighlighter.show(position, useSelection); } @@ -202,7 +207,8 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom @NotNull public XDebugSession[] getDebugSessions() { - return mySessions.toArray(new XDebugSession[mySessions.size()]); + final Collection sessions = mySessions.values(); + return sessions.toArray(new XDebugSessionImpl[sessions.size()]); } @Override @@ -220,7 +226,7 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom @Override public Collection getDebugProcesses(Class processClass) { final List list = new ArrayList(); - for (XDebugSessionImpl session : mySessions) { + for (XDebugSessionImpl session : mySessions.values()) { final XDebugProcess process = session.getDebugProcess(); if (processClass.isInstance(process)) { list.add(processClass.cast(process)); @@ -231,10 +237,7 @@ public class XDebuggerManagerImpl extends XDebuggerManager implements ProjectCom @Nullable public XDebugSessionImpl getCurrentSession() { - if (myLastActiveSession != null) { - return myLastActiveSession; - } - return !mySessions.isEmpty() ? mySessions.get(0) : null; + return myActiveSession; } public XDebuggerState getState() { From 39c76001c6296807ee441e0b6c190fb1dd6f8181 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 23 Nov 2010 15:56:34 +0300 Subject: [PATCH 2/2] allow discontinuous multi selection in library chooser --- .../intellij/util/ui/classpath/ChooseLibrariesDialogBase.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java b/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java index 4a4c74884170..cd06228cc62b 100644 --- a/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java +++ b/platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java @@ -151,14 +151,12 @@ public abstract class ChooseLibrariesDialogBase extends DialogWrapper { myBuilder.initRootNode(); myTree.setDragEnabled(false); - myTree.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myTree.setRowHeight(Icons.CLASS_ICON.getIconHeight()); myTree.setShowsRootHandles(true); UIUtil.setLineStyleAngled(myTree); myTree.setRootVisible(false); - myTree.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); myTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(final TreeSelectionEvent e) { updateOKAction();