mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Chris Wiebe: BasicSearchResultCollector refactoring
Refactored MouseClickListener out of CEditor; modified it to use CppCodeScanner keywords Fixed Outline refresh problem by reverting to an earlier copy of WorkingCopyManager
This commit is contained in:
parent
a9ed54e459
commit
7ddc725965
8 changed files with 719 additions and 664 deletions
|
@ -1,3 +1,7 @@
|
|||
2004-03-08 Bogdan Gheorghe
|
||||
BasicSearchResultCollector patch from Chris Wiebe - adds setProgressMonitor method,
|
||||
cleans up some of the CoreException warnings
|
||||
|
||||
2004-02-16 Andrew Niefer
|
||||
fixed a couple of warnings
|
||||
moved OrPattern from org.eclipse.cdt.internal.core.search.matching to org.eclipse.cdt.core.search
|
||||
|
|
|
@ -53,14 +53,14 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class BasicSearchResultCollector implements ICSearchResultCollector {
|
||||
IProgressMonitor fProgressMonitor = null;
|
||||
IProgressMonitor fProgressMonitor = null;
|
||||
|
||||
public BasicSearchResultCollector() {
|
||||
}
|
||||
|
||||
public BasicSearchResultCollector(IProgressMonitor monitor) {
|
||||
fProgressMonitor = monitor;
|
||||
}
|
||||
public BasicSearchResultCollector() {
|
||||
}
|
||||
|
||||
public BasicSearchResultCollector(IProgressMonitor monitor) {
|
||||
fProgressMonitor = monitor;
|
||||
}
|
||||
|
||||
public void aboutToStart() {
|
||||
results = new HashSet();
|
||||
|
@ -73,13 +73,17 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
|
|||
return fProgressMonitor;
|
||||
}
|
||||
|
||||
public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node ) throws CoreException
|
||||
public void setProgressMonitor(IProgressMonitor monitor) {
|
||||
fProgressMonitor = monitor;
|
||||
}
|
||||
|
||||
public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node )
|
||||
{
|
||||
BasicSearchMatch result = new BasicSearchMatch();
|
||||
return createMatch( result, fileResource, start, end, node );
|
||||
}
|
||||
|
||||
public IMatch createMatch( BasicSearchMatch result, Object fileResource, int start, int end, ISourceElementCallbackDelegate node ) throws CoreException {
|
||||
public IMatch createMatch( BasicSearchMatch result, Object fileResource, int start, int end, ISourceElementCallbackDelegate node ) {
|
||||
if( fileResource instanceof IResource )
|
||||
result.resource = (IResource) fileResource;
|
||||
else if( fileResource instanceof IPath )
|
||||
|
@ -90,7 +94,7 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
|
|||
result.parentName = ""; //$NON-NLS-1$
|
||||
|
||||
IASTOffsetableNamedElement offsetable = null;
|
||||
|
||||
|
||||
if( node instanceof IASTReference ){
|
||||
offsetable = (IASTOffsetableNamedElement) ((IASTReference)node).getReferencedElement();
|
||||
result.name = ((IASTReference)node).getName();
|
||||
|
@ -107,7 +111,7 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
|
|||
} else if( offsetable instanceof IASTQualifiedNameElement ) {
|
||||
names = ((IASTQualifiedNameElement) offsetable).getFullyQualifiedName();
|
||||
}
|
||||
|
||||
|
||||
if( names != null ){
|
||||
for( int i = 0; i < names.length - 1; i++ ){
|
||||
if( i > 0 )
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
2004-03-08 Bogdan Gheorghe
|
||||
|
||||
Refactored the hyperlink-enabling MouseListener class out of CEditor.
|
||||
Fixed Outline view not refreshing bug - reverted to an earlier version of
|
||||
WorkingCopyManager.
|
||||
Modified CPPCodeScanner to return the entire list of keywords for use with
|
||||
the MouseListener hyperlink class.
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/MouseClickListener.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
|
||||
* src/org/eclipse/cdt/internal/ui/opentype/TypeSearchResultCollector.java
|
||||
* src/org/eclipse/cdt/internal/ui/text/CPPCodeScanner.java
|
||||
|
||||
|
||||
2004-03-07 Alain Magloire
|
||||
|
||||
Fix the point size of the icon in the CElementLabelProvider.
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.List;
|
|||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
@ -40,7 +39,6 @@ import org.eclipse.jface.action.IMenuManager;
|
|||
import org.eclipse.jface.action.IStatusLineManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
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;
|
||||
|
@ -48,10 +46,7 @@ import org.eclipse.jface.text.IRegion;
|
|||
import org.eclipse.jface.text.ITextOperationTarget;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.text.ITextViewerExtension;
|
||||
import org.eclipse.jface.text.ITextViewerExtension2;
|
||||
import org.eclipse.jface.text.ITextViewerExtension3;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.text.contentassist.ContentAssistant;
|
||||
import org.eclipse.jface.text.contentassist.IContentAssistant;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
|
@ -64,7 +59,6 @@ import org.eclipse.jface.text.source.IVerticalRuler;
|
|||
import org.eclipse.jface.text.source.OverviewRuler;
|
||||
import org.eclipse.jface.text.source.SourceViewer;
|
||||
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
|
@ -72,26 +66,8 @@ import org.eclipse.jface.viewers.ISelectionProvider;
|
|||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.FocusEvent;
|
||||
import org.eclipse.swt.events.FocusListener;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.KeyListener;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.events.MouseMoveListener;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Cursor;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.IEditorActionBarContributor;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
|
@ -1020,631 +996,13 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
|||
*/
|
||||
private void enableBrowserLikeLinks() {
|
||||
if (fMouseListener == null) {
|
||||
fMouseListener= new MouseClickListener();
|
||||
IAction openDeclAction = getAction("OpenDeclarations"); //$NON-NLS-1$
|
||||
fMouseListener= new MouseClickListener(this, getSourceViewer(), getPreferenceStore(), openDeclAction);
|
||||
fMouseListener.install();
|
||||
}
|
||||
}
|
||||
|
||||
class MouseClickListener
|
||||
implements
|
||||
MouseListener,
|
||||
KeyListener,
|
||||
MouseMoveListener,
|
||||
FocusListener,
|
||||
PaintListener,
|
||||
IPropertyChangeListener{
|
||||
|
||||
/** The session is active. */
|
||||
private boolean fActive;
|
||||
|
||||
/** The currently active style range. */
|
||||
private IRegion fActiveRegion;
|
||||
/** The currently active style range as position. */
|
||||
private Position fRememberedPosition;
|
||||
/** The hand cursor. */
|
||||
private Cursor fCursor;
|
||||
/** The link color. */
|
||||
private Color fColor;
|
||||
/** The key modifier mask. */
|
||||
private int fKeyModifierMask;
|
||||
/** The key modifier mask. */
|
||||
private boolean fIncludeMode;
|
||||
|
||||
//TODO: Replace Keywords
|
||||
//Temp. Keywords: Once the selection parser is complete, we can use
|
||||
//it to determine if a word can be underlined
|
||||
|
||||
private String[] fgKeywords= {
|
||||
"and", "and_eq", "asm", "auto",
|
||||
"bitand", "bitor", "break",
|
||||
"case", "catch", "class", "compl", "const", "const_cast", "continue",
|
||||
"default", "delete", "do", "dynamic_cast",
|
||||
"else", "enum", "explicit", "export", "extern",
|
||||
"false", "final", "finally", "for", "friend",
|
||||
"goto",
|
||||
"if", "inline",
|
||||
"mutable",
|
||||
"namespace", "new", "not", "not_eq",
|
||||
"operator", "or", "or_eq",
|
||||
"private", "protected", "public",
|
||||
"redeclared", "register", "reinterpret_cast", "return", "restrict",
|
||||
"sizeof", "static", "static_cast", "struct", "switch",
|
||||
"template", "this", "throw", "true", "try", "typedef", "typeid", "typename",
|
||||
"union", "using",
|
||||
"virtual", "volatile",
|
||||
"while",
|
||||
"xor", "xor_eq", "bool", "char", "double", "float", "int", "long", "short", "signed", "unsigned", "void", "wchar_t", "_Bool", "_Complex", "_Imaginary",
|
||||
"false", "NULL", "true", "__DATE__", "__LINE__", "__TIME__", "__FILE__", "__STDC__",
|
||||
"#define", "#undef", "#error", "#warning", "#pragma", "#ifdef", "#ifndef", "#line", "#undef", "#if", "#else", "#elif", "#endif"
|
||||
};
|
||||
|
||||
public void deactivate() {
|
||||
deactivate(false);
|
||||
}
|
||||
|
||||
public void deactivate(boolean redrawAll) {
|
||||
if (!fActive)
|
||||
return;
|
||||
|
||||
repairRepresentation(redrawAll);
|
||||
fActive= false;
|
||||
fIncludeMode = false;
|
||||
}
|
||||
|
||||
private void repairRepresentation(boolean redrawAll) {
|
||||
|
||||
if (fActiveRegion == null)
|
||||
return;
|
||||
|
||||
ISourceViewer viewer= getSourceViewer();
|
||||
if (viewer != null) {
|
||||
resetCursor(viewer);
|
||||
|
||||
int offset= fActiveRegion.getOffset();
|
||||
int length= fActiveRegion.getLength();
|
||||
|
||||
// remove style
|
||||
if (!redrawAll && viewer instanceof ITextViewerExtension2)
|
||||
((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
|
||||
else
|
||||
viewer.invalidateTextPresentation();
|
||||
|
||||
// remove underline
|
||||
if (viewer instanceof ITextViewerExtension3) {
|
||||
ITextViewerExtension3 extension= (ITextViewerExtension3) viewer;
|
||||
offset= extension.modelOffset2WidgetOffset(offset);
|
||||
} else {
|
||||
offset -= viewer.getVisibleRegion().getOffset();
|
||||
}
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
try {
|
||||
text.redrawRange(offset, length, true);
|
||||
} catch (IllegalArgumentException x) {
|
||||
org.eclipse.cdt.internal.core.model.Util.log(x, "Error in CEditor.MouseClickListener.repairRepresentation", ICLogConstants.CDT);
|
||||
}
|
||||
}
|
||||
|
||||
fActiveRegion= null;
|
||||
}
|
||||
|
||||
private void activateCursor(ISourceViewer viewer) {
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
Display display= text.getDisplay();
|
||||
if (fCursor == null)
|
||||
fCursor= new Cursor(display, SWT.CURSOR_HAND);
|
||||
text.setCursor(fCursor);
|
||||
}
|
||||
|
||||
private void resetCursor(ISourceViewer viewer) {
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text != null && !text.isDisposed())
|
||||
text.setCursor(null);
|
||||
|
||||
if (fCursor != null) {
|
||||
fCursor.dispose();
|
||||
fCursor= null;
|
||||
}
|
||||
}
|
||||
|
||||
public void install() {
|
||||
|
||||
ISourceViewer sourceViewer= getSourceViewer();
|
||||
if (sourceViewer == null)
|
||||
return;
|
||||
|
||||
StyledText text= sourceViewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
updateColor(sourceViewer);
|
||||
|
||||
text.addKeyListener(this);
|
||||
text.addMouseListener(this);
|
||||
text.addMouseMoveListener(this);
|
||||
text.addFocusListener(this);
|
||||
text.addPaintListener(this);
|
||||
|
||||
updateKeyModifierMask();
|
||||
|
||||
IPreferenceStore preferenceStore= getPreferenceStore();
|
||||
preferenceStore.addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
public void uninstall() {
|
||||
|
||||
if (fColor != null) {
|
||||
fColor.dispose();
|
||||
fColor= null;
|
||||
}
|
||||
|
||||
if (fCursor != null) {
|
||||
fCursor.dispose();
|
||||
fCursor= null;
|
||||
}
|
||||
|
||||
ISourceViewer sourceViewer= getSourceViewer();
|
||||
if (sourceViewer == null)
|
||||
return;
|
||||
|
||||
IPreferenceStore preferenceStore= getPreferenceStore();
|
||||
if (preferenceStore != null)
|
||||
preferenceStore.removePropertyChangeListener(this);
|
||||
|
||||
StyledText text= sourceViewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
text.removeKeyListener(this);
|
||||
text.removeMouseListener(this);
|
||||
text.removeMouseMoveListener(this);
|
||||
text.removeFocusListener(this);
|
||||
text.removePaintListener(this);
|
||||
}
|
||||
private void updateKeyModifierMask() {
|
||||
//Add code here to allow for specification of hyperlink trigger key
|
||||
fKeyModifierMask=262144;
|
||||
}
|
||||
|
||||
private void updateColor(ISourceViewer viewer) {
|
||||
if (fColor != null)
|
||||
fColor.dispose();
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
Display display= text.getDisplay();
|
||||
fColor= createColor(getPreferenceStore(), LINKED_POSITION_COLOR, display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color from the information stored in the given preference store.
|
||||
* Returns <code>null</code> if there is no such information available.
|
||||
*/
|
||||
private Color createColor(IPreferenceStore store, String key, Display display) {
|
||||
|
||||
RGB rgb= null;
|
||||
|
||||
if (store.contains(key)) {
|
||||
|
||||
if (store.isDefault(key))
|
||||
rgb= PreferenceConverter.getDefaultColor(store, key);
|
||||
else
|
||||
rgb= PreferenceConverter.getColor(store, key);
|
||||
|
||||
if (rgb != null)
|
||||
return new Color(display, rgb);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void mouseDoubleClick(MouseEvent e) {}
|
||||
|
||||
public void mouseDown(MouseEvent event) {
|
||||
if (!fActive)
|
||||
return;
|
||||
|
||||
if (event.stateMask != fKeyModifierMask) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.button != 1) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseUp(MouseEvent e) {
|
||||
if (!fActive)
|
||||
return;
|
||||
|
||||
if (e.button != 1) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean wasActive= fCursor != null;
|
||||
boolean wasInclude = fIncludeMode;
|
||||
|
||||
deactivate();
|
||||
|
||||
if (wasActive) {
|
||||
if (wasInclude){
|
||||
IAction action= getAction("OpenInclude"); //$NON-NLS-1$
|
||||
if (action != null){
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
else {
|
||||
IAction action= getAction("OpenDeclarations"); //$NON-NLS-1$
|
||||
if (action != null)
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent event) {
|
||||
if (fActive) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.keyCode != fKeyModifierMask) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
fActive= true;
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
if (!fActive)
|
||||
return;
|
||||
|
||||
deactivate();
|
||||
}
|
||||
|
||||
public void mouseMove(MouseEvent event) {
|
||||
if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fActive) {
|
||||
if (event.stateMask != fKeyModifierMask)
|
||||
return;
|
||||
// modifier was already pressed
|
||||
fActive= true;
|
||||
}
|
||||
|
||||
ISourceViewer viewer= getSourceViewer();
|
||||
if (viewer == null) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed()) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
IRegion region= getCurrentTextRegion(viewer);
|
||||
if (region == null || region.getLength() == 0) {
|
||||
repairRepresentation();
|
||||
return;
|
||||
}
|
||||
|
||||
highlightRegion(viewer, region);
|
||||
activateCursor(viewer);
|
||||
}
|
||||
|
||||
IRegion getCurrentTextRegion(ISourceViewer viewer) {
|
||||
int offset= getCurrentTextOffset(viewer);
|
||||
if (offset == -1)
|
||||
return null;
|
||||
|
||||
//Need some code in here to determine if the selected input should
|
||||
//be selected - the JDT does this by doing a code complete on the input -
|
||||
//if there are any elements presented it selects the word
|
||||
|
||||
return selectWord(viewer.getDocument(), offset);
|
||||
}
|
||||
//TODO: Modify this to work with qualified name
|
||||
private IRegion selectWord(IDocument document, int anchor) {
|
||||
|
||||
try {
|
||||
int offset= anchor;
|
||||
char c;
|
||||
|
||||
while (offset >= 0) {
|
||||
c= document.getChar(offset);
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
break;
|
||||
--offset;
|
||||
}
|
||||
|
||||
int start= offset;
|
||||
|
||||
offset= anchor;
|
||||
int length= document.getLength();
|
||||
|
||||
while (offset < length) {
|
||||
c= document.getChar(offset);
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
break;
|
||||
++offset;
|
||||
}
|
||||
|
||||
int end= offset;
|
||||
//Allow for new lines
|
||||
if (start == end)
|
||||
return new Region(start, 0);
|
||||
else{
|
||||
String selWord = null;
|
||||
String slas = document.get(start,1);
|
||||
if (slas.equals("\n") ||
|
||||
slas.equals("\t") ||
|
||||
slas.equals(" "))
|
||||
{
|
||||
|
||||
selWord =document.get(start+1, end - start - 1);
|
||||
}
|
||||
else{
|
||||
selWord =document.get(start, end - start);
|
||||
}
|
||||
//Check for keyword
|
||||
if (isKeyWord(selWord))
|
||||
return null;
|
||||
//Avoid selecting literals, includes etc.
|
||||
char charX = selWord.charAt(0);
|
||||
if (charX == '"' ||
|
||||
charX == '.' ||
|
||||
charX == '<' ||
|
||||
charX == '>')
|
||||
return null;
|
||||
|
||||
if (selWord.equals("#include"))
|
||||
{
|
||||
//get start of next identifier
|
||||
|
||||
|
||||
int end2 = end;
|
||||
|
||||
while (!Character.isJavaIdentifierPart(document.getChar(end2))){
|
||||
++end2;
|
||||
|
||||
}
|
||||
|
||||
while (end2 < length){
|
||||
c = document.getChar(end2);
|
||||
|
||||
if (!Character.isJavaIdentifierPart(c) &&
|
||||
c != '.')
|
||||
break;
|
||||
++end2;
|
||||
}
|
||||
|
||||
int finalEnd = end2;
|
||||
selWord =document.get(start, finalEnd - start);
|
||||
end = finalEnd + 1;
|
||||
start--;
|
||||
fIncludeMode = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return new Region(start + 1, end - start - 1);
|
||||
}
|
||||
|
||||
} catch (BadLocationException x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isKeyWord(String selWord) {
|
||||
for (int i=0; i<fgKeywords.length; i++){
|
||||
if (selWord.equals(fgKeywords[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getCurrentTextOffset(ISourceViewer viewer) {
|
||||
|
||||
try {
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return -1;
|
||||
|
||||
Display display= text.getDisplay();
|
||||
Point absolutePosition= display.getCursorLocation();
|
||||
Point relativePosition= text.toControl(absolutePosition);
|
||||
|
||||
int widgetOffset= text.getOffsetAtLocation(relativePosition);
|
||||
if (viewer instanceof ITextViewerExtension3) {
|
||||
ITextViewerExtension3 extension= (ITextViewerExtension3) viewer;
|
||||
return extension.widgetOffset2ModelOffset(widgetOffset);
|
||||
} else {
|
||||
return widgetOffset + viewer.getVisibleRegion().getOffset();
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void highlightRegion(ISourceViewer viewer, IRegion region) {
|
||||
|
||||
if (region.equals(fActiveRegion))
|
||||
return;
|
||||
|
||||
repairRepresentation();
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
// highlight region
|
||||
int offset= 0;
|
||||
int length= 0;
|
||||
|
||||
if (viewer instanceof ITextViewerExtension3) {
|
||||
ITextViewerExtension3 extension= (ITextViewerExtension3) viewer;
|
||||
IRegion widgetRange= extension.modelRange2WidgetRange(region);
|
||||
if (widgetRange == null)
|
||||
return;
|
||||
|
||||
offset= widgetRange.getOffset();
|
||||
length= widgetRange.getLength();
|
||||
|
||||
} else {
|
||||
offset= region.getOffset() - viewer.getVisibleRegion().getOffset();
|
||||
length= region.getLength();
|
||||
}
|
||||
|
||||
StyleRange oldStyleRange= text.getStyleRangeAtOffset(offset);
|
||||
Color foregroundColor= fColor;
|
||||
Color backgroundColor= oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
|
||||
StyleRange styleRange= new StyleRange(offset, length, foregroundColor, backgroundColor);
|
||||
text.setStyleRange(styleRange);
|
||||
|
||||
// underline
|
||||
text.redrawRange(offset, length, true);
|
||||
|
||||
fActiveRegion= region;
|
||||
}
|
||||
|
||||
|
||||
private void repairRepresentation() {
|
||||
repairRepresentation(false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
|
||||
*/
|
||||
public void focusGained(FocusEvent arg0) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
|
||||
*/
|
||||
public void focusLost(FocusEvent arg0) {
|
||||
deactivate();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
|
||||
*/
|
||||
public void paintControl(PaintEvent event) {
|
||||
if (fActiveRegion == null)
|
||||
return;
|
||||
|
||||
ISourceViewer viewer= getSourceViewer();
|
||||
if (viewer == null)
|
||||
return;
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
|
||||
int offset= 0;
|
||||
int length= 0;
|
||||
|
||||
if (viewer instanceof ITextViewerExtension3) {
|
||||
|
||||
ITextViewerExtension3 extension= (ITextViewerExtension3) viewer;
|
||||
IRegion widgetRange= extension.modelRange2WidgetRange(new Region(offset, length));
|
||||
if (widgetRange == null)
|
||||
return;
|
||||
|
||||
offset= widgetRange.getOffset();
|
||||
length= widgetRange.getLength();
|
||||
|
||||
} else {
|
||||
|
||||
IRegion region= viewer.getVisibleRegion();
|
||||
if (!includes(region, fActiveRegion))
|
||||
return;
|
||||
|
||||
offset= fActiveRegion.getOffset() - region.getOffset();
|
||||
length= fActiveRegion.getLength();
|
||||
}
|
||||
|
||||
// support for bidi
|
||||
Point minLocation= getMinimumLocation(text, offset, length);
|
||||
Point maxLocation= getMaximumLocation(text, offset, length);
|
||||
|
||||
int x1= minLocation.x;
|
||||
int x2= minLocation.x + maxLocation.x - minLocation.x - 1;
|
||||
int y= minLocation.y + text.getLineHeight() - 1;
|
||||
|
||||
GC gc= event.gc;
|
||||
if (fColor != null && !fColor.isDisposed())
|
||||
gc.setForeground(fColor);
|
||||
gc.drawLine(x1, y, x2, y);
|
||||
|
||||
}
|
||||
|
||||
private boolean includes(IRegion region, IRegion position) {
|
||||
return
|
||||
position.getOffset() >= region.getOffset() &&
|
||||
position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
|
||||
}
|
||||
|
||||
private Point getMinimumLocation(StyledText text, int offset, int length) {
|
||||
Point minLocation= new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
for (int i= 0; i <= length; i++) {
|
||||
Point location= text.getLocationAtOffset(offset + i);
|
||||
|
||||
if (location.x < minLocation.x)
|
||||
minLocation.x= location.x;
|
||||
if (location.y < minLocation.y)
|
||||
minLocation.y= location.y;
|
||||
}
|
||||
|
||||
return minLocation;
|
||||
}
|
||||
|
||||
private Point getMaximumLocation(StyledText text, int offset, int length) {
|
||||
Point maxLocation= new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
|
||||
for (int i= 0; i <= length; i++) {
|
||||
Point location= text.getLocationAtOffset(offset + i);
|
||||
|
||||
if (location.x > maxLocation.x)
|
||||
maxLocation.x= location.x;
|
||||
if (location.y > maxLocation.y)
|
||||
maxLocation.y= location.y;
|
||||
}
|
||||
|
||||
return maxLocation;
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if (event.getProperty().equals(CEditor.LINKED_POSITION_COLOR)) {
|
||||
ISourceViewer viewer= getSourceViewer();
|
||||
if (viewer != null)
|
||||
updateColor(viewer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private boolean hyperLinkEnabled() {
|
||||
|
|
|
@ -0,0 +1,660 @@
|
|||
/*
|
||||
* Created on Mar 5, 2004
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.internal.ui.text.CppCodeScanner;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceConverter;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextViewerExtension2;
|
||||
import org.eclipse.jface.text.ITextViewerExtension3;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.FocusEvent;
|
||||
import org.eclipse.swt.events.FocusListener;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.KeyListener;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.events.MouseMoveListener;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Cursor;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
|
||||
class MouseClickListener
|
||||
implements
|
||||
MouseListener,
|
||||
KeyListener,
|
||||
MouseMoveListener,
|
||||
FocusListener,
|
||||
PaintListener,
|
||||
IPropertyChangeListener{
|
||||
|
||||
private final CEditor fEditor;
|
||||
|
||||
private ISourceViewer fViewer;
|
||||
|
||||
private IPreferenceStore fPrefStore;
|
||||
|
||||
private IAction fOpenDeclAction;
|
||||
|
||||
/**
|
||||
* @param editor
|
||||
* @param viewer
|
||||
* @param store
|
||||
*/
|
||||
public MouseClickListener(CEditor editor, ISourceViewer viewer, IPreferenceStore store, IAction openDeclAction) {
|
||||
this.fEditor = editor;
|
||||
this.fViewer = viewer;
|
||||
this.fPrefStore = store;
|
||||
this.fOpenDeclAction = openDeclAction;
|
||||
this.fgKeywords = CppCodeScanner.getKeywords();
|
||||
}
|
||||
|
||||
/** The session is active. */
|
||||
private boolean fActive;
|
||||
|
||||
/** The currently active style range. */
|
||||
private IRegion fActiveRegion;
|
||||
/** The currently active style range as position. */
|
||||
private Position fRememberedPosition;
|
||||
/** The hand cursor. */
|
||||
private Cursor fCursor;
|
||||
/** The link color. */
|
||||
private Color fColor;
|
||||
/** The key modifier mask. */
|
||||
private int fKeyModifierMask;
|
||||
/** The key modifier mask. */
|
||||
private boolean fIncludeMode;
|
||||
|
||||
//TODO: Replace Keywords
|
||||
//Temp. Keywords: Once the selection parser is complete, we can use
|
||||
//it to determine if a word can be underlined
|
||||
|
||||
private String[] fgKeywords;
|
||||
|
||||
public void deactivate() {
|
||||
deactivate(false);
|
||||
}
|
||||
|
||||
public void deactivate(boolean redrawAll) {
|
||||
if (!fActive)
|
||||
return;
|
||||
|
||||
repairRepresentation(redrawAll);
|
||||
fActive= false;
|
||||
fIncludeMode = false;
|
||||
}
|
||||
|
||||
private void repairRepresentation(boolean redrawAll) {
|
||||
|
||||
if (fActiveRegion == null)
|
||||
return;
|
||||
|
||||
ISourceViewer viewer= fViewer;
|
||||
if (viewer != null) {
|
||||
resetCursor(viewer);
|
||||
|
||||
int offset= fActiveRegion.getOffset();
|
||||
int length= fActiveRegion.getLength();
|
||||
|
||||
// remove style
|
||||
if (!redrawAll && viewer instanceof ITextViewerExtension2)
|
||||
((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
|
||||
else
|
||||
viewer.invalidateTextPresentation();
|
||||
|
||||
// remove underline
|
||||
if (viewer instanceof ITextViewerExtension3) {
|
||||
ITextViewerExtension3 extension= (ITextViewerExtension3) viewer;
|
||||
offset= extension.modelOffset2WidgetOffset(offset);
|
||||
} else {
|
||||
offset -= viewer.getVisibleRegion().getOffset();
|
||||
}
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
try {
|
||||
text.redrawRange(offset, length, true);
|
||||
} catch (IllegalArgumentException x) {
|
||||
org.eclipse.cdt.internal.core.model.Util.log(x, "Error in CEditor.MouseClickListener.repairRepresentation", ICLogConstants.CDT);
|
||||
}
|
||||
}
|
||||
|
||||
fActiveRegion= null;
|
||||
}
|
||||
|
||||
private void activateCursor(ISourceViewer viewer) {
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
Display display= text.getDisplay();
|
||||
if (fCursor == null)
|
||||
fCursor= new Cursor(display, SWT.CURSOR_HAND);
|
||||
text.setCursor(fCursor);
|
||||
}
|
||||
|
||||
private void resetCursor(ISourceViewer viewer) {
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text != null && !text.isDisposed())
|
||||
text.setCursor(null);
|
||||
|
||||
if (fCursor != null) {
|
||||
fCursor.dispose();
|
||||
fCursor= null;
|
||||
}
|
||||
}
|
||||
|
||||
public void install() {
|
||||
|
||||
ISourceViewer sourceViewer= fViewer;
|
||||
if (sourceViewer == null)
|
||||
return;
|
||||
|
||||
StyledText text= sourceViewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
updateColor(sourceViewer);
|
||||
|
||||
text.addKeyListener(this);
|
||||
text.addMouseListener(this);
|
||||
text.addMouseMoveListener(this);
|
||||
text.addFocusListener(this);
|
||||
text.addPaintListener(this);
|
||||
|
||||
updateKeyModifierMask();
|
||||
|
||||
IPreferenceStore preferenceStore= fPrefStore;
|
||||
preferenceStore.addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
public void uninstall() {
|
||||
|
||||
if (fColor != null) {
|
||||
fColor.dispose();
|
||||
fColor= null;
|
||||
}
|
||||
|
||||
if (fCursor != null) {
|
||||
fCursor.dispose();
|
||||
fCursor= null;
|
||||
}
|
||||
|
||||
ISourceViewer sourceViewer= fViewer;
|
||||
if (sourceViewer == null)
|
||||
return;
|
||||
|
||||
IPreferenceStore preferenceStore= fPrefStore;
|
||||
if (preferenceStore != null)
|
||||
preferenceStore.removePropertyChangeListener(this);
|
||||
|
||||
StyledText text= sourceViewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
text.removeKeyListener(this);
|
||||
text.removeMouseListener(this);
|
||||
text.removeMouseMoveListener(this);
|
||||
text.removeFocusListener(this);
|
||||
text.removePaintListener(this);
|
||||
}
|
||||
private void updateKeyModifierMask() {
|
||||
//Add code here to allow for specification of hyperlink trigger key
|
||||
fKeyModifierMask=262144;
|
||||
}
|
||||
|
||||
private void updateColor(ISourceViewer viewer) {
|
||||
if (fColor != null)
|
||||
fColor.dispose();
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
Display display= text.getDisplay();
|
||||
fColor= createColor(fPrefStore, CEditor.LINKED_POSITION_COLOR, display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color from the information stored in the given preference store.
|
||||
* Returns <code>null</code> if there is no such information available.
|
||||
*/
|
||||
private Color createColor(IPreferenceStore store, String key, Display display) {
|
||||
|
||||
RGB rgb= null;
|
||||
|
||||
if (store.contains(key)) {
|
||||
|
||||
if (store.isDefault(key))
|
||||
rgb= PreferenceConverter.getDefaultColor(store, key);
|
||||
else
|
||||
rgb= PreferenceConverter.getColor(store, key);
|
||||
|
||||
if (rgb != null)
|
||||
return new Color(display, rgb);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void mouseDoubleClick(MouseEvent e) {}
|
||||
|
||||
public void mouseDown(MouseEvent event) {
|
||||
if (!fActive)
|
||||
return;
|
||||
|
||||
if (event.stateMask != fKeyModifierMask) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.button != 1) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseUp(MouseEvent e) {
|
||||
if (!fActive)
|
||||
return;
|
||||
|
||||
if (e.button != 1) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean wasActive= fCursor != null;
|
||||
boolean wasInclude = fIncludeMode;
|
||||
|
||||
deactivate();
|
||||
|
||||
if (wasActive) {
|
||||
if (wasInclude){
|
||||
/* IAction action= getAction("OpenInclude"); //$NON-NLS-1$
|
||||
if (action != null){
|
||||
action.run();
|
||||
}*/
|
||||
}
|
||||
else {
|
||||
if (fOpenDeclAction != null)
|
||||
fOpenDeclAction.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent event) {
|
||||
if (fActive) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.keyCode != fKeyModifierMask) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
fActive= true;
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
if (!fActive)
|
||||
return;
|
||||
|
||||
deactivate();
|
||||
}
|
||||
|
||||
public void mouseMove(MouseEvent event) {
|
||||
if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fActive) {
|
||||
if (event.stateMask != fKeyModifierMask)
|
||||
return;
|
||||
// modifier was already pressed
|
||||
fActive= true;
|
||||
}
|
||||
|
||||
ISourceViewer viewer= fViewer;
|
||||
if (viewer == null) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed()) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
|
||||
deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
IRegion region= getCurrentTextRegion(viewer);
|
||||
if (region == null || region.getLength() == 0) {
|
||||
repairRepresentation();
|
||||
return;
|
||||
}
|
||||
|
||||
highlightRegion(viewer, region);
|
||||
activateCursor(viewer);
|
||||
}
|
||||
|
||||
IRegion getCurrentTextRegion(ISourceViewer viewer) {
|
||||
int offset= getCurrentTextOffset(viewer);
|
||||
if (offset == -1)
|
||||
return null;
|
||||
|
||||
//Need some code in here to determine if the selected input should
|
||||
//be selected - the JDT does this by doing a code complete on the input -
|
||||
//if there are any elements presented it selects the word
|
||||
|
||||
return selectWord(viewer.getDocument(), offset);
|
||||
}
|
||||
//TODO: Modify this to work with qualified name
|
||||
private IRegion selectWord(IDocument document, int anchor) {
|
||||
|
||||
try {
|
||||
int offset= anchor;
|
||||
char c;
|
||||
|
||||
while (offset >= 0) {
|
||||
c= document.getChar(offset);
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
break;
|
||||
--offset;
|
||||
}
|
||||
|
||||
int start= offset;
|
||||
|
||||
offset= anchor;
|
||||
int length= document.getLength();
|
||||
|
||||
while (offset < length) {
|
||||
c= document.getChar(offset);
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
break;
|
||||
++offset;
|
||||
}
|
||||
|
||||
int end= offset;
|
||||
//Allow for new lines
|
||||
if (start == end)
|
||||
return new Region(start, 0);
|
||||
else{
|
||||
String selWord = null;
|
||||
String slas = document.get(start,1);
|
||||
if (slas.equals("\n") ||
|
||||
slas.equals("\t") ||
|
||||
slas.equals(" "))
|
||||
{
|
||||
|
||||
selWord =document.get(start+1, end - start - 1);
|
||||
}
|
||||
else{
|
||||
selWord =document.get(start, end - start);
|
||||
}
|
||||
//Check for keyword
|
||||
if (isKeyWord(selWord))
|
||||
return null;
|
||||
//Avoid selecting literals, includes etc.
|
||||
char charX = selWord.charAt(0);
|
||||
if (charX == '"' ||
|
||||
charX == '.' ||
|
||||
charX == '<' ||
|
||||
charX == '>')
|
||||
return null;
|
||||
|
||||
if (selWord.equals("#include"))
|
||||
{
|
||||
//get start of next identifier
|
||||
|
||||
|
||||
int end2 = end;
|
||||
|
||||
while (!Character.isJavaIdentifierPart(document.getChar(end2))){
|
||||
++end2;
|
||||
|
||||
}
|
||||
|
||||
while (end2 < length){
|
||||
c = document.getChar(end2);
|
||||
|
||||
if (!Character.isJavaIdentifierPart(c) &&
|
||||
c != '.')
|
||||
break;
|
||||
++end2;
|
||||
}
|
||||
|
||||
int finalEnd = end2;
|
||||
selWord =document.get(start, finalEnd - start);
|
||||
end = finalEnd + 1;
|
||||
start--;
|
||||
fIncludeMode = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return new Region(start + 1, end - start - 1);
|
||||
}
|
||||
|
||||
} catch (BadLocationException x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isKeyWord(String selWord) {
|
||||
for (int i=0; i<fgKeywords.length; i++){
|
||||
if (selWord.equals(fgKeywords[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getCurrentTextOffset(ISourceViewer viewer) {
|
||||
|
||||
try {
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return -1;
|
||||
|
||||
Display display= text.getDisplay();
|
||||
Point absolutePosition= display.getCursorLocation();
|
||||
Point relativePosition= text.toControl(absolutePosition);
|
||||
|
||||
int widgetOffset= text.getOffsetAtLocation(relativePosition);
|
||||
if (viewer instanceof ITextViewerExtension3) {
|
||||
ITextViewerExtension3 extension= (ITextViewerExtension3) viewer;
|
||||
return extension.widgetOffset2ModelOffset(widgetOffset);
|
||||
} else {
|
||||
return widgetOffset + viewer.getVisibleRegion().getOffset();
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void highlightRegion(ISourceViewer viewer, IRegion region) {
|
||||
|
||||
if (region.equals(fActiveRegion))
|
||||
return;
|
||||
|
||||
repairRepresentation();
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
// highlight region
|
||||
int offset= 0;
|
||||
int length= 0;
|
||||
|
||||
if (viewer instanceof ITextViewerExtension3) {
|
||||
ITextViewerExtension3 extension= (ITextViewerExtension3) viewer;
|
||||
IRegion widgetRange= extension.modelRange2WidgetRange(region);
|
||||
if (widgetRange == null)
|
||||
return;
|
||||
|
||||
offset= widgetRange.getOffset();
|
||||
length= widgetRange.getLength();
|
||||
|
||||
} else {
|
||||
offset= region.getOffset() - viewer.getVisibleRegion().getOffset();
|
||||
length= region.getLength();
|
||||
}
|
||||
|
||||
StyleRange oldStyleRange= text.getStyleRangeAtOffset(offset);
|
||||
Color foregroundColor= fColor;
|
||||
Color backgroundColor= oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
|
||||
StyleRange styleRange= new StyleRange(offset, length, foregroundColor, backgroundColor);
|
||||
text.setStyleRange(styleRange);
|
||||
|
||||
// underline
|
||||
text.redrawRange(offset, length, true);
|
||||
|
||||
fActiveRegion= region;
|
||||
}
|
||||
|
||||
|
||||
private void repairRepresentation() {
|
||||
repairRepresentation(false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
|
||||
*/
|
||||
public void focusGained(FocusEvent arg0) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
|
||||
*/
|
||||
public void focusLost(FocusEvent arg0) {
|
||||
deactivate();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
|
||||
*/
|
||||
public void paintControl(PaintEvent event) {
|
||||
if (fActiveRegion == null)
|
||||
return;
|
||||
|
||||
ISourceViewer viewer= fViewer;
|
||||
if (viewer == null)
|
||||
return;
|
||||
|
||||
StyledText text= viewer.getTextWidget();
|
||||
if (text == null || text.isDisposed())
|
||||
return;
|
||||
|
||||
|
||||
int offset= 0;
|
||||
int length= 0;
|
||||
|
||||
if (viewer instanceof ITextViewerExtension3) {
|
||||
|
||||
ITextViewerExtension3 extension= (ITextViewerExtension3) viewer;
|
||||
IRegion widgetRange= extension.modelRange2WidgetRange(new Region(offset, length));
|
||||
if (widgetRange == null)
|
||||
return;
|
||||
|
||||
offset= widgetRange.getOffset();
|
||||
length= widgetRange.getLength();
|
||||
|
||||
} else {
|
||||
|
||||
IRegion region= viewer.getVisibleRegion();
|
||||
if (!includes(region, fActiveRegion))
|
||||
return;
|
||||
|
||||
offset= fActiveRegion.getOffset() - region.getOffset();
|
||||
length= fActiveRegion.getLength();
|
||||
}
|
||||
|
||||
// support for bidi
|
||||
Point minLocation= getMinimumLocation(text, offset, length);
|
||||
Point maxLocation= getMaximumLocation(text, offset, length);
|
||||
|
||||
int x1= minLocation.x;
|
||||
int x2= minLocation.x + maxLocation.x - minLocation.x - 1;
|
||||
int y= minLocation.y + text.getLineHeight() - 1;
|
||||
|
||||
GC gc= event.gc;
|
||||
if (fColor != null && !fColor.isDisposed())
|
||||
gc.setForeground(fColor);
|
||||
gc.drawLine(x1, y, x2, y);
|
||||
|
||||
}
|
||||
|
||||
private boolean includes(IRegion region, IRegion position) {
|
||||
return
|
||||
position.getOffset() >= region.getOffset() &&
|
||||
position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
|
||||
}
|
||||
|
||||
private Point getMinimumLocation(StyledText text, int offset, int length) {
|
||||
Point minLocation= new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
for (int i= 0; i <= length; i++) {
|
||||
Point location= text.getLocationAtOffset(offset + i);
|
||||
|
||||
if (location.x < minLocation.x)
|
||||
minLocation.x= location.x;
|
||||
if (location.y < minLocation.y)
|
||||
minLocation.y= location.y;
|
||||
}
|
||||
|
||||
return minLocation;
|
||||
}
|
||||
|
||||
private Point getMaximumLocation(StyledText text, int offset, int length) {
|
||||
Point maxLocation= new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
|
||||
for (int i= 0; i <= length; i++) {
|
||||
Point location= text.getLocationAtOffset(offset + i);
|
||||
|
||||
if (location.x > maxLocation.x)
|
||||
maxLocation.x= location.x;
|
||||
if (location.y > maxLocation.y)
|
||||
maxLocation.y= location.y;
|
||||
}
|
||||
|
||||
return maxLocation;
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if (event.getProperty().equals(CEditor.LINKED_POSITION_COLOR)) {
|
||||
ISourceViewer viewer= fViewer;
|
||||
if (viewer != null)
|
||||
updateColor(viewer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -42,7 +42,6 @@ public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyMana
|
|||
public WorkingCopyManager(CDocumentProvider provider) {
|
||||
Assert.isNotNull(provider);
|
||||
fDocumentProvider= provider;
|
||||
fMap = new HashMap();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -82,13 +81,9 @@ public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyMana
|
|||
*/
|
||||
public IWorkingCopy getWorkingCopy(IEditorInput input) {
|
||||
IWorkingCopy unit= fMap == null ? null : (IWorkingCopy) fMap.get(input);
|
||||
if(unit != null)
|
||||
return unit;
|
||||
IWorkingCopy copy = fDocumentProvider.getWorkingCopy(input);
|
||||
if(copy != null)
|
||||
fMap.put(input, copy);
|
||||
return copy;
|
||||
return unit != null ? unit : fDocumentProvider.getWorkingCopy(input);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.editor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput, org.eclipse.cdt.core.model.ITranslationUnit)
|
||||
*/
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TypeSearchResultCollector extends BasicSearchResultCollector {
|
|||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node ) throws CoreException
|
||||
public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node )
|
||||
{
|
||||
TypeSearchMatch result = new TypeSearchMatch();
|
||||
return super.createMatch( result, fileResource, start, end, node );
|
||||
|
|
|
@ -153,4 +153,23 @@ public final class CppCodeScanner extends AbstractCScanner {
|
|||
super.adaptToPreferenceChange(event);
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] getKeywords(){
|
||||
|
||||
int keysLength = fgKeywords.length;
|
||||
int typesLength = fgTypes.length;
|
||||
int preprocessorLength = fgPreprocessor.length;
|
||||
int constsLength = fgConstants.length;
|
||||
|
||||
String[] keywords = new String[keysLength + typesLength + preprocessorLength + constsLength];
|
||||
|
||||
|
||||
|
||||
System.arraycopy(fgKeywords,0,keywords,0,keysLength);
|
||||
System.arraycopy(fgTypes,0,keywords,keysLength,typesLength);
|
||||
System.arraycopy(fgPreprocessor,0,keywords,(keysLength + typesLength),preprocessorLength);
|
||||
System.arraycopy(fgConstants,0,keywords,(keysLength + typesLength + preprocessorLength),constsLength);
|
||||
|
||||
return keywords;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue