X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index a2f3ae0..47c1963 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -12,8 +12,10 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.ResourceBundle; import java.util.StringTokenizer; @@ -32,7 +34,6 @@ import net.sourceforge.phpdt.ui.JavaUI; import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction; -import net.sourceforge.phpdt.ui.text.IColorManager; import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPCore; import net.sourceforge.phpeclipse.PHPeclipsePlugin; @@ -41,8 +42,11 @@ import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IAction; @@ -72,19 +76,12 @@ import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.information.IInformationProvider; import org.eclipse.jface.text.information.InformationPresenter; import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.AnnotationRulerColumn; -import org.eclipse.jface.text.source.CompositeRuler; -import org.eclipse.jface.text.source.IAnnotationAccess; import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IAnnotationModelExtension; import org.eclipse.jface.text.source.IOverviewRuler; -import org.eclipse.jface.text.source.ISharedTextColors; import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.ISourceViewerExtension; import org.eclipse.jface.text.source.IVerticalRuler; -import org.eclipse.jface.text.source.IVerticalRulerColumn; -import org.eclipse.jface.text.source.LineNumberRulerColumn; 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; @@ -130,18 +127,15 @@ import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.editors.text.DefaultEncodingSupport; import org.eclipse.ui.editors.text.IEncodingSupport; import org.eclipse.ui.part.IShowInTargetList; -import org.eclipse.ui.texteditor.AddTaskAction; import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.DefaultRangeIndicator; -import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds; +import org.eclipse.ui.texteditor.ExtendedTextEditor; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.ResourceAction; -import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; -import org.eclipse.ui.texteditor.StatusTextEditor; import org.eclipse.ui.texteditor.TextEditorAction; import org.eclipse.ui.texteditor.TextOperationAction; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; @@ -150,7 +144,8 @@ import org.eclipse.ui.views.tasklist.TaskList; /** * PHP specific text editor. */ -public abstract class PHPEditor extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor { +public abstract class PHPEditor extends ExtendedTextEditor implements IViewPartInputProvider { +//extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor { /** * "Smart" runnable for updating the outline page's selection. */ @@ -960,38 +955,38 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp } }; - static protected class AnnotationAccess implements IAnnotationAccess { - /* - * @see org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation) - */ - public Object getType(Annotation annotation) { - if (annotation instanceof IJavaAnnotation) { - IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation; - if (javaAnnotation.isRelevant()) - return javaAnnotation.getAnnotationType(); - } - return null; - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation) - */ - public boolean isMultiLine(Annotation annotation) { - return true; - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation) - */ - public boolean isTemporary(Annotation annotation) { - if (annotation instanceof IJavaAnnotation) { - IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation; - if (javaAnnotation.isRelevant()) - return javaAnnotation.isTemporary(); - } - return false; - } - }; +// static protected class AnnotationAccess implements IAnnotationAccess { +// /* +// * @see org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation) +// */ +// public Object getType(Annotation annotation) { +// if (annotation instanceof IJavaAnnotation) { +// IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation; +// // if (javaAnnotation.isRelevant()) +// // return javaAnnotation.getAnnotationType(); +// } +// return null; +// } +// +// /* +// * @see org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation) +// */ +// public boolean isMultiLine(Annotation annotation) { +// return true; +// } +// +// /* +// * @see org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation) +// */ +// public boolean isTemporary(Annotation annotation) { +// if (annotation instanceof IJavaAnnotation) { +// IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation; +// if (javaAnnotation.isRelevant()) +// return javaAnnotation.isTemporary(); +// } +// return false; +// } +// }; private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener { /* @@ -1001,10 +996,130 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp handlePreferencePropertyChanged(event); } }; + + /** + * Finds and marks occurrence annotations. + * + * @since 3.0 + */ + class OccurrencesFinderJob extends Job implements IDocumentListener { + + private IDocument fDocument; + private boolean fCancelled= false; + private IProgressMonitor fProgressMonitor; + private Position[] fPositions; + + public OccurrencesFinderJob(IDocument document, Position[] positions) { + super("Occurrences Marker"); //$NON-NLS-1$ + fDocument= document; + fPositions= positions; + fDocument.addDocumentListener(this); + } + + private boolean isCancelled() { + return fCancelled || fProgressMonitor.isCanceled(); + } + + /* + * @see Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + public IStatus run(IProgressMonitor progressMonitor) { + + fProgressMonitor= progressMonitor; + + try { + + if (isCancelled()) + return Status.CANCEL_STATUS; + + ITextViewer textViewer= getViewer(); + if (textViewer == null) + return Status.CANCEL_STATUS; + + IDocument document= textViewer.getDocument(); + if (document == null) + return Status.CANCEL_STATUS; + + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return Status.CANCEL_STATUS; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null) + return Status.CANCEL_STATUS; + + // Add occurrence annotations + int length= fPositions.length; + Map annotationMap= new HashMap(length); + for (int i= 0; i < length; i++) { + + if (isCancelled()) + return Status.CANCEL_STATUS; + + String message; + Position position= fPositions[i]; + + // Create & add annotation + try { + message= document.get(position.offset, position.length); + } catch (BadLocationException ex) { + // Skip this match + continue; + } + annotationMap.put( + new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$ + position); + } + + if (isCancelled()) + return Status.CANCEL_STATUS; + + synchronized (annotationModel) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap); + } else { + removeOccurrenceAnnotations(); + Iterator iter= annotationMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry mapEntry= (Map.Entry)iter.next(); + annotationModel.addAnnotation((Annotation)mapEntry.getKey(), (Position)mapEntry.getValue()); + } + } + fOccurrenceAnnotations= (Annotation[])annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); + } + } finally { + fDocument.removeDocumentListener(this); + } + return Status.OK_STATUS; + } + + /* + * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentAboutToBeChanged(DocumentEvent event) { + fCancelled= true; + } + + /* + * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentChanged(DocumentEvent event) { + } + } + + + /** + * Holds the current occurrence annotations. + * @since 3.0 + */ + private Annotation[] fOccurrenceAnnotations= null; + + private Job fOccurrencesFinderJob; + /** Preference key for showing the line number ruler */ - private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER; +// private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER; /** Preference key for the foreground color of the line numbers */ - private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR; + // private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR; /** Preference key for the link color */ private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR; /** Preference key for compiler task tags */ @@ -1033,7 +1148,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp /** The line number ruler column */ - private LineNumberRulerColumn fLineNumberRulerColumn; +// private LineNumberRulerColumn fLineNumberRulerColumn; /** This editor's encoding support */ private DefaultEncodingSupport fEncodingSupport; /** The mouse listener */ @@ -1047,13 +1162,13 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp /** The information presenter. */ private InformationPresenter fInformationPresenter; /** The annotation access */ - protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess(); +// protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess(); /** The overview ruler */ protected OverviewRuler isOverviewRulerVisible; /** The source viewer decoration support */ - protected SourceViewerDecorationSupport fSourceViewerDecorationSupport; + //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport; /** The overview ruler */ - protected OverviewRuler fOverviewRuler; + //protected OverviewRuler fOverviewRuler; /** The preference property change listener for java core. */ private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener(); @@ -1166,7 +1281,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp public void createPartControl(Composite parent) { super.createPartControl(parent); - fSourceViewerDecorationSupport.install(getPreferenceStore()); + //fSourceViewerDecorationSupport.install(getPreferenceStore()); Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences(); preferences.addPropertyChangeListener(fPropertyChangeListener); @@ -1220,12 +1335,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp protected void createActions() { super.createActions(); - ResourceAction resAction = new AddTaskAction(PHPEditorMessages.getResourceBundle(), "AddTask.", this); //$NON-NLS-1$ - resAction.setHelpContextId(IAbstractTextEditorHelpContextIds.ADD_TASK_ACTION); - resAction.setActionDefinitionId(ITextEditorActionDefinitionIds.ADD_TASK); - setAction(ITextEditorActionConstants.ADD_TASK, resAction); - - resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$ + ResourceAction resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$ resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$ resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC); setAction("ShowJavaDoc", resAction); //$NON-NLS-1$ @@ -1278,15 +1388,9 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp // rg, // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)}); - // if (fValidationThread == null) { - // fValidationThread = - // new PHPSyntaxParserThread(this, getSourceViewer()); - // //Thread defaults - // - // fValidationThread.start(); - // } - // - // fValidationThread.setText(getSourceViewer().getTextWidget().getText()); + // add annotation actions + action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$ + setAction("AnnotationAction", action); //$NON-NLS-1$ } /** The PHPEditor implementation of this @@ -1315,10 +1419,10 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp fPropertyChangeListener = null; } - if (fSourceViewerDecorationSupport != null) { - fSourceViewerDecorationSupport.dispose(); - fSourceViewerDecorationSupport = null; - } +// if (fSourceViewerDecorationSupport != null) { +// fSourceViewerDecorationSupport.dispose(); +// fSourceViewerDecorationSupport = null; +// } if (fBracketMatcher != null) { fBracketMatcher.dispose(); @@ -1805,28 +1909,28 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp } return; } - - if (OVERVIEW_RULER.equals(property)) { - if (isOverviewRulerVisible()) - showOverviewRuler(); - else - hideOverviewRuler(); - return; - } - - if (LINE_NUMBER_RULER.equals(property)) { - if (isLineNumberRulerVisible()) - showLineNumberRuler(); - else - hideLineNumberRuler(); - return; - } - - if (fLineNumberRulerColumn != null - && (LINE_NUMBER_COLOR.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property))) { - - initializeLineNumberRulerColumn(fLineNumberRulerColumn); - } + +// if (OVERVIEW_RULER.equals(property)) { +// if (isOverviewRulerVisible()) +// showOverviewRuler(); +// else +// hideOverviewRuler(); +// return; +// } + +// if (LINE_NUMBER_RULER.equals(property)) { +// if (isLineNumberRulerVisible()) +// showLineNumberRuler(); +// else +// hideLineNumberRuler(); +// return; +// } + +// if (fLineNumberRulerColumn != null +// && (LINE_NUMBER_COLOR.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property))) { +// +// initializeLineNumberRulerColumn(fLineNumberRulerColumn); +// } if (isJavaEditorHoverProperty(property)) updateHoverBehavior(); @@ -1902,13 +2006,13 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp /** * Shows the line number ruler column. */ - private void showLineNumberRuler() { - IVerticalRuler v = getVerticalRuler(); - if (v instanceof CompositeRuler) { - CompositeRuler c = (CompositeRuler) v; - c.addDecorator(1, createLineNumberRulerColumn()); - } - } +// private void showLineNumberRuler() { +// IVerticalRuler v = getVerticalRuler(); +// if (v instanceof CompositeRuler) { +// CompositeRuler c = (CompositeRuler) v; +// c.addDecorator(1, createLineNumberRulerColumn()); +// } +// } private boolean isJavaEditorHoverProperty(String property) { return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property); } @@ -1963,23 +2067,23 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp * visible according to the preference store settings. * @return true if the line numbers should be visible */ - private boolean isLineNumberRulerVisible() { - IPreferenceStore store = getPreferenceStore(); - return store.getBoolean(LINE_NUMBER_RULER); - } +// protected boolean isLineNumberRulerVisible() { +// IPreferenceStore store = getPreferenceStore(); +// return store.getBoolean(LINE_NUMBER_RULER); +// } /** * Hides the line number ruler column. */ - private void hideLineNumberRuler() { - IVerticalRuler v = getVerticalRuler(); - if (v instanceof CompositeRuler) { - CompositeRuler c = (CompositeRuler) v; - try { - c.removeDecorator(1); - } catch (Throwable e) { - } - } - } +// private void hideLineNumberRuler() { +// IVerticalRuler v = getVerticalRuler(); +// if (v instanceof CompositeRuler) { +// CompositeRuler c = (CompositeRuler) v; +// try { +// c.removeDecorator(1); +// } catch (Throwable e) { +// } +// } +// } /* * @see AbstractTextEditor#handleCursorPositionChanged() @@ -1994,56 +2098,56 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp * Initializes the given line number ruler column from the preference store. * @param rulerColumn the ruler column to be initialized */ - protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) { - JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); - IColorManager manager = textTools.getColorManager(); - - IPreferenceStore store = getPreferenceStore(); - if (store != null) { - - RGB rgb = null; - // foreground color - if (store.contains(LINE_NUMBER_COLOR)) { - if (store.isDefault(LINE_NUMBER_COLOR)) - rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR); - else - rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR); - } - rulerColumn.setForeground(manager.getColor(rgb)); - - rgb = null; - // background color - if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) { - if (store.contains(PREFERENCE_COLOR_BACKGROUND)) { - if (store.isDefault(PREFERENCE_COLOR_BACKGROUND)) - rgb = PreferenceConverter.getDefaultColor(store, PREFERENCE_COLOR_BACKGROUND); - else - rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND); - } - } - rulerColumn.setBackground(manager.getColor(rgb)); - } - } +// protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) { +// JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); +// IColorManager manager = textTools.getColorManager(); +// +// IPreferenceStore store = getPreferenceStore(); +// if (store != null) { +// +// RGB rgb = null; +// // foreground color +// if (store.contains(LINE_NUMBER_COLOR)) { +// if (store.isDefault(LINE_NUMBER_COLOR)) +// rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR); +// else +// rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR); +// } +// rulerColumn.setForeground(manager.getColor(rgb)); +// +// rgb = null; +// // background color +// if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) { +// if (store.contains(PREFERENCE_COLOR_BACKGROUND)) { +// if (store.isDefault(PREFERENCE_COLOR_BACKGROUND)) +// rgb = PreferenceConverter.getDefaultColor(store, PREFERENCE_COLOR_BACKGROUND); +// else +// rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND); +// } +// } +// rulerColumn.setBackground(manager.getColor(rgb)); +// } +// } /** * Creates a new line number ruler column that is appropriately initialized. */ - protected IVerticalRulerColumn createLineNumberRulerColumn() { - fLineNumberRulerColumn = new LineNumberRulerColumn(); - initializeLineNumberRulerColumn(fLineNumberRulerColumn); - return fLineNumberRulerColumn; - } +// protected IVerticalRulerColumn createLineNumberRulerColumn() { +// fLineNumberRulerColumn = new LineNumberRulerColumn(); +// initializeLineNumberRulerColumn(fLineNumberRulerColumn); +// return fLineNumberRulerColumn; +// } /* * @see AbstractTextEditor#createVerticalRuler() */ - protected IVerticalRuler createVerticalRuler() { - CompositeRuler ruler = new CompositeRuler(); - ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH)); - if (isLineNumberRulerVisible()) - ruler.addDecorator(1, createLineNumberRulerColumn()); - return ruler; - } +// protected IVerticalRuler createVerticalRuler() { +// CompositeRuler ruler = new CompositeRuler(); +// ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH)); +// if (isLineNumberRulerVisible()) +// ruler.addDecorator(1, createLineNumberRulerColumn()); +// return ruler; +// } private static IRegion getSignedSelection(ITextViewer viewer) { @@ -2154,54 +2258,54 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp } } - protected void configureSourceViewerDecorationSupport() { - - fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher); - - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.UNKNOWN, - UNKNOWN_INDICATION_COLOR, - UNKNOWN_INDICATION, - UNKNOWN_INDICATION_IN_OVERVIEW_RULER, - 0); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.BOOKMARK, - BOOKMARK_INDICATION_COLOR, - BOOKMARK_INDICATION, - BOOKMARK_INDICATION_IN_OVERVIEW_RULER, - 1); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.TASK, - TASK_INDICATION_COLOR, - TASK_INDICATION, - TASK_INDICATION_IN_OVERVIEW_RULER, - 2); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.SEARCH, - SEARCH_RESULT_INDICATION_COLOR, - SEARCH_RESULT_INDICATION, - SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER, - 3); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.WARNING, - WARNING_INDICATION_COLOR, - WARNING_INDICATION, - WARNING_INDICATION_IN_OVERVIEW_RULER, - 4); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.ERROR, - ERROR_INDICATION_COLOR, - ERROR_INDICATION, - ERROR_INDICATION_IN_OVERVIEW_RULER, - 5); - - fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR); - fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN); - fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR); - - fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey()); - - } +// protected void configureSourceViewerDecorationSupport() { +// +// fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher); +// +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.UNKNOWN, +// UNKNOWN_INDICATION_COLOR, +// UNKNOWN_INDICATION, +// UNKNOWN_INDICATION_IN_OVERVIEW_RULER, +// 0); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.BOOKMARK, +// BOOKMARK_INDICATION_COLOR, +// BOOKMARK_INDICATION, +// BOOKMARK_INDICATION_IN_OVERVIEW_RULER, +// 1); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.TASK, +// TASK_INDICATION_COLOR, +// TASK_INDICATION, +// TASK_INDICATION_IN_OVERVIEW_RULER, +// 2); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.SEARCH, +// SEARCH_RESULT_INDICATION_COLOR, +// SEARCH_RESULT_INDICATION, +// SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER, +// 3); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.WARNING, +// WARNING_INDICATION_COLOR, +// WARNING_INDICATION, +// WARNING_INDICATION_IN_OVERVIEW_RULER, +// 4); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.ERROR, +// ERROR_INDICATION_COLOR, +// ERROR_INDICATION, +// ERROR_INDICATION_IN_OVERVIEW_RULER, +// 5); +// +// fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR); +// fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN); +// fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR); +// +// fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey()); +// +// } /** * Jumps to the matching bracket. */ @@ -2363,64 +2467,89 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); // return viewer; // } - protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) { - - ISharedTextColors sharedColors = PHPeclipsePlugin.getDefault().getJavaTextTools().getColorManager(); - - fOverviewRuler = new OverviewRuler(fAnnotationAccess, VERTICAL_RULER_WIDTH, sharedColors); - fOverviewRuler.addHeaderAnnotationType(AnnotationType.WARNING); - fOverviewRuler.addHeaderAnnotationType(AnnotationType.ERROR); - - ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, fOverviewRuler, isOverviewRulerVisible(), styles); - - StyledText text = viewer.getTextWidget(); - text.addBidiSegmentListener(new BidiSegmentListener() { - public void lineGetSegments(BidiSegmentEvent event) { - event.segments = getBidiLineSegments(event.lineOffset, event.lineText); - } - }); - - // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); - - fSourceViewerDecorationSupport = new SourceViewerDecorationSupport(viewer, fOverviewRuler, fAnnotationAccess, sharedColors); - configureSourceViewerDecorationSupport(); - - return viewer; - } - - protected void showOverviewRuler() { - if (fOverviewRuler != null) { - if (getSourceViewer() instanceof ISourceViewerExtension) { - ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(true); - fSourceViewerDecorationSupport.updateOverviewDecorations(); - } - } + + public final ISourceViewer getViewer() { + return getSourceViewer(); } + + protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) { + ISourceViewer viewer= createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles); + + StyledText text= viewer.getTextWidget(); + text.addBidiSegmentListener(new BidiSegmentListener() { + public void lineGetSegments(BidiSegmentEvent event) { + event.segments= getBidiLineSegments(event.lineOffset, event.lineText); + } + }); + +// JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); - protected void hideOverviewRuler() { - if (getSourceViewer() instanceof ISourceViewerExtension) { - fSourceViewerDecorationSupport.hideAnnotationOverview(); - ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(false); - } + // ensure source viewer decoration support has been created and configured + getSourceViewerDecorationSupport(viewer); + + return viewer; + +// ISharedTextColors sharedColors = PHPeclipsePlugin.getDefault().getJavaTextTools().getColorManager(); +// +// fOverviewRuler = new OverviewRuler(fAnnotationAccess, VERTICAL_RULER_WIDTH, sharedColors); +// fOverviewRuler.addHeaderAnnotationType(AnnotationType.WARNING); +// fOverviewRuler.addHeaderAnnotationType(AnnotationType.ERROR); +// +// ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, fOverviewRuler, isOverviewRulerVisible(), styles); +// +// StyledText text = viewer.getTextWidget(); +// text.addBidiSegmentListener(new BidiSegmentListener() { +// public void lineGetSegments(BidiSegmentEvent event) { +// event.segments = getBidiLineSegments(event.lineOffset, event.lineText); +// } +// }); +// +// // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); +// +// fSourceViewerDecorationSupport = new SourceViewerDecorationSupport(viewer, fOverviewRuler, fAnnotationAccess, sharedColors); +// configureSourceViewerDecorationSupport(); +// +// return viewer; } - protected boolean isOverviewRulerVisible() { - IPreferenceStore store = getPreferenceStore(); - return store.getBoolean(OVERVIEW_RULER); - } +// protected void showOverviewRuler() { +// if (fOverviewRuler != null) { +// if (getSourceViewer() instanceof ISourceViewerExtension) { +// ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(true); +// fSourceViewerDecorationSupport.updateOverviewDecorations(); +// } +// } +// } +// +// protected void hideOverviewRuler() { +// if (getSourceViewer() instanceof ISourceViewerExtension) { +// fSourceViewerDecorationSupport.hideAnnotationOverview(); +// ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(false); +// } +// } + +// protected boolean isOverviewRulerVisible() { +// IPreferenceStore store = getPreferenceStore(); +// return store.getBoolean(OVERVIEW_RULER); +// } /* * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int) */ - protected ISourceViewer createJavaSourceViewer( - Composite parent, - IVerticalRuler ruler, - IOverviewRuler overviewRuler, - boolean isOverviewRulerVisible, - int styles) { - return new SourceViewer(parent, ruler, overviewRuler, isOverviewRulerVisible(), styles); - // return super.createSourceViewer(parent, ruler, styles); - } - +// protected ISourceViewer createJavaSourceViewer( +// Composite parent, +// IVerticalRuler ruler, +// IOverviewRuler overviewRuler, +// boolean isOverviewRulerVisible, +// int styles) { +// return new SourceViewer(parent, ruler, overviewRuler, isOverviewRulerVisible(), styles); +// } + + /* + * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int) + */ + protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles) { + return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles); + } /* * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent) */ @@ -2468,7 +2597,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp } selectAndReveal(errorPosition.getOffset(), errorPosition.getLength()); - setStatusLineErrorMessage(nextError.getMessage()); +// setStatusLineErrorMessage(nextError.getMessage()); } else { @@ -2524,4 +2653,23 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp return nextError; } + void removeOccurrenceAnnotations() { + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null || fOccurrenceAnnotations == null) + return; + + synchronized (annotationModel) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null); + } else { + for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++) + annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); + } + fOccurrenceAnnotations= null; + } +} }