Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Khodjaiants2008-04-09 16:58:49 +0000
committerMikhail Khodjaiants2008-04-09 16:58:49 +0000
commit4e172a4c9909760f3483d719ad99426f7dd055fb (patch)
tree3415c1081230709f64e5629940a1c5e60f488623
parent9404ffb8d45bae7128e3a9804fb73a7833972c55 (diff)
downloadorg.eclipse.cdt-4e172a4c9909760f3483d719ad99426f7dd055fb.tar.gz
org.eclipse.cdt-4e172a4c9909760f3483d719ad99426f7dd055fb.tar.xz
org.eclipse.cdt-4e172a4c9909760f3483d719ad99426f7dd055fb.zip
Contributing new disassembly.
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DisassemblyDocumentProvider.java6
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DocumentLabelProvider.java2
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/VirtualDocument.java170
3 files changed, 168 insertions, 10 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DisassemblyDocumentProvider.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DisassemblyDocumentProvider.java
index de8dfb8afb1..c6630a1d834 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DisassemblyDocumentProvider.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DisassemblyDocumentProvider.java
@@ -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 );
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DocumentLabelProvider.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DocumentLabelProvider.java
index f7401d2efa6..3cd5bae2aa0 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DocumentLabelProvider.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/DocumentLabelProvider.java
@@ -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;
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/VirtualDocument.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/VirtualDocument.java
index 1de09659bc5..7942e5bc06a 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/VirtualDocument.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/viewer/VirtualDocument.java
@@ -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
+ }
}
}

Back to the top