X-Git-Url: http://git.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java
index ef1bbab..c37b2e4 100644
--- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java
+++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java
@@ -12,28 +12,43 @@ Contributors:
Klaus Hartlage - www.eclipseproject.de
**********************************************************************/
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
+import net.sourceforge.phpdt.core.ICompilationUnit;
+import net.sourceforge.phpdt.core.IJavaElement;
+import net.sourceforge.phpdt.core.IMember;
+import net.sourceforge.phpdt.core.ISourceRange;
+import net.sourceforge.phpdt.core.ISourceReference;
+import net.sourceforge.phpdt.core.JavaCore;
+import net.sourceforge.phpdt.core.JavaModelException;
import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
+import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
+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.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.GenerateActionGroup;
import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
-import net.sourceforge.phpdt.ui.text.IColorManager;
import net.sourceforge.phpdt.ui.text.JavaTextTools;
+import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IAction;
@@ -51,33 +66,34 @@ import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextInputListener;
-import org.eclipse.jface.text.ITextOperationTarget;
+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.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.source.Annotation;
-import org.eclipse.jface.text.source.AnnotationRulerColumn;
-import org.eclipse.jface.text.source.CompositeRuler;
-import org.eclipse.jface.text.source.IAnnotationAccess;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.IAnnotationModelExtension;
import org.eclipse.jface.text.source.IOverviewRuler;
-import org.eclipse.jface.text.source.ISharedTextColors;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.ISourceViewerExtension;
import org.eclipse.jface.text.source.IVerticalRuler;
-import org.eclipse.jface.text.source.IVerticalRulerColumn;
-import org.eclipse.jface.text.source.LineNumberRulerColumn;
import org.eclipse.jface.text.source.OverviewRuler;
-import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.text.source.projection.ProjectionSupport;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BidiSegmentEvent;
import org.eclipse.swt.custom.BidiSegmentListener;
@@ -95,6 +111,7 @@ import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
@@ -102,32 +119,67 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPartService;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
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.IEncodingSupport;
-import org.eclipse.ui.texteditor.AddTaskAction;
-import org.eclipse.ui.texteditor.ContentAssistAction;
+import org.eclipse.ui.part.IShowInTargetList;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
-import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.IEditorStatusLine;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
-import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.ui.texteditor.ResourceAction;
-import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
-import org.eclipse.ui.texteditor.StatusTextEditor;
import org.eclipse.ui.texteditor.TextEditorAction;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.ui.views.tasklist.TaskList;
/**
* PHP specific text editor.
*/
-public abstract class PHPEditor extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor {
+public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider {
+//extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor {
+ /**
+ * "Smart" runnable for updating the outline page's selection.
+ */
+ class OutlinePageSelectionUpdater implements Runnable {
+
+ /** Has the runnable already been posted? */
+ private boolean fPosted = false;
+
+ public OutlinePageSelectionUpdater() {
+ }
+
+ /*
+ * @see Runnable#run()
+ */
+ public void run() {
+ synchronizeOutlinePageSelection();
+ fPosted = false;
+ }
+
+ /**
+ * Posts this runnable into the event queue.
+ */
+ public void post() {
+ if (fPosted)
+ return;
+
+ Shell shell = getSite().getShell();
+ if (shell != null & !shell.isDisposed()) {
+ fPosted = true;
+ shell.getDisplay().asyncExec(this);
+ }
+ }
+ };
class SelectionChangedListener implements ISelectionChangedListener {
public void selectionChanged(SelectionChangedEvent event) {
doSelectionChanged(event);
@@ -138,15 +190,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
* Link mode.
*/
class MouseClickListener
- implements
- KeyListener,
- MouseListener,
- MouseMoveListener,
- FocusListener,
- PaintListener,
- IPropertyChangeListener,
- IDocumentListener,
- ITextInputListener {
+ implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener, IPropertyChangeListener, IDocumentListener, ITextInputListener {
/** The session is active. */
private boolean fActive;
@@ -402,25 +446,25 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
return null;
return null;
- // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
- // if (input == null)
- // return null;
- //
- // try {
- //
- // IJavaElement[] elements= null;
- // synchronized (input) {
- // elements= ((ICodeAssist) input).codeSelect(offset, 0);
- // }
- //
- // if (elements == null || elements.length == 0)
- // return null;
- //
- // return selectWord(viewer.getDocument(), offset);
- //
- // } catch (JavaModelException e) {
- // return null;
- // }
+ // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
+ // if (input == null)
+ // return null;
+ //
+ // try {
+ //
+ // IJavaElement[] elements= null;
+ // synchronized (input) {
+ // elements= ((ICodeAssist) input).codeSelect(offset, 0);
+ // }
+ //
+ // if (elements == null || elements.length == 0)
+ // return null;
+ //
+ // return selectWord(viewer.getDocument(), offset);
+ //
+ // } catch (JavaModelException e) {
+ // return null;
+ // }
}
private int getCurrentTextOffset(ISourceViewer viewer) {
@@ -765,8 +809,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
}
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) {
@@ -913,38 +956,38 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
}
};
- static protected class AnnotationAccess implements IAnnotationAccess {
- /*
- * @see org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
- */
- public Object getType(Annotation annotation) {
- if (annotation instanceof IJavaAnnotation) {
- IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
- if (javaAnnotation.isRelevant())
- return javaAnnotation.getAnnotationType();
- }
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
- */
- public boolean isMultiLine(Annotation annotation) {
- return true;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
- */
- public boolean isTemporary(Annotation annotation) {
- if (annotation instanceof IJavaAnnotation) {
- IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
- if (javaAnnotation.isRelevant())
- return javaAnnotation.isTemporary();
- }
- return false;
- }
- };
+// static protected class AnnotationAccess implements IAnnotationAccess {
+// /*
+// * @see org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
+// */
+// public Object getType(Annotation annotation) {
+// if (annotation instanceof IJavaAnnotation) {
+// IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
+// // if (javaAnnotation.isRelevant())
+// // return javaAnnotation.getAnnotationType();
+// }
+// return null;
+// }
+//
+// /*
+// * @see org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
+// */
+// public boolean isMultiLine(Annotation annotation) {
+// return true;
+// }
+//
+// /*
+// * @see org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
+// */
+// public boolean isTemporary(Annotation annotation) {
+// if (annotation instanceof IJavaAnnotation) {
+// IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
+// if (javaAnnotation.isRelevant())
+// return javaAnnotation.isTemporary();
+// }
+// return false;
+// }
+// };
private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
/*
@@ -954,17 +997,153 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
handlePreferencePropertyChanged(event);
}
};
+
+ /**
+ * Finds and marks occurrence annotations.
+ *
+ * @since 3.0
+ */
+ class OccurrencesFinderJob extends Job implements IDocumentListener {
+
+ private IDocument fDocument;
+ private boolean fCancelled= false;
+ private IProgressMonitor fProgressMonitor;
+ private Position[] fPositions;
+
+ public OccurrencesFinderJob(IDocument document, Position[] positions) {
+ super("Occurrences Marker"); //$NON-NLS-1$
+ fDocument= document;
+ fPositions= positions;
+ fDocument.addDocumentListener(this);
+ }
+
+ private boolean isCancelled() {
+ return fCancelled || fProgressMonitor.isCanceled();
+ }
+
+ /*
+ * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus run(IProgressMonitor progressMonitor) {
+
+ fProgressMonitor= progressMonitor;
+
+ try {
+
+ if (isCancelled())
+ return Status.CANCEL_STATUS;
+
+ ITextViewer textViewer= getViewer();
+ if (textViewer == null)
+ return Status.CANCEL_STATUS;
+
+ IDocument document= textViewer.getDocument();
+ if (document == null)
+ return Status.CANCEL_STATUS;
+
+ IDocumentProvider documentProvider= getDocumentProvider();
+ if (documentProvider == null)
+ return Status.CANCEL_STATUS;
+
+ IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput());
+ if (annotationModel == null)
+ return Status.CANCEL_STATUS;
+
+ // Add occurrence annotations
+ int length= fPositions.length;
+ Map annotationMap= new HashMap(length);
+ for (int i= 0; i < length; i++) {
+
+ if (isCancelled())
+ return Status.CANCEL_STATUS;
+
+ String message;
+ Position position= fPositions[i];
+
+ // Create & add annotation
+ try {
+ message= document.get(position.offset, position.length);
+ } catch (BadLocationException ex) {
+ // Skip this match
+ continue;
+ }
+ annotationMap.put(
+ new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
+ position);
+ }
+
+ if (isCancelled())
+ return Status.CANCEL_STATUS;
+
+ synchronized (annotationModel) {
+ if (annotationModel instanceof IAnnotationModelExtension) {
+ ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
+ } else {
+ removeOccurrenceAnnotations();
+ Iterator iter= annotationMap.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry mapEntry= (Map.Entry)iter.next();
+ annotationModel.addAnnotation((Annotation)mapEntry.getKey(), (Position)mapEntry.getValue());
+ }
+ }
+ fOccurrenceAnnotations= (Annotation[])annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
+ }
+ } finally {
+ fDocument.removeDocumentListener(this);
+ }
+ return Status.OK_STATUS;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
+ */
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ fCancelled= true;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
+ */
+ public void documentChanged(DocumentEvent event) {
+ }
+ }
+
+
+ /**
+ * Holds the current occurrence annotations.
+ * @since 3.0
+ */
+ private Annotation[] fOccurrenceAnnotations= null;
+
+ private Job fOccurrencesFinderJob;
+
/** Preference key for showing the line number ruler */
- private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
+// private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
/** Preference key for the foreground color of the line numbers */
- private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
+ // private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
/** Preference key for the link color */
private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
+ /** Preference key for compiler task tags */
+ private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
// protected PHPActionGroup fActionGroups;
+ // /** The outline page */
+ // private AbstractContentOutlinePage fOutlinePage;
/** The outline page */
- private AbstractContentOutlinePage fOutlinePage;
-
+ 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 */
+ private int fIgnoreOutlinePageSelection;
+
+ /** The outline page selection updater */
+ private OutlinePageSelectionUpdater fUpdater;
// protected PHPSyntaxParserThread fValidationThread = null;
// private IPreferenceStore fPHPPrefStore;
@@ -973,63 +1152,83 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
/** 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;
protected CompositeActionGroup fActionGroups;
- /** The standard action groups added to the menu */
- protected GenerateActionGroup fGenerateActionGroup;
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;
+
/** The information presenter. */
private InformationPresenter fInformationPresenter;
/** The annotation access */
- protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
+// protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
/** The overview ruler */
protected OverviewRuler isOverviewRulerVisible;
/** The source viewer decoration support */
- protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
+ //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
/** The overview ruler */
- protected OverviewRuler fOverviewRuler;
+ //protected OverviewRuler fOverviewRuler;
/** The preference property change listener for java core. */
private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
+ /**
+ * Returns the most narrow java element including the given offset
+ *
+ * @param offset the offset inside of the requested element
+ */
+ abstract protected IJavaElement getElementAt(int offset);
+
+ /**
+ * 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.
+ */
+ abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input);
/**
* Default constructor.
*/
public PHPEditor() {
super();
- JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
- setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this));
- setRangeIndicator(new DefaultRangeIndicator());
- setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
-
- // don't activate this scope without synchronizing plugin.xml !!!
- // setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
-
- // if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
- // fUpdater= new OutlinePageSelectionUpdater();
+ 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 IMember#getCompilationUnit()
- // */
- // public ICompilationUnit getCompilationUnit() {
- // return this;
- // }
- // /**
- // * @see org.phpeclipse.phpdt.internal.compiler.env.ICompilationUnit#getContents()
- // */
- // public char[] getContents() {
- // IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
- //
- // return doc.get().toCharArray();
- // }
+
/*
* @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
*/
@@ -1038,7 +1237,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
if (fEncodingSupport != null)
fEncodingSupport.reset();
}
-
+
/*
* Update the hovering behavior depending on the preferences.
*/
@@ -1069,13 +1268,25 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
}
}
+ 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)
+ */
+ protected void doSetSelection(ISelection selection) {
+ super.doSetSelection(selection);
+ synchronizeOutlinePageSelection();
+ }
+ boolean isFoldingEnabled() {
+ return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
+ }
/*
* @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.
* widgets.Composite)
@@ -1083,11 +1294,29 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
public void createPartControl(Composite parent) {
super.createPartControl(parent);
- fSourceViewerDecorationSupport.install(getPreferenceStore());
-
- Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
+ //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);
+ }
+ });
+ 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();
preferences.addPropertyChangeListener(fPropertyChangeListener);
-
+
IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
boolean cutDown = false;
@@ -1099,6 +1328,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
fInformationPresenter = new InformationPresenter(informationControlCreator);
fInformationPresenter.setSizeConstraints(60, 10, true, true);
fInformationPresenter.install(getSourceViewer());
+
}
/**
@@ -1112,15 +1342,22 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
}
/**
+ * Sets the outliner's context menu ID.
+ */
+ protected void setOutlinerContextMenuId(String menuId) {
+ fOutlinerContextMenuId = menuId;
+ }
+
+ /**
* Returns the standard action group of this editor.
*/
protected ActionGroup getActionGroup() {
return fActionGroups;
}
- public AbstractContentOutlinePage getfOutlinePage() {
- return fOutlinePage;
- }
+ // public JavaOutlinePage getfOutlinePage() {
+ // return fOutlinePage;
+ // }
/** The PHPEditor
implementation of this
* AbstractTextEditor
method extend the
@@ -1128,85 +1365,119 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
*/
protected void createActions() {
super.createActions();
-
- ResourceAction resAction = new AddTaskAction(PHPEditorMessages.getResourceBundle(), "AddTask.", this); //$NON-NLS-1$
- resAction.setHelpContextId(IAbstractTextEditorHelpContextIds.ADD_TASK_ACTION);
- resAction.setActionDefinitionId(ITextEditorActionDefinitionIds.ADD_TASK);
- setAction(ITextEditorActionConstants.ADD_TASK, resAction);
-
- resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
- resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
- resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
- setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
- // WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
-
- Action action;
-
- setAction(
- "ContentAssistTip",
- new TextOperationAction(
- PHPEditorMessages.getResourceBundle(),
- "ContentAssistTip.",
- this,
- ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
-
- action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$
- action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
- setAction("ContentAssistProposal", action); //$NON-NLS-1$
- markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
- // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
-
- fEncodingSupport = new DefaultEncodingSupport();
- fEncodingSupport.initialize(this);
-
- action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
- action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
- setAction("Comment", action); //$NON-NLS-1$
- markAsStateDependentAction("Comment", true); //$NON-NLS-1$
- // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
-
- action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
- action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
- setAction("Uncomment", action); //$NON-NLS-1$
- markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
- // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
-
- action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
- action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
- setAction("Format", action); //$NON-NLS-1$
- markAsStateDependentAction("Format", true); //$NON-NLS-1$
- markAsSelectionDependentAction("Format", true); //$NON-NLS-1$
- // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
-
- action = new GotoMatchingBracketAction(this);
- action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
- setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
-
- fGenerateActionGroup = new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
-
- fActionGroups = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
-
- // We have to keep the context menu group separate to have better control over positioning
- fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
- // rg,
- // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)});
-
- // if (fValidationThread == null) {
- // fValidationThread =
- // new PHPSyntaxParserThread(this, getSourceViewer());
- // //Thread defaults
- //
- // fValidationThread.start();
- // }
- //
- // fValidationThread.setText(getSourceViewer().getTextWidget().getText());
+
+ 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(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.
*/
public void dispose() {
+ if (fProjectionModelUpdater != null) {
+ fProjectionModelUpdater.uninstall();
+ fProjectionModelUpdater= null;
+ }
+
+ if (fProjectionSupport != null) {
+ fProjectionSupport.dispose();
+ fProjectionSupport= null;
+ }
// PHPEditorEnvironment.disconnect(this);
if (fOutlinePage != null)
fOutlinePage.setInput(null);
@@ -1228,10 +1499,10 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
fPropertyChangeListener = null;
}
- if (fSourceViewerDecorationSupport != null) {
- fSourceViewerDecorationSupport.dispose();
- fSourceViewerDecorationSupport = null;
- }
+// if (fSourceViewerDecorationSupport != null) {
+// fSourceViewerDecorationSupport.dispose();
+// fSourceViewerDecorationSupport = null;
+// }
if (fBracketMatcher != null) {
fBracketMatcher.dispose();
@@ -1244,46 +1515,46 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
* AbstractTextEditor
method performs any extra
* revert behavior required by the php editor.
*/
- public void doRevertToSaved() {
- super.doRevertToSaved();
- if (fOutlinePage != null)
- fOutlinePage.update();
- }
+ // 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.
*/
- public void doSave(IProgressMonitor monitor) {
- super.doSave(monitor);
- // compile or not, according to the user preferences
- // 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)
- // a.run();
- // }
- if (fOutlinePage != null)
- fOutlinePage.update();
- }
+ // public void doSave(IProgressMonitor monitor) {
+ // super.doSave(monitor);
+ // compile or not, according to the user preferences
+ // 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)
+ // a.run();
+ // }
+ // if (fOutlinePage != null)
+ // fOutlinePage.update();
+ // }
/** The PHPEditor
implementation of this
* AbstractTextEditor
method performs any extra
* save as behavior required by the php editor.
*/
- public void doSaveAs() {
- super.doSaveAs();
- if (fOutlinePage != null)
- fOutlinePage.update();
- }
+ // public void doSaveAs() {
+ // super.doSaveAs();
+ // if (fOutlinePage != null)
+ // fOutlinePage.update();
+ // }
/*
* @see StatusTextEditor#getStatusHeader(IStatus)
*/
@@ -1323,16 +1594,21 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
* 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);
+ //
+ // if (fEncodingSupport != null)
+ // fEncodingSupport.reset();
+ // if (fOutlinePage != null)
+ // fOutlinePage.setInput(input);
+ // // setOutlinePageInput(fOutlinePage, input);
+ // }
protected void doSetInput(IEditorInput input) throws CoreException {
super.doSetInput(input);
-
if (fEncodingSupport != null)
fEncodingSupport.reset();
- if (fOutlinePage != null)
- fOutlinePage.setInput(input);
- // setOutlinePageInput(fOutlinePage, input);
+ setOutlinePageInput(fOutlinePage, input);
}
-
/*
* @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
*/
@@ -1365,14 +1641,20 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
/**
* Creates the outline page used with this editor.
*/
- protected AbstractContentOutlinePage createOutlinePage() {
+ protected JavaOutlinePage createOutlinePage() {
- AbstractContentOutlinePage page = new PHPContentOutlinePage(getDocumentProvider(), this);
+ // 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);
- // setOutlinePageInput(page, getEditorInput());
- if (getEditorInput() != null)
- fOutlinePage.setInput(getEditorInput());
+ setOutlinePageInput(page, getEditorInput());
return page;
}
@@ -1387,56 +1669,264 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
resetHighlightRange();
}
}
- protected void updateStateDependentActions() {
- super.updateStateDependentActions();
- fGenerateActionGroup.editorStateChanged();
+ /**
+ * Synchronizes the outliner selection with the actual cursor
+ * position in the editor.
+ */
+ public void synchronizeOutlinePageSelection() {
+
+ // if (isEditingScriptRunning())
+ // return;
+
+ 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) {
+
+ ISelection selection = getSelectionProvider().getSelection();
+ if (selection instanceof TextSelection) {
+ TextSelection textSelection = (TextSelection) selection;
+ if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
+ markInNavigationHistory();
+ }
+
+ if (reference != null) {
+
+ StyledText textWidget = null;
+
+ ISourceViewer sourceViewer = getSourceViewer();
+ if (sourceViewer != null)
+ textWidget = sourceViewer.getTextWidget();
+
+ if (textWidget == null)
+ return;
+
+ try {
+
+ ISourceRange range = reference.getSourceRange();
+ if (range == null)
+ return;
+
+ int offset = range.getOffset();
+ int length = range.getLength();
+
+ if (offset < 0 || length < 0)
+ return;
+
+ textWidget.setRedraw(false);
+
+ setHighlightRange(offset, length, moveCursor);
+
+ if (!moveCursor)
+ return;
+
+ offset = -1;
+ length = -1;
+
+ if (reference instanceof IMember) {
+ range = ((IMember) reference).getNameRange();
+ if (range != null) {
+ offset = range.getOffset();
+ length = range.getLength();
+ }
+ }
+ // else if (reference instanceof IImportDeclaration) {
+ // String name= ((IImportDeclaration) reference).getElementName();
+ // if (name != null && name.length() > 0) {
+ // String content= reference.getSource();
+ // if (content != null) {
+ // offset= range.getOffset() + content.indexOf(name);
+ // length= name.length();
+ // }
+ // }
+ // } else if (reference instanceof IPackageDeclaration) {
+ // String name= ((IPackageDeclaration) reference).getElementName();
+ // if (name != null && name.length() > 0) {
+ // String content= reference.getSource();
+ // if (content != null) {
+ // offset= range.getOffset() + content.indexOf(name);
+ // length= name.length();
+ // }
+ // }
+ // }
+
+ if (offset > -1 && length > 0) {
+ sourceViewer.revealRange(offset, length);
+ sourceViewer.setSelectedRange(offset, length);
+ }
+
+ } catch (JavaModelException x) {
+ } catch (IllegalArgumentException x) {
+ } finally {
+ if (textWidget != null)
+ textWidget.setRedraw(true);
+ }
+
+ } else if (moveCursor) {
+ resetHighlightRange();
+ }
+
+ markInNavigationHistory();
+ }
+
+ public void setSelection(IJavaElement element) {
+
+ 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)
+ */
+ return;
+ }
+
+ IJavaElement corresponding = getCorrespondingElement(element);
+ if (corresponding instanceof ISourceReference) {
+ ISourceReference reference = (ISourceReference) corresponding;
+ // set hightlight range
+ setSelection(reference, true);
+ // set outliner selection
+ if (fOutlinePage != null) {
+ fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
+ fOutlinePage.select(reference);
+ fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
+ }
+ }
}
+ 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) {
+
if (IContentOutlinePage.class.equals(required)) {
- if (fOutlinePage == null) {
- fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
- if (getEditorInput() != null)
- fOutlinePage.setInput(getEditorInput());
- }
+ if (fOutlinePage == null)
+ fOutlinePage = createOutlinePage();
return fOutlinePage;
}
if (IEncodingSupport.class.equals(required))
return fEncodingSupport;
+ if (required == IShowInTargetList.class) {
+ return new IShowInTargetList() {
+ public String[] getShowInTargetIds() {
+ return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
+ }
+
+ };
+ }
+ if (fProjectionSupport != null) {
+ 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) {
+ // fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
+ // if (getEditorInput() != null)
+ // fOutlinePage.setInput(getEditorInput());
+ // }
+ // return fOutlinePage;
+ // }
+ //
+ // if (IEncodingSupport.class.equals(required))
+ // return fEncodingSupport;
+ //
+ // return super.getAdapter(required);
+ // }
protected void doSelectionChanged(SelectionChangedEvent event) {
+ ISourceReference reference = null;
+
+ ISelection selection = event.getSelection();
+ Iterator iter = ((IStructuredSelection) selection).iterator();
+ while (iter.hasNext()) {
+ Object o = iter.next();
+ if (o instanceof ISourceReference) {
+ reference = (ISourceReference) o;
+ break;
+ }
+ }
- // ISourceReference reference= null;
- //
- // ISelection selection= event.getSelection();
- // Iterator iter= ((IStructuredSelection) selection).iterator();
- // while (iter.hasNext()) {
- // Object o= iter.next();
- // if (o instanceof ISourceReference) {
- // reference= (ISourceReference) o;
- // break;
- // }
- // }
if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
PHPeclipsePlugin.getActivePage().bringToTop(this);
- // try {
- // editingScriptStarted();
- // setSelection(reference, !isActivePart());
- // } finally {
- // editingScriptEnded();
- // }
+ try {
+ editingScriptStarted();
+ setSelection(reference, !isActivePart());
+ } finally {
+ editingScriptEnded();
+ }
}
+ /*
+ * @see AbstractTextEditor#adjustHighlightRange(int, int)
+ */
+ protected void adjustHighlightRange(int offset, int length) {
+
+ try {
+
+ IJavaElement element = getElementAt(offset);
+ while (element instanceof ISourceReference) {
+ ISourceRange range = ((ISourceReference) element).getSourceRange();
+ if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) {
+ setHighlightRange(range.getOffset(), range.getLength(), true);
+ if (fOutlinePage != null) {
+ fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
+ fOutlinePage.select((ISourceReference) element);
+ fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
+ }
+ return;
+ }
+ element = element.getParent();
+ }
+ } catch (JavaModelException x) {
+ PHPeclipsePlugin.log(x.getStatus());
+ }
+
+ resetHighlightRange();
+ }
protected boolean isActivePart() {
IWorkbenchWindow window = getSite().getWorkbenchWindow();
IPartService service = window.getPartService();
@@ -1444,7 +1934,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
return part != null && part.equals(this);
}
-
+
// public void openContextHelp() {
// IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
// ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
@@ -1500,35 +1990,91 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
}
return;
}
+
+// if (OVERVIEW_RULER.equals(property)) {
+// if (isOverviewRulerVisible())
+// showOverviewRuler();
+// else
+// hideOverviewRuler();
+// return;
+// }
+
+// if (LINE_NUMBER_RULER.equals(property)) {
+// if (isLineNumberRulerVisible())
+// showLineNumberRuler();
+// else
+// hideLineNumberRuler();
+// return;
+// }
+
+// if (fLineNumberRulerColumn != null
+// && (LINE_NUMBER_COLOR.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
+//
+// initializeLineNumberRulerColumn(fLineNumberRulerColumn);
+// }
+
+ if (isJavaEditorHoverProperty(property))
+ updateHoverBehavior();
- if (OVERVIEW_RULER.equals(property)) {
- if (isOverviewRulerVisible())
- showOverviewRuler();
- else
- hideOverviewRuler();
- return;
- }
-
- if (LINE_NUMBER_RULER.equals(property)) {
- if (isLineNumberRulerVisible())
- showLineNumberRuler();
+ if (BROWSER_LIKE_LINKS.equals(property)) {
+ if (isBrowserLikeLinks())
+ enableBrowserLikeLinks();
else
- hideLineNumberRuler();
+ disableBrowserLikeLinks();
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();
- }
-
+// 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;
+ }
} finally {
super.handlePreferenceStoreChanged(event);
}
@@ -1578,27 +2124,31 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
// }
// }
- private boolean isJavaEditorHoverProperty(String property) {
- return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
- || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
- || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
- || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
- || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
- || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
- || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
- || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
- }
+ // private boolean isJavaEditorHoverProperty(String property) {
+ // return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
+ // || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
+ // || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
+ // || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
+ // || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
+ // || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
+ // || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
+ // || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
+ // }
/**
* 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.
@@ -1636,11 +2186,12 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
* @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())))
- // sourceViewer.invalidateTextPresentation();
- // }
+ if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
+ ISourceViewer sourceViewer = getSourceViewer();
+ if (sourceViewer != null
+ && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue())))
+ sourceViewer.invalidateTextPresentation();
+ }
}
/**
@@ -1648,78 +2199,94 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
* visible according to the preference store settings.
* @return true
if the line numbers should be visible
*/
- private boolean isLineNumberRulerVisible() {
- IPreferenceStore store = getPreferenceStore();
- return store.getBoolean(LINE_NUMBER_RULER);
- }
+// protected boolean isLineNumberRulerVisible() {
+// IPreferenceStore store = getPreferenceStore();
+// return store.getBoolean(LINE_NUMBER_RULER);
+// }
/**
* Hides the line number ruler column.
*/
- private void hideLineNumberRuler() {
- IVerticalRuler v = getVerticalRuler();
- if (v instanceof CompositeRuler) {
- CompositeRuler c = (CompositeRuler) v;
- try {
- c.removeDecorator(1);
- } catch (Throwable e) {
- }
- }
- }
-
+// private void hideLineNumberRuler() {
+// IVerticalRuler v = getVerticalRuler();
+// if (v instanceof CompositeRuler) {
+// CompositeRuler c = (CompositeRuler) v;
+// try {
+// c.removeDecorator(1);
+// } catch (Throwable e) {
+// }
+// }
+// }
+
+ /*
+ * @see AbstractTextEditor#handleCursorPositionChanged()
+ */
+ 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));
- }
- }
+// protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) {
+// JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
+// IColorManager manager = textTools.getColorManager();
+//
+// IPreferenceStore store = getPreferenceStore();
+// if (store != null) {
+//
+// RGB rgb = null;
+// // foreground color
+// if (store.contains(LINE_NUMBER_COLOR)) {
+// if (store.isDefault(LINE_NUMBER_COLOR))
+// rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
+// else
+// rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
+// }
+// rulerColumn.setForeground(manager.getColor(rgb));
+//
+// rgb = null;
+// // background color
+// if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
+// if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
+// if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
+// rgb = PreferenceConverter.getDefaultColor(store, PREFERENCE_COLOR_BACKGROUND);
+// else
+// rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
+// }
+// }
+// rulerColumn.setBackground(manager.getColor(rgb));
+// }
+// }
/**
* Creates a new line number ruler column that is appropriately initialized.
*/
- protected IVerticalRulerColumn createLineNumberRulerColumn() {
- fLineNumberRulerColumn = new LineNumberRulerColumn();
- initializeLineNumberRulerColumn(fLineNumberRulerColumn);
- return fLineNumberRulerColumn;
- }
+// protected IVerticalRulerColumn createLineNumberRulerColumn() {
+// fLineNumberRulerColumn = new LineNumberRulerColumn();
+// initializeLineNumberRulerColumn(fLineNumberRulerColumn);
+// return fLineNumberRulerColumn;
+// }
/*
* @see AbstractTextEditor#createVerticalRuler()
*/
- protected IVerticalRuler createVerticalRuler() {
- CompositeRuler ruler = new CompositeRuler();
- ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
- if (isLineNumberRulerVisible())
- ruler.addDecorator(1, createLineNumberRulerColumn());
- return ruler;
- }
+// protected IVerticalRuler createVerticalRuler() {
+// CompositeRuler ruler = new CompositeRuler();
+// ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
+// if (isLineNumberRulerVisible())
+// ruler.addDecorator(1, createLineNumberRulerColumn());
+// return ruler;
+// }
private static IRegion getSignedSelection(ITextViewer viewer) {
@@ -1757,13 +2324,13 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
/** Preference key for print margin ruler 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 */
@@ -1785,19 +2352,15 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
/** 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;
+ 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;
+ 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;
+ 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;
+ 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;
/** Preference key for browser like links */
@@ -1811,8 +2374,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
*
* @since 2.1.1
*/
- private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK =
- PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
+ private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
@@ -1835,53 +2397,54 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
}
}
- protected void configureSourceViewerDecorationSupport() {
-
- fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
-
- fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
- AnnotationType.UNKNOWN,
- UNKNOWN_INDICATION_COLOR,
- UNKNOWN_INDICATION,
- UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
- 0);
- fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
- AnnotationType.BOOKMARK,
- BOOKMARK_INDICATION_COLOR,
- BOOKMARK_INDICATION,
- BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
- 1);
- fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
- AnnotationType.TASK,
- TASK_INDICATION_COLOR,
- TASK_INDICATION,
- TASK_INDICATION_IN_OVERVIEW_RULER,
- 2);
- fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
- AnnotationType.SEARCH,
- SEARCH_RESULT_INDICATION_COLOR,
- SEARCH_RESULT_INDICATION,
- SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
- 3);
- fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
- AnnotationType.WARNING,
- WARNING_INDICATION_COLOR,
- WARNING_INDICATION,
- WARNING_INDICATION_IN_OVERVIEW_RULER,
- 4);
- fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
- AnnotationType.ERROR,
- ERROR_INDICATION_COLOR,
- ERROR_INDICATION,
- ERROR_INDICATION_IN_OVERVIEW_RULER,
- 5);
-
- fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR);
- fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
- fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
-
- fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
- }
+// protected void configureSourceViewerDecorationSupport() {
+//
+// fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
+//
+// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
+// AnnotationType.UNKNOWN,
+// UNKNOWN_INDICATION_COLOR,
+// UNKNOWN_INDICATION,
+// UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
+// 0);
+// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
+// AnnotationType.BOOKMARK,
+// BOOKMARK_INDICATION_COLOR,
+// BOOKMARK_INDICATION,
+// BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
+// 1);
+// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
+// AnnotationType.TASK,
+// TASK_INDICATION_COLOR,
+// TASK_INDICATION,
+// TASK_INDICATION_IN_OVERVIEW_RULER,
+// 2);
+// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
+// AnnotationType.SEARCH,
+// SEARCH_RESULT_INDICATION_COLOR,
+// SEARCH_RESULT_INDICATION,
+// SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
+// 3);
+// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
+// AnnotationType.WARNING,
+// WARNING_INDICATION_COLOR,
+// WARNING_INDICATION,
+// WARNING_INDICATION_IN_OVERVIEW_RULER,
+// 4);
+// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
+// AnnotationType.ERROR,
+// ERROR_INDICATION_COLOR,
+// ERROR_INDICATION,
+// ERROR_INDICATION_IN_OVERVIEW_RULER,
+// 5);
+//
+// fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR);
+// fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
+// fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
+//
+// fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
+//
+// }
/**
* Jumps to the matching bracket.
*/
@@ -1969,7 +2532,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
List segmentation = new ArrayList();
for (int i = 0; i < linePartitioning.length; i++) {
- if (IPHPPartitionScannerConstants.PHP_STRING.equals(linePartitioning[i].getType()))
+ if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType()))
segmentation.add(linePartitioning[i]);
}
@@ -2043,70 +2606,251 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp
// // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
// return viewer;
// }
- protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {
+
+ public final ISourceViewer getViewer() {
+ return getSourceViewer();
+ }
+
- ISharedTextColors sharedColors = PHPeclipsePlugin.getDefault().getJavaTextTools().getColorManager();
+// 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);
+ }
+ /*
+ * @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);
- fOverviewRuler = new OverviewRuler(fAnnotationAccess, VERTICAL_RULER_WIDTH, sharedColors);
- fOverviewRuler.addHeaderAnnotationType(AnnotationType.WARNING);
- fOverviewRuler.addHeaderAnnotationType(AnnotationType.ERROR);
+ // 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#affectsTextPresentation(PropertyChangeEvent)
+ */
+ protected boolean affectsTextPresentation(PropertyChangeEvent event) {
+ JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
+ return textTools.affectsBehavior(event);
+ }
- ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, fOverviewRuler, isOverviewRulerVisible(), styles);
+ /**
+ * Jumps to the error next according to the given direction.
+ */
+ public void gotoError(boolean forward) {
+
+ ISelectionProvider provider = getSelectionProvider();
+
+ ITextSelection s = (ITextSelection) provider.getSelection();
+ Position errorPosition = new Position(0, 0);
+ IJavaAnnotation nextError = getNextError(s.getOffset(), forward, errorPosition);
+
+ if (nextError != null) {
+
+ IMarker marker = null;
+ if (nextError instanceof MarkerAnnotation)
+ marker = ((MarkerAnnotation) nextError).getMarker();
+ else {
+ Iterator e = nextError.getOverlaidIterator();
+ if (e != null) {
+ while (e.hasNext()) {
+ Object o = e.next();
+ if (o instanceof MarkerAnnotation) {
+ marker = ((MarkerAnnotation) o).getMarker();
+ break;
+ }
+ }
+ }
+ }
- StyledText text = viewer.getTextWidget();
- text.addBidiSegmentListener(new BidiSegmentListener() {
- public void lineGetSegments(BidiSegmentEvent event) {
- event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
+ if (marker != null) {
+ IWorkbenchPage page = getSite().getPage();
+ IViewPart view = view = page.findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
+ if (view instanceof TaskList) {
+ StructuredSelection ss = new StructuredSelection(marker);
+ ((TaskList) view).setSelection(ss, true);
+ }
}
- });
- // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
+ selectAndReveal(errorPosition.getOffset(), errorPosition.getLength());
+// setStatusLineErrorMessage(nextError.getMessage());
- fSourceViewerDecorationSupport = new SourceViewerDecorationSupport(viewer, fOverviewRuler, fAnnotationAccess, sharedColors);
- configureSourceViewerDecorationSupport();
+ } else {
- return viewer;
+ setStatusLineErrorMessage(null);
+
+ }
}
- protected void showOverviewRuler() {
- if (fOverviewRuler != null) {
- if (getSourceViewer() instanceof ISourceViewerExtension) {
- ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(true);
- fSourceViewerDecorationSupport.updateOverviewDecorations();
+ private IJavaAnnotation getNextError(int offset, boolean forward, Position errorPosition) {
+
+ IJavaAnnotation nextError = null;
+ Position nextErrorPosition = null;
+
+ IDocument document = getDocumentProvider().getDocument(getEditorInput());
+ int endOfDocument = document.getLength();
+ int distance = 0;
+
+ IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
+ Iterator e = new JavaAnnotationIterator(model, false);
+ while (e.hasNext()) {
+
+ IJavaAnnotation a = (IJavaAnnotation) e.next();
+ if (a.hasOverlay() || !a.isProblem())
+ continue;
+
+ Position p = model.getPosition((Annotation) a);
+ if (!p.includes(offset)) {
+
+ int currentDistance = 0;
+
+ if (forward) {
+ currentDistance = p.getOffset() - offset;
+ if (currentDistance < 0)
+ currentDistance = endOfDocument - offset + p.getOffset();
+ } else {
+ currentDistance = offset - p.getOffset();
+ if (currentDistance < 0)
+ currentDistance = offset + endOfDocument - p.getOffset();
+ }
+
+ if (nextError == null || currentDistance < distance) {
+ distance = currentDistance;
+ nextError = a;
+ nextErrorPosition = p;
+ }
}
}
- }
- protected void hideOverviewRuler() {
- if (getSourceViewer() instanceof ISourceViewerExtension) {
- fSourceViewerDecorationSupport.hideAnnotationOverview();
- ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(false);
+ if (nextErrorPosition != null) {
+ errorPosition.setOffset(nextErrorPosition.getOffset());
+ errorPosition.setLength(nextErrorPosition.getLength());
}
- }
- protected boolean isOverviewRulerVisible() {
- IPreferenceStore store = getPreferenceStore();
- return store.getBoolean(OVERVIEW_RULER);
- }
- /*
- * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
- */
- protected ISourceViewer createJavaSourceViewer(
- Composite parent,
- IVerticalRuler ruler,
- IOverviewRuler overviewRuler,
- boolean isOverviewRulerVisible,
- int styles) {
- return new SourceViewer(parent, ruler, overviewRuler, isOverviewRulerVisible(), styles);
- // return super.createSourceViewer(parent, ruler, styles);
+ 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);
+}
- /*
- * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
- */
- protected boolean affectsTextPresentation(PropertyChangeEvent event) {
- JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
- return textTools.affectsBehavior(event);
- }
+/**
+ * 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;
+ }
}