mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 04:15:35 +02:00
Contributing new disassembly.
This commit is contained in:
parent
9404ffb8d4
commit
4e172a4c99
3 changed files with 168 additions and 10 deletions
|
@ -104,7 +104,7 @@ public class DisassemblyDocumentProvider implements IDocumentProvider {
|
|||
Object disassemblyContext = ((DisassemblyEditorInput)element).getDisassemblyContext();
|
||||
if ( fDocumentInfos.get( disassemblyContext ) == null ) {
|
||||
IDocumentPresentation presentation = createDocumentPresentation( disassemblyContext );
|
||||
IAnnotationModel annotationModel = createAnnotationModel();
|
||||
AnnotationModel annotationModel = createAnnotationModel();
|
||||
VirtualDocument document = createDocument( disassemblyContext, presentation, annotationModel );
|
||||
fDocumentInfos.put( disassemblyContext, new DocumentInfo( document, annotationModel, presentation ) );
|
||||
}
|
||||
|
@ -206,11 +206,11 @@ public class DisassemblyDocumentProvider implements IDocumentProvider {
|
|||
return ( info != null ) ? info.getPresentation() : null;
|
||||
}
|
||||
|
||||
private IAnnotationModel createAnnotationModel() {
|
||||
private AnnotationModel createAnnotationModel() {
|
||||
return new AnnotationModel();
|
||||
}
|
||||
|
||||
private VirtualDocument createDocument( Object disassemblyContext, IDocumentPresentation presentationContext, IAnnotationModel annotationModel ) {
|
||||
private VirtualDocument createDocument( Object disassemblyContext, IDocumentPresentation presentationContext, AnnotationModel annotationModel ) {
|
||||
return new VirtualDocument( annotationModel, presentationContext, disassemblyContext );
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
package org.eclipse.cdt.debug.internal.ui.disassembly.viewer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.cdt.debug.ui.disassembly.IDocumentElementLabelProvider;
|
||||
|
|
|
@ -14,41 +14,94 @@ package org.eclipse.cdt.debug.internal.ui.disassembly.viewer;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.cdt.debug.ui.disassembly.IDocumentPresentation;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.BadPositionCategoryException;
|
||||
import org.eclipse.jface.text.DefaultPositionUpdater;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
import org.eclipse.jface.text.source.IAnnotationModel;
|
||||
import org.eclipse.jface.text.source.AnnotationModel;
|
||||
|
||||
/**
|
||||
* Converts the model elements into the text content
|
||||
*/
|
||||
public class VirtualDocument extends Document {
|
||||
|
||||
public class LinePosition extends Position {
|
||||
|
||||
private int fDistance = 0;
|
||||
|
||||
LinePosition( int offset, int distance ) {
|
||||
super( offset );
|
||||
fDistance = distance;
|
||||
}
|
||||
|
||||
LinePosition( int offset, int length, int distance ) {
|
||||
super( offset, length );
|
||||
fDistance = distance;
|
||||
}
|
||||
|
||||
int getDistance() {
|
||||
return fDistance;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.Position#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals( Object other ) {
|
||||
if ( !(other instanceof LinePosition) )
|
||||
return false;
|
||||
return ( getDistance() == ((LinePosition)other).getDistance() );
|
||||
}
|
||||
}
|
||||
|
||||
public final static String CATEGORY_LINE = "category_line"; // "category_line"; //$NON-NLS-1$
|
||||
private static final String PENDING_LINE = ".............................."; //$NON-NLS-1$
|
||||
|
||||
private Object fRoot;
|
||||
private int fCurrentOffset = 0;
|
||||
|
||||
private IDocumentPresentation fPresentationContext;
|
||||
private IAnnotationModel fAnnotationModel;
|
||||
private AnnotationModel fAnnotationModel;
|
||||
private DocumentContentProvider fContentProvider;
|
||||
private DocumentLabelProvider fLabelProvider;
|
||||
private DocumentAnnotationProvider fAnnotationProvider;
|
||||
|
||||
public VirtualDocument( IAnnotationModel annotationModel, IDocumentPresentation presentationContext, Object root ) {
|
||||
public VirtualDocument( AnnotationModel annotationModel, IDocumentPresentation presentationContext, Object root ) {
|
||||
super();
|
||||
fRoot = root;
|
||||
fPresentationContext = presentationContext;
|
||||
fAnnotationModel = annotationModel;
|
||||
fContentProvider = new DocumentContentProvider( this );
|
||||
fLabelProvider = new DocumentLabelProvider( this );
|
||||
fAnnotationProvider = new DocumentAnnotationProvider( this );
|
||||
getContentProvider().init( fRoot );
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
getContentProvider().dispose();
|
||||
getLabelProvider().dispose();
|
||||
getAnnotationProvider().dispose();
|
||||
fRoot = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.AbstractDocument#completeInitialization()
|
||||
*/
|
||||
@Override
|
||||
protected void completeInitialization() {
|
||||
super.completeInitialization();
|
||||
addPositionCategory( CATEGORY_LINE );
|
||||
addPositionUpdater( new DefaultPositionUpdater( CATEGORY_LINE ) );
|
||||
}
|
||||
|
||||
public IDocumentPresentation getPresentationContext() {
|
||||
return fPresentationContext;
|
||||
}
|
||||
|
||||
public IAnnotationModel getAnnotationModel() {
|
||||
public AnnotationModel getAnnotationModel() {
|
||||
return fAnnotationModel;
|
||||
}
|
||||
|
||||
|
@ -56,6 +109,66 @@ public class VirtualDocument extends Document {
|
|||
return fContentProvider;
|
||||
}
|
||||
|
||||
protected DocumentLabelProvider getLabelProvider() {
|
||||
return fLabelProvider;
|
||||
}
|
||||
|
||||
protected DocumentAnnotationProvider getAnnotationProvider() {
|
||||
return fAnnotationProvider;
|
||||
}
|
||||
|
||||
private String createPendingContent( int lineCount, int oldOffset, int offset ) {
|
||||
int oldLineCount = getNumberOfLines() - 1;
|
||||
int intersectStart = Math.max( oldOffset, offset );
|
||||
int intersectEnd = Math.min( oldOffset + oldLineCount, offset + lineCount );
|
||||
int intersectCount = intersectEnd - intersectStart;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int line = 0;
|
||||
if ( oldOffset > offset ) { // scrolling up
|
||||
for ( int i = 0; i < oldOffset - offset; ++i ) {
|
||||
try {
|
||||
addPosition( CATEGORY_LINE, new LinePosition( sb.length(), offset - i ) );
|
||||
sb.append( PENDING_LINE ).append( '\n' );
|
||||
++line;
|
||||
}
|
||||
catch( BadLocationException e ) {
|
||||
// shouldn't happen
|
||||
}
|
||||
catch( BadPositionCategoryException e ) {
|
||||
// shouldn't happen
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // scrolling down
|
||||
for ( int i = 0; i < offset - oldOffset; ++i ) {
|
||||
// removePosition( CATEGORY_LINE, new LinePosition( ) )
|
||||
}
|
||||
line += offset - oldOffset;
|
||||
}
|
||||
for ( int i = 0; i < intersectCount; ++i ) {
|
||||
try {
|
||||
IRegion region = getLineInformation( line++ );
|
||||
sb.append( get( region.getOffset(), region.getLength() ) ).append( '\n' );
|
||||
}
|
||||
catch( BadLocationException e ) {
|
||||
// shouldn't happen
|
||||
}
|
||||
}
|
||||
// Assuming the offset isn't changed when resizing
|
||||
int pendingLines = 0;
|
||||
if ( oldLineCount < lineCount ) { // resizing
|
||||
pendingLines = lineCount - oldLineCount;
|
||||
}
|
||||
else if ( offset > oldOffset ) { // scrolling down
|
||||
pendingLines = offset - oldOffset;
|
||||
}
|
||||
for ( int i = 0; i < pendingLines; ++i ) {
|
||||
sb.append( PENDING_LINE ).append( '\n' );
|
||||
++line;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public int getCurrentOffset() {
|
||||
return fCurrentOffset;
|
||||
}
|
||||
|
@ -69,17 +182,64 @@ public class VirtualDocument extends Document {
|
|||
}
|
||||
|
||||
public void updateContent( int lineCount, int offset, boolean revealInput ) {
|
||||
int oldOffset = fCurrentOffset;
|
||||
fCurrentOffset = offset;
|
||||
removePositions();
|
||||
getAnnotationModel().removeAllAnnotations();
|
||||
set( createPendingContent( lineCount, oldOffset, offset ) );
|
||||
setPositions();
|
||||
getContentProvider().update( getPresentationContext(), lineCount, offset, revealInput );
|
||||
}
|
||||
|
||||
protected void updateElement( Object input, int index, Object element ) {
|
||||
getLabelProvider().update( input, element, index, getPresentationContext() );
|
||||
getAnnotationProvider().update( getContentProvider().getInput(), element, index, getPresentationContext() );
|
||||
}
|
||||
|
||||
protected void updateAnnotations( int lineNumber, Annotation[] annotations ) {
|
||||
}
|
||||
|
||||
final void labelDone( Object element, int lineNumber, Properties labels ) {
|
||||
}
|
||||
|
||||
protected void removeLine( int lineNumber ) {
|
||||
try {
|
||||
IRegion region = getLineInformation( lineNumber );
|
||||
replace( region.getOffset(), region.getLength(), "" ); //$NON-NLS-1$
|
||||
}
|
||||
catch( BadLocationException e ) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateAnnotations( int lineNumber, Annotation[] annotations ) {
|
||||
private void removePositions() {
|
||||
try {
|
||||
Position[] oldPositions = getPositions( CATEGORY_LINE );
|
||||
for ( Position p : oldPositions ) {
|
||||
removePosition( CATEGORY_LINE, p );
|
||||
}
|
||||
}
|
||||
catch( BadPositionCategoryException e ) {
|
||||
}
|
||||
}
|
||||
|
||||
private void setPositions() {
|
||||
try {
|
||||
Position[] oldPositions = getPositions( CATEGORY_LINE );
|
||||
int offset = getCurrentOffset();
|
||||
int lines = getNumberOfLines();
|
||||
for ( Position p : oldPositions ) {
|
||||
removePosition( CATEGORY_LINE, p );
|
||||
}
|
||||
for ( int i = 0; i < lines; ++i ) {
|
||||
IRegion info = getLineInformation( i );
|
||||
addPosition( CATEGORY_LINE, new LinePosition( info.getOffset(), info.getLength(), offset + i ) );
|
||||
}
|
||||
}
|
||||
catch( BadPositionCategoryException e ) {
|
||||
// shouldn't happen
|
||||
}
|
||||
catch( BadLocationException e ) {
|
||||
// shouldn't happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue