1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 20:05:35 +02:00

Preserving the registers tree structure during the debug session.

This commit is contained in:
Mikhail Khodjaiants 2003-04-08 18:15:28 +00:00
parent 90aaf1dfaa
commit 928199b44e
4 changed files with 120 additions and 1 deletions

View file

@ -1,3 +1,9 @@
2003-04-08 Mikhail Khodjaiants
Preserving the registers tree structure during the debug session.
* ViewerState.java: new
* RegistersView.java
* RegistersViewEventHandler.java
2003-04-07 Mikhail Khodjaiants 2003-04-07 Mikhail Khodjaiants
No dialog if switch to frame failed. No dialog if switch to frame failed.
* CDebugUIPlugin.java * CDebugUIPlugin.java

View file

@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.views;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeViewer;
/**
* Memento of the expanded and selected items in a tree
* viewer for.
*
* @since 2.1
*/
public class ViewerState {
private Object[] fExpandedElements = null;
private ISelection fSelection = null;
/**
* Constructs a memento for the given viewer.
*/
public ViewerState(TreeViewer viewer) {
saveState(viewer);
}
/**
* Saves the current state of the given viewer into
* this memento.
*
* @param viewer viewer of which to save the state
*/
public void saveState(TreeViewer viewer) {
fExpandedElements = viewer.getExpandedElements();
fSelection = viewer.getSelection();
}
/**
* Restores the state of the given viewer to this mementos
* saved state.
*
* @param viewer viewer to which state is restored
*/
public void restoreState(TreeViewer viewer) {
if (fExpandedElements != null) {
viewer.setExpandedElements(fExpandedElements);
}
if (fSelection != null) {
viewer.setSelection(fSelection);
}
}
}

View file

@ -6,6 +6,8 @@
package org.eclipse.cdt.debug.internal.ui.views.registers; package org.eclipse.cdt.debug.internal.ui.views.registers;
import java.util.HashMap;
import org.eclipse.cdt.debug.core.ICRegisterManager; import org.eclipse.cdt.debug.core.ICRegisterManager;
import org.eclipse.cdt.debug.internal.ui.CDebugImages; import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds; import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
@ -17,6 +19,7 @@ import org.eclipse.cdt.debug.internal.ui.preferences.ICDebugPreferenceConstants;
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler;
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandlerView; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandlerView;
import org.eclipse.cdt.debug.internal.ui.views.IDebugExceptionHandler; import org.eclipse.cdt.debug.internal.ui.views.IDebugExceptionHandler;
import org.eclipse.cdt.debug.internal.ui.views.ViewerState;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.ICDebugUIConstants; import org.eclipse.cdt.debug.ui.ICDebugUIConstants;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
@ -60,6 +63,14 @@ public class RegistersView extends AbstractDebugEventHandlerView
protected static final String VARIABLES_SELECT_ALL_ACTION = SELECT_ALL_ACTION + ".Registers"; //$NON-NLS-1$ protected static final String VARIABLES_SELECT_ALL_ACTION = SELECT_ALL_ACTION + ".Registers"; //$NON-NLS-1$
/**
* A map of register managers to <code>ViewerState</code>s.
* Used to restore the expanded state of the registers view on
* re-selection of the register manager. The cache is cleared on
* a frame by frame basis when a thread/target is terminated.
*/
private HashMap fExpandedRegisters = new HashMap( 10 );
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.ui.AbstractDebugView#createViewer(Composite) * @see org.eclipse.debug.ui.AbstractDebugView#createViewer(Composite)
*/ */
@ -262,8 +273,26 @@ public class RegistersView extends AbstractDebugEventHandlerView
return; return;
} }
if ( current != null )
{
// save state
ViewerState state = new ViewerState( getRegistersViewer() );
fExpandedRegisters.put( current, state );
}
showViewer(); showViewer();
getViewer().setInput( rm ); getViewer().setInput( rm );
// restore state
if ( rm != null )
{
ViewerState state = (ViewerState)fExpandedRegisters.get( rm );
if ( state != null )
{
state.restoreState( getRegistersViewer() );
}
}
updateObjects(); updateObjects();
} }
@ -279,4 +308,14 @@ public class RegistersView extends AbstractDebugEventHandlerView
setViewerInput( (IStructuredSelection)selection ); setViewerInput( (IStructuredSelection)selection );
} }
} }
protected RegistersViewer getRegistersViewer()
{
return (RegistersViewer)getViewer();
}
protected void clearExpandedRegisters( ICRegisterManager rm )
{
fExpandedRegisters.remove( rm );
}
} }

View file

@ -5,8 +5,10 @@
*/ */
package org.eclipse.cdt.debug.internal.ui.views.registers; package org.eclipse.cdt.debug.internal.ui.views.registers;
import org.eclipse.cdt.debug.core.ICRegisterManager;
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler;
import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.core.model.IVariable;
import org.eclipse.debug.ui.AbstractDebugView; import org.eclipse.debug.ui.AbstractDebugView;
@ -38,6 +40,13 @@ public class RegistersViewEventHandler extends AbstractDebugEventHandler
DebugEvent event = events[i]; DebugEvent event = events[i];
switch( event.getKind() ) switch( event.getKind() )
{ {
case DebugEvent.TERMINATE :
if ( event.getSource() instanceof IDebugTarget &&
((IDebugTarget)event.getSource()).getAdapter( ICRegisterManager.class ) != null )
{
getRegistersView().clearExpandedRegisters( (ICRegisterManager)(((IDebugTarget)event.getSource()).getAdapter( ICRegisterManager.class )) );
}
break;
case DebugEvent.SUSPEND : case DebugEvent.SUSPEND :
if ( event.getDetail() != DebugEvent.EVALUATION_IMPLICIT ) if ( event.getDetail() != DebugEvent.EVALUATION_IMPLICIT )
{ {
@ -66,4 +75,9 @@ public class RegistersViewEventHandler extends AbstractDebugEventHandler
} }
} }
} }
protected RegistersView getRegistersView()
{
return (RegistersView)getView();
}
} }