mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
update ceditor to 2.0/2.1
This commit is contained in:
parent
e6ecdc51cd
commit
445d0d51ee
15 changed files with 1150 additions and 3492 deletions
|
@ -1,3 +1,23 @@
|
|||
2003-04-21 David Inglis
|
||||
|
||||
Update CEditor to be 2.0/2.1 compliant.
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties
|
||||
* src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java
|
||||
* src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
|
||||
* src/org/eclipse/cdt/internal/ui/text/CPairMatcher.java
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/editor/BracketPainter.java (removed)
|
||||
* src/org/eclipse/cdt/internal/ui/editor/IPainter.java (removed)
|
||||
* src/org/eclipse/cdt/internal/ui/editor/LinePainter.java (removed)
|
||||
* src/org/eclipse/cdt/internal/ui/editor/OverviewRuler.java (removed)
|
||||
* src/org/eclipse/cdt/internal/ui/editor/PaintManager.java (removed)
|
||||
* src/org/eclipse/cdt/internal/ui/editor/PrintMarginPainter.java (removed)
|
||||
* src/org/eclipse/cdt/internal/ui/editor/ProblemPainter.java (removed)
|
||||
* src/org/eclipse/cdt/internal/ui/preferences/CLaunchingPropertyPage.java (removed)
|
||||
* src/org/eclipse/cdt/internal/ui/util/CoreUtility.java (removed)
|
||||
|
||||
2003-04-17 Alain Magloire
|
||||
|
||||
Bug 36584
|
||||
|
|
|
@ -1,169 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CPairMatcher;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
|
||||
|
||||
|
||||
|
||||
public final class BracketPainter implements IPainter, PaintListener {
|
||||
|
||||
private CPairMatcher fMatcher= new CPairMatcher(new char[] { '{', '}', '(', ')', '[', ']' });
|
||||
private Position fBracketPosition= new Position(0, 0);
|
||||
private int fAnchor;
|
||||
|
||||
private boolean fIsActive= false;
|
||||
private ISourceViewer fSourceViewer;
|
||||
private StyledText fTextWidget;
|
||||
private Color fColor;
|
||||
private boolean fNoBox;
|
||||
|
||||
private IPositionManager fPositionManager;
|
||||
|
||||
|
||||
public BracketPainter(ISourceViewer sourceViewer) {
|
||||
fSourceViewer= sourceViewer;
|
||||
fTextWidget= sourceViewer.getTextWidget();
|
||||
}
|
||||
|
||||
public void setHighlightColor(Color color) {
|
||||
fColor= color;
|
||||
}
|
||||
|
||||
public void setHighlightStyle(boolean nobox) {
|
||||
fNoBox = nobox;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (fMatcher != null) {
|
||||
fMatcher.dispose();
|
||||
fMatcher= null;
|
||||
}
|
||||
|
||||
fColor= null;
|
||||
fTextWidget= null;
|
||||
}
|
||||
|
||||
public void deactivate(boolean redraw) {
|
||||
if (fIsActive) {
|
||||
fIsActive= false;
|
||||
fTextWidget.removePaintListener(this);
|
||||
if (fPositionManager != null)
|
||||
fPositionManager.removeManagedPosition(fBracketPosition);
|
||||
if (redraw)
|
||||
handleDrawRequest(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void paintControl(PaintEvent event) {
|
||||
if (fTextWidget != null)
|
||||
handleDrawRequest(event.gc);
|
||||
}
|
||||
|
||||
private void handleDrawRequest(GC gc) {
|
||||
|
||||
if (fBracketPosition.isDeleted)
|
||||
return;
|
||||
|
||||
int length= fBracketPosition.getLength();
|
||||
if (length < 1)
|
||||
return;
|
||||
|
||||
int offset= fBracketPosition.getOffset();
|
||||
IRegion region= fSourceViewer.getVisibleRegion();
|
||||
|
||||
if (region.getOffset() <= offset && region.getOffset() + region.getLength() >= offset + length) {
|
||||
offset -= region.getOffset();
|
||||
if (CPairMatcher.RIGHT == fAnchor)
|
||||
draw(gc, offset, 1);
|
||||
else
|
||||
draw(gc, offset + length -1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void draw(GC gc, int offset, int length) {
|
||||
if (gc != null) {
|
||||
Point left= fTextWidget.getLocationAtOffset(offset);
|
||||
Point right= fTextWidget.getLocationAtOffset(offset + length);
|
||||
|
||||
gc.setForeground(fColor);
|
||||
if(fNoBox) {
|
||||
gc.drawString(fTextWidget.getTextRange(offset, 1), left.x, left.y, true);
|
||||
} else {
|
||||
gc.drawRectangle(left.x, left.y, right.x - left.x - 1, gc.getFontMetrics().getHeight() - 1);
|
||||
}
|
||||
} else {
|
||||
fTextWidget.redrawRange(offset, length, true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#paint(int)
|
||||
*/
|
||||
public void paint(int reason) {
|
||||
Point selection= fSourceViewer.getSelectedRange();
|
||||
if (selection.y > 0) {
|
||||
deactivate(true);
|
||||
return;
|
||||
}
|
||||
|
||||
IRegion pair= fMatcher.match(fSourceViewer.getDocument(), selection.x);
|
||||
if (pair == null) {
|
||||
deactivate(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fIsActive) {
|
||||
// only if different
|
||||
if (pair.getOffset() != fBracketPosition.getOffset() ||
|
||||
pair.getLength() != fBracketPosition.getLength() ||
|
||||
fMatcher.getAnchor() != fAnchor) {
|
||||
|
||||
// remove old highlighting
|
||||
handleDrawRequest(null);
|
||||
// update position
|
||||
fBracketPosition.isDeleted= false;
|
||||
fBracketPosition.offset= pair.getOffset();
|
||||
fBracketPosition.length= pair.getLength();
|
||||
fAnchor= fMatcher.getAnchor();
|
||||
// apply new highlighting
|
||||
handleDrawRequest(null);
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
fIsActive= true;
|
||||
|
||||
fBracketPosition.isDeleted= false;
|
||||
fBracketPosition.offset= pair.getOffset();
|
||||
fBracketPosition.length= pair.getLength();
|
||||
fAnchor= fMatcher.getAnchor();
|
||||
|
||||
fTextWidget.addPaintListener(this);
|
||||
fPositionManager.addManagedPosition(fBracketPosition);
|
||||
handleDrawRequest(null);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#setPositionManager(IPositionManager)
|
||||
*/
|
||||
public void setPositionManager(IPositionManager manager) {
|
||||
fPositionManager= manager;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -19,12 +19,9 @@ ClassFileMarkerAnnotationModel.error.isAcceptable=ClassFileMarkerAnnotationModel
|
|||
ClassFileMarkerAnnotationModel.error.isAffected=ClassFileMarkerAnnotationModel.isAffected
|
||||
ClassFileMarkerAnnotationModel.error.resourceChanged=ClassFileMarkerAnnotationModel.resourceChanged
|
||||
|
||||
CEditor.error.saving.message1=File has been deleted.
|
||||
CEditor.error.saving.message2=Could not save file.
|
||||
CEditor.error.saving.message3=Could not save file.
|
||||
CEditor.error.saving.title1=Cannot Save
|
||||
CEditor.error.saving.title2=Save Problems
|
||||
CEditor.error.saving.title3=Save Problems
|
||||
CEditor.error.saving.message=Save could not be completed. {0}
|
||||
CEditor.error.saving.title=Problems During Save As...
|
||||
|
||||
CEditorPreferencePage.description= C Editor Preferences
|
||||
|
||||
DeleteISourceManipulations.description=Delete the selected element in the editor
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
public interface IPainter {
|
||||
|
||||
/** Paint reasons */
|
||||
int SELECTION= 0;
|
||||
int TEXT_CHANGE= 1;
|
||||
int KEY_STROKE= 2;
|
||||
int MOUSE_BUTTON= 4;
|
||||
int INTERNAL= 8;
|
||||
|
||||
|
||||
void dispose();
|
||||
|
||||
void paint(int reason);
|
||||
|
||||
void deactivate(boolean redraw);
|
||||
|
||||
void setPositionManager(IPositionManager manager);
|
||||
}
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.swt.custom.LineBackgroundEvent;
|
||||
import org.eclipse.swt.custom.LineBackgroundListener;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.custom.StyledTextContent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
|
||||
|
||||
public class LinePainter implements IPainter, LineBackgroundListener {
|
||||
|
||||
private StyledText fTextWidget;
|
||||
private Color fHighlightColor;
|
||||
private int[] fLine= { -1, -1 };
|
||||
private boolean fIsActive= false;
|
||||
|
||||
|
||||
public LinePainter(ISourceViewer sourceViewer) {
|
||||
fTextWidget= sourceViewer.getTextWidget();
|
||||
}
|
||||
|
||||
public void setHighlightColor(Color highlightColor) {
|
||||
fHighlightColor= highlightColor;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see LineBackgroundListener#lineGetBackground(LineBackgroundEvent)
|
||||
*/
|
||||
public void lineGetBackground(LineBackgroundEvent event) {
|
||||
/* Don't use cached line information because of batched redrawing events. */
|
||||
|
||||
if (fTextWidget != null) {
|
||||
|
||||
|
||||
int caret= fTextWidget.getCaretOffset();
|
||||
int length= event.lineText.length();
|
||||
|
||||
if (event.lineOffset <= caret && caret <= event.lineOffset + length && fIsActive) {
|
||||
StyledTextContent content= fTextWidget.getContent();
|
||||
Point p= fTextWidget.getSelectionRange();
|
||||
if(content.getLineAtOffset(caret) == content.getLineAtOffset(p.x)) {
|
||||
event.lineBackground= fHighlightColor;
|
||||
} else {
|
||||
event.lineBackground= fTextWidget.getBackground();
|
||||
}
|
||||
}
|
||||
else
|
||||
event.lineBackground= fTextWidget.getBackground();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateHighlightLine() {
|
||||
StyledTextContent content= fTextWidget.getContent();
|
||||
|
||||
|
||||
int offset= fTextWidget.getCaretOffset();
|
||||
int length= content.getCharCount();
|
||||
if (offset > length)
|
||||
offset= length;
|
||||
|
||||
int lineNumber= content.getLineAtOffset(offset);
|
||||
fLine[0]= content.getOffsetAtLine(lineNumber);
|
||||
|
||||
try {
|
||||
fLine[1]= content.getOffsetAtLine(lineNumber + 1);
|
||||
} catch (IllegalArgumentException x) {
|
||||
fLine[1]= -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void clearHighlightLine() {
|
||||
if (fLine[0] <= fTextWidget.getCharCount())
|
||||
drawHighlightLine();
|
||||
}
|
||||
|
||||
private void drawHighlightLine() {
|
||||
if (fLine[1] >= fTextWidget.getCharCount())
|
||||
fLine[1]= -1;
|
||||
|
||||
if (fLine[1] == -1) {
|
||||
|
||||
Point upperLeft= fTextWidget.getLocationAtOffset(fLine[0]);
|
||||
int width= fTextWidget.getClientArea().width;
|
||||
int height= fTextWidget.getLineHeight();
|
||||
fTextWidget.redraw(upperLeft.x, upperLeft.y, width, height, false);
|
||||
|
||||
} else {
|
||||
fTextWidget.redrawRange(fLine[0], fLine[1] - fLine[0], true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#deactivate(boolean)
|
||||
*/
|
||||
public void deactivate(boolean redraw) {
|
||||
if (fIsActive) {
|
||||
fIsActive= false;
|
||||
fTextWidget.removeLineBackgroundListener(this);
|
||||
if (redraw)
|
||||
drawHighlightLine();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
fTextWidget= null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#paint(int)
|
||||
*/
|
||||
public void paint(int reason) {
|
||||
if (!fIsActive) {
|
||||
fIsActive= true;
|
||||
fTextWidget.addLineBackgroundListener(this);
|
||||
} else if (fLine[0] != -1) {
|
||||
clearHighlightLine();
|
||||
}
|
||||
|
||||
updateHighlightLine();
|
||||
|
||||
drawHighlightLine();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#setPositionManager(IPositionManager)
|
||||
*/
|
||||
public void setPositionManager(IPositionManager manager) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,498 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
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.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Canvas;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextListener;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.TextEvent;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
import org.eclipse.jface.text.source.IAnnotationModel;
|
||||
import org.eclipse.jface.text.source.IAnnotationModelListener;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class OverviewRuler {
|
||||
|
||||
/**
|
||||
* Internal listener class.
|
||||
*/
|
||||
class InternalListener implements ITextListener, IAnnotationModelListener {
|
||||
|
||||
/*
|
||||
* @see ITextListener#textChanged
|
||||
*/
|
||||
public void textChanged(TextEvent e) {
|
||||
if (fTextViewer != null && e.getDocumentEvent() == null && e.getViewerRedrawState()) {
|
||||
// handle only changes of visible document
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IAnnotationModelListener#modelChanged(IAnnotationModel)
|
||||
*/
|
||||
public void modelChanged(IAnnotationModel model) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters problems based on their types.
|
||||
*/
|
||||
class FilterIterator implements Iterator {
|
||||
|
||||
private Iterator fIterator;
|
||||
private int fType;
|
||||
private Annotation fNext;
|
||||
|
||||
public FilterIterator(int type) {
|
||||
fType= type;
|
||||
if (fModel != null) {
|
||||
fIterator= fModel.getAnnotationIterator();
|
||||
skip();
|
||||
}
|
||||
}
|
||||
|
||||
private void skip() {
|
||||
while (fIterator.hasNext()) {
|
||||
fNext= (Annotation) fIterator.next();
|
||||
int type= getType(fNext);
|
||||
if ((fType == ALL && type != UNKNOWN) || fType == type)
|
||||
return;
|
||||
}
|
||||
fNext= null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see Iterator#hasNext()
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return fNext != null;
|
||||
}
|
||||
/*
|
||||
* @see Iterator#next()
|
||||
*/
|
||||
public Object next() {
|
||||
try {
|
||||
return fNext;
|
||||
} finally {
|
||||
if (fModel != null)
|
||||
skip();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* @see Iterator#remove()
|
||||
*/
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Problem types */
|
||||
private static final int ALL= -1;
|
||||
private static final int COMPILE_WARNING= 0;
|
||||
private static final int COMPILE_ERROR= 1;
|
||||
private static final int TEMPORARY= 2;
|
||||
private static final int UNKNOWN= 4;
|
||||
|
||||
/** Color table */
|
||||
private static final RGB[][] COLORS= new RGB[][] {
|
||||
/* fill */ /* stroke */
|
||||
/* warning */ { new RGB(248, 218, 114), new RGB(139, 109, 7) },
|
||||
/* error */ { new RGB(255, 140, 140), new RGB(255, 0 ,0) },
|
||||
/* temp */ { new RGB(240, 230, 230), new RGB(200, 100, 100) }
|
||||
};
|
||||
|
||||
/** drawing layers */
|
||||
private static final int[] LAYERS= new int[] { COMPILE_WARNING, TEMPORARY, COMPILE_ERROR };
|
||||
|
||||
private static final int INSET= 2;
|
||||
private static final int PROBLEM_HEIGHT_MIN= 4;
|
||||
private static boolean PROBLEM_HEIGHT_SCALABLE= false;
|
||||
|
||||
|
||||
|
||||
/** The model of the overview ruler */
|
||||
protected IAnnotationModel fModel;
|
||||
/** The view to which this ruler is connected */
|
||||
protected ITextViewer fTextViewer;
|
||||
/** The ruler's canvas */
|
||||
private Canvas fCanvas;
|
||||
/** The drawable for double buffering */
|
||||
private Image fBuffer;
|
||||
/** The internal listener */
|
||||
private InternalListener fInternalListener= new InternalListener();
|
||||
/** The width of this vertical ruler */
|
||||
private int fWidth;
|
||||
/** The hit detection cursor */
|
||||
private Cursor fHitDetectionCursor;
|
||||
/** The last cursor */
|
||||
private Cursor fLastCursor;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a vertical ruler with the given width.
|
||||
*
|
||||
* @param width the width of the vertical ruler
|
||||
*/
|
||||
public OverviewRuler(int width) {
|
||||
fWidth= width;
|
||||
}
|
||||
|
||||
public Control getControl() {
|
||||
return fCanvas;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return fWidth;
|
||||
}
|
||||
|
||||
protected int getType(Annotation annotation) {
|
||||
if (annotation instanceof IProblemAnnotation) {
|
||||
IProblemAnnotation pa= (IProblemAnnotation) annotation;
|
||||
//if (!pa.isRelevant())
|
||||
// return UNKNOWN;
|
||||
if (pa.isTemporaryProblem())
|
||||
return TEMPORARY;
|
||||
if (pa.isError())
|
||||
return COMPILE_ERROR;
|
||||
if (pa.isWarning())
|
||||
return COMPILE_WARNING;
|
||||
}
|
||||
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public void setModel(IAnnotationModel model) {
|
||||
if (model != fModel || model != null) {
|
||||
|
||||
if (fModel != null)
|
||||
fModel.removeAnnotationModelListener(fInternalListener);
|
||||
|
||||
fModel= model;
|
||||
|
||||
if (fModel != null)
|
||||
fModel.addAnnotationModelListener(fInternalListener);
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
public Control createControl(Composite parent, ITextViewer textViewer) {
|
||||
|
||||
fTextViewer= textViewer;
|
||||
|
||||
fHitDetectionCursor= new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
|
||||
fCanvas= new Canvas(parent, SWT.NO_BACKGROUND);
|
||||
|
||||
fCanvas.addPaintListener(new PaintListener() {
|
||||
public void paintControl(PaintEvent event) {
|
||||
if (fTextViewer != null)
|
||||
doubleBufferPaint(event.gc);
|
||||
}
|
||||
});
|
||||
|
||||
fCanvas.addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent event) {
|
||||
handleDispose();
|
||||
fTextViewer= null;
|
||||
}
|
||||
});
|
||||
|
||||
fCanvas.addMouseListener(new MouseAdapter() {
|
||||
public void mouseDown(MouseEvent event) {
|
||||
handleMouseDown(event);
|
||||
}
|
||||
});
|
||||
|
||||
fCanvas.addMouseMoveListener(new MouseMoveListener() {
|
||||
public void mouseMove(MouseEvent event) {
|
||||
handleMouseMove(event);
|
||||
}
|
||||
});
|
||||
|
||||
if (fTextViewer != null)
|
||||
fTextViewer.addTextListener(fInternalListener);
|
||||
|
||||
return fCanvas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes the ruler's resources.
|
||||
*/
|
||||
protected void handleDispose() {
|
||||
|
||||
if (fTextViewer != null) {
|
||||
fTextViewer.removeTextListener(fInternalListener);
|
||||
fTextViewer= null;
|
||||
}
|
||||
|
||||
if (fModel != null)
|
||||
fModel.removeAnnotationModelListener(fInternalListener);
|
||||
|
||||
if (fBuffer != null) {
|
||||
fBuffer.dispose();
|
||||
fBuffer= null;
|
||||
}
|
||||
|
||||
if (fHitDetectionCursor != null) {
|
||||
fHitDetectionCursor.dispose();
|
||||
fHitDetectionCursor= null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Double buffer drawing.
|
||||
*/
|
||||
protected void doubleBufferPaint(GC dest) {
|
||||
|
||||
Point size= fCanvas.getSize();
|
||||
|
||||
if (size.x <= 0 || size.y <= 0)
|
||||
return;
|
||||
|
||||
if (fBuffer != null) {
|
||||
Rectangle r= fBuffer.getBounds();
|
||||
if (r.width != size.x || r.height != size.y) {
|
||||
fBuffer.dispose();
|
||||
fBuffer= null;
|
||||
}
|
||||
}
|
||||
if (fBuffer == null)
|
||||
fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y);
|
||||
|
||||
GC gc= new GC(fBuffer);
|
||||
try {
|
||||
gc.setBackground(fCanvas.getBackground());
|
||||
gc.fillRectangle(0, 0, size.x, size.y);
|
||||
doPaint(gc);
|
||||
} finally {
|
||||
gc.dispose();
|
||||
}
|
||||
|
||||
dest.drawImage(fBuffer, 0, 0);
|
||||
}
|
||||
|
||||
private Color getColor(RGB rgb) {
|
||||
CTextTools textTools= CUIPlugin.getDefault().getTextTools();
|
||||
return textTools.getColorManager().getColor(rgb);
|
||||
}
|
||||
|
||||
private void doPaint(GC gc) {
|
||||
|
||||
if (fTextViewer == null)
|
||||
return;
|
||||
|
||||
Rectangle r= new Rectangle(0, 0, 0, 0);
|
||||
int yy, hh= PROBLEM_HEIGHT_MIN;
|
||||
|
||||
|
||||
IDocument document= fTextViewer.getDocument();
|
||||
IRegion visible= fTextViewer.getVisibleRegion();
|
||||
|
||||
StyledText textWidget= fTextViewer.getTextWidget();
|
||||
int maxLines= textWidget.getLineCount();
|
||||
|
||||
Point size= fCanvas.getSize();
|
||||
int writable= maxLines * textWidget.getLineHeight();
|
||||
if (size.y > writable)
|
||||
size.y= writable;
|
||||
|
||||
for (int l= 0 ; l < LAYERS.length; l++) {
|
||||
|
||||
Iterator e= new FilterIterator(LAYERS[l]);
|
||||
Color fill= getColor(COLORS[LAYERS[l]][0]);
|
||||
Color stroke= getColor(COLORS[LAYERS[l]][1]);
|
||||
|
||||
for (int i= 0; e.hasNext(); i++) {
|
||||
|
||||
Annotation a= (Annotation) e.next();
|
||||
Position p= fModel.getPosition(a);
|
||||
|
||||
if (!p.overlapsWith(visible.getOffset(), visible.getLength()))
|
||||
continue;
|
||||
|
||||
int problemOffset= Math.max(p.getOffset(), visible.getOffset());
|
||||
int problemEnd= Math.min(p.getOffset() + p.getLength(), visible.getOffset() + visible.getLength());
|
||||
int problemLength= problemEnd - problemOffset;
|
||||
|
||||
try {
|
||||
|
||||
int startLine= textWidget.getLineAtOffset(problemOffset - visible.getOffset());
|
||||
yy= (startLine * size.y) / maxLines;
|
||||
|
||||
if (PROBLEM_HEIGHT_SCALABLE) {
|
||||
int numbersOfLines= document.getNumberOfLines(problemOffset, problemLength);
|
||||
hh= (numbersOfLines * size.y) / maxLines;
|
||||
if (hh < PROBLEM_HEIGHT_MIN)
|
||||
hh= PROBLEM_HEIGHT_MIN;
|
||||
}
|
||||
|
||||
if (fill != null) {
|
||||
gc.setBackground(fill);
|
||||
gc.fillRectangle(INSET, yy, size.x-(2*INSET), hh);
|
||||
}
|
||||
|
||||
if (stroke != null) {
|
||||
gc.setForeground(stroke);
|
||||
r.x= INSET;
|
||||
r.y= yy;
|
||||
r.width= size.x - (2 * INSET) - 1;
|
||||
r.height= hh;
|
||||
gc.setLineWidth(1);
|
||||
gc.drawRectangle(r);
|
||||
}
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Thread-safe implementation.
|
||||
* Can be called from any thread.
|
||||
*/
|
||||
public void update() {
|
||||
if (fCanvas != null && !fCanvas.isDisposed()) {
|
||||
Display d= fCanvas.getDisplay();
|
||||
if (d != null) {
|
||||
d.asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
redraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraws the overview ruler.
|
||||
*/
|
||||
protected void redraw() {
|
||||
if (fCanvas != null && !fCanvas.isDisposed()) {
|
||||
GC gc= new GC(fCanvas);
|
||||
doubleBufferPaint(gc);
|
||||
gc.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private int[] toLineNumbers(int y_coordinate) {
|
||||
|
||||
IRegion visible= fTextViewer.getVisibleRegion();
|
||||
int lineNumber= 0;
|
||||
try {
|
||||
lineNumber= fTextViewer.getDocument().getLineOfOffset(visible.getOffset());
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
StyledText textWidget= fTextViewer.getTextWidget();
|
||||
int maxLines= textWidget.getContent().getLineCount();
|
||||
|
||||
Point size= fCanvas.getSize();
|
||||
int writable= maxLines * textWidget.getLineHeight();
|
||||
if (size.y > writable)
|
||||
size.y= writable;
|
||||
|
||||
int[] lines= new int[2];
|
||||
|
||||
int pixel= Math.max(y_coordinate - 1, 0);
|
||||
lines[0]= lineNumber + (pixel * maxLines) / size.y;
|
||||
|
||||
pixel= Math.min(size.y, y_coordinate + 1);
|
||||
lines[1]= lineNumber + (pixel * maxLines) / size.y;
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
private Position getProblemPositionAt(int[] lineNumbers) {
|
||||
|
||||
Position found= null;
|
||||
|
||||
try {
|
||||
IDocument d= fTextViewer.getDocument();
|
||||
IRegion line= d.getLineInformation(lineNumbers[0]);
|
||||
int start= line.getOffset();
|
||||
|
||||
line= d.getLineInformation(lineNumbers[lineNumbers.length - 1]);
|
||||
int end= line.getOffset() + line.getLength();
|
||||
|
||||
Iterator e= new FilterIterator(ALL);
|
||||
while (e.hasNext()) {
|
||||
Annotation a= (Annotation) e.next();
|
||||
Position p= fModel.getPosition(a);
|
||||
if (start <= p.getOffset() && p.getOffset() < end) {
|
||||
if (found == null || p.getOffset() < found.getOffset())
|
||||
found= p;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
protected void handleMouseDown(MouseEvent event) {
|
||||
if (fTextViewer != null) {
|
||||
int[] lines= toLineNumbers(event.y);
|
||||
Position p= getProblemPositionAt(lines);
|
||||
if (p != null) {
|
||||
fTextViewer.revealRange(p.getOffset(), p.getLength());
|
||||
fTextViewer.setSelectedRange(p.getOffset(), p.getLength());
|
||||
}
|
||||
fTextViewer.getTextWidget().setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleMouseMove(MouseEvent event) {
|
||||
if (fTextViewer != null) {
|
||||
int[] lines= toLineNumbers(event.y);
|
||||
Position p= getProblemPositionAt(lines);
|
||||
Cursor cursor= (p != null ? fHitDetectionCursor : null);
|
||||
if (cursor != fLastCursor) {
|
||||
fCanvas.setCursor(cursor);
|
||||
fLastCursor= cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,257 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
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.widgets.Control;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.BadPositionCategoryException;
|
||||
import org.eclipse.jface.text.DefaultPositionUpdater;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IPositionUpdater;
|
||||
import org.eclipse.jface.text.ITextInputListener;
|
||||
import org.eclipse.jface.text.ITextListener;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.TextEvent;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
|
||||
|
||||
public final class PaintManager implements KeyListener, MouseListener, ISelectionChangedListener, ITextListener, ITextInputListener {
|
||||
|
||||
static class PositionManager implements IPositionManager {
|
||||
|
||||
private IDocument fDocument;
|
||||
private IPositionUpdater fPositionUpdater;
|
||||
private String fCategory;
|
||||
|
||||
public PositionManager() {
|
||||
fCategory= getClass().getName() + hashCode();
|
||||
fPositionUpdater= new DefaultPositionUpdater(fCategory);
|
||||
}
|
||||
|
||||
public void install(IDocument document) {
|
||||
fDocument= document;
|
||||
fDocument.addPositionCategory(fCategory);
|
||||
fDocument.addPositionUpdater(fPositionUpdater);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
uninstall(fDocument);
|
||||
}
|
||||
|
||||
public void uninstall(IDocument document) {
|
||||
if (document == fDocument && document != null) {
|
||||
try {
|
||||
fDocument.removePositionUpdater(fPositionUpdater);
|
||||
fDocument.removePositionCategory(fCategory);
|
||||
} catch (BadPositionCategoryException x) {
|
||||
// should not happen
|
||||
}
|
||||
fDocument= null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPositionManager#addManagedPosition(Position)
|
||||
*/
|
||||
public void addManagedPosition(Position position) {
|
||||
try {
|
||||
fDocument.addPosition(fCategory, position);
|
||||
} catch (BadPositionCategoryException x) {
|
||||
// should not happen
|
||||
} catch (BadLocationException x) {
|
||||
// should not happen
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPositionManager#removeManagedPosition(Position)
|
||||
*/
|
||||
public void removeManagedPosition(Position position) {
|
||||
try {
|
||||
fDocument.removePosition(fCategory, position);
|
||||
} catch (BadPositionCategoryException x) {
|
||||
// should not happen
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private List fPainters= new ArrayList(2);
|
||||
private PositionManager fManager;
|
||||
protected ISourceViewer fSourceViewer;
|
||||
protected boolean fTextChanged= false;
|
||||
private boolean fAutoRepeat= false;
|
||||
|
||||
|
||||
public PaintManager(ISourceViewer sourceViewer) {
|
||||
fSourceViewer= sourceViewer;
|
||||
}
|
||||
|
||||
public void addPainter(IPainter painter) {
|
||||
if (!fPainters.contains(painter)) {
|
||||
fPainters.add(painter);
|
||||
if (fPainters.size() == 1)
|
||||
install();
|
||||
painter.setPositionManager(fManager);
|
||||
painter.paint(IPainter.INTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePainter(IPainter painter) {
|
||||
if (fPainters.remove(painter))
|
||||
painter.setPositionManager(null);
|
||||
if (fPainters.size() == 0)
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void install() {
|
||||
|
||||
fManager= new PositionManager();
|
||||
fManager.install(fSourceViewer.getDocument());
|
||||
|
||||
fSourceViewer.addTextInputListener(this);
|
||||
|
||||
ISelectionProvider provider= fSourceViewer.getSelectionProvider();
|
||||
provider.addSelectionChangedListener(this);
|
||||
|
||||
fSourceViewer.addTextListener(this);
|
||||
|
||||
StyledText text= fSourceViewer.getTextWidget();
|
||||
text.addKeyListener(this);
|
||||
text.addMouseListener(this);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
||||
if (fManager != null) {
|
||||
fManager.dispose();
|
||||
fManager= null;
|
||||
}
|
||||
|
||||
for (Iterator e = fPainters.iterator(); e.hasNext();)
|
||||
((IPainter) e.next()).dispose();
|
||||
fPainters.clear();
|
||||
|
||||
fSourceViewer.removeTextInputListener(this);
|
||||
|
||||
ISelectionProvider provider= fSourceViewer.getSelectionProvider();
|
||||
if (provider != null)
|
||||
provider.removeSelectionChangedListener(this);
|
||||
|
||||
fSourceViewer.removeTextListener(this);
|
||||
|
||||
StyledText text= fSourceViewer.getTextWidget();
|
||||
if (text != null && !text.isDisposed()) {
|
||||
text.removeKeyListener(this);
|
||||
text.removeMouseListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected void paint(int reason) {
|
||||
for (Iterator e = fPainters.iterator(); e.hasNext();)
|
||||
((IPainter) e.next()).paint(reason);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see KeyListener#keyPressed(KeyEvent)
|
||||
*/
|
||||
public void keyPressed(KeyEvent e) {
|
||||
// This leaves artifacts when scrolling
|
||||
//if (fAutoRepeat)
|
||||
paint(IPainter.KEY_STROKE);
|
||||
|
||||
fTextChanged= false;
|
||||
fAutoRepeat= true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see KeyListener#keyReleased(KeyEvent)
|
||||
*/
|
||||
public void keyReleased(KeyEvent e) {
|
||||
fAutoRepeat= false;
|
||||
if (!fTextChanged)
|
||||
paint(IPainter.KEY_STROKE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see MouseListener#mouseDoubleClick(MouseEvent)
|
||||
*/
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see MouseListener#mouseDown(MouseEvent)
|
||||
*/
|
||||
public void mouseDown(MouseEvent e) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see MouseListener#mouseUp(MouseEvent)
|
||||
*/
|
||||
public void mouseUp(MouseEvent e) {
|
||||
paint(IPainter.MOUSE_BUTTON);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent)
|
||||
*/
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
paint(IPainter.SELECTION);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ITextListener#textChanged(TextEvent)
|
||||
*/
|
||||
public void textChanged(TextEvent event) {
|
||||
fTextChanged= true;
|
||||
Control control= fSourceViewer.getTextWidget();
|
||||
if (control != null) {
|
||||
control.getDisplay().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
if (fTextChanged && fSourceViewer != null)
|
||||
paint(IPainter.TEXT_CHANGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument, IDocument)
|
||||
*/
|
||||
public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
|
||||
if (oldInput != null) {
|
||||
for (Iterator e = fPainters.iterator(); e.hasNext();)
|
||||
((IPainter) e.next()).deactivate(false);
|
||||
fManager.uninstall(oldInput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ITextInputListener#inputDocumentChanged(IDocument, IDocument)
|
||||
*/
|
||||
public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
|
||||
if (newInput != null) {
|
||||
fManager.install(newInput);
|
||||
paint(IPainter.TEXT_CHANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
|
||||
|
||||
|
||||
public class PrintMarginPainter implements IPainter, PaintListener {
|
||||
|
||||
|
||||
private StyledText fTextWidget;
|
||||
|
||||
private int fMarginWidth= 80;
|
||||
private Color fColor;
|
||||
private int fLineStyle= SWT.LINE_SOLID;
|
||||
private int fLineWidth= 1;
|
||||
|
||||
private int fCachedWidgetX= -1;
|
||||
private boolean fIsActive= false;
|
||||
|
||||
public PrintMarginPainter(ISourceViewer sourceViewer) {
|
||||
fTextWidget= sourceViewer.getTextWidget();
|
||||
}
|
||||
|
||||
public void setMarginRulerColumn(int width) {
|
||||
fMarginWidth= width;
|
||||
intialize();
|
||||
}
|
||||
|
||||
public void setMarginRulerStyle(int lineStyle) {
|
||||
fLineStyle= lineStyle;
|
||||
}
|
||||
|
||||
public void setMarginRulerWidth(int lineWidth) {
|
||||
fLineWidth= lineWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called before <code>paint</code> is called the first time.
|
||||
*/
|
||||
public void setMarginRulerColor(Color color) {
|
||||
fColor= color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called explicitly when font of text widget changes.
|
||||
*/
|
||||
public void intialize() {
|
||||
computeWidgetX();
|
||||
fTextWidget.redraw();
|
||||
}
|
||||
|
||||
private void computeWidgetX() {
|
||||
GC gc= new GC(fTextWidget);
|
||||
int pixels= gc.getFontMetrics().getAverageCharWidth();
|
||||
gc.dispose();
|
||||
|
||||
fCachedWidgetX= pixels * fMarginWidth;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#deactivate(boolean)
|
||||
*/
|
||||
public void deactivate(boolean redraw) {
|
||||
if (fIsActive) {
|
||||
fIsActive= false;
|
||||
fTextWidget.removePaintListener(this);
|
||||
if (redraw)
|
||||
fTextWidget.redraw();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
fTextWidget= null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#paint(int)
|
||||
*/
|
||||
public void paint(int reason) {
|
||||
if (!fIsActive) {
|
||||
fIsActive= true;
|
||||
fTextWidget.addPaintListener(this);
|
||||
if (fCachedWidgetX == -1)
|
||||
computeWidgetX();
|
||||
fTextWidget.redraw();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#setPositionManager(IPositionManager)
|
||||
*/
|
||||
public void setPositionManager(IPositionManager manager) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PaintListener#paintControl(PaintEvent)
|
||||
*/
|
||||
public void paintControl(PaintEvent e) {
|
||||
if (fTextWidget != null) {
|
||||
int x= fCachedWidgetX - fTextWidget.getHorizontalPixel();
|
||||
if (x >= 0) {
|
||||
Rectangle area= fTextWidget.getClientArea();
|
||||
e.gc.setForeground(fColor);
|
||||
e.gc.setLineStyle(fLineStyle);
|
||||
e.gc.setLineWidth(fLineWidth);
|
||||
e.gc.drawLine(x, 0, x, area.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,248 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
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.IAnnotationModelListener;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
|
||||
//import org.eclipse.jdt.core.compiler.IProblem;
|
||||
|
||||
|
||||
/**
|
||||
* Highlights the temporary problems.
|
||||
*/
|
||||
public class ProblemPainter implements IPainter, PaintListener, IAnnotationModelListener {
|
||||
|
||||
private boolean fIsActive= false;
|
||||
private boolean fIsPainting= false;
|
||||
protected boolean fIsModelChanging= false;
|
||||
|
||||
private Color fColor;
|
||||
private ITextEditor fTextEditor;
|
||||
private ISourceViewer fSourceViewer;
|
||||
private StyledText fTextWidget;
|
||||
private IAnnotationModel fModel;
|
||||
private List fProblemPositions= new ArrayList();
|
||||
|
||||
|
||||
|
||||
public ProblemPainter(ITextEditor textEditor, ISourceViewer sourceViewer) {
|
||||
fTextEditor= textEditor;
|
||||
fSourceViewer= sourceViewer;
|
||||
fTextWidget= sourceViewer.getTextWidget();
|
||||
}
|
||||
|
||||
private boolean hasProblems() {
|
||||
if (fProblemPositions != null) {
|
||||
return !fProblemPositions.isEmpty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void enablePainting() {
|
||||
if (!fIsPainting && hasProblems()) {
|
||||
fIsPainting= true;
|
||||
fTextWidget.addPaintListener(this);
|
||||
handleDrawRequest(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void disablePainting(boolean redraw) {
|
||||
if (fIsPainting) {
|
||||
fIsPainting= false;
|
||||
fTextWidget.removePaintListener(this);
|
||||
if (redraw && hasProblems())
|
||||
handleDrawRequest(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setModel(IAnnotationModel model) {
|
||||
|
||||
if (fModel != model) {
|
||||
if (fModel != null)
|
||||
fModel.removeAnnotationModelListener(this);
|
||||
fModel= model;
|
||||
if (fModel != null)
|
||||
fModel.addAnnotationModelListener(this);
|
||||
}
|
||||
|
||||
if (fProblemPositions != null) {
|
||||
fProblemPositions.clear();
|
||||
if (fModel != null) {
|
||||
Iterator e= new ProblemAnnotationIterator(fModel);
|
||||
while (e.hasNext()) {
|
||||
IProblemAnnotation pa= (IProblemAnnotation) e.next();
|
||||
if (pa.isProblem()) {
|
||||
Annotation a= (Annotation) pa;
|
||||
Position p= fModel.getPosition(a);
|
||||
fProblemPositions.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IAnnotationModelListener#modelChanged(IAnnotationModel)
|
||||
*/
|
||||
public void modelChanged(final IAnnotationModel model) {
|
||||
if (fTextWidget != null && !fTextWidget.isDisposed() && !fIsModelChanging) {
|
||||
Display d= fTextWidget.getDisplay();
|
||||
if (d != null) {
|
||||
d.asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
disablePainting(true);
|
||||
try {
|
||||
fIsModelChanging= true;
|
||||
setModel(model);
|
||||
} finally {
|
||||
fIsModelChanging= false;
|
||||
}
|
||||
enablePainting();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setHighlightColor(Color color) {
|
||||
fColor= color;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
fColor= null;
|
||||
fTextWidget= null;
|
||||
fModel= null;
|
||||
fProblemPositions= null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PaintListener#paintControl(PaintEvent)
|
||||
*/
|
||||
public void paintControl(PaintEvent event) {
|
||||
if (fTextWidget != null)
|
||||
handleDrawRequest(event.gc);
|
||||
}
|
||||
|
||||
private void handleDrawRequest(GC gc) {
|
||||
|
||||
IRegion region= fSourceViewer.getVisibleRegion();
|
||||
int offset= region.getOffset();
|
||||
int length= region.getLength();
|
||||
|
||||
for (Iterator e = fProblemPositions.iterator(); e.hasNext();) {
|
||||
Position p = (Position) e.next();
|
||||
if (p.overlapsWith(offset, length)) {
|
||||
int p1= Math.max(offset, p.getOffset());
|
||||
int p2= Math.min(offset + length, p.getOffset() + p.getLength());
|
||||
draw(gc, p1 - offset, p2 - p1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int[] computePolyline(Point left, Point right, int height) {
|
||||
|
||||
final int WIDTH= 4; // must be even
|
||||
final int HEIGHT= 2; // can be any number
|
||||
|
||||
int leftX= left.x;
|
||||
int peeks= (right.x - left.x) / WIDTH;
|
||||
|
||||
// compute (number of point) * 2
|
||||
int length= ((2 * peeks) + 1) * 2;
|
||||
if (length < 0)
|
||||
return new int[0];
|
||||
|
||||
int[] coordinates= new int[length];
|
||||
|
||||
// cache peeks' y-coordinates
|
||||
int bottom= left.y + height - 1;
|
||||
int top= bottom - HEIGHT;
|
||||
|
||||
// populate array with peek coordinates
|
||||
for (int i= 0; i < peeks; i++) {
|
||||
int index= 4 * i;
|
||||
coordinates[index]= leftX + (WIDTH * i);
|
||||
coordinates[index+1]= bottom;
|
||||
coordinates[index+2]= coordinates[index] + WIDTH/2;
|
||||
coordinates[index+3]= top;
|
||||
}
|
||||
|
||||
// the last down flank is missing
|
||||
coordinates[length-2]= left.x + (WIDTH * peeks);
|
||||
coordinates[length-1]= bottom;
|
||||
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
private void draw(GC gc, int offset, int length) {
|
||||
if (gc != null) {
|
||||
|
||||
Point left= fTextWidget.getLocationAtOffset(offset);
|
||||
Point right= fTextWidget.getLocationAtOffset(offset + length);
|
||||
|
||||
gc.setForeground(fColor);
|
||||
int[] polyline= computePolyline(left, right, gc.getFontMetrics().getHeight());
|
||||
gc.drawPolyline(polyline);
|
||||
|
||||
} else {
|
||||
fTextWidget.redrawRange(offset, length, true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#deactivate(boolean)
|
||||
*/
|
||||
public void deactivate(boolean redraw) {
|
||||
if (fIsActive) {
|
||||
fIsActive= false;
|
||||
disablePainting(redraw);
|
||||
setModel(null);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#paint(int)
|
||||
*/
|
||||
public void paint(int reason) {
|
||||
if (!fIsActive) {
|
||||
fIsActive= true;
|
||||
IDocumentProvider provider= fTextEditor.getDocumentProvider();
|
||||
setModel(provider.getAnnotationModel(fTextEditor.getEditorInput()));
|
||||
enablePainting();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPainter#setPositionManager(IPositionManager)
|
||||
*/
|
||||
public void setPositionManager(IPositionManager manager) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,8 +114,8 @@ public class AsmTextEditor extends StatusTextEditor {
|
|||
} catch (InterruptedException x) {
|
||||
} catch (InvocationTargetException x) {
|
||||
// Shared with C editor
|
||||
String title= CEditorMessages.getString("CEditor.error.save.title"); //$NON-NLS-1$
|
||||
String msg= MessageFormat.format(CEditorMessages.getString("CEditor.error.save.message"), new Object[] { x.getTargetException().getMessage() }); //$NON-NLS-1$
|
||||
String title= CEditorMessages.getString("CEditor.error.saving.title"); //$NON-NLS-1$
|
||||
String msg= MessageFormat.format(CEditorMessages.getString("CEditor.error.saving.message"), new Object[] { x.getTargetException().getMessage() }); //$NON-NLS-1$
|
||||
MessageDialog.openError(shell, title, msg);
|
||||
} finally {
|
||||
getDocumentProvider().changed(newInput);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,216 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusTool;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
|
||||
import org.eclipse.cdt.internal.ui.wizards.swt.MGridLayout;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.DirectoryDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.dialogs.PropertyPage;
|
||||
import org.eclipse.ui.help.WorkbenchHelp;
|
||||
public class CLaunchingPropertyPage extends PropertyPage {
|
||||
|
||||
private static final String PAGE_NAME= "CLaunchingPropertyPage";
|
||||
private static final String ARGUMENTS= PAGE_NAME + ".arguments";
|
||||
private static final String WORKINGDIR= PAGE_NAME + ".workingdir";
|
||||
|
||||
private static final String NO_CPROJECT= PAGE_NAME + ".nocproject.label";
|
||||
|
||||
private static final String ERROR_WORKINGDIR_NOTEXISTS= PAGE_NAME + ".error.WorkingDirNotExists";
|
||||
|
||||
private StringDialogField fArgumentField;
|
||||
protected StringButtonDialogField fWorkingDirField;
|
||||
|
||||
private StatusInfo fWorkingDirStatus;
|
||||
|
||||
private QualifiedName fArgumentsPropertyName;
|
||||
private QualifiedName fWorkingDirPropertyName;
|
||||
|
||||
private Shell fShell;
|
||||
|
||||
public CLaunchingPropertyPage() {
|
||||
LaunchingDialogFieldsAdapter adapter= new LaunchingDialogFieldsAdapter();
|
||||
|
||||
fArgumentField= new StringDialogField();
|
||||
fArgumentField.setLabelText(CUIPlugin.getResourceString(ARGUMENTS + ".label"));
|
||||
fArgumentField.setDialogFieldListener(adapter);
|
||||
|
||||
fWorkingDirField= new StringButtonDialogField(adapter);
|
||||
fWorkingDirField.setLabelText(CUIPlugin.getResourceString(WORKINGDIR + ".label"));
|
||||
fWorkingDirField.setButtonLabel(CUIPlugin.getResourceString(WORKINGDIR + ".browse"));
|
||||
fWorkingDirField.setDialogFieldListener(adapter);
|
||||
|
||||
fWorkingDirStatus= new StatusInfo();
|
||||
|
||||
fArgumentsPropertyName= new QualifiedName(CUIPlugin.PLUGIN_ID, "arguments");
|
||||
fWorkingDirPropertyName= new QualifiedName(CUIPlugin.PLUGIN_ID, "workingdir");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreferencePage#createContents(Composite)
|
||||
*/
|
||||
protected Control createContents(Composite parent) {
|
||||
Composite composite= new Composite(parent, SWT.NONE);
|
||||
fShell= parent.getShell();
|
||||
|
||||
MGridLayout layout= new MGridLayout();
|
||||
layout.marginWidth= 0;
|
||||
layout.marginHeight= 0;
|
||||
layout.minimumWidth= 400;
|
||||
layout.minimumHeight= 350;
|
||||
layout.numColumns= 3;
|
||||
composite.setLayout(layout);
|
||||
|
||||
boolean isCProject= false;
|
||||
try {
|
||||
IFile file= getInputFile();
|
||||
isCProject= (file.getProject().hasNature(CProjectNature.C_NATURE_ID));
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
|
||||
if (isCProject) {
|
||||
fArgumentField.doFillIntoGrid(composite, 3);
|
||||
fWorkingDirField.doFillIntoGrid(composite, 3);
|
||||
initialize();
|
||||
} else {
|
||||
DialogField labelField= new DialogField();
|
||||
labelField.setLabelText(CUIPlugin.getResourceString(NO_CPROJECT));
|
||||
labelField.doFillIntoGrid(composite, 3);
|
||||
}
|
||||
WorkbenchHelp.setHelp(parent, ICHelpContextIds.LAUNCH_PROPERTY_PAGE);
|
||||
|
||||
return composite;
|
||||
}
|
||||
|
||||
|
||||
private void initialize() {
|
||||
IFile file= getInputFile();
|
||||
if (file != null) {
|
||||
try {
|
||||
String arguments= file.getPersistentProperty(fArgumentsPropertyName);
|
||||
if (arguments != null) {
|
||||
fArgumentField.setText(arguments);
|
||||
}
|
||||
|
||||
String workingdir= file.getPersistentProperty(fWorkingDirPropertyName);
|
||||
if (workingdir != null) {
|
||||
fWorkingDirField.setText(workingdir);
|
||||
} else {
|
||||
fWorkingDirField.setText(file.getParent().getLocation().toOSString());
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e.getStatus());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreferencePage#performOk
|
||||
*/
|
||||
public boolean performOk() {
|
||||
IFile file= getInputFile();
|
||||
if (file != null) {
|
||||
try {
|
||||
file.setPersistentProperty(fArgumentsPropertyName, fArgumentField.getText());
|
||||
file.setPersistentProperty(fWorkingDirPropertyName, fWorkingDirField.getText());
|
||||
} catch (CoreException e) {
|
||||
ErrorDialog.openError(fShell, "Error", null, e.getStatus());
|
||||
CUIPlugin.getDefault().log(e.getStatus());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreferencePage#doDefaults
|
||||
*/
|
||||
protected void performDefaults() {
|
||||
initialize();
|
||||
super.performDefaults();
|
||||
}
|
||||
|
||||
private class LaunchingDialogFieldsAdapter implements IDialogFieldListener, IStringButtonAdapter {
|
||||
|
||||
public void changeControlPressed(DialogField field) {
|
||||
String oldValue= fWorkingDirField.getText();
|
||||
String newValue= chooseFolder(oldValue);
|
||||
if (newValue != null) {
|
||||
fWorkingDirField.setText(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void dialogFieldChanged(DialogField field) {
|
||||
doFieldChanged(field);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doFieldChanged(DialogField field) {
|
||||
if (field == fWorkingDirField) {
|
||||
updateWorkingDirStatus();
|
||||
}
|
||||
projectStatusChanged(fWorkingDirStatus);
|
||||
}
|
||||
|
||||
|
||||
private void updateWorkingDirStatus() {
|
||||
String str= fWorkingDirField.getText();
|
||||
if (!"".equals(str)) {
|
||||
IPath path= new Path(str);
|
||||
if (!path.toFile().isDirectory()) {
|
||||
fWorkingDirStatus.setError(CUIPlugin.getResourceString(ERROR_WORKINGDIR_NOTEXISTS));
|
||||
return;
|
||||
}
|
||||
}
|
||||
fWorkingDirStatus.setOK();
|
||||
}
|
||||
|
||||
private IFile getInputFile() {
|
||||
return (IFile)getElement();
|
||||
}
|
||||
|
||||
protected String chooseFolder(String initPath) {
|
||||
DirectoryDialog dialog= new DirectoryDialog(fShell, 0);
|
||||
dialog.setFilterPath(initPath);
|
||||
String res= dialog.open();
|
||||
return res;
|
||||
}
|
||||
|
||||
public void projectStatusChanged(IStatus status) {
|
||||
setValid(!status.matches(IStatus.ERROR));
|
||||
StatusTool.applyToStatusLine(this, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DialogPage#setVisible(boolean)
|
||||
*/
|
||||
public void setVisible(boolean visible) {
|
||||
super.setVisible(visible);
|
||||
if (visible && fShell != null) {
|
||||
fArgumentField.postSetFocusOnDialogField(fShell.getDisplay());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,105 +7,91 @@ package org.eclipse.cdt.internal.ui.text;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.Region;
|
||||
|
||||
import org.eclipse.jface.text.source.ICharacterPairMatcher;
|
||||
|
||||
/**
|
||||
* Helper class for match pairs of characters.
|
||||
*/
|
||||
public class CPairMatcher {
|
||||
|
||||
|
||||
public static final int LEFT= 1;
|
||||
public static final int RIGHT= 2;
|
||||
public class CPairMatcher implements ICharacterPairMatcher {
|
||||
|
||||
|
||||
|
||||
protected char[] fPairs;
|
||||
protected IDocument fDocument;
|
||||
protected int fOffset;
|
||||
|
||||
|
||||
protected int fStartPos;
|
||||
protected int fEndPos;
|
||||
protected int fAnchor;
|
||||
|
||||
protected CCodeReader fReader= new CCodeReader();
|
||||
|
||||
|
||||
|
||||
protected CCodeReader fReader = new CCodeReader();
|
||||
|
||||
public CPairMatcher(char[] pairs) {
|
||||
fPairs= pairs;
|
||||
fPairs = pairs;
|
||||
}
|
||||
|
||||
|
||||
public IRegion match(IDocument document, int offset) {
|
||||
|
||||
|
||||
fOffset= offset;
|
||||
|
||||
fOffset = offset;
|
||||
|
||||
if (fOffset < 0)
|
||||
return null;
|
||||
|
||||
|
||||
fDocument= document;
|
||||
|
||||
fDocument = document;
|
||||
|
||||
if (matchPairsAt() && fStartPos != fEndPos)
|
||||
return new Region(fStartPos, fEndPos - fStartPos + 1);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public int getAnchor() {
|
||||
return fAnchor;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
fDocument= null;
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.source.ICharacterPairMatcher#clear()
|
||||
*/
|
||||
public void clear() {
|
||||
if (fReader != null) {
|
||||
try {
|
||||
fReader.close();
|
||||
} catch (IOException x) {
|
||||
// ignore
|
||||
}
|
||||
fReader= null;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean matchPairsAt() {
|
||||
|
||||
public void dispose() {
|
||||
clear();
|
||||
fDocument = null;
|
||||
fReader = null;
|
||||
}
|
||||
protected boolean matchPairsAt() {
|
||||
|
||||
int i;
|
||||
int pairIndex1= fPairs.length;
|
||||
int pairIndex2= fPairs.length;
|
||||
|
||||
|
||||
fStartPos= -1;
|
||||
fEndPos= -1;
|
||||
|
||||
|
||||
// get the chars preceding and following the start position
|
||||
try {
|
||||
|
||||
|
||||
/*
|
||||
A quick hack to get around the fact that we can't bracket
|
||||
match on the very first element of a document. We make the
|
||||
character to match a null character which is unlikely to match.
|
||||
*/
|
||||
char prevChar= (fOffset > 0) ? fDocument.getChar(fOffset - 1) : '\0';
|
||||
char nextChar= fDocument.getChar(fOffset);
|
||||
|
||||
char prevChar= fDocument.getChar(Math.max(fOffset - 1, 0));
|
||||
// modified behavior for http://dev.eclipse.org/bugs/show_bug.cgi?id=16879
|
||||
// char nextChar= fDocument.getChar(fOffset);
|
||||
|
||||
// search for opening peer character next to the activation point
|
||||
for (i= 0; i < fPairs.length; i= i + 2) {
|
||||
if (nextChar == fPairs[i]) {
|
||||
fStartPos= fOffset;
|
||||
pairIndex1= i;
|
||||
} else if (prevChar == fPairs[i]) {
|
||||
// if (nextChar == fPairs[i]) {
|
||||
// fStartPos= fOffset;
|
||||
// pairIndex1= i;
|
||||
// } else
|
||||
if (prevChar == fPairs[i]) {
|
||||
fStartPos= fOffset - 1;
|
||||
pairIndex1= i;
|
||||
}
|
||||
|
@ -116,13 +102,13 @@ public class CPairMatcher {
|
|||
if (prevChar == fPairs[i]) {
|
||||
fEndPos= fOffset - 1;
|
||||
pairIndex2= i;
|
||||
} else if (nextChar == fPairs[i]) {
|
||||
fEndPos= fOffset;
|
||||
pairIndex2= i;
|
||||
}
|
||||
}
|
||||
// else if (nextChar == fPairs[i]) {
|
||||
// fEndPos= fOffset;
|
||||
// pairIndex2= i;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
if (fEndPos > -1) {
|
||||
fAnchor= RIGHT;
|
||||
fStartPos= searchForOpeningPeer(fEndPos, fPairs[pairIndex2 - 1], fPairs[pairIndex2], fDocument);
|
||||
|
@ -139,54 +125,119 @@ public class CPairMatcher {
|
|||
fStartPos= -1;
|
||||
}
|
||||
|
||||
|
||||
} catch (BadLocationException x) {
|
||||
} catch (IOException x) {
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// protected boolean matchPairsAt() {
|
||||
//
|
||||
// int i;
|
||||
// int pairIndex1 = fPairs.length;
|
||||
// int pairIndex2 = fPairs.length;
|
||||
//
|
||||
// fStartPos = -1;
|
||||
// fEndPos = -1;
|
||||
//
|
||||
// // get the chars preceding and following the start position
|
||||
// try {
|
||||
//
|
||||
// /*
|
||||
// A quick hack to get around the fact that we can't bracket
|
||||
// match on the very first element of a document. We make the
|
||||
// character to match a null character which is unlikely to match.
|
||||
// */
|
||||
// char prevChar = (fOffset > 0) ? fDocument.getChar(fOffset - 1) : '\0';
|
||||
// char nextChar = fDocument.getChar(fOffset);
|
||||
//
|
||||
// // search for opening peer character next to the activation point
|
||||
// for (i = 0; i < fPairs.length; i = i + 2) {
|
||||
// if (nextChar == fPairs[i]) {
|
||||
// fStartPos = fOffset;
|
||||
// pairIndex1 = i;
|
||||
// } else if (prevChar == fPairs[i]) {
|
||||
// fStartPos = fOffset - 1;
|
||||
// pairIndex1 = i;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // search for closing peer character next to the activation point
|
||||
// for (i = 1; i < fPairs.length; i = i + 2) {
|
||||
// if (prevChar == fPairs[i]) {
|
||||
// fEndPos = fOffset - 1;
|
||||
// pairIndex2 = i;
|
||||
// } else if (nextChar == fPairs[i]) {
|
||||
// fEndPos = fOffset;
|
||||
// pairIndex2 = i;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (fEndPos > -1) {
|
||||
// fAnchor = RIGHT;
|
||||
// fStartPos = searchForOpeningPeer(fEndPos, fPairs[pairIndex2 - 1], fPairs[pairIndex2], fDocument);
|
||||
// if (fStartPos > -1)
|
||||
// return true;
|
||||
// else
|
||||
// fEndPos = -1;
|
||||
// } else if (fStartPos > -1) {
|
||||
// fAnchor = LEFT;
|
||||
// fEndPos = searchForClosingPeer(fStartPos, fPairs[pairIndex1], fPairs[pairIndex1 + 1], fDocument);
|
||||
// if (fEndPos > -1)
|
||||
// return true;
|
||||
// else
|
||||
// fStartPos = -1;
|
||||
// }
|
||||
//
|
||||
// } catch (BadLocationException x) {
|
||||
// } catch (IOException x) {
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
protected int searchForClosingPeer(int offset, int openingPeer, int closingPeer, IDocument document) throws IOException {
|
||||
|
||||
|
||||
fReader.configureForwardReader(document, offset + 1, document.getLength(), true, true);
|
||||
|
||||
int stack= 1;
|
||||
int c= fReader.read();
|
||||
|
||||
int stack = 1;
|
||||
int c = fReader.read();
|
||||
while (c != CCodeReader.EOF) {
|
||||
if (c == openingPeer && c != closingPeer)
|
||||
stack++;
|
||||
else if (c == closingPeer)
|
||||
stack--;
|
||||
|
||||
|
||||
if (stack == 0)
|
||||
return fReader.getOffset();
|
||||
|
||||
c= fReader.read();
|
||||
|
||||
c = fReader.read();
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
protected int searchForOpeningPeer(int offset, int openingPeer, int closingPeer, IDocument document) throws IOException {
|
||||
|
||||
|
||||
fReader.configureBackwardReader(document, offset, true, true);
|
||||
|
||||
int stack= 1;
|
||||
int c= fReader.read();
|
||||
|
||||
int stack = 1;
|
||||
int c = fReader.read();
|
||||
while (c != CCodeReader.EOF) {
|
||||
if (c == closingPeer && c != openingPeer)
|
||||
stack++;
|
||||
else if (c == openingPeer)
|
||||
stack--;
|
||||
|
||||
|
||||
if (stack == 0)
|
||||
return fReader.getOffset();
|
||||
|
||||
c= fReader.read();
|
||||
|
||||
c = fReader.read();
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.util;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
|
||||
public class CoreUtility {
|
||||
|
||||
/**
|
||||
* Adds a nauture to a project
|
||||
*/
|
||||
public static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
/**
|
||||
* Creates a folder and all parent folders if not existing
|
||||
* Project must exist
|
||||
*/
|
||||
public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
|
||||
if (!folder.exists()) {
|
||||
IContainer parent= folder.getParent();
|
||||
if (parent instanceof IFolder) {
|
||||
createFolder((IFolder)parent, force, local, monitor);
|
||||
}
|
||||
folder.create(force, local, monitor);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue