1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +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
Added theme category for CDT debugger.
Moved the disassembly font definition to the theme.

View file

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

View file

@ -27,6 +27,12 @@ public interface IInternalCDebugUIConstants {
*/
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
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.debug.core.DebugException;
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.IPersistableElement;
@ -46,6 +48,8 @@ public class DisassemblyEditorInput implements IEditorInput {
private IDisassemblyBlock fBlock;
private String fContents = ""; //$NON-NLS-1$
private IRegion[] fSourceRegions = new IRegion[0];
/**
* Constructor for DisassemblyEditorInput.
@ -186,6 +190,7 @@ public class DisassemblyEditorInput implements IEditorInput {
}
private void createContents() {
fSourceRegions = new IRegion[0];
StringBuffer lines = new StringBuffer();
int maxFunctionName = 0;
int maxOpcodeLength = 0;
@ -209,13 +214,16 @@ public class DisassemblyEditorInput implements IEditorInput {
}
int instrPos = calculateInstructionPosition( maxFunctionName, maxOffset );
int argPosition = instrPos + maxOpcodeLength + 1;
if ( fBlock.isMixedMode() )
fSourceRegions = new IRegion[mi.length];
for ( int j = 0; j < mi.length; ++j ) {
if ( fBlock.isMixedMode() )
lines.append( getSourceLineString( mi[j] ) );
if ( fBlock.isMixedMode() ) {
String sl = getSourceLineString( mi[j] );
fSourceRegions[j] = new Region( lines.length(), sl.length() );
lines.append( sl );
}
IAsmInstruction[] instructions = mi[j].getInstructions();
for( int i = 0; i < instructions.length; ++i ) {
// if ( fBlock.isMixedMode() )
// lines.append( "\t" ); //$NON-NLS-1$
lines.append( getInstructionString( instructions[i], instrPos, argPosition ) );
}
}
@ -261,4 +269,17 @@ public class DisassemblyEditorInput implements IEditorInput {
}
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.Separator;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
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.IAnnotationModel;
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.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
@ -278,7 +281,6 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
getSourceViewerDecorationSupport( viewer );
EditorsPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( this );
CDebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( this );
getSite().getPage().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
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)
*/
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)
@ -388,6 +398,8 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
private SourceViewer createSourceViewer( Composite parent, IVerticalRuler vertRuler, IOverviewRuler ovRuler ) {
DisassemblyViewer viewer = new DisassemblyViewer( parent, vertRuler, ovRuler );
viewer.setRangeIndicator( new DefaultRangeIndicator() );
JFaceResources.getFontRegistry().addListener( this );
JFaceResources.getColorRegistry().addListener( this );
return viewer;
}
@ -449,6 +461,8 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
}
getSourceViewer().setDocument( getDocumentProvider().getDocument( input ),
getDocumentProvider().getAnnotationModel( input ) );
if ( input instanceof DisassemblyEditorInput )
getSourceViewer().changeTextPresentation( createTextPresentation( ((DisassemblyEditorInput)input).getSourceRegions() ), true );
updateObjects();
}
@ -457,8 +471,9 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
*/
public void dispose() {
getSite().getPage().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
JFaceResources.getFontRegistry().removeListener( this );
JFaceResources.getColorRegistry().removeListener( this );
EditorsPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this );
CDebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this );
if ( fSourceViewerDecorationSupport != null ) {
fSourceViewerDecorationSupport.dispose();
@ -880,4 +895,15 @@ public class DisassemblyView extends AbstractDebugEventHandlerView
private IVerticalRuler getVerticalRuler() {
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;
}
}