X-Git-Url: http://secure.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 a4f0ef5..d5eeb74 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -1,16 +1,18 @@ package net.sourceforge.phpeclipse.phpeditor; /********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - IBM Corporation - Initial implementation - Klaus Hartlage - www.eclipseproject.de -**********************************************************************/ + Copyright (c) 2000, 2002 IBM Corp. and others. + All rights reserved. This program and the accompanying materials + are made available under the terms of the Common Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/cpl-v10.html + + Contributors: + IBM Corporation - Initial implementation + www.phpeclipse.de + **********************************************************************/ +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -20,7 +22,10 @@ import java.util.ResourceBundle; import java.util.StringTokenizer; import net.sourceforge.phpdt.core.ICompilationUnit; +import net.sourceforge.phpdt.core.IImportContainer; +import net.sourceforge.phpdt.core.IImportDeclaration; import net.sourceforge.phpdt.core.IJavaElement; +import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.IMember; import net.sourceforge.phpdt.core.ISourceRange; import net.sourceforge.phpdt.core.ISourceReference; @@ -32,12 +37,14 @@ import net.sourceforge.phpdt.internal.ui.text.CustomSourceInformationControl; import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter; import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher; +import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter; import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider; import net.sourceforge.phpdt.ui.IContextMenuConstants; import net.sourceforge.phpdt.ui.JavaUI; import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction; import net.sourceforge.phpdt.ui.text.JavaTextTools; +import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration; import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider; import net.sourceforge.phpeclipse.PHPeclipsePlugin; @@ -64,18 +71,21 @@ import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ISynchronizable; import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.ITextInputListener; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.ITextViewerExtension2; import org.eclipse.jface.text.ITextViewerExtension3; +import org.eclipse.jface.text.ITextViewerExtension5; import org.eclipse.jface.text.ITypedRegion; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.Region; 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.reconciler.IReconciler; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IAnnotationModelExtension; @@ -87,7 +97,9 @@ import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.text.source.projection.ProjectionSupport; import org.eclipse.jface.text.source.projection.ProjectionViewer; import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.ListenerList; import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.IPostSelectionProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; @@ -128,28 +140,95 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.editors.text.DefaultEncodingSupport; +import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.editors.text.IEncodingSupport; import org.eclipse.ui.part.IShowInTargetList; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; -import org.eclipse.ui.texteditor.DefaultRangeIndicator; +import org.eclipse.ui.texteditor.AnnotationPreference; +import org.eclipse.ui.texteditor.ChainedPreferenceStore; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.ResourceAction; +import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; import org.eclipse.ui.texteditor.TextEditorAction; import org.eclipse.ui.texteditor.TextOperationAction; +import org.eclipse.ui.views.contentoutline.ContentOutline; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import org.eclipse.ui.views.tasklist.TaskList; + /** * PHP specific text editor. */ -public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider { -//extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor { +public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider { + //extends StatusTextEditor implements IViewPartInputProvider { // extends + // TextEditor { + + /** + * Internal implementation class for a change listener. + * + * @since 3.0 + */ + protected abstract class AbstractSelectionChangedListener implements ISelectionChangedListener { + + /** + * Installs this selection changed listener with the given selection provider. If the selection provider is a post selection + * provider, post selection changed events are the preferred choice, otherwise normal selection changed events are requested. + * + * @param selectionProvider + */ + public void install(ISelectionProvider selectionProvider) { + if (selectionProvider == null) + return; + + if (selectionProvider instanceof IPostSelectionProvider) { + IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; + provider.addPostSelectionChangedListener(this); + } else { + selectionProvider.addSelectionChangedListener(this); + } + } + + /** + * Removes this selection changed listener from the given selection provider. + * + * @param selectionProvider + * the selection provider + */ + public void uninstall(ISelectionProvider selectionProvider) { + if (selectionProvider == null) + return; + + if (selectionProvider instanceof IPostSelectionProvider) { + IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; + provider.removePostSelectionChangedListener(this); + } else { + selectionProvider.removeSelectionChangedListener(this); + } + } + } + + /** + * Updates the Java outline page selection and this editor's range indicator. + * + * @since 3.0 + */ + private class EditorSelectionChangedListener extends AbstractSelectionChangedListener { + + /* + * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent event) { + // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161 + PHPEditor.this.selectionChanged(); + } + } + /** - * "Smart" runnable for updating the outline page's selection. - */ + * "Smart" runnable for updating the outline page's selection. + */ class OutlinePageSelectionUpdater implements Runnable { /** Has the runnable already been posted? */ @@ -180,30 +259,421 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } } }; + class SelectionChangedListener implements ISelectionChangedListener { public void selectionChanged(SelectionChangedEvent event) { doSelectionChanged(event); } }; + /** + * Adapts an options {@link java.util.Map}to {@link org.eclipse.jface.preference.IPreferenceStore}. + *

+ * This preference store is read-only i.e. write access throws an {@link java.lang.UnsupportedOperationException}. + *

+ * + * @since 3.0 + */ + private static class OptionsAdapter implements IPreferenceStore { + + /** + * A property change event filter. + */ + public interface IPropertyChangeEventFilter { + + /** + * Should the given event be filtered? + * + * @param event + * The property change event. + * @return true iff the given event should be filtered. + */ + public boolean isFiltered(PropertyChangeEvent event); + + } + + /** + * Property change listener. Listens for events in the options Map and fires a + * {@link org.eclipse.jface.util.PropertyChangeEvent}on this adapter with arguments from the received event. + */ + private class PropertyChangeListener implements IPropertyChangeListener { + + /** + * {@inheritDoc} + */ + public void propertyChange(PropertyChangeEvent event) { + if (getFilter().isFiltered(event)) + return; + + if (event.getNewValue() == null) + fOptions.remove(event.getProperty()); + else + fOptions.put(event.getProperty(), event.getNewValue()); + + firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue()); + } + } + + /** Listeners on this adapter */ + private ListenerList fListeners = new ListenerList(); + + /** Listener on the adapted options Map */ + private IPropertyChangeListener fListener = new PropertyChangeListener(); + + /** Adapted options Map */ + private Map fOptions; + + /** Preference store through which events are received. */ + private IPreferenceStore fMockupPreferenceStore; + + /** Property event filter. */ + private IPropertyChangeEventFilter fFilter; + + /** + * Initialize with the given options. + * + * @param options + * The options to wrap + * @param mockupPreferenceStore + * the mock-up preference store + * @param filter + * the property change filter + */ + public OptionsAdapter(Map options, IPreferenceStore mockupPreferenceStore, IPropertyChangeEventFilter filter) { + fMockupPreferenceStore = mockupPreferenceStore; + fOptions = options; + setFilter(filter); + } + + /** + * {@inheritDoc} + */ + public void addPropertyChangeListener(IPropertyChangeListener listener) { + if (fListeners.size() == 0) + fMockupPreferenceStore.addPropertyChangeListener(fListener); + fListeners.add(listener); + } + + /** + * {@inheritDoc} + */ + public void removePropertyChangeListener(IPropertyChangeListener listener) { + fListeners.remove(listener); + if (fListeners.size() == 0) + fMockupPreferenceStore.removePropertyChangeListener(fListener); + } + + /** + * {@inheritDoc} + */ + public boolean contains(String name) { + return fOptions.containsKey(name); + } + + /** + * {@inheritDoc} + */ + public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) { + PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue); + Object[] listeners = fListeners.getListeners(); + for (int i = 0; i < listeners.length; i++) + ((IPropertyChangeListener) listeners[i]).propertyChange(event); + } + + /** + * {@inheritDoc} + */ + public boolean getBoolean(String name) { + boolean value = BOOLEAN_DEFAULT_DEFAULT; + String s = (String) fOptions.get(name); + if (s != null) + value = s.equals(TRUE); + return value; + } + + /** + * {@inheritDoc} + */ + public boolean getDefaultBoolean(String name) { + return BOOLEAN_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public double getDefaultDouble(String name) { + return DOUBLE_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public float getDefaultFloat(String name) { + return FLOAT_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public int getDefaultInt(String name) { + return INT_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public long getDefaultLong(String name) { + return LONG_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public String getDefaultString(String name) { + return STRING_DEFAULT_DEFAULT; + } + + /** + * {@inheritDoc} + */ + public double getDouble(String name) { + double value = DOUBLE_DEFAULT_DEFAULT; + String s = (String) fOptions.get(name); + if (s != null) { + try { + value = new Double(s).doubleValue(); + } catch (NumberFormatException e) { + } + } + return value; + } + + /** + * {@inheritDoc} + */ + public float getFloat(String name) { + float value = FLOAT_DEFAULT_DEFAULT; + String s = (String) fOptions.get(name); + if (s != null) { + try { + value = new Float(s).floatValue(); + } catch (NumberFormatException e) { + } + } + return value; + } + + /** + * {@inheritDoc} + */ + public int getInt(String name) { + int value = INT_DEFAULT_DEFAULT; + String s = (String) fOptions.get(name); + if (s != null) { + try { + value = new Integer(s).intValue(); + } catch (NumberFormatException e) { + } + } + return value; + } + + /** + * {@inheritDoc} + */ + public long getLong(String name) { + long value = LONG_DEFAULT_DEFAULT; + String s = (String) fOptions.get(name); + if (s != null) { + try { + value = new Long(s).longValue(); + } catch (NumberFormatException e) { + } + } + return value; + } + + /** + * {@inheritDoc} + */ + public String getString(String name) { + String value = (String) fOptions.get(name); + if (value == null) + value = STRING_DEFAULT_DEFAULT; + return value; + } + + /** + * {@inheritDoc} + */ + public boolean isDefault(String name) { + return false; + } + + /** + * {@inheritDoc} + */ + public boolean needsSaving() { + return !fOptions.isEmpty(); + } + + /** + * {@inheritDoc} + */ + public void putValue(String name, String value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, double value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, float value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, int value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, long value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, String defaultObject) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setDefault(String name, boolean value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setToDefault(String name) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, double value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, float value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, int value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, long value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, String value) { + throw new UnsupportedOperationException(); + } + + /** + * {@inheritDoc} + */ + public void setValue(String name, boolean value) { + throw new UnsupportedOperationException(); + } + + /** + * Returns the adapted options Map. + * + * @return Returns the adapted options Map. + */ + public Map getOptions() { + return fOptions; + } + + /** + * Returns the mock-up preference store, events are received through this preference store. + * + * @return Returns the mock-up preference store. + */ + public IPreferenceStore getMockupPreferenceStore() { + return fMockupPreferenceStore; + } + + /** + * Set the event filter to the given filter. + * + * @param filter + * The new filter. + */ + public void setFilter(IPropertyChangeEventFilter filter) { + fFilter = filter; + } + + /** + * Returns the event filter. + * + * @return The event filter. + */ + public IPropertyChangeEventFilter getFilter() { + return fFilter; + } + } + /* - * Link mode. - */ - class MouseClickListener - implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener, IPropertyChangeListener, IDocumentListener, ITextInputListener { + * Link mode. + */ + class MouseClickListener implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener, + IPropertyChangeListener, IDocumentListener, ITextInputListener { /** The session is active. */ private boolean fActive; /** The currently active style range. */ private IRegion fActiveRegion; + /** The currently active style range as position. */ private Position fRememberedPosition; + /** The hand cursor. */ private Cursor fCursor; /** The link color. */ private Color fColor; + /** The key modifier mask. */ private int fKeyModifierMask; @@ -255,7 +725,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements if (fKeyModifierMask == -1) { // Fallback to stored state mask fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK); - }; + } + ; } private int computeStateMask(String modifiers) { @@ -339,8 +810,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } /** - * Creates a color from the information stored in the given preference store. - * Returns null if there is no such information available. + * Creates a color from the information stored in the given preference store. Returns null if there is no such + * information available. */ private Color createColor(IPreferenceStore store, String key, Display display) { @@ -378,11 +849,11 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // remove style if (!redrawAll && viewer instanceof ITextViewerExtension2) - ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length); + ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length); else viewer.invalidateTextPresentation(); - // remove underline + // remove underline if (viewer instanceof ITextViewerExtension3) { ITextViewerExtension3 extension = (ITextViewerExtension3) viewer; offset = extension.modelOffset2WidgetOffset(offset); @@ -401,7 +872,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements fActiveRegion = null; } - // will eventually be replaced by a method provided by jdt.core + // will eventually be replaced by a method provided by jdt.core private IRegion selectWord(IDocument document, int anchor) { try { @@ -463,7 +934,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // return selectWord(viewer.getDocument(), offset); // // } catch (JavaModelException e) { - // return null; + // return null; // } } @@ -570,7 +1041,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements fActive = true; - // removed for #25871 + // removed for #25871 // // ISourceViewer viewer= getSourceViewer(); // if (viewer == null) @@ -581,7 +1052,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // return; // // highlightRegion(viewer, region); - // activateCursor(viewer); + // activateCursor(viewer); } /* @@ -600,6 +1071,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements */ public void mouseDoubleClick(MouseEvent e) { } + /* * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent) */ @@ -738,7 +1210,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } /* - * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) + * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, + * org.eclipse.jface.text.IDocument) */ public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { if (oldInput == null) @@ -748,7 +1221,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } /* - * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) + * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, + * org.eclipse.jface.text.IDocument) */ public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { if (newInput == null) @@ -809,7 +1283,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } private boolean includes(IRegion region, IRegion position) { - return position.getOffset() >= region.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength(); + return position.getOffset() >= region.getOffset() + && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength(); } private Point getMinimumLocation(StyledText text, int offset, int length) { @@ -844,10 +1319,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements }; /** - * This action dispatches into two behaviours: If there is no current text - * hover, the javadoc is displayed using information presenter. If there is - * a current text hover, it is converted into a information presenter in - * order to make it sticky. + * This action dispatches into two behaviours: If there is no current text hover, the javadoc is displayed using information + * presenter. If there is a current text hover, it is converted into a information presenter in order to make it sticky. */ class InformationDispatchAction extends TextEditorAction { @@ -915,8 +1388,10 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements public IRegion getSubject(ITextViewer textViewer, int offset) { return hoverRegion; } + /* - * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) + * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, + * org.eclipse.jface.text.IRegion) */ public String getInformation(ITextViewer textViewer, IRegion subject) { return hoverInfo; @@ -956,38 +1431,41 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } }; -// 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 { /* @@ -997,132 +1475,146 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements 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; - + + /** + * 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) { + } + } + + /** + * Updates the selection in the editor's widget with the selection of the outline page. + */ + class OutlineSelectionChangedListener extends AbstractSelectionChangedListener { + public void selectionChanged(SelectionChangedEvent event) { + doSelectionChanged(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 */ private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS; @@ -1131,73 +1623,110 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // private AbstractContentOutlinePage fOutlinePage; /** The outline page */ protected JavaOutlinePage fOutlinePage; + /** Outliner context menu Id */ protected String fOutlinerContextMenuId; - /** - * The editor selection changed listener. - * - * @since 3.0 - */ -// private EditorSelectionChangedListener fEditorSelectionChangedListener; - /** Indicates whether this editor should react on outline page selection changes */ + + /** + * Indicates whether this editor should react on outline page selection changes + */ private int fIgnoreOutlinePageSelection; - - /** The outline page selection updater */ - private OutlinePageSelectionUpdater fUpdater; + + /** The outline page selection updater */ + private OutlinePageSelectionUpdater fUpdater; + // protected PHPSyntaxParserThread fValidationThread = null; // private IPreferenceStore fPHPPrefStore; /** The selection changed listener */ - protected ISelectionChangedListener fSelectionChangedListener = new SelectionChangedListener(); + // protected ISelectionChangedListener fSelectionChangedListener = new + // SelectionChangedListener(); + /** + * The editor selection changed listener. + * + * @since 3.0 + */ + private EditorSelectionChangedListener fEditorSelectionChangedListener; + + /** The selection changed listener */ + protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener(); /** The editor's bracket matcher */ private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS); - /** The line number ruler column */ -// private LineNumberRulerColumn fLineNumberRulerColumn; + // private LineNumberRulerColumn fLineNumberRulerColumn; /** This editor's encoding support */ private DefaultEncodingSupport fEncodingSupport; + /** The mouse listener */ private MouseClickListener fMouseListener; + /** + * Indicates whether this editor is about to update any annotation views. + * + * @since 3.0 + */ + private boolean fIsUpdatingAnnotationViews = false; + + /** + * The marker that served as last target for a goto marker request. + * + * @since 3.0 + */ + private IMarker fLastMarkerTarget = null; + protected CompositeActionGroup fActionGroups; + protected CompositeActionGroup fContextMenuGroup; - /** - * This editor's projection support - * @since 3.0 - */ - private ProjectionSupport fProjectionSupport; - /** - * This editor's projection model updater - * @since 3.0 - */ - private IJavaFoldingStructureProvider fProjectionModelUpdater; - /** - * The action group for folding. - * - * @since 3.0 - */ - private FoldingActionGroup fFoldingGroup; - + /** + * This editor's projection support + * + * @since 3.0 + */ + private ProjectionSupport fProjectionSupport; + + /** + * This editor's projection model updater + * + * @since 3.0 + */ + private IJavaFoldingStructureProvider fProjectionModelUpdater; + + /** + * The override and implements indicator manager for this editor. + * + * @since 3.0 + */ + // protected OverrideIndicatorManager fOverrideIndicatorManager; + /** + * The action group for folding. + * + * @since 3.0 + */ + private FoldingActionGroup fFoldingGroup; + /** 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; /** The overview ruler */ //protected OverviewRuler fOverviewRuler; - /** The preference property change listener for java core. */ private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener(); + /** * Returns the most narrow java element including the given offset * - * @param offset the offset inside of the requested element + * @param offset + * the offset inside of the requested element */ abstract protected IJavaElement getElementAt(int offset); @@ -1205,9 +1734,10 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements * Returns the java element of this editor's input corresponding to the given IJavaElement */ abstract protected IJavaElement getCorrespondingElement(IJavaElement element); + /** - * Sets the input of the editor's outline page. - */ + * Sets the input of the editor's outline page. + */ abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input); /** @@ -1215,20 +1745,61 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements */ public PHPEditor() { super(); - JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools(); - setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this)); //, IJavaPartitions.JAVA_PARTITIONING)); - setRangeIndicator(new DefaultRangeIndicator()); - IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore(); - setPreferenceStore(store); - setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$ -// fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES); -// fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES); - - // TODO changed in 3.x ? - if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE)) - fUpdater= new OutlinePageSelectionUpdater(); } - + + /* + * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes() + */ + protected void initializeKeyBindingScopes() { + setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$ + } + + /* + * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor() + */ + protected void initializeEditor() { + //jsurfer old code + // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); + // setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this, IPHPPartitions.PHP_PARTITIONING)); //, + // IJavaPartitions.JAVA_PARTITIONING)); + IPreferenceStore store = createCombinedPreferenceStore(null); + setPreferenceStore(store); + JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); + setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this, + IPHPPartitions.PHP_PARTITIONING)); + // TODO changed in 3.x ? + // setRangeIndicator(new DefaultRangeIndicator()); + // if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE)) + // fUpdater = new OutlinePageSelectionUpdater(); + // jsurfer end + + // IPreferenceStore store= createCombinedPreferenceStore(null); + // setPreferenceStore(store); + // JavaTextTools textTools= + // PHPeclipsePlugin.getDefault().getJavaTextTools(); + // setSourceViewerConfiguration(new + // JavaSourceViewerConfiguration(textTools.getColorManager(), store, + // this, IJavaPartitions.JAVA_PARTITIONING)); + // fMarkOccurrenceAnnotations= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES); + // fStickyOccurrenceAnnotations= + // store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES); + // fMarkTypeOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES); + // fMarkMethodOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES); + // fMarkConstantOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES); + // fMarkFieldOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES); + // fMarkLocalVariableypeOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES); + // fMarkExceptionOccurrences= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES); + // fMarkMethodExitPoints= + // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS); + } + /* * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions() */ @@ -1271,12 +1842,14 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements public void updatedTitleImage(Image image) { setTitleImage(image); } + /* * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput() */ public Object getViewPartInput() { return getEditorInput().getAdapter(IResource.class); } + /* * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection) */ @@ -1284,39 +1857,40 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements super.doSetSelection(selection); synchronizeOutlinePageSelection(); } - boolean isFoldingEnabled() { - return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED); - } + + boolean isFoldingEnabled() { + return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED); + } + /* - * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt. - * widgets.Composite) + * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt. widgets.Composite) */ public void createPartControl(Composite parent) { super.createPartControl(parent); //fSourceViewerDecorationSupport.install(getPreferenceStore()); - ProjectionViewer projectionViewer= (ProjectionViewer) getSourceViewer(); - - fProjectionSupport= new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors()); - fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$ - fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$ - fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() { - public IInformationControl createInformationControl(Shell shell) { - return new CustomSourceInformationControl(shell, IDocument.DEFAULT_CONTENT_TYPE); - } - }); + ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer(); + + fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors()); + fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$ + fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$ + fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() { + public IInformationControl createInformationControl(Shell shell) { + return new CustomSourceInformationControl(shell, IDocument.DEFAULT_CONTENT_TYPE); + } + }); fProjectionSupport.install(); - - fProjectionModelUpdater= PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); - if (fProjectionModelUpdater != null) - fProjectionModelUpdater.install(this, projectionViewer); - - if (isFoldingEnabled()) - projectionViewer.doOperation(ProjectionViewer.TOGGLE); - Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences(); + + fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); + if (fProjectionModelUpdater != null) + fProjectionModelUpdater.install(this, projectionViewer); + + if (isFoldingEnabled()) + projectionViewer.doOperation(ProjectionViewer.TOGGLE); + Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences(); preferences.addPropertyChangeListener(fPropertyChangeListener); - + IInformationControlCreator informationControlCreator = new IInformationControlCreator() { public IInformationControl createInformationControl(Shell parent) { boolean cutDown = false; @@ -1329,11 +1903,125 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements fInformationPresenter.setSizeConstraints(60, 10, true, true); fInformationPresenter.install(getSourceViewer()); + fEditorSelectionChangedListener = new EditorSelectionChangedListener(); + fEditorSelectionChangedListener.install(getSelectionProvider()); + + if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE)) + enableOverwriteMode(false); + + setWordWrap(); + // getEditorSite().getShell().addShellListener(fActivationListener); + } + + private void setWordWrap() { + if (getSourceViewer() != null) { + getSourceViewer().getTextWidget().setWordWrap( + PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_WRAP_WORDS)); + } + } + + protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) { + + support.setCharacterPairMatcher(fBracketMatcher); + support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR); + + super.configureSourceViewerDecorationSupport(support); + } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#gotoMarker(org.eclipse.core.resources.IMarker) + */ + public void gotoMarker(IMarker marker) { + fLastMarkerTarget = marker; + if (!fIsUpdatingAnnotationViews) { + super.gotoMarker(marker); + } + } + + /** + * Jumps to the next enabled annotation according to the given direction. An annotation type is enabled if it is configured to be + * in the Next/Previous tool bar drop down menu and if it is checked. + * + * @param forward + * true if search direction is forward, false if backward + */ + public void gotoAnnotation(boolean forward) { + ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection(); + Position position = new Position(0, 0); + if (false /* delayed - see bug 18316 */) { + getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position); + selectAndReveal(position.getOffset(), position.getLength()); + } else /* no delay - see bug 18316 */{ + Annotation annotation = getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position); + setStatusLineErrorMessage(null); + setStatusLineMessage(null); + if (annotation != null) { + updateAnnotationViews(annotation); + selectAndReveal(position.getOffset(), position.getLength()); + setStatusLineMessage(annotation.getText()); + } + } + } + + /** + * Returns the lock object for the given annotation model. + * + * @param annotationModel + * the annotation model + * @return the annotation model's lock object + * @since 3.0 + */ + private Object getLockObject(IAnnotationModel annotationModel) { + if (annotationModel instanceof ISynchronizable) + return ((ISynchronizable) annotationModel).getLockObject(); + else + return annotationModel; + } + + /** + * Updates the annotation views that show the given annotation. + * + * @param annotation + * the annotation + */ + private void updateAnnotationViews(Annotation annotation) { + IMarker marker = null; + if (annotation instanceof MarkerAnnotation) + marker = ((MarkerAnnotation) annotation).getMarker(); + else if (annotation instanceof IJavaAnnotation) { + Iterator e = ((IJavaAnnotation) annotation).getOverlaidIterator(); + if (e != null) { + while (e.hasNext()) { + Object o = e.next(); + if (o instanceof MarkerAnnotation) { + marker = ((MarkerAnnotation) o).getMarker(); + break; + } + } + } + } + + if (marker != null && !marker.equals(fLastMarkerTarget)) { + try { + boolean isProblem = marker.isSubtypeOf(IMarker.PROBLEM); + IWorkbenchPage page = getSite().getPage(); + IViewPart view = page.findView(isProblem ? IPageLayout.ID_PROBLEM_VIEW : IPageLayout.ID_TASK_LIST); //$NON-NLS-1$ //$NON-NLS-2$ + if (view != null) { + Method method = view.getClass().getMethod("setSelection", new Class[] { IStructuredSelection.class, boolean.class }); //$NON-NLS-1$ + method.invoke(view, new Object[] { new StructuredSelection(marker), Boolean.TRUE }); + } + } catch (CoreException x) { + } catch (NoSuchMethodException x) { + } catch (IllegalAccessException x) { + } catch (InvocationTargetException x) { + } + // ignore exceptions, don't update any of the lists, just set status line + } } /** * Returns this document's complete text. - * + * * @return the document's complete text */ public String get() { @@ -1342,14 +2030,14 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } /** - * Sets the outliner's context menu ID. - */ + * Sets the outliner's context menu ID. + */ protected void setOutlinerContextMenuId(String menuId) { fOutlinerContextMenuId = menuId; } /** - * Returns the standard action group of this editor. + * Returns the standard action group of this editor. */ protected ActionGroup getActionGroup() { return fActionGroups; @@ -1359,125 +2047,154 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // return fOutlinePage; // } - /** The PHPEditor implementation of this - * AbstractTextEditor method extend the - * actions to add those specific to the receiver + /** + * The PHPEditor implementation of this AbstractTextEditor method extend the actions to add those + * specific to the receiver */ protected void createActions() { super.createActions(); - - fFoldingGroup= new FoldingActionGroup(this, getViewer()); - - 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(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC); - setAction("ShowJavaDoc", resAction); //$NON-NLS-1$ -// WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION); - - Action action= new GotoMatchingBracketAction(this); - action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); - setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action); - -// action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.", this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$ -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE); -// setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action); -//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.SHOW_OUTLINE_ACTION); -// -// action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.", this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$ -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE); -// setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE, action); -//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.OPEN_STRUCTURE_ACTION); -// -// action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.", this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$ -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY); -// setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY, action); -//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.OPEN_HIERARCHY_ACTION); - - fEncodingSupport= new DefaultEncodingSupport(); - fEncodingSupport.initialize(this); - -// fSelectionHistory= new SelectionHistory(this); -// -// action= new StructureSelectEnclosingAction(this, fSelectionHistory); -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING); -// setAction(StructureSelectionAction.ENCLOSING, action); -// -// action= new StructureSelectNextAction(this, fSelectionHistory); -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT); -// setAction(StructureSelectionAction.NEXT, action); -// -// action= new StructureSelectPreviousAction(this, fSelectionHistory); -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS); -// setAction(StructureSelectionAction.PREVIOUS, action); -// -// StructureSelectHistoryAction historyAction= new StructureSelectHistoryAction(this, fSelectionHistory); -// historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST); -// setAction(StructureSelectionAction.HISTORY, historyAction); -// fSelectionHistory.setHistoryAction(historyAction); -// -// action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this); -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER); -// setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action); -// -// action= GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this); -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER); -// setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action); -// -// action= new QuickFormatAction(); -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT); -// setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action); -// -// action= new RemoveOccurrenceAnnotations(this); -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS); -// setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$ - - // add annotation actions - action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$ - setAction("AnnotationAction", action); //$NON-NLS-1$ - } - - private void internalDoSetInput(IEditorInput input) throws CoreException { - super.doSetInput(input); - - if (fEncodingSupport != null) - fEncodingSupport.reset(); - - setOutlinePageInput(fOutlinePage, input); - - if (fProjectionModelUpdater != null) - fProjectionModelUpdater.initialize(); - -// if (isShowingOverrideIndicators()) -// installOverrideIndicator(true); - } - - /* - * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) - * @since 3.0 - */ - protected void setPreferenceStore(IPreferenceStore store) { - super.setPreferenceStore(store); - if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) { - JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools(); - setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this, IPHPPartitions.PHP_PARTITIONING)); - } - if (getSourceViewer() instanceof JavaSourceViewer) - ((JavaSourceViewer)getSourceViewer()).setPreferenceStore(store); - } - /** The PHPEditor implementation of this - * AbstractTextEditor method performs any extra - * disposal actions required by the php editor. + + fFoldingGroup = new FoldingActionGroup(this, getViewer()); + + 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(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC); + setAction("ShowJavaDoc", resAction); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(resAction, + // IJavaHelpContextIds.SHOW_JAVADOC_ACTION); + + Action action = new GotoMatchingBracketAction(this); + action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); + setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action); + + // action= new + // TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.", + // this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$ + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE); + // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action); + //// WorkbenchHelp.setHelp(action, + // IJavaHelpContextIds.SHOW_OUTLINE_ACTION); + // + // action= new + // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.", + // this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$ + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE); + // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE, + // action); + //// WorkbenchHelp.setHelp(action, + // IJavaHelpContextIds.OPEN_STRUCTURE_ACTION); + // + // action= new + // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.", + // this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$ + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY); + // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY, + // action); + //// WorkbenchHelp.setHelp(action, + // IJavaHelpContextIds.OPEN_HIERARCHY_ACTION); + + fEncodingSupport = new DefaultEncodingSupport(); + fEncodingSupport.initialize(this); + + // fSelectionHistory= new SelectionHistory(this); + // + // action= new StructureSelectEnclosingAction(this, fSelectionHistory); + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING); + // setAction(StructureSelectionAction.ENCLOSING, action); + // + // action= new StructureSelectNextAction(this, fSelectionHistory); + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT); + // setAction(StructureSelectionAction.NEXT, action); + // + // action= new StructureSelectPreviousAction(this, fSelectionHistory); + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS); + // setAction(StructureSelectionAction.PREVIOUS, action); + // + // StructureSelectHistoryAction historyAction= new + // StructureSelectHistoryAction(this, fSelectionHistory); + // historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST); + // setAction(StructureSelectionAction.HISTORY, historyAction); + // fSelectionHistory.setHistoryAction(historyAction); + // + // action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this); + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER); + // setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action); + // + // action= + // GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this); + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER); + // setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action); + // + // action= new QuickFormatAction(); + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT); + // setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action); + // + // action= new RemoveOccurrenceAnnotations(this); + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS); + // setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$ + + // add annotation actions + action = new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$ + setAction("AnnotationAction", action); //$NON-NLS-1$ + } + + private void internalDoSetInput(IEditorInput input) throws CoreException { + super.doSetInput(input); + + if (getSourceViewer() instanceof JavaSourceViewer) { + JavaSourceViewer viewer = (JavaSourceViewer) getSourceViewer(); + if (viewer.getReconciler() == null) { + IReconciler reconciler = getSourceViewerConfiguration().getReconciler(viewer); + if (reconciler != null) { + reconciler.install(viewer); + viewer.setReconciler(reconciler); + } + } + } + + if (fEncodingSupport != null) + fEncodingSupport.reset(); + + setOutlinePageInput(fOutlinePage, input); + + if (fProjectionModelUpdater != null) + fProjectionModelUpdater.initialize(); + + // if (isShowingOverrideIndicators()) + // installOverrideIndicator(false); + } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) + * @since 3.0 + */ + protected void setPreferenceStore(IPreferenceStore store) { + super.setPreferenceStore(store); + if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) { + JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); + setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this, + IPHPPartitions.PHP_PARTITIONING)); + } + if (getSourceViewer() instanceof JavaSourceViewer) + ((JavaSourceViewer) getSourceViewer()).setPreferenceStore(store); + } + + /** + * The PHPEditor implementation of this AbstractTextEditor method performs any extra disposal + * actions required by the php editor. */ public void dispose() { - if (fProjectionModelUpdater != null) { - fProjectionModelUpdater.uninstall(); - fProjectionModelUpdater= null; - } - - if (fProjectionSupport != null) { - fProjectionSupport.dispose(); - fProjectionSupport= null; - } + if (fProjectionModelUpdater != null) { + fProjectionModelUpdater.uninstall(); + fProjectionModelUpdater = null; + } + + if (fProjectionSupport != null) { + fProjectionSupport.dispose(); + fProjectionSupport = null; + } // PHPEditorEnvironment.disconnect(this); if (fOutlinePage != null) fOutlinePage.setInput(null); @@ -1499,44 +2216,47 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements fPropertyChangeListener = null; } -// if (fSourceViewerDecorationSupport != null) { -// fSourceViewerDecorationSupport.dispose(); -// fSourceViewerDecorationSupport = null; -// } + // if (fSourceViewerDecorationSupport != null) { + // fSourceViewerDecorationSupport.dispose(); + // fSourceViewerDecorationSupport = null; + // } if (fBracketMatcher != null) { fBracketMatcher.dispose(); fBracketMatcher = null; } + + if (fEditorSelectionChangedListener != null) { + fEditorSelectionChangedListener.uninstall(getSelectionProvider()); + fEditorSelectionChangedListener = null; + } + super.dispose(); } - /** The PHPEditor implementation of this - * AbstractTextEditor method performs any extra - * revert behavior required by the php editor. + /** + * The PHPEditor implementation of this AbstractTextEditor method performs any extra revert behavior + * required by the php editor. */ // public void doRevertToSaved() { // super.doRevertToSaved(); // if (fOutlinePage != null) // fOutlinePage.update(); // } - - /** The PHPEditor implementation of this - * AbstractTextEditor method performs any extra - * save behavior required by the php editor. + /** + * The PHPEditor implementation of this AbstractTextEditor method performs any extra save behavior + * required by the php editor. */ // public void doSave(IProgressMonitor monitor) { // super.doSave(monitor); // compile or not, according to the user preferences - // IPreferenceStore store = getPreferenceStore(); - + // IPreferenceStore store = getPreferenceStore(); // the parse on save was changed to the eclipse "builders" concept // if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) { // IAction a = PHPParserAction.getInstance(); // if (a != null) // a.run(); // } - // if (SWT.getPlatform().equals("win32")) { // IAction a = ShowExternalPreviewAction.getInstance(); // if (a != null) @@ -1545,10 +2265,9 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // if (fOutlinePage != null) // fOutlinePage.update(); // } - - /** The PHPEditor implementation of this - * AbstractTextEditor method performs any extra - * save as behavior required by the php editor. + /** + * The PHPEditor implementation of this AbstractTextEditor method performs any extra save as + * behavior required by the php editor. */ // public void doSaveAs() { // super.doSaveAs(); @@ -1556,8 +2275,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // fOutlinePage.update(); // } /* - * @see StatusTextEditor#getStatusHeader(IStatus) - */ + * @see StatusTextEditor#getStatusHeader(IStatus) + */ protected String getStatusHeader(IStatus status) { if (fEncodingSupport != null) { String message = fEncodingSupport.getStatusHeader(status); @@ -1590,9 +2309,10 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } return super.getStatusMessage(status); } - /** The PHPEditor implementation of this - * AbstractTextEditor method performs sets the - * input of the outline page after AbstractTextEditor has set input. + + /** + * The PHPEditor implementation of this AbstractTextEditor method performs sets the input of the + * outline page after AbstractTextEditor has set input. */ // protected void doSetInput(IEditorInput input) throws CoreException { // super.doSetInput(input); @@ -1601,24 +2321,24 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // fEncodingSupport.reset(); // if (fOutlinePage != null) // fOutlinePage.setInput(input); - // // setOutlinePageInput(fOutlinePage, input); - // } + // // setOutlinePageInput(fOutlinePage, input); + // } protected void doSetInput(IEditorInput input) throws CoreException { super.doSetInput(input); if (fEncodingSupport != null) fEncodingSupport.reset(); setOutlinePageInput(fOutlinePage, input); } + /* * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput() */ // public Object getViewPartInput() { // return getEditorInput().getAdapter(IFile.class); // } - - /** The PHPEditor implementation of this - * AbstractTextEditor method adds any - * PHPEditor specific entries. + /** + * The PHPEditor implementation of this AbstractTextEditor method adds any PHPEditor specific + * entries. */ public void editorContextMenuAboutToShow(MenuManager menu) { super.editorContextMenuAboutToShow(menu); @@ -1629,7 +2349,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements fContextMenuGroup.setContext(context); fContextMenuGroup.fillContextMenu(menu); fContextMenuGroup.setContext(null); - // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$ + // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); + // //$NON-NLS-1$ // // ActionContext context = // new ActionContext(getSelectionProvider().getSelection()); @@ -1642,20 +2363,9 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements * Creates the outline page used with this editor. */ protected JavaOutlinePage createOutlinePage() { - - // AbstractContentOutlinePage page = new PHPContentOutlinePage(getDocumentProvider(), this); - // - // page.addSelectionChangedListener(fSelectionChangedListener); - // // setOutlinePageInput(page, getEditorInput()); - // if (getEditorInput() != null) - // fOutlinePage.setInput(getEditorInput()); - // - // return page; JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this); - - page.addSelectionChangedListener(fSelectionChangedListener); + fOutlineSelectionChangedListener.install(page); setOutlinePageInput(page, getEditorInput()); - return page; } @@ -1664,43 +2374,69 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements */ public void outlinePageClosed() { if (fOutlinePage != null) { - fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener); + fOutlineSelectionChangedListener.uninstall(fOutlinePage); fOutlinePage = null; resetHighlightRange(); } } + /** - * Synchronizes the outliner selection with the actual cursor - * position in the editor. + * Synchronizes the outliner selection with the given element position in the editor. + * + * @param element + * the java element to select */ - public void synchronizeOutlinePageSelection() { - - // if (isEditingScriptRunning()) - // return; - - ISourceViewer sourceViewer = getSourceViewer(); - if (sourceViewer == null || fOutlinePage == null) - return; - - StyledText styledText = sourceViewer.getTextWidget(); - if (styledText == null) - return; + protected void synchronizeOutlinePage(ISourceReference element) { + synchronizeOutlinePage(element, true); + } - int caret = 0; - if (sourceViewer instanceof ITextViewerExtension3) { - ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer; - caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); - } else { - int offset = sourceViewer.getVisibleRegion().getOffset(); - caret = offset + styledText.getCaretOffset(); + /** + * Synchronizes the outliner selection with the given element position in the editor. + * + * @param element + * the java element to select + * @param checkIfOutlinePageActive + * true if check for active outline page needs to be done + */ + protected void synchronizeOutlinePage(ISourceReference element, boolean checkIfOutlinePageActive) { + if (fOutlinePage != null && element != null && !(checkIfOutlinePageActive && isJavaOutlinePageActive())) { + fOutlineSelectionChangedListener.uninstall(fOutlinePage); + fOutlinePage.select(element); + fOutlineSelectionChangedListener.install(fOutlinePage); } + } - IJavaElement element = getElementAt(caret); - if (element instanceof ISourceReference) { - fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener); - fOutlinePage.select((ISourceReference) element); - fOutlinePage.addSelectionChangedListener(fSelectionChangedListener); - } + /** + * Synchronizes the outliner selection with the actual cursor position in the editor. + */ + public void synchronizeOutlinePageSelection() { + synchronizeOutlinePage(computeHighlightRangeSourceReference()); + + // ISourceViewer sourceViewer = getSourceViewer(); + // if (sourceViewer == null || fOutlinePage == null) + // return; + // + // StyledText styledText = sourceViewer.getTextWidget(); + // if (styledText == null) + // return; + // + // int caret = 0; + // if (sourceViewer instanceof ITextViewerExtension3) { + // ITextViewerExtension3 extension = (ITextViewerExtension3) + // sourceViewer; + // caret = + // extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); + // } else { + // int offset = sourceViewer.getVisibleRegion().getOffset(); + // caret = offset + styledText.getCaretOffset(); + // } + // + // IJavaElement element = getElementAt(caret); + // if (element instanceof ISourceReference) { + // fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener); + // fOutlinePage.select((ISourceReference) element); + // fOutlinePage.addSelectionChangedListener(fSelectionChangedListener); + // } } protected void setSelection(ISourceReference reference, boolean moveCursor) { @@ -1753,7 +2489,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } } // else if (reference instanceof IImportDeclaration) { - // String name= ((IImportDeclaration) reference).getElementName(); + // String name= ((IImportDeclaration) + // reference).getElementName(); // if (name != null && name.length() > 0) { // String content= reference.getSource(); // if (content != null) { @@ -1762,7 +2499,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // } // } // } else if (reference instanceof IPackageDeclaration) { - // String name= ((IPackageDeclaration) reference).getElementName(); + // String name= ((IPackageDeclaration) + // reference).getElementName(); // if (name != null && name.length() > 0) { // String content= reference.getSource(); // if (content != null) { @@ -1792,12 +2530,14 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } public void setSelection(IJavaElement element) { - - if (element == null || element instanceof ICompilationUnit) { // || element instanceof IClassFile) { + if (element == null || element instanceof ICompilationUnit) { // || + // element + // instanceof + // IClassFile) + // { /* - * If the element is an ICompilationUnit this unit is either the input - * of this editor or not being displayed. In both cases, nothing should - * happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128) + * If the element is an ICompilationUnit this unit is either the input of this editor or not being displayed. In both cases, + * nothing should happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128) */ return; } @@ -1805,33 +2545,32 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IJavaElement corresponding = getCorrespondingElement(element); if (corresponding instanceof ISourceReference) { ISourceReference reference = (ISourceReference) corresponding; - // set hightlight range + // set highlight range setSelection(reference, true); // set outliner selection if (fOutlinePage != null) { - fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener); + fOutlineSelectionChangedListener.uninstall(fOutlinePage); fOutlinePage.select(reference); - fOutlinePage.addSelectionChangedListener(fSelectionChangedListener); + fOutlineSelectionChangedListener.install(fOutlinePage); } } } - public synchronized void editingScriptStarted() { - ++ fIgnoreOutlinePageSelection; - } - - public synchronized void editingScriptEnded() { - -- fIgnoreOutlinePageSelection; - } - - public synchronized boolean isEditingScriptRunning() { - return (fIgnoreOutlinePageSelection > 0); - } - - /** The PHPEditor implementation of this - * AbstractTextEditor method performs gets - * the java content outline page if request is for a an - * outline page. + public synchronized void editingScriptStarted() { + ++fIgnoreOutlinePageSelection; + } + + public synchronized void editingScriptEnded() { + --fIgnoreOutlinePageSelection; + } + + public synchronized boolean isEditingScriptRunning() { + return (fIgnoreOutlinePageSelection > 0); + } + + /** + * The PHPEditor implementation of this AbstractTextEditor method performs gets the java content + * outline page if request is for a an outline page. */ public Object getAdapter(Class required) { @@ -1853,13 +2592,14 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements }; } if (fProjectionSupport != null) { - Object adapter= fProjectionSupport.getAdapter(getSourceViewer(), required); - if (adapter != null) - return adapter; - } - + Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required); + if (adapter != null) + return adapter; + } + return super.getAdapter(required); } + // public Object getAdapter(Class required) { // if (IContentOutlinePage.class.equals(required)) { // if (fOutlinePage == null) { @@ -1899,9 +2639,10 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements editingScriptEnded(); } } + /* - * @see AbstractTextEditor#adjustHighlightRange(int, int) - */ + * @see AbstractTextEditor#adjustHighlightRange(int, int) + */ protected void adjustHighlightRange(int offset, int length) { try { @@ -1910,12 +2651,20 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements while (element instanceof ISourceReference) { ISourceRange range = ((ISourceReference) element).getSourceRange(); if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) { + + ISourceViewer viewer = getSourceViewer(); + if (viewer instanceof ITextViewerExtension5) { + ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; + extension.exposeModelRange(new Region(range.getOffset(), range.getLength())); + } + setHighlightRange(range.getOffset(), range.getLength(), true); if (fOutlinePage != null) { - fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener); + fOutlineSelectionChangedListener.uninstall(fOutlinePage); fOutlinePage.select((ISourceReference) element); - fOutlinePage.addSelectionChangedListener(fSelectionChangedListener); + fOutlineSelectionChangedListener.install(fOutlinePage); } + return; } element = element.getParent(); @@ -1925,8 +2674,16 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements PHPeclipsePlugin.log(x.getStatus()); } - resetHighlightRange(); + ISourceViewer viewer = getSourceViewer(); + if (viewer instanceof ITextViewerExtension5) { + ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; + extension.exposeModelRange(new Region(offset, length)); + } else { + resetHighlightRange(); + } + } + protected boolean isActivePart() { IWorkbenchWindow window = getSite().getWorkbenchWindow(); IPartService service = window.getPartService(); @@ -1934,10 +2691,11 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements return part != null && part.equals(this); } - // public void openContextHelp() { - // IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput()); - // ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection(); + // IDocument doc = + // this.getDocumentProvider().getDocument(this.getEditorInput()); + // ITextSelection selection = (ITextSelection) + // this.getSelectionProvider().getSelection(); // int pos = selection.getOffset(); // String word = getFunctionName(doc, pos); // openContextHelp(word); @@ -1953,7 +2711,8 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // IHelpResource helpResource = new PHPFunctionHelpResource(word); // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource); // } else { - // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$ + // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help + // not available"), false); //$NON-NLS-1$ // } // } @@ -1986,32 +2745,39 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements if (value instanceof Integer) { sourceViewer.getTextWidget().setTabs(((Integer) value).intValue()); } else if (value instanceof String) { - sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value)); + try { + sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value)); + } catch (NumberFormatException e){ + // bug #1038071 - set default tab: + sourceViewer.getTextWidget().setTabs(80); + } } 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(); @@ -2024,64 +2790,85 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements return; } -// if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) { -// if ((event.getNewValue() instanceof Boolean) && ((Boolean)event.getNewValue()).booleanValue()) -// fEditorSelectionChangedListener.selectionChanged(); -// return; -// } - - if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) { - if (event.getNewValue() instanceof Boolean) { - Boolean disable= (Boolean) event.getNewValue(); - enableOverwriteMode(!disable.booleanValue()); - } - return; - } - -// if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) { -// if (event.getNewValue() instanceof Boolean) { -// boolean markOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue(); -// if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) { -// fMarkOccurrenceAnnotations= markOccurrenceAnnotations; -// if (!fMarkOccurrenceAnnotations) -// uninstallOccurrencesFinder(); -// else -// installOccurrencesFinder(); -// } -// } -// } -// if (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) { -// if (event.getNewValue() instanceof Boolean) { -// boolean stickyOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue(); -// if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations) { -// fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations; -//// if (!fMarkOccurrenceAnnotations) -//// uninstallOccurrencesFinder(); -//// else -//// installOccurrencesFinder(); -// } -// } -// } - if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) { - if (sourceViewer instanceof ProjectionViewer) { - ProjectionViewer projectionViewer= (ProjectionViewer) sourceViewer; - if (fProjectionModelUpdater != null) - fProjectionModelUpdater.uninstall(); - // either freshly enabled or provider changed - fProjectionModelUpdater= PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); - if (fProjectionModelUpdater != null) { - fProjectionModelUpdater.install(this, projectionViewer); - } - } - return; - } + if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) { + if ((event.getNewValue() instanceof Boolean) && ((Boolean) event.getNewValue()).booleanValue()) + selectionChanged(); + return; + } + + if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) { + if (event.getNewValue() instanceof Boolean) { + Boolean disable = (Boolean) event.getNewValue(); + enableOverwriteMode(!disable.booleanValue()); + } + return; + } + + // if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) + // { + // if (event.getNewValue() instanceof Boolean) { + // boolean markOccurrenceAnnotations= + // ((Boolean)event.getNewValue()).booleanValue(); + // if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) { + // fMarkOccurrenceAnnotations= markOccurrenceAnnotations; + // if (!fMarkOccurrenceAnnotations) + // uninstallOccurrencesFinder(); + // else + // installOccurrencesFinder(); + // } + // } + // } + // if + // (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) + // { + // if (event.getNewValue() instanceof Boolean) { + // boolean stickyOccurrenceAnnotations= + // ((Boolean)event.getNewValue()).booleanValue(); + // if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations) + // { + // fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations; + //// if (!fMarkOccurrenceAnnotations) + //// uninstallOccurrencesFinder(); + //// else + //// installOccurrencesFinder(); + // } + // } + // } + + ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event); + + // if (affectsOverrideIndicatorAnnotations(event)) { + // if (isShowingOverrideIndicators()) { + // if (fOverrideIndicatorManager == null) + // installOverrideIndicator(true); + // } else { + // if (fOverrideIndicatorManager != null) + // uninstallOverrideIndicator(); + // } + // return; + // } + + if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) { + if (sourceViewer instanceof ProjectionViewer) { + ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer; + if (fProjectionModelUpdater != null) + fProjectionModelUpdater.uninstall(); + // either freshly enabled or provider changed + fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider(); + if (fProjectionModelUpdater != null) { + fProjectionModelUpdater.install(this, projectionViewer); + } + } + return; + } } finally { super.handlePreferenceStoreChanged(event); } } // /* - // * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent) + // * @see + // AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent) // */ // protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { // @@ -2093,15 +2880,17 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // // String property = event.getProperty(); // - // // if (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) { - // // Object value= event.getNewValue(); - // // if (value instanceof Integer) { - // // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue()); - // // } else if (value instanceof String) { - // // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value)); - // // } - // // return; - // // } + // // if + // (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) { + // // Object value= event.getNewValue(); + // // if (value instanceof Integer) { + // // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue()); + // // } else if (value instanceof String) { + // // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) + // value)); + // // } + // // return; + // // } // // if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) { // if (isLineNumberRulerVisible()) @@ -2138,22 +2927,22 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements /** * 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); } /** - * Return whether the browser like links should be enabled - * according to the preference store settings. - * @return true if the browser like links should be enabled - */ + * Return whether the browser like links should be enabled according to the preference store settings. + * + * @return true if the browser like links should be enabled + */ private boolean isBrowserLikeLinks() { IPreferenceStore store = getPreferenceStore(); return store.getBoolean(BROWSER_LIKE_LINKS); @@ -2178,199 +2967,243 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements fMouseListener = null; } } + /** - * Handles a property change event describing a change - * of the java core's preferences and updates the preference - * related editor properties. + * Handles a property change event describing a change of the java core's preferences and updates the preference related editor + * properties. * - * @param event the property change event + * @param event + * the property change event */ protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) { if (COMPILER_TASK_TAGS.equals(event.getProperty())) { ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer != null - && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()))) + && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event + .getNewValue()))) sourceViewer.invalidateTextPresentation(); } + if (PreferenceConstants.EDITOR_WRAP_WORDS.equals(event.getProperty())) { + setWordWrap(); + } } /** - * Return whether the line number ruler column should be - * visible according to the preference store settings. + * Return whether the line number ruler column should be visible according to the preference store settings. + * * @return true if the line numbers should be visible */ -// protected 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) { -// } -// } -// } - - /* - * @see AbstractTextEditor#handleCursorPositionChanged() - */ - protected void handleCursorPositionChanged() { - super.handleCursorPositionChanged(); - if (!isEditingScriptRunning() && fUpdater != null) - fUpdater.post(); - } - /* - * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced() - */ - protected void handleElementContentReplaced() { - super.handleElementContentReplaced(); - if (fProjectionModelUpdater != null) - fProjectionModelUpdater.initialize(); - } + // private void hideLineNumberRuler() { + // IVerticalRuler v = getVerticalRuler(); + // if (v instanceof CompositeRuler) { + // CompositeRuler c = (CompositeRuler) v; + // try { + // c.removeDecorator(1); + // } catch (Throwable e) { + // } + // } + // } + /* + * @see AbstractTextEditor#handleCursorPositionChanged() + */ + protected void handleCursorPositionChanged() { + super.handleCursorPositionChanged(); + if (!isEditingScriptRunning() && fUpdater != null) + fUpdater.post(); + } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced() + */ + protected void handleElementContentReplaced() { + super.handleElementContentReplaced(); + if (fProjectionModelUpdater != null) + fProjectionModelUpdater.initialize(); + } + /** * 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)); -// } -// } - + * + * @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)); + // } + // } /** * 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; -// } - - private static IRegion getSignedSelection(ITextViewer viewer) { - - StyledText text = viewer.getTextWidget(); - int caretOffset = text.getCaretOffset(); - Point selection = text.getSelection(); - - // caret left - int offset, length; - if (caretOffset == selection.x) { - offset = selection.y; - length = selection.x - selection.y; + // 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) { + // + // StyledText text = viewer.getTextWidget(); + // int caretOffset = text.getCaretOffset(); + // Point selection = text.getSelection(); + // + // // caret left + // int offset, length; + // if (caretOffset == selection.x) { + // offset = selection.y; + // length = selection.x - selection.y; + // + // // caret right + // } else { + // offset = selection.x; + // length = selection.y - selection.x; + // } + // + // return new Region(offset, length); + // } + protected IRegion getSignedSelection(ISourceViewer sourceViewer) { + StyledText text = sourceViewer.getTextWidget(); + Point selection = text.getSelectionRange(); - // caret right - } else { - offset = selection.x; - length = selection.y - selection.x; + if (text.getCaretOffset() == selection.x) { + selection.x = selection.x + selection.y; + selection.y = -selection.y; } - return new Region(offset, length); + selection.x = widgetOffset2ModelOffset(sourceViewer, selection.x); + + return new Region(selection.x, selection.y); } /** Preference key for matching brackets */ protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS; + /** Preference key for matching brackets color */ protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR; + /** Preference key for highlighting current line */ - protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE; + // protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE; /** Preference key for highlight color of current line */ - protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR; + // protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR; /** Preference key for showing print marging ruler */ - protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN; + // protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN; /** Preference key for print margin ruler color */ - protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR; + // protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR; /** Preference key for print margin ruler column */ - protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN; + // protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN; /** Preference key for error indication */ -// protected final static String ERROR_INDICATION = PreferenceConstants.EDITOR_PROBLEM_INDICATION; + // protected final static String ERROR_INDICATION = + // PreferenceConstants.EDITOR_PROBLEM_INDICATION; /** Preference key for error color */ -// protected final static String ERROR_INDICATION_COLOR = PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR; + // protected final static String ERROR_INDICATION_COLOR = + // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR; /** Preference key for warning indication */ -// protected final static String WARNING_INDICATION = PreferenceConstants.EDITOR_WARNING_INDICATION; + // protected final static String WARNING_INDICATION = + // PreferenceConstants.EDITOR_WARNING_INDICATION; /** Preference key for warning color */ -// protected final static String WARNING_INDICATION_COLOR = PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR; + // protected final static String WARNING_INDICATION_COLOR = + // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR; /** Preference key for task indication */ protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION; + /** Preference key for task color */ protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR; + /** Preference key for bookmark indication */ protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION; + /** Preference key for bookmark color */ protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR; + /** Preference key for search result indication */ protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION; + /** Preference key for search result color */ protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR; + /** Preference key for unknown annotation indication */ protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION; + /** Preference key for unknown annotation color */ protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR; + /** Preference key for shwoing the overview ruler */ protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER; + /** Preference key for error indication in overview ruler */ protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for warning indication in overview ruler */ protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for task indication in overview ruler */ protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for bookmark indication in overview ruler */ protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for search result indication in overview ruler */ protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for unknown annotation indication in overview ruler */ protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER; + // /** Preference key for compiler task tags */ - // private final static String COMPILER_TASK_TAGS= JavaCore.COMPILER_TASK_TAGS; + // private final static String COMPILER_TASK_TAGS= + // JavaCore.COMPILER_TASK_TAGS; /** Preference key for browser like links */ private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS; + /** Preference key for key modifier of browser like links */ private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER; + /** - * Preference key for key modifier mask of browser like links. - * The value is only used if the value of EDITOR_BROWSER_LIKE_LINKS - * cannot be resolved to valid SWT modifier bits. + * Preference key for key modifier mask of browser like links. The value is only used if the value of + * EDITOR_BROWSER_LIKE_LINKS cannot be resolved to valid SWT modifier bits. * * @since 2.1.1 */ @@ -2397,57 +3230,85 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } } -// 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. - */ + // 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()); + // + // } + /** + * Returns the Java element wrapped by this editors input. + * + * @return the Java element wrapped by this editors input. + * @since 3.0 + */ + abstract protected IJavaElement getInputJavaElement(); + + protected void updateStatusLine() { + ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection(); + Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength()); + setStatusLineErrorMessage(null); + setStatusLineMessage(null); + if (annotation != null) { + try { + fIsUpdatingAnnotationViews = true; + updateAnnotationViews(annotation); + } finally { + fIsUpdatingAnnotationViews = false; + } + if (annotation instanceof IJavaAnnotation && ((IJavaAnnotation) annotation).isProblem()) + setStatusLineMessage(annotation.getText()); + } + } + + /** + * Jumps to the matching bracket. + */ public void gotoMatchingBracket() { ISourceViewer sourceViewer = getSourceViewer(); @@ -2506,10 +3367,13 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements sourceViewer.setSelectedRange(targetOffset, selection.getLength()); sourceViewer.revealRange(targetOffset, selection.getLength()); } + /** - * Ses the given message as error message to this editor's status line. - * @param msg message to be set - */ + * Ses the given message as error message to this editor's status line. + * + * @param msg + * message to be set + */ protected void setStatusLineErrorMessage(String msg) { IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class); if (statusLine != null) @@ -2517,14 +3381,157 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } /** - * Returns a segmentation of the line of the given document appropriate for bidi rendering. - * The default implementation returns only the string literals of a php code line as segments. - * - * @param document the document - * @param lineOffset the offset of the line - * @return the line's bidi segmentation - * @throws BadLocationException in case lineOffset is not valid in document - */ + * Sets the given message as message to this editor's status line. + * + * @param msg + * message to be set + * @since 3.0 + */ + protected void setStatusLineMessage(String msg) { + IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class); + if (statusLine != null) + statusLine.setMessage(false, msg, null); + } + + /** + * Returns the annotation closest to the given range respecting the given direction. If an annotation is found, the annotations + * current position is copied into the provided annotation position. + * + * @param offset + * the region offset + * @param length + * the region length + * @param forward + * true for forwards, false for backward + * @param annotationPosition + * the position of the found annotation + * @return the found annotation + */ + private Annotation getNextAnnotation(final int offset, final int length, boolean forward, Position annotationPosition) { + + Annotation nextAnnotation = null; + Position nextAnnotationPosition = null; + Annotation containingAnnotation = null; + Position containingAnnotationPosition = null; + boolean currentAnnotation = false; + + IDocument document = getDocumentProvider().getDocument(getEditorInput()); + int endOfDocument = document.getLength(); + int distance = Integer.MAX_VALUE; + + IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput()); + Iterator e = new JavaAnnotationIterator(model, true, true); + while (e.hasNext()) { + Annotation a = (Annotation) e.next(); + if ((a instanceof IJavaAnnotation) && ((IJavaAnnotation) a).hasOverlay() || !isNavigationTarget(a)) + continue; + + Position p = model.getPosition(a); + if (p == null) + continue; + + if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {// || p.includes(offset)) { + if (containingAnnotation == null + || (forward && p.length >= containingAnnotationPosition.length || !forward + && p.length >= containingAnnotationPosition.length)) { + containingAnnotation = a; + containingAnnotationPosition = p; + currentAnnotation = p.length == length; + } + } else { + int currentDistance = 0; + + if (forward) { + currentDistance = p.getOffset() - offset; + if (currentDistance < 0) + currentDistance = endOfDocument + currentDistance; + + if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) { + distance = currentDistance; + nextAnnotation = a; + nextAnnotationPosition = p; + } + } else { + currentDistance = offset + length - (p.getOffset() + p.length); + if (currentDistance < 0) + currentDistance = endOfDocument + currentDistance; + + if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) { + distance = currentDistance; + nextAnnotation = a; + nextAnnotationPosition = p; + } + } + } + } + if (containingAnnotationPosition != null && (!currentAnnotation || nextAnnotation == null)) { + annotationPosition.setOffset(containingAnnotationPosition.getOffset()); + annotationPosition.setLength(containingAnnotationPosition.getLength()); + return containingAnnotation; + } + if (nextAnnotationPosition != null) { + annotationPosition.setOffset(nextAnnotationPosition.getOffset()); + annotationPosition.setLength(nextAnnotationPosition.getLength()); + } + + return nextAnnotation; + } + + /** + * Returns the annotation overlapping with the given range or null. + * + * @param offset + * the region offset + * @param length + * the region length + * @return the found annotation or null + * @since 3.0 + */ + private Annotation getAnnotation(int offset, int length) { + IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput()); + Iterator e = new JavaAnnotationIterator(model, true, true); + while (e.hasNext()) { + Annotation a = (Annotation) e.next(); + if (!isNavigationTarget(a)) + continue; + + Position p = model.getPosition(a); + if (p != null && p.overlapsWith(offset, length)) + return a; + } + + return null; + } + + /** + * Returns whether the given annotation is configured as a target for the "Go to Next/Previous Annotation" actions + * + * @param annotation + * the annotation + * @return true if this is a target, false otherwise + * @since 3.0 + */ + private boolean isNavigationTarget(Annotation annotation) { + Preferences preferences = EditorsUI.getPluginPreferences(); + AnnotationPreference preference = getAnnotationPreferenceLookup().getAnnotationPreference(annotation); + // See bug 41689 + // String key= forward ? preference.getIsGoToNextNavigationTargetKey() : preference.getIsGoToPreviousNavigationTargetKey(); + String key = preference == null ? null : preference.getIsGoToNextNavigationTargetKey(); + return (key != null && preferences.getBoolean(key)); + } + + /** + * Returns a segmentation of the line of the given document appropriate for bidi rendering. The default implementation returns + * only the string literals of a php code line as segments. + * + * @param document + * the document + * @param lineOffset + * the offset of the line + * @return the line's bidi segmentation + * @throws BadLocationException + * in case lineOffset is not valid in document + */ public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException { IRegion line = document.getLineInformationOfOffset(lineOffset); @@ -2567,14 +3574,17 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements return segments; } + /** - * Returns a segmentation of the given line appropriate for bidi rendering. The default - * implementation returns only the string literals of a php code line as segments. - * - * @param lineOffset the offset of the line - * @param line the content of the line - * @return the line's bidi segmentation - */ + * Returns a segmentation of the given line appropriate for bidi rendering. The default implementation returns only the string + * literals of a php code line as segments. + * + * @param lineOffset + * the offset of the line + * @param line + * the content of the line + * @return the line's bidi segmentation + */ protected int[] getBidiLineSegments(int lineOffset, String line) { IDocumentProvider provider = getDocumentProvider(); if (provider != null && line != null && line.length() > 0) { @@ -2603,85 +3613,125 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements // event.segments = getBidiLineSegments(event.lineOffset, event.lineText); // } // }); - // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); + // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); // return viewer; // } - public final ISourceViewer getViewer() { - return getSourceViewer(); - } - - -// 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); -// } + return getSourceViewer(); + } + + // 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); -// } - /* - * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int) - */ - protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles, IPreferenceStore store) { - return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, store); - } + // 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 final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) { - - ISourceViewer viewer= createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, getPreferenceStore()); - - 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); - - // ensure source viewer decoration support has been created and configured - getSourceViewerDecorationSupport(viewer); - - return viewer; - } - /* - * @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#createSourceViewer(Composite, IVerticalRuler, int) + */ + protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, + boolean isOverviewRulerVisible, int styles, IPreferenceStore store) { + return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, store); + } + + /* + * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int) + */ + protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) { + + ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, + getPreferenceStore()); + + 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); + + // ensure source viewer decoration support has been created and + // configured + getSourceViewerDecorationSupport(viewer); + + return viewer; + } + /* * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent) */ protected boolean affectsTextPresentation(PropertyChangeEvent event) { - JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); - return textTools.affectsBehavior(event); + return ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).affectsTextPresentation(event) + || super.affectsTextPresentation(event); + } + + // + // protected boolean affectsTextPresentation(PropertyChangeEvent event) { + // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); + // return textTools.affectsBehavior(event); + // } + /** + * Creates and returns the preference store for this Java editor with the given input. + * + * @param input + * The editor input for which to create the preference store + * @return the preference store for this editor + * + * @since 3.0 + */ + private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) { + List stores = new ArrayList(3); + + IJavaProject project = EditorUtility.getJavaProject(input); + if (project != null) + stores.add(new OptionsAdapter(project.getOptions(false), PHPeclipsePlugin.getDefault().getMockupPreferenceStore(), + new OptionsAdapter.IPropertyChangeEventFilter() { + + public boolean isFiltered(PropertyChangeEvent event) { + IJavaElement inputJavaElement = getInputJavaElement(); + IJavaProject javaProject = inputJavaElement != null ? inputJavaElement.getJavaProject() : null; + if (javaProject == null) + return true; + + return !javaProject.getProject().equals(event.getSource()); + } + + })); + + stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore()); + stores.add(new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences())); + stores.add(EditorsUI.getPreferenceStore()); + + return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()])); } /** @@ -2723,7 +3773,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } selectAndReveal(errorPosition.getOffset(), errorPosition.getLength()); -// setStatusLineErrorMessage(nextError.getMessage()); + // setStatusLineErrorMessage(nextError.getMessage()); } else { @@ -2779,78 +3829,188 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements 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; - } -} -// protected void uninstallOverrideIndicator() { -// if (fOverrideIndicatorManager != null) { -// fOverrideIndicatorManager.removeAnnotations(); -// fOverrideIndicatorManager= null; -// } -//} - -protected void installOverrideIndicator(boolean waitForReconcilation) { -// uninstallOverrideIndicator(); - IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput()); -// IJavaElement inputElement= getInputJavaElement(); - -// if (model == null || inputElement == null) -// return; - -// CompilationUnit ast= PHPeclipsePlugin.getDefault().getASTProvider().getAST(inputElement, true, null); -// fOverrideIndicatorManager= new OverrideIndicatorManager(model, inputElement, ast); -} + IDocumentProvider documentProvider = getDocumentProvider(); + if (documentProvider == null) + return; -/** - * Tells whether override indicators are shown. - * - * @return true if the override indicators are shown - * @since 3.0 - */ -//protected boolean isShowingOverrideIndicators() { -// AnnotationPreference preference= getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE); -// IPreferenceStore store= getPreferenceStore(); -// return getBoolean(store, preference.getHighlightPreferenceKey()) -// || getBoolean(store, preference.getVerticalRulerPreferenceKey()) -// || getBoolean(store, preference.getOverviewRulerPreferenceKey()) -// || getBoolean(store, preference.getTextPreferenceKey()); -//} + IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null || fOccurrenceAnnotations == null) + return; -/** - * Returns the boolean preference for the given key. - * - * @param store the preference store - * @param key the preference key - * @return true if the key exists in the store and its value is true - * @since 3.0 - */ -private boolean getBoolean(IPreferenceStore store, String key) { - return key != null && store.getBoolean(key); -} - - /** - * Returns the folding action group, or null if there is none. - * - * @return the folding action group, or null if there is none - * @since 3.0 - */ - protected FoldingActionGroup getFoldingActionGroup() { - return fFoldingGroup; - } -} + 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; + } + } + + protected void uninstallOverrideIndicator() { + // if (fOverrideIndicatorManager != null) { + // fOverrideIndicatorManager.removeAnnotations(); + // fOverrideIndicatorManager= null; + // } + } + + protected void installOverrideIndicator(boolean waitForReconcilation) { + uninstallOverrideIndicator(); + IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput()); + final IJavaElement inputElement = getInputJavaElement(); + + if (model == null || inputElement == null) + return; + + // fOverrideIndicatorManager= new OverrideIndicatorManager(model, inputElement, null); + // + // if (provideAST) { + // Job job= new Job(JavaEditorMessages.getString("OverrideIndicatorManager.intallJob")) { //$NON-NLS-1$ + // /* + // * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + // * @since 3.0 + // */ + // protected IStatus run(IProgressMonitor monitor) { + // CompilationUnit ast= JavaPlugin.getDefault().getASTProvider().getAST(inputElement, true, null); + // if (fOverrideIndicatorManager != null) // editor might have been closed in the meanwhile + // fOverrideIndicatorManager.reconciled(ast, true, monitor); + // return Status.OK_STATUS; + // } + // }; + // job.setPriority(Job.DECORATE); + // job.setSystem(true); + // job.schedule(); + // } + } + + /** + * Tells whether override indicators are shown. + * + * @return true if the override indicators are shown + * @since 3.0 + */ + // protected boolean isShowingOverrideIndicators() { + // AnnotationPreference preference= + // getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE); + // IPreferenceStore store= getPreferenceStore(); + // return getBoolean(store, preference.getHighlightPreferenceKey()) + // || getBoolean(store, preference.getVerticalRulerPreferenceKey()) + // || getBoolean(store, preference.getOverviewRulerPreferenceKey()) + // || getBoolean(store, preference.getTextPreferenceKey()); + // } + /** + * Returns the boolean preference for the given key. + * + * @param store + * the preference store + * @param key + * the preference key + * @return true if the key exists in the store and its value is true + * @since 3.0 + */ + private boolean getBoolean(IPreferenceStore store, String key) { + return key != null && store.getBoolean(key); + } + + /** + * Returns the folding action group, or null if there is none. + * + * @return the folding action group, or null if there is none + * @since 3.0 + */ + protected FoldingActionGroup getFoldingActionGroup() { + return fFoldingGroup; + } + + /** + * React to changed selection. + * + * @since 3.0 + */ + protected void selectionChanged() { + if (getSelectionProvider() == null) + return; + ISourceReference element = computeHighlightRangeSourceReference(); + if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE)) + synchronizeOutlinePage(element); + setSelection(element, false); + updateStatusLine(); + } + + private boolean isJavaOutlinePageActive() { + IWorkbenchPart part = getActivePart(); + return part instanceof ContentOutline && ((ContentOutline) part).getCurrentPage() == fOutlinePage; + } + + private IWorkbenchPart getActivePart() { + IWorkbenchWindow window = getSite().getWorkbenchWindow(); + IPartService service = window.getPartService(); + IWorkbenchPart part = service.getActivePart(); + return part; + } + + /** + * Computes and returns the source reference that includes the caret and serves as provider for the outline page selection and the + * editor range indication. + * + * @return the computed source reference + * @since 3.0 + */ + protected ISourceReference computeHighlightRangeSourceReference() { + ISourceViewer sourceViewer = getSourceViewer(); + if (sourceViewer == null) + return null; + + StyledText styledText = sourceViewer.getTextWidget(); + if (styledText == null) + return null; + + int caret = 0; + if (sourceViewer instanceof ITextViewerExtension5) { + ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer; + caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); + } else { + int offset = sourceViewer.getVisibleRegion().getOffset(); + caret = offset + styledText.getCaretOffset(); + } + + IJavaElement element = getElementAt(caret, false); + + if (!(element instanceof ISourceReference)) + return null; + + if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) { + + IImportDeclaration declaration = (IImportDeclaration) element; + IImportContainer container = (IImportContainer) declaration.getParent(); + ISourceRange srcRange = null; + + try { + srcRange = container.getSourceRange(); + } catch (JavaModelException e) { + } + + if (srcRange != null && srcRange.getOffset() == caret) + return container; + } + + return (ISourceReference) element; + } + + /** + * Returns the most narrow java element including the given offset. + * + * @param offset + * the offset inside of the requested element + * @param reconcile + * true if editor input should be reconciled in advance + * @return the most narrow java element + * @since 3.0 + */ + protected IJavaElement getElementAt(int offset, boolean reconcile) { + return getElementAt(offset); + } +} \ No newline at end of file