Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] 1.0.1 editor/binaryinfo fix...

Hi!

This is really just an informational patch describing changes that I had to make to the core of 1.0.1 to get navigation working for functions shown under binary objects in the CView. I don't actually think that this is a particularly important feature, but do think that these objects are pretty important as a building blocks for other features.

These changes do two things:

- add line information to IFunctions and IVariables that are created by BinaryInfo. - enable CEditor::setSelection() to handle ISourceRanges that do not have character position information, but do have line information.

Much like the recent +19 fix, realizing that it needs to be fixed is the tricky bit. Perhaps these things are already fixed or obsolete in the head anyway.

Thanks!
-Chris

diff -c -r xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java *** xide_compare/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java Sat Feb 1 12:54:38 2003 --- xide/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java Tue Mar 11 14:29:21 2003
***************
*** 204,209 ****
--- 204,210 ----
  				addChild(tu);
  			}
  			function = new Function(tu, symbol.getName());
+ 			function.setLines( symbol.getLineNumber(), symbol.getLineNumber());
  			tu.addChild(function);
  		} else {
  			function = new Function(parent, symbol.getName());
***************
*** 232,237 ****
--- 233,239 ----
  				addChild(tu);
  			}
  			variable = new Variable(tu, symbol.getName());
+ 			variable.setLines(symbol.getLineNumber(), symbol.getLineNumber());
  			tu.addChild(variable);
  		} else {
  			variable = new Variable(parent, symbol.getName());
diff -c -r xide_compare/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java xide/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java *** xide_compare/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java Sat Feb 1 12:54:50 2003 --- xide/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java Tue Mar 11 14:50:22 2003
***************
*** 38,45 ****
--- 38,47 ----
  import org.eclipse.jface.dialogs.ProgressMonitorDialog;
  import org.eclipse.jface.preference.IPreferenceStore;
  import org.eclipse.jface.preference.PreferenceConverter;
+ import org.eclipse.jface.text.BadLocationException;
  import org.eclipse.jface.text.DocumentCommand;
  import org.eclipse.jface.text.IDocument;
+ import org.eclipse.jface.text.IRegion;
  import org.eclipse.jface.text.ITextOperationTarget;
  import org.eclipse.jface.text.ITextSelection;
  import org.eclipse.jface.text.ITextViewerExtension;
***************
*** 574,601 ****
  		}
  	}
  	
  	private void setSelection(ISourceRange element, boolean moveCursor) {
  		if (element != null) {
  			try {
  				int start= element.getStartPos();
  				int length= element.getLength();
  				setHighlightRange(start, length, moveCursor);
  				
  				if (moveCursor) {
  					start= element.getIdStartPos();
! 					if (start > -1) {
! 						length= element.getIdLength();
! 						if (getSourceViewer() != null) {
! 							getSourceViewer().revealRange(start, length);
! 							getSourceViewer().setSelectedRange(start, length);
! 						}
  					}
  					updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS);
  				}
  				return;
  				
  			} catch (IllegalArgumentException x) {
  			}
  		}
  		
  		if (moveCursor)
--- 576,630 ----
  		}
  	}
  	
+ 	/**
+ 	 * Sets the current editor selection to the source range. Optionally
+ 	 * sets the current editor position.
+ 	 *
+ 	 * @param element the source range to be shown in the editor, can be null.
+ 	 * @param moveCursor if true the editor is scrolled to show the range.
+ 	 */
  	private void setSelection(ISourceRange element, boolean moveCursor) {
  		if (element != null) {
  			try {
+ 				IRegion alternateRegion = null;
  				int start= element.getStartPos();
  				int length= element.getLength();
+ 				
+ 				// 0 length and start and non-zero start line says we know
+ 				// the line for some reason, but not the offset.
+ 				if( length == 0 && start == 0 && element.getStartLine() != 0)
+ 				{
+ alternateRegion = getDocumentProvider().getDocument(getEditorInput()).getLineInformation(element.getStartLine());
+ 					if( alternateRegion != null )
+ 					{
+ 						start = alternateRegion.getOffset();
+ 						length = alternateRegion.getLength();
+ 					}
+ 				}
  				setHighlightRange(start, length, moveCursor);
  				
  				if (moveCursor) {
  					start= element.getIdStartPos();
! 					length= element.getIdLength();
! 					
! 					if( start == 0 && length == 0 && alternateRegion != null)
! 					{
! 						start = alternateRegion.getOffset();
! 						length = alternateRegion.getLength();
  					}
+ 					
+ 					if (start > -1 && getSourceViewer() != null) {
+ 						getSourceViewer().revealRange(start, length);
+ 						getSourceViewer().setSelectedRange(start, length);
+ 					}
  					updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS);
  				}
  				return;
  				
  			} catch (IllegalArgumentException x) {
+ 			} catch (BadLocationException e ) {
  			}
+ 			
  		}
  		
  		if (moveCursor)



Back to the top