1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Implemented the color highlighting of the source lines in the Disassembly view.

This commit is contained in:
Mikhail Khodjaiants 2004-05-12 15:41:32 +00:00
parent 7ba7c61143
commit d02be766a4
5 changed files with 68 additions and 8 deletions

View file

@ -1,3 +1,10 @@
2004-05-12 Mikhail Khodjaiants
Implemented the color highlighting of the source lines in the Disassembly view.
* plugin.xml
* IInternalCDebugUIConstants.java
* DisassemblyEditorInput.java
* DisassemblyView.java
2004-05-11 Mikhail Khodjaiants 2004-05-11 Mikhail Khodjaiants
Added theme category for CDT debugger. Added theme category for CDT debugger.
Moved the disassembly font definition to the theme. Moved the disassembly font definition to the theme.

View file

@ -1282,7 +1282,7 @@
<colorDefinition <colorDefinition
label="%DisassemblySourceLineColor.label" label="%DisassemblySourceLineColor.label"
categoryId="org.eclipse.cdt.debug.ui.presentation" categoryId="org.eclipse.cdt.debug.ui.presentation"
value="COLOR_BLUE" value="COLOR_DARK_BLUE"
id="org.eclipse.cdt.debug.ui.disassembly.sourceLineColor"> id="org.eclipse.cdt.debug.ui.disassembly.sourceLineColor">
<description>%DisassemblySourceLineColor.description</description> <description>%DisassemblySourceLineColor.description</description>
</colorDefinition> </colorDefinition>

View file

@ -27,6 +27,12 @@ public interface IInternalCDebugUIConstants {
*/ */
public static final String DISASSEMBLY_FONT = PREFIX + "disassemblyFont"; //$NON-NLS-1$ public static final String DISASSEMBLY_FONT = PREFIX + "disassemblyFont"; //$NON-NLS-1$
/**
* The color id to highlight the source lines in disassembly view. This color is managed via
* the workbench font preference page.
*/
public static final String DISASSEMBLY_SOURCE_LINE_COLOR = PREFIX + "disassembly.sourceLineColor"; //$NON-NLS-1$
//Current stack frame instruction pointer //Current stack frame instruction pointer
public static final String DISASM_INSTRUCTION_POINTER = PREFIX + "disassemblyInstructionPointer"; //$NON-NLS-1$ public static final String DISASM_INSTRUCTION_POINTER = PREFIX + "disassemblyInstructionPointer"; //$NON-NLS-1$

View file

@ -23,6 +23,8 @@ import org.eclipse.cdt.debug.core.model.IDisassemblyBlock;
import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils; import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.IPersistableElement;
@ -47,6 +49,8 @@ public class DisassemblyEditorInput implements IEditorInput {
private String fContents = ""; //$NON-NLS-1$ private String fContents = ""; //$NON-NLS-1$
private IRegion[] fSourceRegions = new IRegion[0];
/** /**
* Constructor for DisassemblyEditorInput. * Constructor for DisassemblyEditorInput.
*/ */
@ -186,6 +190,7 @@ public class DisassemblyEditorInput implements IEditorInput {
} }
private void createContents() { private void createContents() {
fSourceRegions = new IRegion[0];
StringBuffer lines = new StringBuffer(); StringBuffer lines = new StringBuffer();
int maxFunctionName = 0; int maxFunctionName = 0;
int maxOpcodeLength = 0; int maxOpcodeLength = 0;
@ -209,13 +214,16 @@ public class DisassemblyEditorInput implements IEditorInput {
} }
int instrPos = calculateInstructionPosition( maxFunctionName, maxOffset ); int instrPos = calculateInstructionPosition( maxFunctionName, maxOffset );
int argPosition = instrPos + maxOpcodeLength + 1; int argPosition = instrPos + maxOpcodeLength + 1;
if ( fBlock.isMixedMode() )
fSourceRegions = new IRegion[mi.length];
for ( int j = 0; j < mi.length; ++j ) { for ( int j = 0; j < mi.length; ++j ) {
if ( fBlock.isMixedMode() ) if ( fBlock.isMixedMode() ) {
lines.append( getSourceLineString( mi[j] ) ); String sl = getSourceLineString( mi[j] );
fSourceRegions[j] = new Region( lines.length(), sl.length() );
lines.append( sl );
}
IAsmInstruction[] instructions = mi[j].getInstructions(); IAsmInstruction[] instructions = mi[j].getInstructions();
for( int i = 0; i < instructions.length; ++i ) { for( int i = 0; i < instructions.length; ++i ) {
// if ( fBlock.isMixedMode() )
// lines.append( "\t" ); //$NON-NLS-1$
lines.append( getInstructionString( instructions[i], instrPos, argPosition ) ); lines.append( getInstructionString( instructions[i], instrPos, argPosition ) );
} }
} }
@ -261,4 +269,17 @@ public class DisassemblyEditorInput implements IEditorInput {
} }
return text; return text;
} }
// private void addSourceLineRegion( int offset, int length ) {
// if ( fTextPresentation != null ) {
// fTextPresentation.addStyleRange( new StyleRange( offset,
// length,
// JFaceResources.getColorRegistry().get( IInternalCDebugUIConstants.DISASSEMBLY_SOURCE_LINE_COLOR ),
// null ) );
// }
// }
public IRegion[] getSourceRegions() {
return this.fSourceRegions;
}
} }

View file

@ -38,9 +38,11 @@ import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.Separator;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position; import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.TextPresentation;
import org.eclipse.jface.text.source.IAnnotationAccess; import org.eclipse.jface.text.source.IAnnotationAccess;
import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.IOverviewRuler;
@ -58,6 +60,7 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.MouseListener;
@ -278,7 +281,6 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
getSourceViewerDecorationSupport( viewer ); getSourceViewerDecorationSupport( viewer );
EditorsPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( this ); EditorsPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( this );
CDebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( this );
getSite().getPage().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); getSite().getPage().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
getSite().setSelectionProvider( viewer.getSelectionProvider() ); getSite().setSelectionProvider( viewer.getSelectionProvider() );
@ -346,7 +348,15 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
*/ */
public void propertyChange( PropertyChangeEvent event ) { public void propertyChange( PropertyChangeEvent event ) {
// TODO Auto-generated method stub String propertyName = event.getProperty();
if ( IInternalCDebugUIConstants.DISASSEMBLY_SOURCE_LINE_COLOR.equals( propertyName ) ) {
IEditorInput input = getInput();
if ( input instanceof DisassemblyEditorInput )
getSourceViewer().changeTextPresentation( createTextPresentation( ((DisassemblyEditorInput)input).getSourceRegions() ), true );
}
else if ( IInternalCDebugUIConstants.DISASSEMBLY_FONT.equals( propertyName ) ) {
getSourceViewer().getTextWidget().setFont(JFaceResources.getFont( IInternalCDebugUIConstants.DISASSEMBLY_FONT ) );
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -388,6 +398,8 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
private SourceViewer createSourceViewer( Composite parent, IVerticalRuler vertRuler, IOverviewRuler ovRuler ) { private SourceViewer createSourceViewer( Composite parent, IVerticalRuler vertRuler, IOverviewRuler ovRuler ) {
DisassemblyViewer viewer = new DisassemblyViewer( parent, vertRuler, ovRuler ); DisassemblyViewer viewer = new DisassemblyViewer( parent, vertRuler, ovRuler );
viewer.setRangeIndicator( new DefaultRangeIndicator() ); viewer.setRangeIndicator( new DefaultRangeIndicator() );
JFaceResources.getFontRegistry().addListener( this );
JFaceResources.getColorRegistry().addListener( this );
return viewer; return viewer;
} }
@ -449,6 +461,8 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
} }
getSourceViewer().setDocument( getDocumentProvider().getDocument( input ), getSourceViewer().setDocument( getDocumentProvider().getDocument( input ),
getDocumentProvider().getAnnotationModel( input ) ); getDocumentProvider().getAnnotationModel( input ) );
if ( input instanceof DisassemblyEditorInput )
getSourceViewer().changeTextPresentation( createTextPresentation( ((DisassemblyEditorInput)input).getSourceRegions() ), true );
updateObjects(); updateObjects();
} }
@ -457,8 +471,9 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
*/ */
public void dispose() { public void dispose() {
getSite().getPage().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); getSite().getPage().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
JFaceResources.getFontRegistry().removeListener( this );
JFaceResources.getColorRegistry().removeListener( this );
EditorsPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this ); EditorsPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this );
CDebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this );
if ( fSourceViewerDecorationSupport != null ) { if ( fSourceViewerDecorationSupport != null ) {
fSourceViewerDecorationSupport.dispose(); fSourceViewerDecorationSupport.dispose();
@ -880,4 +895,15 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
private IVerticalRuler getVerticalRuler() { private IVerticalRuler getVerticalRuler() {
return this.fVerticalRuler; return this.fVerticalRuler;
} }
private TextPresentation createTextPresentation( IRegion[] regions ) {
TextPresentation p = new TextPresentation();
for ( int i = 0; i < regions.length; ++i ) {
p.addStyleRange( new StyleRange( regions[i].getOffset(),
regions[i].getLength(),
JFaceResources.getColorRegistry().get( IInternalCDebugUIConstants.DISASSEMBLY_SOURCE_LINE_COLOR ),
null ) );
}
return p;
}
} }