1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
13 **********************************************************************/
14 import java.lang.reflect.InvocationTargetException;
15 import java.lang.reflect.Method;
16 import java.text.BreakIterator;
17 import java.text.CharacterIterator;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.List;
23 import java.util.ResourceBundle;
24 import java.util.StringTokenizer;
26 import net.sourceforge.phpdt.core.ICompilationUnit;
27 import net.sourceforge.phpdt.core.IImportContainer;
28 import net.sourceforge.phpdt.core.IImportDeclaration;
29 import net.sourceforge.phpdt.core.IJavaElement;
30 import net.sourceforge.phpdt.core.IJavaProject;
31 import net.sourceforge.phpdt.core.IMember;
32 import net.sourceforge.phpdt.core.ISourceRange;
33 import net.sourceforge.phpdt.core.ISourceReference;
34 import net.sourceforge.phpdt.core.JavaCore;
35 import net.sourceforge.phpdt.core.JavaModelException;
36 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
37 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
38 import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
39 import net.sourceforge.phpdt.internal.ui.actions.SelectionConverter;
40 import net.sourceforge.phpdt.internal.ui.text.CustomSourceInformationControl;
41 import net.sourceforge.phpdt.internal.ui.text.DocumentCharacterIterator;
42 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
43 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
44 import net.sourceforge.phpdt.internal.ui.text.JavaWordIterator;
45 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
46 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
47 import net.sourceforge.phpdt.internal.ui.text.java.JavaExpandHover;
48 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
49 import net.sourceforge.phpdt.ui.IContextMenuConstants;
50 import net.sourceforge.phpdt.ui.JavaUI;
51 import net.sourceforge.phpdt.ui.PreferenceConstants;
52 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
53 import net.sourceforge.phpdt.ui.actions.OpenEditorActionGroup;
54 import net.sourceforge.phpdt.ui.text.JavaTextTools;
55 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
56 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
57 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
58 import net.sourceforge.phpeclipse.ui.editor.BrowserUtil;
59 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
61 import org.eclipse.core.resources.IMarker;
62 import org.eclipse.core.resources.IResource;
63 import org.eclipse.core.runtime.CoreException;
64 import org.eclipse.core.runtime.IProgressMonitor;
65 import org.eclipse.core.runtime.IStatus;
66 import org.eclipse.core.runtime.Preferences;
67 import org.eclipse.core.runtime.Status;
68 import org.eclipse.core.runtime.jobs.Job;
69 import org.eclipse.jface.action.Action;
70 import org.eclipse.jface.action.GroupMarker;
71 import org.eclipse.jface.action.IAction;
72 import org.eclipse.jface.action.MenuManager;
73 import org.eclipse.jface.action.Separator;
74 import org.eclipse.jface.preference.IPreferenceStore;
75 import org.eclipse.jface.preference.PreferenceConverter;
76 import org.eclipse.jface.text.BadLocationException;
77 import org.eclipse.jface.text.DefaultInformationControl;
78 import org.eclipse.jface.text.DocumentEvent;
79 import org.eclipse.jface.text.IDocument;
80 import org.eclipse.jface.text.IDocumentListener;
81 import org.eclipse.jface.text.IInformationControl;
82 import org.eclipse.jface.text.IInformationControlCreator;
83 import org.eclipse.jface.text.IRegion;
84 import org.eclipse.jface.text.ISynchronizable;
85 import org.eclipse.jface.text.ITextHover;
86 import org.eclipse.jface.text.ITextInputListener;
87 import org.eclipse.jface.text.ITextPresentationListener;
88 import org.eclipse.jface.text.ITextSelection;
89 import org.eclipse.jface.text.ITextViewer;
90 import org.eclipse.jface.text.ITextViewerExtension2;
91 import org.eclipse.jface.text.ITextViewerExtension3;
92 import org.eclipse.jface.text.ITextViewerExtension4;
93 import org.eclipse.jface.text.ITextViewerExtension5;
94 import org.eclipse.jface.text.ITypedRegion;
95 import org.eclipse.jface.text.Position;
96 import org.eclipse.jface.text.Region;
97 import org.eclipse.jface.text.TextPresentation;
98 import org.eclipse.jface.text.TextSelection;
99 import org.eclipse.jface.text.TextUtilities;
100 import org.eclipse.jface.text.information.IInformationProvider;
101 import org.eclipse.jface.text.information.InformationPresenter;
102 import org.eclipse.jface.text.reconciler.IReconciler;
103 import org.eclipse.jface.text.source.Annotation;
104 import org.eclipse.jface.text.source.AnnotationRulerColumn;
105 import org.eclipse.jface.text.source.CompositeRuler;
106 import org.eclipse.jface.text.source.IAnnotationModel;
107 import org.eclipse.jface.text.source.IAnnotationModelExtension;
108 import org.eclipse.jface.text.source.IOverviewRuler;
109 import org.eclipse.jface.text.source.ISourceViewer;
110 import org.eclipse.jface.text.source.ISourceViewerExtension2;
111 import org.eclipse.jface.text.source.IVerticalRuler;
112 import org.eclipse.jface.text.source.OverviewRuler;
113 import org.eclipse.jface.text.source.SourceViewerConfiguration;
114 import org.eclipse.jface.text.source.projection.ProjectionSupport;
115 import org.eclipse.jface.text.source.projection.ProjectionViewer;
116 import org.eclipse.jface.util.IPropertyChangeListener;
117 import org.eclipse.jface.util.ListenerList;
118 import org.eclipse.jface.util.PropertyChangeEvent;
119 import org.eclipse.jface.viewers.DoubleClickEvent;
120 import org.eclipse.jface.viewers.IDoubleClickListener;
121 import org.eclipse.jface.viewers.IPostSelectionProvider;
122 import org.eclipse.jface.viewers.ISelection;
123 import org.eclipse.jface.viewers.ISelectionChangedListener;
124 import org.eclipse.jface.viewers.ISelectionProvider;
125 import org.eclipse.jface.viewers.IStructuredSelection;
126 import org.eclipse.jface.viewers.SelectionChangedEvent;
127 import org.eclipse.jface.viewers.StructuredSelection;
128 import org.eclipse.swt.SWT;
129 import org.eclipse.swt.custom.BidiSegmentEvent;
130 import org.eclipse.swt.custom.BidiSegmentListener;
131 import org.eclipse.swt.custom.ST;
132 import org.eclipse.swt.custom.StyleRange;
133 import org.eclipse.swt.custom.StyledText;
134 import org.eclipse.swt.events.FocusEvent;
135 import org.eclipse.swt.events.FocusListener;
136 import org.eclipse.swt.events.KeyEvent;
137 import org.eclipse.swt.events.KeyListener;
138 import org.eclipse.swt.events.MouseEvent;
139 import org.eclipse.swt.events.MouseListener;
140 import org.eclipse.swt.events.MouseMoveListener;
141 import org.eclipse.swt.events.PaintEvent;
142 import org.eclipse.swt.events.PaintListener;
143 import org.eclipse.swt.graphics.Color;
144 import org.eclipse.swt.graphics.Cursor;
145 import org.eclipse.swt.graphics.GC;
146 import org.eclipse.swt.graphics.Image;
147 import org.eclipse.swt.graphics.Point;
148 import org.eclipse.swt.graphics.RGB;
149 import org.eclipse.swt.widgets.Composite;
150 import org.eclipse.swt.widgets.Control;
151 import org.eclipse.swt.widgets.Display;
152 import org.eclipse.swt.widgets.Shell;
153 import org.eclipse.ui.IEditorInput;
154 import org.eclipse.ui.IPageLayout;
155 import org.eclipse.ui.IPartService;
156 import org.eclipse.ui.ISelectionListener;
157 import org.eclipse.ui.IViewPart;
158 import org.eclipse.ui.IWorkbenchPage;
159 import org.eclipse.ui.IWorkbenchPart;
160 import org.eclipse.ui.IWorkbenchWindow;
161 import org.eclipse.ui.actions.ActionContext;
162 import org.eclipse.ui.actions.ActionGroup;
163 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
164 import org.eclipse.ui.editors.text.EditorsUI;
165 import org.eclipse.ui.editors.text.IEncodingSupport;
166 import org.eclipse.ui.part.FileEditorInput;
167 import org.eclipse.ui.part.IShowInSource;
168 import org.eclipse.ui.part.IShowInTargetList;
169 import org.eclipse.ui.part.ShowInContext;
170 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
171 import org.eclipse.ui.texteditor.AnnotationPreference;
172 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
173 import org.eclipse.ui.texteditor.IDocumentProvider;
174 import org.eclipse.ui.texteditor.IEditorStatusLine;
175 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
176 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
177 import org.eclipse.ui.texteditor.IUpdate;
178 import org.eclipse.ui.texteditor.MarkerAnnotation;
179 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
180 import org.eclipse.ui.texteditor.TextEditorAction;
181 import org.eclipse.ui.texteditor.TextNavigationAction;
182 import org.eclipse.ui.texteditor.TextOperationAction;
183 import org.eclipse.ui.views.contentoutline.ContentOutline;
184 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
185 import org.eclipse.ui.views.tasklist.TaskList;
188 * PHP specific text editor.
190 public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider, IShowInTargetList,
192 // extends StatusTextEditor implements IViewPartInputProvider { // extends
196 * Internal implementation class for a change listener.
200 protected abstract class AbstractSelectionChangedListener implements ISelectionChangedListener {
203 * Installs this selection changed listener with the given selection
204 * provider. If the selection provider is a post selection provider, post
205 * selection changed events are the preferred choice, otherwise normal
206 * selection changed events are requested.
208 * @param selectionProvider
210 public void install(ISelectionProvider selectionProvider) {
211 if (selectionProvider == null)
214 if (selectionProvider instanceof IPostSelectionProvider) {
215 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
216 provider.addPostSelectionChangedListener(this);
218 selectionProvider.addSelectionChangedListener(this);
223 * Removes this selection changed listener from the given selection
226 * @param selectionProvider
227 * the selection provider
229 public void uninstall(ISelectionProvider selectionProvider) {
230 if (selectionProvider == null)
233 if (selectionProvider instanceof IPostSelectionProvider) {
234 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
235 provider.removePostSelectionChangedListener(this);
237 selectionProvider.removeSelectionChangedListener(this);
243 * Updates the Java outline page selection and this editor's range indicator.
247 private class EditorSelectionChangedListener extends AbstractSelectionChangedListener {
250 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
252 public void selectionChanged(SelectionChangedEvent event) {
253 // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161
254 PHPEditor.this.selectionChanged();
259 * "Smart" runnable for updating the outline page's selection.
261 // class OutlinePageSelectionUpdater implements Runnable {
263 // /** Has the runnable already been posted? */
264 // private boolean fPosted = false;
266 // public OutlinePageSelectionUpdater() {
270 // * @see Runnable#run()
272 // public void run() {
273 // synchronizeOutlinePageSelection();
278 // * Posts this runnable into the event queue.
280 // public void post() {
284 // Shell shell = getSite().getShell();
285 // if (shell != null & !shell.isDisposed()) {
287 // shell.getDisplay().asyncExec(this);
291 class SelectionChangedListener implements ISelectionChangedListener {
292 public void selectionChanged(SelectionChangedEvent event) {
293 doSelectionChanged(event);
298 * Adapts an options {@link java.util.Map}to
299 * {@link org.eclipse.jface.preference.IPreferenceStore}.
301 * This preference store is read-only i.e. write access throws an
302 * {@link java.lang.UnsupportedOperationException}.
307 private static class OptionsAdapter implements IPreferenceStore {
310 * A property change event filter.
312 public interface IPropertyChangeEventFilter {
315 * Should the given event be filtered?
318 * The property change event.
319 * @return <code>true</code> iff the given event should be filtered.
321 public boolean isFiltered(PropertyChangeEvent event);
326 * Property change listener. Listens for events in the options Map and fires
327 * a {@link org.eclipse.jface.util.PropertyChangeEvent}on this adapter with
328 * arguments from the received event.
330 private class PropertyChangeListener implements IPropertyChangeListener {
335 public void propertyChange(PropertyChangeEvent event) {
336 if (getFilter().isFiltered(event))
339 if (event.getNewValue() == null)
340 fOptions.remove(event.getProperty());
342 fOptions.put(event.getProperty(), event.getNewValue());
344 firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
348 /** Listeners on this adapter */
349 private ListenerList fListeners = new ListenerList();
351 /** Listener on the adapted options Map */
352 private IPropertyChangeListener fListener = new PropertyChangeListener();
354 /** Adapted options Map */
355 private Map fOptions;
357 /** Preference store through which events are received. */
358 private IPreferenceStore fMockupPreferenceStore;
360 /** Property event filter. */
361 private IPropertyChangeEventFilter fFilter;
364 * Initialize with the given options.
367 * The options to wrap
368 * @param mockupPreferenceStore
369 * the mock-up preference store
371 * the property change filter
373 public OptionsAdapter(Map options, IPreferenceStore mockupPreferenceStore, IPropertyChangeEventFilter filter) {
374 fMockupPreferenceStore = mockupPreferenceStore;
382 public void addPropertyChangeListener(IPropertyChangeListener listener) {
383 if (fListeners.size() == 0)
384 fMockupPreferenceStore.addPropertyChangeListener(fListener);
385 fListeners.add(listener);
391 public void removePropertyChangeListener(IPropertyChangeListener listener) {
392 fListeners.remove(listener);
393 if (fListeners.size() == 0)
394 fMockupPreferenceStore.removePropertyChangeListener(fListener);
400 public boolean contains(String name) {
401 return fOptions.containsKey(name);
407 public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
408 PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
409 Object[] listeners = fListeners.getListeners();
410 for (int i = 0; i < listeners.length; i++)
411 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
417 public boolean getBoolean(String name) {
418 boolean value = BOOLEAN_DEFAULT_DEFAULT;
419 String s = (String) fOptions.get(name);
421 value = s.equals(TRUE);
428 public boolean getDefaultBoolean(String name) {
429 return BOOLEAN_DEFAULT_DEFAULT;
435 public double getDefaultDouble(String name) {
436 return DOUBLE_DEFAULT_DEFAULT;
442 public float getDefaultFloat(String name) {
443 return FLOAT_DEFAULT_DEFAULT;
449 public int getDefaultInt(String name) {
450 return INT_DEFAULT_DEFAULT;
456 public long getDefaultLong(String name) {
457 return LONG_DEFAULT_DEFAULT;
463 public String getDefaultString(String name) {
464 return STRING_DEFAULT_DEFAULT;
470 public double getDouble(String name) {
471 double value = DOUBLE_DEFAULT_DEFAULT;
472 String s = (String) fOptions.get(name);
475 value = new Double(s).doubleValue();
476 } catch (NumberFormatException e) {
485 public float getFloat(String name) {
486 float value = FLOAT_DEFAULT_DEFAULT;
487 String s = (String) fOptions.get(name);
490 value = new Float(s).floatValue();
491 } catch (NumberFormatException e) {
500 public int getInt(String name) {
501 int value = INT_DEFAULT_DEFAULT;
502 String s = (String) fOptions.get(name);
505 value = new Integer(s).intValue();
506 } catch (NumberFormatException e) {
515 public long getLong(String name) {
516 long value = LONG_DEFAULT_DEFAULT;
517 String s = (String) fOptions.get(name);
520 value = new Long(s).longValue();
521 } catch (NumberFormatException e) {
530 public String getString(String name) {
531 String value = (String) fOptions.get(name);
533 value = STRING_DEFAULT_DEFAULT;
540 public boolean isDefault(String name) {
547 public boolean needsSaving() {
548 return !fOptions.isEmpty();
554 public void putValue(String name, String value) {
555 throw new UnsupportedOperationException();
561 public void setDefault(String name, double value) {
562 throw new UnsupportedOperationException();
568 public void setDefault(String name, float value) {
569 throw new UnsupportedOperationException();
575 public void setDefault(String name, int value) {
576 throw new UnsupportedOperationException();
582 public void setDefault(String name, long value) {
583 throw new UnsupportedOperationException();
589 public void setDefault(String name, String defaultObject) {
590 throw new UnsupportedOperationException();
596 public void setDefault(String name, boolean value) {
597 throw new UnsupportedOperationException();
603 public void setToDefault(String name) {
604 throw new UnsupportedOperationException();
610 public void setValue(String name, double value) {
611 throw new UnsupportedOperationException();
617 public void setValue(String name, float value) {
618 throw new UnsupportedOperationException();
624 public void setValue(String name, int value) {
625 throw new UnsupportedOperationException();
631 public void setValue(String name, long value) {
632 throw new UnsupportedOperationException();
638 public void setValue(String name, String value) {
639 throw new UnsupportedOperationException();
645 public void setValue(String name, boolean value) {
646 throw new UnsupportedOperationException();
650 * Returns the adapted options Map.
652 * @return Returns the adapted options Map.
654 public Map getOptions() {
659 * Returns the mock-up preference store, events are received through this
662 * @return Returns the mock-up preference store.
664 public IPreferenceStore getMockupPreferenceStore() {
665 return fMockupPreferenceStore;
669 * Set the event filter to the given filter.
674 public void setFilter(IPropertyChangeEventFilter filter) {
679 * Returns the event filter.
681 * @return The event filter.
683 public IPropertyChangeEventFilter getFilter() {
691 // class MouseClickListener implements KeyListener, MouseListener,
692 // MouseMoveListener, FocusListener, PaintListener,
693 // IPropertyChangeListener, IDocumentListener, ITextInputListener {
695 // /** The session is active. */
696 // private boolean fActive;
698 // /** The currently active style range. */
699 // private IRegion fActiveRegion;
701 // /** The currently active style range as position. */
702 // private Position fRememberedPosition;
704 // /** The hand cursor. */
705 // private Cursor fCursor;
707 // /** The link color. */
708 // private Color fColor;
710 // /** The key modifier mask. */
711 // private int fKeyModifierMask;
713 // public void deactivate() {
714 // deactivate(false);
717 // public void deactivate(boolean redrawAll) {
721 // repairRepresentation(redrawAll);
725 // public void install() {
727 // ISourceViewer sourceViewer = getSourceViewer();
728 // if (sourceViewer == null)
731 // StyledText text = sourceViewer.getTextWidget();
732 // if (text == null || text.isDisposed())
735 // updateColor(sourceViewer);
737 // sourceViewer.addTextInputListener(this);
739 // IDocument document = sourceViewer.getDocument();
740 // if (document != null)
741 // document.addDocumentListener(this);
743 // text.addKeyListener(this);
744 // text.addMouseListener(this);
745 // text.addMouseMoveListener(this);
746 // text.addFocusListener(this);
747 // text.addPaintListener(this);
749 // updateKeyModifierMask();
751 // IPreferenceStore preferenceStore = getPreferenceStore();
752 // preferenceStore.addPropertyChangeListener(this);
755 // private void updateKeyModifierMask() {
756 // String modifiers =
757 // getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
758 // fKeyModifierMask = computeStateMask(modifiers);
759 // if (fKeyModifierMask == -1) {
760 // // Fallback to stored state mask
761 // fKeyModifierMask =
762 // getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
767 // private int computeStateMask(String modifiers) {
768 // if (modifiers == null)
771 // if (modifiers.length() == 0)
774 // int stateMask = 0;
775 // StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-*
777 // while (modifierTokenizer.hasMoreTokens()) {
779 // EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
780 // if (modifier == 0 || (stateMask & modifier) == modifier)
782 // stateMask = stateMask | modifier;
787 // public void uninstall() {
789 // if (fColor != null) {
794 // if (fCursor != null) {
795 // fCursor.dispose();
799 // ISourceViewer sourceViewer = getSourceViewer();
800 // if (sourceViewer == null)
803 // sourceViewer.removeTextInputListener(this);
805 // IDocument document = sourceViewer.getDocument();
806 // if (document != null)
807 // document.removeDocumentListener(this);
809 // IPreferenceStore preferenceStore = getPreferenceStore();
810 // if (preferenceStore != null)
811 // preferenceStore.removePropertyChangeListener(this);
813 // StyledText text = sourceViewer.getTextWidget();
814 // if (text == null || text.isDisposed())
817 // text.removeKeyListener(this);
818 // text.removeMouseListener(this);
819 // text.removeMouseMoveListener(this);
820 // text.removeFocusListener(this);
821 // text.removePaintListener(this);
825 // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
827 // public void propertyChange(PropertyChangeEvent event) {
828 // if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
829 // ISourceViewer viewer = getSourceViewer();
830 // if (viewer != null)
831 // updateColor(viewer);
832 // } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
833 // updateKeyModifierMask();
837 // private void updateColor(ISourceViewer viewer) {
838 // if (fColor != null)
841 // StyledText text = viewer.getTextWidget();
842 // if (text == null || text.isDisposed())
845 // Display display = text.getDisplay();
846 // fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
850 // * Creates a color from the information stored in the given preference
851 // store. Returns <code>null</code> if there is no such
852 // * information available.
854 // private Color createColor(IPreferenceStore store, String key, Display
859 // if (store.contains(key)) {
861 // if (store.isDefault(key))
862 // rgb = PreferenceConverter.getDefaultColor(store, key);
864 // rgb = PreferenceConverter.getColor(store, key);
867 // return new Color(display, rgb);
873 // private void repairRepresentation() {
874 // repairRepresentation(false);
877 // private void repairRepresentation(boolean redrawAll) {
879 // if (fActiveRegion == null)
882 // ISourceViewer viewer = getSourceViewer();
883 // if (viewer != null) {
884 // resetCursor(viewer);
886 // int offset = fActiveRegion.getOffset();
887 // int length = fActiveRegion.getLength();
890 // if (!redrawAll && viewer instanceof ITextViewerExtension2)
891 // ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset,
894 // viewer.invalidateTextPresentation();
896 // // remove underline
897 // if (viewer instanceof ITextViewerExtension3) {
898 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
899 // offset = extension.modelOffset2WidgetOffset(offset);
901 // offset -= viewer.getVisibleRegion().getOffset();
904 // StyledText text = viewer.getTextWidget();
906 // text.redrawRange(offset, length, true);
907 // } catch (IllegalArgumentException x) {
908 // PHPeclipsePlugin.log(x);
912 // fActiveRegion = null;
915 // // will eventually be replaced by a method provided by jdt.core
916 // private IRegion selectWord(IDocument document, int anchor) {
919 // int offset = anchor;
922 // while (offset >= 0) {
923 // c = document.getChar(offset);
924 // if (!Scanner.isPHPIdentifierPart(c))
929 // int start = offset;
932 // int length = document.getLength();
934 // while (offset < length) {
935 // c = document.getChar(offset);
936 // if (!Scanner.isPHPIdentifierPart(c))
944 // return new Region(start, 0);
946 // return new Region(start + 1, end - start - 1);
948 // } catch (BadLocationException x) {
953 // IRegion getCurrentTextRegion(ISourceViewer viewer) {
955 // int offset = getCurrentTextOffset(viewer);
960 // // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
961 // // if (input == null)
966 // // IJavaElement[] elements= null;
967 // // synchronized (input) {
968 // // elements= ((ICodeAssist) input).codeSelect(offset, 0);
971 // // if (elements == null || elements.length == 0)
974 // // return selectWord(viewer.getDocument(), offset);
976 // // } catch (JavaModelException e) {
981 // private int getCurrentTextOffset(ISourceViewer viewer) {
984 // StyledText text = viewer.getTextWidget();
985 // if (text == null || text.isDisposed())
988 // Display display = text.getDisplay();
989 // Point absolutePosition = display.getCursorLocation();
990 // Point relativePosition = text.toControl(absolutePosition);
992 // int widgetOffset = text.getOffsetAtLocation(relativePosition);
993 // if (viewer instanceof ITextViewerExtension3) {
994 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
995 // return extension.widgetOffset2ModelOffset(widgetOffset);
997 // return widgetOffset + viewer.getVisibleRegion().getOffset();
1000 // } catch (IllegalArgumentException e) {
1005 // private void highlightRegion(ISourceViewer viewer, IRegion region) {
1007 // if (region.equals(fActiveRegion))
1010 // repairRepresentation();
1012 // StyledText text = viewer.getTextWidget();
1013 // if (text == null || text.isDisposed())
1016 // // highlight region
1020 // if (viewer instanceof ITextViewerExtension3) {
1021 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1022 // IRegion widgetRange = extension.modelRange2WidgetRange(region);
1023 // if (widgetRange == null)
1026 // offset = widgetRange.getOffset();
1027 // length = widgetRange.getLength();
1030 // offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
1031 // length = region.getLength();
1034 // StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
1035 // Color foregroundColor = fColor;
1036 // Color backgroundColor = oldStyleRange == null ? text.getBackground() :
1037 // oldStyleRange.background;
1038 // StyleRange styleRange = new StyleRange(offset, length, foregroundColor,
1039 // backgroundColor);
1040 // text.setStyleRange(styleRange);
1043 // text.redrawRange(offset, length, true);
1045 // fActiveRegion = region;
1048 // private void activateCursor(ISourceViewer viewer) {
1049 // StyledText text = viewer.getTextWidget();
1050 // if (text == null || text.isDisposed())
1052 // Display display = text.getDisplay();
1053 // if (fCursor == null)
1054 // fCursor = new Cursor(display, SWT.CURSOR_HAND);
1055 // text.setCursor(fCursor);
1058 // private void resetCursor(ISourceViewer viewer) {
1059 // StyledText text = viewer.getTextWidget();
1060 // if (text != null && !text.isDisposed())
1061 // text.setCursor(null);
1063 // if (fCursor != null) {
1064 // fCursor.dispose();
1071 // org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1073 // public void keyPressed(KeyEvent event) {
1080 // if (event.keyCode != fKeyModifierMask) {
1087 // // removed for #25871
1089 // // ISourceViewer viewer= getSourceViewer();
1090 // // if (viewer == null)
1093 // // IRegion region= getCurrentTextRegion(viewer);
1094 // // if (region == null)
1097 // // highlightRegion(viewer, region);
1098 // // activateCursor(viewer);
1103 // org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1105 // public void keyReleased(KeyEvent event) {
1115 // org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1117 // public void mouseDoubleClick(MouseEvent e) {
1122 // org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1124 // public void mouseDown(MouseEvent event) {
1129 // if (event.stateMask != fKeyModifierMask) {
1134 // if (event.button != 1) {
1142 // org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1144 // public void mouseUp(MouseEvent e) {
1149 // if (e.button != 1) {
1154 // boolean wasActive = fCursor != null;
1159 // IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1160 // if (action != null)
1167 // org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1169 // public void mouseMove(MouseEvent event) {
1171 // if (event.widget instanceof Control && !((Control)
1172 // event.widget).isFocusControl()) {
1178 // if (event.stateMask != fKeyModifierMask)
1180 // // modifier was already pressed
1184 // ISourceViewer viewer = getSourceViewer();
1185 // if (viewer == null) {
1190 // StyledText text = viewer.getTextWidget();
1191 // if (text == null || text.isDisposed()) {
1196 // if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0)
1202 // IRegion region = getCurrentTextRegion(viewer);
1203 // if (region == null || region.getLength() == 0) {
1204 // repairRepresentation();
1208 // highlightRegion(viewer, region);
1209 // activateCursor(viewer);
1214 // org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1216 // public void focusGained(FocusEvent e) {
1221 // org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1223 // public void focusLost(FocusEvent event) {
1229 // org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1231 // public void documentAboutToBeChanged(DocumentEvent event) {
1232 // if (fActive && fActiveRegion != null) {
1233 // fRememberedPosition = new Position(fActiveRegion.getOffset(),
1234 // fActiveRegion.getLength());
1236 // event.getDocument().addPosition(fRememberedPosition);
1237 // } catch (BadLocationException x) {
1238 // fRememberedPosition = null;
1245 // org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1247 // public void documentChanged(DocumentEvent event) {
1248 // if (fRememberedPosition != null && !fRememberedPosition.isDeleted()) {
1249 // event.getDocument().removePosition(fRememberedPosition);
1250 // fActiveRegion = new Region(fRememberedPosition.getOffset(),
1251 // fRememberedPosition.getLength());
1253 // fRememberedPosition = null;
1255 // ISourceViewer viewer = getSourceViewer();
1256 // if (viewer != null) {
1257 // StyledText widget = viewer.getTextWidget();
1258 // if (widget != null && !widget.isDisposed()) {
1259 // widget.getDisplay().asyncExec(new Runnable() {
1260 // public void run() {
1270 // org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
1271 // * org.eclipse.jface.text.IDocument)
1273 // public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument
1275 // if (oldInput == null)
1278 // oldInput.removeDocumentListener(this);
1283 // org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
1284 // * org.eclipse.jface.text.IDocument)
1286 // public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
1287 // if (newInput == null)
1289 // newInput.addDocumentListener(this);
1293 // * @see PaintListener#paintControl(PaintEvent)
1295 // public void paintControl(PaintEvent event) {
1296 // if (fActiveRegion == null)
1299 // ISourceViewer viewer = getSourceViewer();
1300 // if (viewer == null)
1303 // StyledText text = viewer.getTextWidget();
1304 // if (text == null || text.isDisposed())
1310 // if (viewer instanceof ITextViewerExtension3) {
1312 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1313 // IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset,
1315 // if (widgetRange == null)
1318 // offset = widgetRange.getOffset();
1319 // length = widgetRange.getLength();
1323 // IRegion region = viewer.getVisibleRegion();
1324 // if (!includes(region, fActiveRegion))
1327 // offset = fActiveRegion.getOffset() - region.getOffset();
1328 // length = fActiveRegion.getLength();
1331 // // support for bidi
1332 // Point minLocation = getMinimumLocation(text, offset, length);
1333 // Point maxLocation = getMaximumLocation(text, offset, length);
1335 // int x1 = minLocation.x;
1336 // int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
1337 // int y = minLocation.y + text.getLineHeight() - 1;
1339 // GC gc = event.gc;
1340 // if (fColor != null && !fColor.isDisposed())
1341 // gc.setForeground(fColor);
1342 // gc.drawLine(x1, y, x2, y);
1345 // private boolean includes(IRegion region, IRegion position) {
1346 // return position.getOffset() >= region.getOffset()
1347 // && position.getOffset() + position.getLength() <= region.getOffset() +
1348 // region.getLength();
1351 // private Point getMinimumLocation(StyledText text, int offset, int length) {
1352 // Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
1354 // for (int i = 0; i <= length; i++) {
1355 // Point location = text.getLocationAtOffset(offset + i);
1357 // if (location.x < minLocation.x)
1358 // minLocation.x = location.x;
1359 // if (location.y < minLocation.y)
1360 // minLocation.y = location.y;
1363 // return minLocation;
1366 // private Point getMaximumLocation(StyledText text, int offset, int length) {
1367 // Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
1369 // for (int i = 0; i <= length; i++) {
1370 // Point location = text.getLocationAtOffset(offset + i);
1372 // if (location.x > maxLocation.x)
1373 // maxLocation.x = location.x;
1374 // if (location.y > maxLocation.y)
1375 // maxLocation.y = location.y;
1378 // return maxLocation;
1384 class MouseClickListener implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener,
1385 IPropertyChangeListener, IDocumentListener, ITextInputListener, ITextPresentationListener {
1387 /** The session is active. */
1388 private boolean fActive;
1390 /** The currently active style range. */
1391 private IRegion fActiveRegion;
1393 /** The currently active style range as position. */
1394 private Position fRememberedPosition;
1396 /** The hand cursor. */
1397 private Cursor fCursor;
1399 /** The link color. */
1400 private Color fColor;
1402 /** The key modifier mask. */
1403 private int fKeyModifierMask;
1405 public void deactivate() {
1409 public void deactivate(boolean redrawAll) {
1413 repairRepresentation(redrawAll);
1417 public void install() {
1418 ISourceViewer sourceViewer = getSourceViewer();
1419 if (sourceViewer == null)
1422 StyledText text = sourceViewer.getTextWidget();
1423 if (text == null || text.isDisposed())
1426 updateColor(sourceViewer);
1428 sourceViewer.addTextInputListener(this);
1430 IDocument document = sourceViewer.getDocument();
1431 if (document != null)
1432 document.addDocumentListener(this);
1434 text.addKeyListener(this);
1435 text.addMouseListener(this);
1436 text.addMouseMoveListener(this);
1437 text.addFocusListener(this);
1438 text.addPaintListener(this);
1440 ((ITextViewerExtension4) sourceViewer).addTextPresentationListener(this);
1442 updateKeyModifierMask();
1444 IPreferenceStore preferenceStore = getPreferenceStore();
1445 preferenceStore.addPropertyChangeListener(this);
1448 private void updateKeyModifierMask() {
1449 String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
1450 fKeyModifierMask = computeStateMask(modifiers);
1451 if (fKeyModifierMask == -1) {
1452 // Fall back to stored state mask
1453 fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
1457 private int computeStateMask(String modifiers) {
1458 if (modifiers == null)
1461 if (modifiers.length() == 0)
1465 StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
1466 while (modifierTokenizer.hasMoreTokens()) {
1467 int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
1468 if (modifier == 0 || (stateMask & modifier) == modifier)
1470 stateMask = stateMask | modifier;
1475 public void uninstall() {
1477 if (fColor != null) {
1482 if (fCursor != null) {
1487 ISourceViewer sourceViewer = getSourceViewer();
1488 if (sourceViewer != null)
1489 sourceViewer.removeTextInputListener(this);
1491 IDocumentProvider documentProvider = getDocumentProvider();
1492 if (documentProvider != null) {
1493 IDocument document = documentProvider.getDocument(getEditorInput());
1494 if (document != null)
1495 document.removeDocumentListener(this);
1498 IPreferenceStore preferenceStore = getPreferenceStore();
1499 if (preferenceStore != null)
1500 preferenceStore.removePropertyChangeListener(this);
1502 if (sourceViewer == null)
1505 StyledText text = sourceViewer.getTextWidget();
1506 if (text == null || text.isDisposed())
1509 text.removeKeyListener(this);
1510 text.removeMouseListener(this);
1511 text.removeMouseMoveListener(this);
1512 text.removeFocusListener(this);
1513 text.removePaintListener(this);
1515 ((ITextViewerExtension4) sourceViewer).removeTextPresentationListener(this);
1519 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
1521 public void propertyChange(PropertyChangeEvent event) {
1522 if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
1523 ISourceViewer viewer = getSourceViewer();
1525 updateColor(viewer);
1526 } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
1527 updateKeyModifierMask();
1531 private void updateColor(ISourceViewer viewer) {
1535 StyledText text = viewer.getTextWidget();
1536 if (text == null || text.isDisposed())
1539 Display display = text.getDisplay();
1540 fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
1544 * Creates a color from the information stored in the given preference
1548 * the preference store
1553 * @return the color or <code>null</code> if there is no such information
1556 private Color createColor(IPreferenceStore store, String key, Display display) {
1560 if (store.contains(key)) {
1562 if (store.isDefault(key))
1563 rgb = PreferenceConverter.getDefaultColor(store, key);
1565 rgb = PreferenceConverter.getColor(store, key);
1568 return new Color(display, rgb);
1574 private void repairRepresentation() {
1575 repairRepresentation(false);
1578 private void repairRepresentation(boolean redrawAll) {
1580 if (fActiveRegion == null)
1583 int offset = fActiveRegion.getOffset();
1584 int length = fActiveRegion.getLength();
1585 fActiveRegion = null;
1587 ISourceViewer viewer = getSourceViewer();
1588 if (viewer != null) {
1590 resetCursor(viewer);
1592 // Invalidate ==> remove applied text presentation
1593 if (!redrawAll && viewer instanceof ITextViewerExtension2)
1594 ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
1596 viewer.invalidateTextPresentation();
1599 if (viewer instanceof ITextViewerExtension5) {
1600 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1601 offset = extension.modelOffset2WidgetOffset(offset);
1603 offset -= viewer.getVisibleRegion().getOffset();
1606 StyledText text = viewer.getTextWidget();
1608 text.redrawRange(offset, length, false);
1609 } catch (IllegalArgumentException x) {
1610 // JavaPlugin.log(x);
1615 // will eventually be replaced by a method provided by jdt.core
1616 private IRegion selectWord(IDocument document, int anchor) {
1619 int offset = anchor;
1622 while (offset >= 0) {
1623 c = document.getChar(offset);
1624 if (!Scanner.isPHPIdentifierPart(c) && c != '$')
1632 int length = document.getLength();
1634 while (offset < length) {
1635 c = document.getChar(offset);
1636 if (!Scanner.isPHPIdentifierPart(c) && c != '$')
1644 return new Region(start, 0);
1646 return new Region(start + 1, end - start - 1);
1648 } catch (BadLocationException x) {
1653 IRegion getCurrentTextRegion(ISourceViewer viewer) {
1655 int offset = getCurrentTextOffset(viewer);
1659 IJavaElement input = SelectionConverter.getInput(PHPEditor.this);
1665 // IJavaElement[] elements= null;
1666 // synchronized (input) {
1667 // elements= ((ICodeAssist) input).codeSelect(offset, 0);
1670 // if (elements == null || elements.length == 0)
1673 return selectWord(viewer.getDocument(), offset);
1675 // } catch (JavaModelException e) {
1680 private int getCurrentTextOffset(ISourceViewer viewer) {
1683 StyledText text = viewer.getTextWidget();
1684 if (text == null || text.isDisposed())
1687 Display display = text.getDisplay();
1688 Point absolutePosition = display.getCursorLocation();
1689 Point relativePosition = text.toControl(absolutePosition);
1691 int widgetOffset = text.getOffsetAtLocation(relativePosition);
1692 if (viewer instanceof ITextViewerExtension5) {
1693 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1694 return extension.widgetOffset2ModelOffset(widgetOffset);
1696 return widgetOffset + viewer.getVisibleRegion().getOffset();
1699 } catch (IllegalArgumentException e) {
1704 public void applyTextPresentation(TextPresentation textPresentation) {
1705 if (fActiveRegion == null)
1707 IRegion region = textPresentation.getExtent();
1708 if (fActiveRegion.getOffset() + fActiveRegion.getLength() >= region.getOffset()
1709 && region.getOffset() + region.getLength() > fActiveRegion.getOffset())
1710 textPresentation.mergeStyleRange(new StyleRange(fActiveRegion.getOffset(), fActiveRegion.getLength(), fColor, null));
1713 private void highlightRegion(ISourceViewer viewer, IRegion region) {
1715 if (region.equals(fActiveRegion))
1718 repairRepresentation();
1720 StyledText text = viewer.getTextWidget();
1721 if (text == null || text.isDisposed())
1727 if (viewer instanceof ITextViewerExtension5) {
1728 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1729 IRegion widgetRange = extension.modelRange2WidgetRange(region);
1730 if (widgetRange == null)
1733 offset = widgetRange.getOffset();
1734 length = widgetRange.getLength();
1737 offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
1738 length = region.getLength();
1740 text.redrawRange(offset, length, false);
1742 // Invalidate region ==> apply text presentation
1743 fActiveRegion = region;
1744 if (viewer instanceof ITextViewerExtension2)
1745 ((ITextViewerExtension2) viewer).invalidateTextPresentation(region.getOffset(), region.getLength());
1747 viewer.invalidateTextPresentation();
1750 private void activateCursor(ISourceViewer viewer) {
1751 StyledText text = viewer.getTextWidget();
1752 if (text == null || text.isDisposed())
1754 Display display = text.getDisplay();
1755 if (fCursor == null)
1756 fCursor = new Cursor(display, SWT.CURSOR_HAND);
1757 text.setCursor(fCursor);
1760 private void resetCursor(ISourceViewer viewer) {
1761 StyledText text = viewer.getTextWidget();
1762 if (text != null && !text.isDisposed())
1763 text.setCursor(null);
1765 if (fCursor != null) {
1772 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1774 public void keyPressed(KeyEvent event) {
1781 if (event.keyCode != fKeyModifierMask) {
1788 // removed for #25871
1790 // ISourceViewer viewer= getSourceViewer();
1791 // if (viewer == null)
1794 // IRegion region= getCurrentTextRegion(viewer);
1795 // if (region == null)
1798 // highlightRegion(viewer, region);
1799 // activateCursor(viewer);
1803 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1805 public void keyReleased(KeyEvent event) {
1814 * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1816 public void mouseDoubleClick(MouseEvent e) {
1820 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1822 public void mouseDown(MouseEvent event) {
1827 if (event.stateMask != fKeyModifierMask) {
1832 if (event.button != 1) {
1839 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1841 public void mouseUp(MouseEvent e) {
1846 if (e.button != 1) {
1851 boolean wasActive = fCursor != null;
1856 IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1863 * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1865 public void mouseMove(MouseEvent event) {
1867 if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
1873 if (event.stateMask != fKeyModifierMask)
1875 // modifier was already pressed
1879 ISourceViewer viewer = getSourceViewer();
1880 if (viewer == null) {
1885 StyledText text = viewer.getTextWidget();
1886 if (text == null || text.isDisposed()) {
1891 if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
1896 IRegion region = getCurrentTextRegion(viewer);
1897 if (region == null || region.getLength() == 0) {
1898 repairRepresentation();
1902 highlightRegion(viewer, region);
1903 activateCursor(viewer);
1907 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1909 public void focusGained(FocusEvent e) {
1913 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1915 public void focusLost(FocusEvent event) {
1920 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1922 public void documentAboutToBeChanged(DocumentEvent event) {
1923 if (fActive && fActiveRegion != null) {
1924 fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
1926 event.getDocument().addPosition(fRememberedPosition);
1927 } catch (BadLocationException x) {
1928 fRememberedPosition = null;
1934 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1936 public void documentChanged(DocumentEvent event) {
1937 if (fRememberedPosition != null) {
1938 if (!fRememberedPosition.isDeleted()) {
1940 event.getDocument().removePosition(fRememberedPosition);
1941 fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
1942 fRememberedPosition = null;
1944 ISourceViewer viewer = getSourceViewer();
1945 if (viewer != null) {
1946 StyledText widget = viewer.getTextWidget();
1947 if (widget != null && !widget.isDisposed()) {
1948 widget.getDisplay().asyncExec(new Runnable() {
1957 fActiveRegion = null;
1958 fRememberedPosition = null;
1965 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
1966 * org.eclipse.jface.text.IDocument)
1968 public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
1969 if (oldInput == null)
1972 oldInput.removeDocumentListener(this);
1976 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
1977 * org.eclipse.jface.text.IDocument)
1979 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
1980 if (newInput == null)
1982 newInput.addDocumentListener(this);
1986 * @see PaintListener#paintControl(PaintEvent)
1988 public void paintControl(PaintEvent event) {
1989 if (fActiveRegion == null)
1992 ISourceViewer viewer = getSourceViewer();
1996 StyledText text = viewer.getTextWidget();
1997 if (text == null || text.isDisposed())
2003 if (viewer instanceof ITextViewerExtension5) {
2005 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
2006 IRegion widgetRange = extension.modelRange2WidgetRange(fActiveRegion);
2007 if (widgetRange == null)
2010 offset = widgetRange.getOffset();
2011 length = widgetRange.getLength();
2015 IRegion region = viewer.getVisibleRegion();
2016 if (!includes(region, fActiveRegion))
2019 offset = fActiveRegion.getOffset() - region.getOffset();
2020 length = fActiveRegion.getLength();
2024 Point minLocation = getMinimumLocation(text, offset, length);
2025 Point maxLocation = getMaximumLocation(text, offset, length);
2027 int x1 = minLocation.x;
2028 int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
2029 int y = minLocation.y + text.getLineHeight() - 1;
2032 if (fColor != null && !fColor.isDisposed())
2033 gc.setForeground(fColor);
2034 gc.drawLine(x1, y, x2, y);
2037 private boolean includes(IRegion region, IRegion position) {
2038 return position.getOffset() >= region.getOffset()
2039 && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
2042 private Point getMinimumLocation(StyledText text, int offset, int length) {
2043 Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
2045 for (int i = 0; i <= length; i++) {
2046 Point location = text.getLocationAtOffset(offset + i);
2048 if (location.x < minLocation.x)
2049 minLocation.x = location.x;
2050 if (location.y < minLocation.y)
2051 minLocation.y = location.y;
2057 private Point getMaximumLocation(StyledText text, int offset, int length) {
2058 Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
2060 for (int i = 0; i <= length; i++) {
2061 Point location = text.getLocationAtOffset(offset + i);
2063 if (location.x > maxLocation.x)
2064 maxLocation.x = location.x;
2065 if (location.y > maxLocation.y)
2066 maxLocation.y = location.y;
2074 * This action dispatches into two behaviours: If there is no current text
2075 * hover, the javadoc is displayed using information presenter. If there is a
2076 * current text hover, it is converted into a information presenter in order
2077 * to make it sticky.
2079 class InformationDispatchAction extends TextEditorAction {
2081 /** The wrapped text operation action. */
2082 private final TextOperationAction fTextOperationAction;
2085 * Creates a dispatch action.
2087 public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
2088 super(resourceBundle, prefix, PHPEditor.this);
2089 if (textOperationAction == null)
2090 throw new IllegalArgumentException();
2091 fTextOperationAction = textOperationAction;
2095 * @see org.eclipse.jface.action.IAction#run()
2099 ISourceViewer sourceViewer = getSourceViewer();
2100 if (sourceViewer == null) {
2101 fTextOperationAction.run();
2105 if (!(sourceViewer instanceof ITextViewerExtension2)) {
2106 fTextOperationAction.run();
2110 ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
2112 // does a text hover exist?
2113 ITextHover textHover = textViewerExtension2.getCurrentTextHover();
2114 if (textHover == null) {
2115 fTextOperationAction.run();
2119 Point hoverEventLocation = textViewerExtension2.getHoverEventLocation();
2120 int offset = computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
2122 fTextOperationAction.run();
2127 // get the text hover content
2128 IDocument document = sourceViewer.getDocument();
2129 String contentType = document.getContentType(offset);
2131 final IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
2132 if (hoverRegion == null)
2135 final String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);
2137 // with information provider
2138 IInformationProvider informationProvider = new IInformationProvider() {
2140 * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer,
2143 public IRegion getSubject(ITextViewer textViewer, int offset) {
2148 * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer,
2149 * org.eclipse.jface.text.IRegion)
2151 public String getInformation(ITextViewer textViewer, IRegion subject) {
2156 fInformationPresenter.setOffset(offset);
2157 fInformationPresenter.setInformationProvider(informationProvider, contentType);
2158 fInformationPresenter.showInformation();
2160 } catch (BadLocationException e) {
2164 // modified version from TextViewer
2165 private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
2167 StyledText styledText = textViewer.getTextWidget();
2168 IDocument document = textViewer.getDocument();
2170 if (document == null)
2174 int widgetLocation = styledText.getOffsetAtLocation(new Point(x, y));
2175 if (textViewer instanceof ITextViewerExtension3) {
2176 ITextViewerExtension3 extension = (ITextViewerExtension3) textViewer;
2177 return extension.widgetOffset2ModelOffset(widgetLocation);
2179 IRegion visibleRegion = textViewer.getVisibleRegion();
2180 return widgetLocation + visibleRegion.getOffset();
2182 } catch (IllegalArgumentException e) {
2190 * This action implements smart home.
2192 * Instead of going to the start of a line it does the following: - if smart
2193 * home/end is enabled and the caret is after the line's first non-whitespace
2194 * then the caret is moved directly before it, taking JavaDoc and multi-line
2195 * comments into account. - if the caret is before the line's first
2196 * non-whitespace the caret is moved to the beginning of the line - if the
2197 * caret is at the beginning of the line see first case.
2201 protected class SmartLineStartAction extends LineStartAction {
2204 * Creates a new smart line start action
2207 * the styled text widget
2209 * a boolean flag which tells if the text up to the beginning of
2210 * the line should be selected
2212 public SmartLineStartAction(final StyledText textWidget, final boolean doSelect) {
2213 super(textWidget, doSelect);
2217 * @see org.eclipse.ui.texteditor.AbstractTextEditor.LineStartAction#getLineStartPosition(java.lang.String,
2218 * int, java.lang.String)
2220 protected int getLineStartPosition(final IDocument document, final String line, final int length, final int offset) {
2222 String type = IDocument.DEFAULT_CONTENT_TYPE;
2224 type = TextUtilities.getContentType(document, IPHPPartitions.PHP_PARTITIONING, offset, true);
2225 } catch (BadLocationException exception) {
2226 // Should not happen
2229 int index = super.getLineStartPosition(document, line, length, offset);
2230 if (type.equals(IPHPPartitions.PHP_PHPDOC_COMMENT) || type.equals(IPHPPartitions.PHP_MULTILINE_COMMENT)) {
2231 if (index < length - 1 && line.charAt(index) == '*' && line.charAt(index + 1) != '/') {
2234 } while (index < length && Character.isWhitespace(line.charAt(index)));
2237 if (index < length - 1 && line.charAt(index) == '/' && line.charAt(index + 1) == '/') {
2241 } while (index < length && Character.isWhitespace(line.charAt(index)));
2249 * Text navigation action to navigate to the next sub-word.
2253 protected abstract class NextSubWordAction extends TextNavigationAction {
2255 protected JavaWordIterator fIterator = new JavaWordIterator();
2258 * Creates a new next sub-word action.
2261 * Action code for the default operation. Must be an action code
2263 * @see org.eclipse.swt.custom.ST.
2265 protected NextSubWordAction(int code) {
2266 super(getSourceViewer().getTextWidget(), code);
2270 * @see org.eclipse.jface.action.IAction#run()
2273 // Check whether we are in a java code partition and the preference is
2275 final IPreferenceStore store = getPreferenceStore();
2276 if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
2281 final ISourceViewer viewer = getSourceViewer();
2282 final IDocument document = viewer.getDocument();
2283 fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document));
2284 int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2288 int next = findNextPosition(position);
2289 if (next != BreakIterator.DONE) {
2290 setCaretPosition(next);
2291 getTextWidget().showSelection();
2292 fireSelectionChanged();
2298 * Finds the next position after the given position.
2301 * the current position
2302 * @return the next position
2304 protected int findNextPosition(int position) {
2305 ISourceViewer viewer = getSourceViewer();
2307 while (position != BreakIterator.DONE && widget == -1) { // TODO:
2309 position = fIterator.following(position);
2310 if (position != BreakIterator.DONE)
2311 widget = modelOffset2WidgetOffset(viewer, position);
2317 * Sets the caret position to the sub-word boundary given with
2318 * <code>position</code>.
2321 * Position where the action should move the caret
2323 protected abstract void setCaretPosition(int position);
2327 * Text navigation action to navigate to the next sub-word.
2331 protected class NavigateNextSubWordAction extends NextSubWordAction {
2334 * Creates a new navigate next sub-word action.
2336 public NavigateNextSubWordAction() {
2337 super(ST.WORD_NEXT);
2341 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2343 protected void setCaretPosition(final int position) {
2344 getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position));
2349 * Text operation action to delete the next sub-word.
2353 protected class DeleteNextSubWordAction extends NextSubWordAction implements IUpdate {
2356 * Creates a new delete next sub-word action.
2358 public DeleteNextSubWordAction() {
2359 super(ST.DELETE_WORD_NEXT);
2363 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2365 protected void setCaretPosition(final int position) {
2366 if (!validateEditorInputState())
2369 final ISourceViewer viewer = getSourceViewer();
2370 final int caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2373 viewer.getDocument().replace(caret, position - caret, ""); //$NON-NLS-1$
2374 } catch (BadLocationException exception) {
2375 // Should not happen
2380 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#findNextPosition(int)
2382 protected int findNextPosition(int position) {
2383 return fIterator.following(position);
2387 * @see org.eclipse.ui.texteditor.IUpdate#update()
2389 public void update() {
2390 setEnabled(isEditorInputModifiable());
2395 * Text operation action to select the next sub-word.
2399 protected class SelectNextSubWordAction extends NextSubWordAction {
2402 * Creates a new select next sub-word action.
2404 public SelectNextSubWordAction() {
2405 super(ST.SELECT_WORD_NEXT);
2409 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2411 protected void setCaretPosition(final int position) {
2412 final ISourceViewer viewer = getSourceViewer();
2414 final StyledText text = viewer.getTextWidget();
2415 if (text != null && !text.isDisposed()) {
2417 final Point selection = text.getSelection();
2418 final int caret = text.getCaretOffset();
2419 final int offset = modelOffset2WidgetOffset(viewer, position);
2421 if (caret == selection.x)
2422 text.setSelectionRange(selection.y, offset - selection.y);
2424 text.setSelectionRange(selection.x, offset - selection.x);
2430 * Text navigation action to navigate to the previous sub-word.
2434 protected abstract class PreviousSubWordAction extends TextNavigationAction {
2436 protected JavaWordIterator fIterator = new JavaWordIterator();
2439 * Creates a new previous sub-word action.
2442 * Action code for the default operation. Must be an action code
2444 * @see org.eclipse.swt.custom.ST.
2446 protected PreviousSubWordAction(final int code) {
2447 super(getSourceViewer().getTextWidget(), code);
2451 * @see org.eclipse.jface.action.IAction#run()
2454 // Check whether we are in a java code partition and the preference is
2456 final IPreferenceStore store = getPreferenceStore();
2457 if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
2462 final ISourceViewer viewer = getSourceViewer();
2463 final IDocument document = viewer.getDocument();
2464 fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document));
2465 int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2469 int previous = findPreviousPosition(position);
2470 if (previous != BreakIterator.DONE) {
2471 setCaretPosition(previous);
2472 getTextWidget().showSelection();
2473 fireSelectionChanged();
2479 * Finds the previous position before the given position.
2482 * the current position
2483 * @return the previous position
2485 protected int findPreviousPosition(int position) {
2486 ISourceViewer viewer = getSourceViewer();
2488 while (position != BreakIterator.DONE && widget == -1) { // TODO:
2490 position = fIterator.preceding(position);
2491 if (position != BreakIterator.DONE)
2492 widget = modelOffset2WidgetOffset(viewer, position);
2498 * Sets the caret position to the sub-word boundary given with
2499 * <code>position</code>.
2502 * Position where the action should move the caret
2504 protected abstract void setCaretPosition(int position);
2508 * Text navigation action to navigate to the previous sub-word.
2512 protected class NavigatePreviousSubWordAction extends PreviousSubWordAction {
2515 * Creates a new navigate previous sub-word action.
2517 public NavigatePreviousSubWordAction() {
2518 super(ST.WORD_PREVIOUS);
2522 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2524 protected void setCaretPosition(final int position) {
2525 getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position));
2530 * Text operation action to delete the previous sub-word.
2534 protected class DeletePreviousSubWordAction extends PreviousSubWordAction implements IUpdate {
2537 * Creates a new delete previous sub-word action.
2539 public DeletePreviousSubWordAction() {
2540 super(ST.DELETE_WORD_PREVIOUS);
2544 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2546 protected void setCaretPosition(final int position) {
2547 if (!validateEditorInputState())
2550 final ISourceViewer viewer = getSourceViewer();
2551 final int caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2554 viewer.getDocument().replace(position, caret - position, ""); //$NON-NLS-1$
2555 } catch (BadLocationException exception) {
2556 // Should not happen
2561 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#findPreviousPosition(int)
2563 protected int findPreviousPosition(int position) {
2564 return fIterator.preceding(position);
2568 * @see org.eclipse.ui.texteditor.IUpdate#update()
2570 public void update() {
2571 setEnabled(isEditorInputModifiable());
2576 * Text operation action to select the previous sub-word.
2580 protected class SelectPreviousSubWordAction extends PreviousSubWordAction {
2583 * Creates a new select previous sub-word action.
2585 public SelectPreviousSubWordAction() {
2586 super(ST.SELECT_WORD_PREVIOUS);
2590 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2592 protected void setCaretPosition(final int position) {
2593 final ISourceViewer viewer = getSourceViewer();
2595 final StyledText text = viewer.getTextWidget();
2596 if (text != null && !text.isDisposed()) {
2598 final Point selection = text.getSelection();
2599 final int caret = text.getCaretOffset();
2600 final int offset = modelOffset2WidgetOffset(viewer, position);
2602 if (caret == selection.x)
2603 text.setSelectionRange(selection.y, offset - selection.y);
2605 text.setSelectionRange(selection.x, offset - selection.x);
2610 // static protected class AnnotationAccess implements IAnnotationAccess {
2613 // org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
2615 // public Object getType(Annotation annotation) {
2616 // if (annotation instanceof IJavaAnnotation) {
2617 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
2618 // // if (javaAnnotation.isRelevant())
2619 // // return javaAnnotation.getAnnotationType();
2626 // org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
2628 // public boolean isMultiLine(Annotation annotation) {
2634 // org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
2636 // public boolean isTemporary(Annotation annotation) {
2637 // if (annotation instanceof IJavaAnnotation) {
2638 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
2639 // if (javaAnnotation.isRelevant())
2640 // return javaAnnotation.isTemporary();
2646 private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
2648 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
2650 public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
2651 handlePreferencePropertyChanged(event);
2656 * Finds and marks occurrence annotations.
2660 class OccurrencesFinderJob extends Job implements IDocumentListener {
2662 private IDocument fDocument;
2664 private boolean fCancelled = false;
2666 private IProgressMonitor fProgressMonitor;
2668 private Position[] fPositions;
2670 public OccurrencesFinderJob(IDocument document, Position[] positions) {
2671 super("Occurrences Marker"); //$NON-NLS-1$
2672 fDocument = document;
2673 fPositions = positions;
2674 fDocument.addDocumentListener(this);
2677 private boolean isCancelled() {
2678 return fCancelled || fProgressMonitor.isCanceled();
2682 * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
2684 public IStatus run(IProgressMonitor progressMonitor) {
2686 fProgressMonitor = progressMonitor;
2691 return Status.CANCEL_STATUS;
2693 ITextViewer textViewer = getViewer();
2694 if (textViewer == null)
2695 return Status.CANCEL_STATUS;
2697 IDocument document = textViewer.getDocument();
2698 if (document == null)
2699 return Status.CANCEL_STATUS;
2701 IDocumentProvider documentProvider = getDocumentProvider();
2702 if (documentProvider == null)
2703 return Status.CANCEL_STATUS;
2705 IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
2706 if (annotationModel == null)
2707 return Status.CANCEL_STATUS;
2709 // Add occurrence annotations
2710 int length = fPositions.length;
2711 Map annotationMap = new HashMap(length);
2712 for (int i = 0; i < length; i++) {
2715 return Status.CANCEL_STATUS;
2718 Position position = fPositions[i];
2720 // Create & add annotation
2722 message = document.get(position.offset, position.length);
2723 } catch (BadLocationException ex) {
2727 annotationMap.put(new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
2732 return Status.CANCEL_STATUS;
2734 synchronized (annotationModel) {
2735 if (annotationModel instanceof IAnnotationModelExtension) {
2736 ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
2738 removeOccurrenceAnnotations();
2739 Iterator iter = annotationMap.entrySet().iterator();
2740 while (iter.hasNext()) {
2741 Map.Entry mapEntry = (Map.Entry) iter.next();
2742 annotationModel.addAnnotation((Annotation) mapEntry.getKey(), (Position) mapEntry.getValue());
2745 fOccurrenceAnnotations = (Annotation[]) annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
2748 fDocument.removeDocumentListener(this);
2750 return Status.OK_STATUS;
2754 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
2756 public void documentAboutToBeChanged(DocumentEvent event) {
2761 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
2763 public void documentChanged(DocumentEvent event) {
2768 * Updates the selection in the editor's widget with the selection of the
2771 class OutlineSelectionChangedListener extends AbstractSelectionChangedListener {
2772 public void selectionChanged(SelectionChangedEvent event) {
2773 doSelectionChanged(event);
2778 * Holds the current occurrence annotations.
2782 private Annotation[] fOccurrenceAnnotations = null;
2784 private Job fOccurrencesFinderJob;
2786 /** Preference key for showing the line number ruler */
2787 // private final static String LINE_NUMBER_RULER =
2788 // PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
2789 /** Preference key for the foreground color of the line numbers */
2790 // private final static String LINE_NUMBER_COLOR =
2791 // PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
2792 /** Preference key for the link color */
2793 private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
2795 /** Preference key for compiler task tags */
2796 private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
2798 // protected PHPActionGroup fActionGroups;
2799 // /** The outline page */
2800 // private AbstractContentOutlinePage fOutlinePage;
2801 /** The outline page */
2802 protected JavaOutlinePage fOutlinePage;
2804 /** Outliner context menu Id */
2805 protected String fOutlinerContextMenuId;
2808 * Indicates whether this editor should react on outline page selection
2811 private int fIgnoreOutlinePageSelection;
2813 /** The outline page selection updater */
2814 // private OutlinePageSelectionUpdater fUpdater;
2815 // protected PHPSyntaxParserThread fValidationThread = null;
2816 // private IPreferenceStore fPHPPrefStore;
2817 /** The selection changed listener */
2818 // protected ISelectionChangedListener fSelectionChangedListener = new
2819 // SelectionChangedListener();
2821 * The editor selection changed listener.
2825 private EditorSelectionChangedListener fEditorSelectionChangedListener;
2827 /** The selection changed listener */
2828 protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener();
2830 /** The editor's bracket matcher */
2831 private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS);
2833 /** The line number ruler column */
2834 // private LineNumberRulerColumn fLineNumberRulerColumn;
2835 /** This editor's encoding support */
2836 private DefaultEncodingSupport fEncodingSupport;
2838 /** The mouse listener */
2839 private MouseClickListener fMouseListener;
2842 * Indicates whether this editor is about to update any annotation views.
2846 private boolean fIsUpdatingAnnotationViews = false;
2849 * The marker that served as last target for a goto marker request.
2853 private IMarker fLastMarkerTarget = null;
2855 protected CompositeActionGroup fActionGroups;
2857 protected CompositeActionGroup fContextMenuGroup;
2860 * This editor's projection support
2864 private ProjectionSupport fProjectionSupport;
2867 * This editor's projection model updater
2871 private IJavaFoldingStructureProvider fProjectionModelUpdater;
2874 * The override and implements indicator manager for this editor.
2878 // protected OverrideIndicatorManager fOverrideIndicatorManager;
2880 * The action group for folding.
2884 private FoldingActionGroup fFoldingGroup;
2886 /** The information presenter. */
2887 private InformationPresenter fInformationPresenter;
2889 /** The annotation access */
2890 // protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
2891 /** The overview ruler */
2892 protected OverviewRuler isOverviewRulerVisible;
2894 /** The source viewer decoration support */
2895 // protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
2896 /** The overview ruler */
2897 // protected OverviewRuler fOverviewRuler;
2898 /** The preference property change listener for java core. */
2899 private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
2902 * Returns the most narrow java element including the given offset
2905 * the offset inside of the requested element
2907 abstract protected IJavaElement getElementAt(int offset);
2910 * Returns the java element of this editor's input corresponding to the given
2913 abstract protected IJavaElement getCorrespondingElement(IJavaElement element);
2916 * Sets the input of the editor's outline page.
2918 abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input);
2921 * Default constructor.
2923 public PHPEditor() {
2928 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
2930 protected void initializeKeyBindingScopes() {
2931 setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
2935 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
2937 protected void initializeEditor() {
2939 // JavaTextTools textTools =
2940 // PHPeclipsePlugin.getDefault().getJavaTextTools();
2941 // setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools,
2942 // this, IPHPPartitions.PHP_PARTITIONING)); //,
2943 // IJavaPartitions.JAVA_PARTITIONING));
2944 IPreferenceStore store = createCombinedPreferenceStore(null);
2945 setPreferenceStore(store);
2946 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2947 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
2948 IPHPPartitions.PHP_PARTITIONING));
2950 // TODO changed in 3.x ?
2951 // setRangeIndicator(new DefaultRangeIndicator());
2953 // (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
2954 // fUpdater = new OutlinePageSelectionUpdater();
2957 // IPreferenceStore store= createCombinedPreferenceStore(null);
2958 // setPreferenceStore(store);
2959 // JavaTextTools textTools=
2960 // PHPeclipsePlugin.getDefault().getJavaTextTools();
2961 // setSourceViewerConfiguration(new
2962 // JavaSourceViewerConfiguration(textTools.getColorManager(), store,
2963 // this, IJavaPartitions.JAVA_PARTITIONING));
2964 // fMarkOccurrenceAnnotations=
2965 // store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
2966 // fStickyOccurrenceAnnotations=
2967 // store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
2968 // fMarkTypeOccurrences=
2969 // store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
2970 // fMarkMethodOccurrences=
2971 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
2972 // fMarkConstantOccurrences=
2973 // store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
2974 // fMarkFieldOccurrences=
2975 // store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
2976 // fMarkLocalVariableypeOccurrences=
2977 // store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
2978 // fMarkExceptionOccurrences=
2979 // store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
2980 // fMarkMethodExitPoints=
2981 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
2985 * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
2987 protected void updatePropertyDependentActions() {
2988 super.updatePropertyDependentActions();
2989 if (fEncodingSupport != null)
2990 fEncodingSupport.reset();
2994 * Update the hovering behavior depending on the preferences.
2996 private void updateHoverBehavior() {
2997 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
2998 String[] types = configuration.getConfiguredContentTypes(getSourceViewer());
3000 for (int i = 0; i < types.length; i++) {
3002 String t = types[i];
3004 int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
3006 ISourceViewer sourceViewer = getSourceViewer();
3007 if (sourceViewer instanceof ITextViewerExtension2) {
3008 if (stateMasks != null) {
3009 for (int j = 0; j < stateMasks.length; j++) {
3010 int stateMask = stateMasks[j];
3011 ITextHover textHover = configuration.getTextHover(sourceViewer, t, stateMask);
3012 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, stateMask);
3015 ITextHover textHover = configuration.getTextHover(sourceViewer, t);
3016 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
3019 sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t);
3023 public void updatedTitleImage(Image image) {
3024 setTitleImage(image);
3028 * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
3030 public Object getViewPartInput() {
3031 return getEditorInput().getAdapter(IResource.class);
3035 * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
3037 protected void doSetSelection(ISelection selection) {
3038 super.doSetSelection(selection);
3039 synchronizeOutlinePageSelection();
3042 boolean isFoldingEnabled() {
3043 return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
3047 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.
3048 * widgets.Composite)
3050 public void createPartControl(Composite parent) {
3051 super.createPartControl(parent);
3053 // fSourceViewerDecorationSupport.install(getPreferenceStore());
3055 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
3057 fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
3058 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
3059 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
3060 fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() {
3061 public IInformationControl createInformationControl(Shell shell) {
3062 return new CustomSourceInformationControl(shell, IDocument.DEFAULT_CONTENT_TYPE);
3065 fProjectionSupport.install();
3067 fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
3068 if (fProjectionModelUpdater != null)
3069 fProjectionModelUpdater.install(this, projectionViewer);
3071 if (isFoldingEnabled())
3072 projectionViewer.doOperation(ProjectionViewer.TOGGLE);
3073 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
3074 preferences.addPropertyChangeListener(fPropertyChangeListener);
3076 IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
3077 public IInformationControl createInformationControl(Shell parent) {
3078 boolean cutDown = false;
3079 int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
3080 return new DefaultInformationControl(parent, SWT.RESIZE, style, new HTMLTextPresenter(cutDown));
3084 fInformationPresenter = new InformationPresenter(informationControlCreator);
3085 fInformationPresenter.setSizeConstraints(60, 10, true, true);
3086 fInformationPresenter.install(getSourceViewer());
3088 fEditorSelectionChangedListener = new EditorSelectionChangedListener();
3089 fEditorSelectionChangedListener.install(getSelectionProvider());
3091 if (isBrowserLikeLinks())
3092 enableBrowserLikeLinks();
3094 if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE))
3095 enableOverwriteMode(false);
3098 // getEditorSite().getShell().addShellListener(fActivationListener);
3101 private void setWordWrap() {
3102 if (getSourceViewer() != null) {
3103 getSourceViewer().getTextWidget().setWordWrap(
3104 PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_WRAP_WORDS));
3108 protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
3110 support.setCharacterPairMatcher(fBracketMatcher);
3111 support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
3113 super.configureSourceViewerDecorationSupport(support);
3117 * @see org.eclipse.ui.texteditor.AbstractTextEditor#gotoMarker(org.eclipse.core.resources.IMarker)
3119 public void gotoMarker(IMarker marker) {
3120 fLastMarkerTarget = marker;
3121 if (!fIsUpdatingAnnotationViews) {
3122 super.gotoMarker(marker);
3127 * Jumps to the next enabled annotation according to the given direction. An
3128 * annotation type is enabled if it is configured to be in the Next/Previous
3129 * tool bar drop down menu and if it is checked.
3132 * <code>true</code> if search direction is forward,
3133 * <code>false</code> if backward
3135 public void gotoAnnotation(boolean forward) {
3136 ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
3137 Position position = new Position(0, 0);
3138 if (false /* delayed - see bug 18316 */) {
3139 getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
3140 selectAndReveal(position.getOffset(), position.getLength());
3141 } else /* no delay - see bug 18316 */{
3142 Annotation annotation = getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
3143 setStatusLineErrorMessage(null);
3144 setStatusLineMessage(null);
3145 if (annotation != null) {
3146 updateAnnotationViews(annotation);
3147 selectAndReveal(position.getOffset(), position.getLength());
3148 setStatusLineMessage(annotation.getText());
3154 * Returns the lock object for the given annotation model.
3156 * @param annotationModel
3157 * the annotation model
3158 * @return the annotation model's lock object
3161 private Object getLockObject(IAnnotationModel annotationModel) {
3162 if (annotationModel instanceof ISynchronizable)
3163 return ((ISynchronizable) annotationModel).getLockObject();
3165 return annotationModel;
3169 * Updates the annotation views that show the given annotation.
3174 private void updateAnnotationViews(Annotation annotation) {
3175 IMarker marker = null;
3176 if (annotation instanceof MarkerAnnotation)
3177 marker = ((MarkerAnnotation) annotation).getMarker();
3178 else if (annotation instanceof IJavaAnnotation) {
3179 Iterator e = ((IJavaAnnotation) annotation).getOverlaidIterator();
3181 while (e.hasNext()) {
3182 Object o = e.next();
3183 if (o instanceof MarkerAnnotation) {
3184 marker = ((MarkerAnnotation) o).getMarker();
3191 if (marker != null && !marker.equals(fLastMarkerTarget)) {
3193 boolean isProblem = marker.isSubtypeOf(IMarker.PROBLEM);
3194 IWorkbenchPage page = getSite().getPage();
3195 IViewPart view = page.findView(isProblem ? IPageLayout.ID_PROBLEM_VIEW : IPageLayout.ID_TASK_LIST); //$NON-NLS-1$ //$NON-NLS-2$
3197 Method method = view.getClass().getMethod("setSelection", new Class[] { IStructuredSelection.class, boolean.class }); //$NON-NLS-1$
3198 method.invoke(view, new Object[] { new StructuredSelection(marker), Boolean.TRUE });
3200 } catch (CoreException x) {
3201 } catch (NoSuchMethodException x) {
3202 } catch (IllegalAccessException x) {
3203 } catch (InvocationTargetException x) {
3205 // ignore exceptions, don't update any of the lists, just set status line
3210 * Returns this document's complete text.
3212 * @return the document's complete text
3214 public String get() {
3215 IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
3220 * Sets the outliner's context menu ID.
3222 protected void setOutlinerContextMenuId(String menuId) {
3223 fOutlinerContextMenuId = menuId;
3227 * Returns the standard action group of this editor.
3229 protected ActionGroup getActionGroup() {
3230 return fActionGroups;
3233 // public JavaOutlinePage getfOutlinePage() {
3234 // return fOutlinePage;
3238 * The <code>PHPEditor</code> implementation of this
3239 * <code>AbstractTextEditor</code> method extend the actions to add those
3240 * specific to the receiver
3242 protected void createActions() {
3243 super.createActions();
3245 ActionGroup oeg, ovg, jsg, sg;
3246 fActionGroups = new CompositeActionGroup(new ActionGroup[] { oeg = new OpenEditorActionGroup(this),
3247 // sg= new ShowActionGroup(this),
3248 // ovg= new OpenViewActionGroup(this),
3249 // jsg= new JavaSearchActionGroup(this)
3251 fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { oeg });
3252 // , ovg, sg, jsg});
3254 fFoldingGroup = new FoldingActionGroup(this, getViewer());
3256 // ResourceAction resAction = new
3257 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
3258 // "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
3260 // InformationDispatchAction(PHPEditorMessages.getResourceBundle(),
3261 // "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
3262 // resAction.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
3263 // setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
3265 // WorkbenchHelp.setHelp(resAction,
3266 // IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
3268 Action action = new GotoMatchingBracketAction(this);
3269 action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
3270 setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
3273 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.",
3274 // this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
3275 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
3276 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action);
3277 // // WorkbenchHelp.setHelp(action,
3278 // IJavaHelpContextIds.SHOW_OUTLINE_ACTION);
3281 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.",
3282 // this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$
3283 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE);
3284 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE,
3286 // // WorkbenchHelp.setHelp(action,
3287 // IJavaHelpContextIds.OPEN_STRUCTURE_ACTION);
3290 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.",
3291 // this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
3292 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY);
3293 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY,
3295 // // WorkbenchHelp.setHelp(action,
3296 // IJavaHelpContextIds.OPEN_HIERARCHY_ACTION);
3298 fEncodingSupport = new DefaultEncodingSupport();
3299 fEncodingSupport.initialize(this);
3301 // fSelectionHistory= new SelectionHistory(this);
3303 // action= new StructureSelectEnclosingAction(this, fSelectionHistory);
3304 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
3305 // setAction(StructureSelectionAction.ENCLOSING, action);
3307 // action= new StructureSelectNextAction(this, fSelectionHistory);
3308 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
3309 // setAction(StructureSelectionAction.NEXT, action);
3311 // action= new StructureSelectPreviousAction(this, fSelectionHistory);
3312 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
3313 // setAction(StructureSelectionAction.PREVIOUS, action);
3315 // StructureSelectHistoryAction historyAction= new
3316 // StructureSelectHistoryAction(this, fSelectionHistory);
3317 // historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
3318 // setAction(StructureSelectionAction.HISTORY, historyAction);
3319 // fSelectionHistory.setHistoryAction(historyAction);
3321 // action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this);
3322 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
3323 // setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action);
3326 // GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this);
3327 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
3328 // setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
3330 // action= new QuickFormatAction();
3331 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT);
3332 // setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action);
3334 // action= new RemoveOccurrenceAnnotations(this);
3335 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
3336 // setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$
3338 // add annotation actions
3339 action = new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
3340 setAction("AnnotationAction", action); //$NON-NLS-1$
3343 private void internalDoSetInput(IEditorInput input) throws CoreException {
3344 super.doSetInput(input);
3346 if (getSourceViewer() instanceof JavaSourceViewer) {
3347 JavaSourceViewer viewer = (JavaSourceViewer) getSourceViewer();
3348 if (viewer.getReconciler() == null) {
3349 IReconciler reconciler = getSourceViewerConfiguration().getReconciler(viewer);
3350 if (reconciler != null) {
3351 reconciler.install(viewer);
3352 viewer.setReconciler(reconciler);
3357 if (fEncodingSupport != null)
3358 fEncodingSupport.reset();
3360 setOutlinePageInput(fOutlinePage, input);
3362 if (fProjectionModelUpdater != null)
3363 fProjectionModelUpdater.initialize();
3365 // if (isShowingOverrideIndicators())
3366 // installOverrideIndicator(false);
3370 * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)
3373 protected void setPreferenceStore(IPreferenceStore store) {
3374 super.setPreferenceStore(store);
3375 if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) {
3376 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
3377 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
3378 IPHPPartitions.PHP_PARTITIONING));
3380 if (getSourceViewer() instanceof JavaSourceViewer)
3381 ((JavaSourceViewer) getSourceViewer()).setPreferenceStore(store);
3385 * The <code>PHPEditor</code> implementation of this
3386 * <code>AbstractTextEditor</code> method performs any extra disposal
3387 * actions required by the php editor.
3389 public void dispose() {
3390 if (fProjectionModelUpdater != null) {
3391 fProjectionModelUpdater.uninstall();
3392 fProjectionModelUpdater = null;
3395 if (fProjectionSupport != null) {
3396 fProjectionSupport.dispose();
3397 fProjectionSupport = null;
3399 // PHPEditorEnvironment.disconnect(this);
3400 if (fOutlinePage != null)
3401 fOutlinePage.setInput(null);
3403 if (fActionGroups != null)
3404 fActionGroups.dispose();
3406 if (isBrowserLikeLinks())
3407 disableBrowserLikeLinks();
3409 if (fEncodingSupport != null) {
3410 fEncodingSupport.dispose();
3411 fEncodingSupport = null;
3414 if (fPropertyChangeListener != null) {
3415 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
3416 preferences.removePropertyChangeListener(fPropertyChangeListener);
3417 fPropertyChangeListener = null;
3420 // if (fSourceViewerDecorationSupport != null) {
3421 // fSourceViewerDecorationSupport.dispose();
3422 // fSourceViewerDecorationSupport = null;
3425 if (fBracketMatcher != null) {
3426 fBracketMatcher.dispose();
3427 fBracketMatcher = null;
3430 if (fEditorSelectionChangedListener != null) {
3431 fEditorSelectionChangedListener.uninstall(getSelectionProvider());
3432 fEditorSelectionChangedListener = null;
3439 * The <code>PHPEditor</code> implementation of this
3440 * <code>AbstractTextEditor</code> method performs any extra revert behavior
3441 * required by the php editor.
3443 // public void doRevertToSaved() {
3444 // super.doRevertToSaved();
3445 // if (fOutlinePage != null)
3446 // fOutlinePage.update();
3449 * The <code>PHPEditor</code> implementation of this
3450 * <code>AbstractTextEditor</code> method performs any extra save behavior
3451 * required by the php editor.
3453 // public void doSave(IProgressMonitor monitor) {
3454 // super.doSave(monitor);
3455 // compile or not, according to the user preferences
3456 // IPreferenceStore store = getPreferenceStore();
3457 // the parse on save was changed to the eclipse "builders" concept
3458 // if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
3459 // IAction a = PHPParserAction.getInstance();
3463 // if (SWT.getPlatform().equals("win32")) {
3464 // IAction a = ShowExternalPreviewAction.getInstance();
3468 // if (fOutlinePage != null)
3469 // fOutlinePage.update();
3472 * The <code>PHPEditor</code> implementation of this
3473 * <code>AbstractTextEditor</code> method performs any extra save as
3474 * behavior required by the php editor.
3476 // public void doSaveAs() {
3477 // super.doSaveAs();
3478 // if (fOutlinePage != null)
3479 // fOutlinePage.update();
3482 * @see StatusTextEditor#getStatusHeader(IStatus)
3484 protected String getStatusHeader(IStatus status) {
3485 if (fEncodingSupport != null) {
3486 String message = fEncodingSupport.getStatusHeader(status);
3487 if (message != null)
3490 return super.getStatusHeader(status);
3494 * @see StatusTextEditor#getStatusBanner(IStatus)
3496 protected String getStatusBanner(IStatus status) {
3497 if (fEncodingSupport != null) {
3498 String message = fEncodingSupport.getStatusBanner(status);
3499 if (message != null)
3502 return super.getStatusBanner(status);
3506 * @see StatusTextEditor#getStatusMessage(IStatus)
3508 protected String getStatusMessage(IStatus status) {
3509 if (fEncodingSupport != null) {
3510 String message = fEncodingSupport.getStatusMessage(status);
3511 if (message != null)
3514 return super.getStatusMessage(status);
3518 * The <code>PHPEditor</code> implementation of this
3519 * <code>AbstractTextEditor</code> method performs sets the input of the
3520 * outline page after AbstractTextEditor has set input.
3522 // protected void doSetInput(IEditorInput input) throws CoreException {
3523 // super.doSetInput(input);
3524 // if (fEncodingSupport != null)
3525 // fEncodingSupport.reset();
3526 // setOutlinePageInput(fOutlinePage, input);
3529 * @see AbstractTextEditor#doSetInput
3531 protected void doSetInput(IEditorInput input) throws CoreException {
3532 ISourceViewer sourceViewer = getSourceViewer();
3533 if (!(sourceViewer instanceof ISourceViewerExtension2)) {
3534 setPreferenceStore(createCombinedPreferenceStore(input));
3535 internalDoSetInput(input);
3539 // uninstall & unregister preference store listener
3540 if (isBrowserLikeLinks())
3541 disableBrowserLikeLinks();
3542 getSourceViewerDecorationSupport(sourceViewer).uninstall();
3543 ((ISourceViewerExtension2) sourceViewer).unconfigure();
3545 setPreferenceStore(createCombinedPreferenceStore(input));
3547 // install & register preference store listener
3548 sourceViewer.configure(getSourceViewerConfiguration());
3549 getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
3550 if (isBrowserLikeLinks())
3551 enableBrowserLikeLinks();
3553 internalDoSetInput(input);
3557 * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
3559 // public Object getViewPartInput() {
3560 // return getEditorInput().getAdapter(IFile.class);
3563 * The <code>PHPEditor</code> implementation of this
3564 * <code>AbstractTextEditor</code> method adds any PHPEditor specific
3567 public void editorContextMenuAboutToShow(MenuManager menu) {
3568 super.editorContextMenuAboutToShow(menu);
3569 menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, new Separator(IContextMenuConstants.GROUP_OPEN));
3570 menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));
3572 ActionContext context = new ActionContext(getSelectionProvider().getSelection());
3573 fContextMenuGroup.setContext(context);
3574 fContextMenuGroup.fillContextMenu(menu);
3575 fContextMenuGroup.setContext(null);
3576 // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format");
3579 // ActionContext context =
3580 // new ActionContext(getSelectionProvider().getSelection());
3581 // fContextMenuGroup.setContext(context);
3582 // fContextMenuGroup.fillContextMenu(menu);
3583 // fContextMenuGroup.setContext(null);
3587 * Creates the outline page used with this editor.
3589 protected JavaOutlinePage createOutlinePage() {
3590 JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this);
3591 fOutlineSelectionChangedListener.install(page);
3592 setOutlinePageInput(page, getEditorInput());
3597 * Informs the editor that its outliner has been closed.
3599 public void outlinePageClosed() {
3600 if (fOutlinePage != null) {
3601 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3602 fOutlinePage = null;
3603 resetHighlightRange();
3608 * Synchronizes the outliner selection with the given element position in the
3612 * the java element to select
3614 protected void synchronizeOutlinePage(ISourceReference element) {
3615 synchronizeOutlinePage(element, true);
3619 * Synchronizes the outliner selection with the given element position in the
3623 * the java element to select
3624 * @param checkIfOutlinePageActive
3625 * <code>true</code> if check for active outline page needs to be
3628 protected void synchronizeOutlinePage(ISourceReference element, boolean checkIfOutlinePageActive) {
3629 if (fOutlinePage != null && element != null && !(checkIfOutlinePageActive && isJavaOutlinePageActive())) {
3630 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3631 fOutlinePage.select(element);
3632 fOutlineSelectionChangedListener.install(fOutlinePage);
3637 * Synchronizes the outliner selection with the actual cursor position in the
3640 public void synchronizeOutlinePageSelection() {
3641 synchronizeOutlinePage(computeHighlightRangeSourceReference());
3643 // ISourceViewer sourceViewer = getSourceViewer();
3644 // if (sourceViewer == null || fOutlinePage == null)
3647 // StyledText styledText = sourceViewer.getTextWidget();
3648 // if (styledText == null)
3652 // if (sourceViewer instanceof ITextViewerExtension3) {
3653 // ITextViewerExtension3 extension = (ITextViewerExtension3)
3656 // extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
3658 // int offset = sourceViewer.getVisibleRegion().getOffset();
3659 // caret = offset + styledText.getCaretOffset();
3662 // IJavaElement element = getElementAt(caret);
3663 // if (element instanceof ISourceReference) {
3664 // fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
3665 // fOutlinePage.select((ISourceReference) element);
3666 // fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
3670 protected void setSelection(ISourceReference reference, boolean moveCursor) {
3672 ISelection selection = getSelectionProvider().getSelection();
3673 if (selection instanceof TextSelection) {
3674 TextSelection textSelection = (TextSelection) selection;
3675 if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
3676 markInNavigationHistory();
3679 if (reference != null) {
3681 StyledText textWidget = null;
3683 ISourceViewer sourceViewer = getSourceViewer();
3684 if (sourceViewer != null)
3685 textWidget = sourceViewer.getTextWidget();
3687 if (textWidget == null)
3692 ISourceRange range = reference.getSourceRange();
3696 int offset = range.getOffset();
3697 int length = range.getLength();
3699 if (offset < 0 || length < 0)
3702 textWidget.setRedraw(false);
3704 setHighlightRange(offset, length, moveCursor);
3712 if (reference instanceof IMember) {
3713 range = ((IMember) reference).getNameRange();
3714 if (range != null) {
3715 offset = range.getOffset();
3716 length = range.getLength();
3719 // else if (reference instanceof IImportDeclaration) {
3720 // String name= ((IImportDeclaration)
3721 // reference).getElementName();
3722 // if (name != null && name.length() > 0) {
3723 // String content= reference.getSource();
3724 // if (content != null) {
3725 // offset= range.getOffset() + content.indexOf(name);
3726 // length= name.length();
3729 // } else if (reference instanceof IPackageDeclaration) {
3730 // String name= ((IPackageDeclaration)
3731 // reference).getElementName();
3732 // if (name != null && name.length() > 0) {
3733 // String content= reference.getSource();
3734 // if (content != null) {
3735 // offset= range.getOffset() + content.indexOf(name);
3736 // length= name.length();
3741 if (offset > -1 && length > 0) {
3742 sourceViewer.revealRange(offset, length);
3743 sourceViewer.setSelectedRange(offset, length);
3746 } catch (JavaModelException x) {
3747 } catch (IllegalArgumentException x) {
3749 if (textWidget != null)
3750 textWidget.setRedraw(true);
3753 } else if (moveCursor) {
3754 resetHighlightRange();
3757 markInNavigationHistory();
3760 public void setSelection(IJavaElement element) {
3761 if (element == null || element instanceof ICompilationUnit) { // ||
3767 * If the element is an ICompilationUnit this unit is either the input of
3768 * this editor or not being displayed. In both cases, nothing should
3769 * happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
3774 IJavaElement corresponding = getCorrespondingElement(element);
3775 if (corresponding instanceof ISourceReference) {
3776 ISourceReference reference = (ISourceReference) corresponding;
3777 // set highlight range
3778 setSelection(reference, true);
3779 // set outliner selection
3780 if (fOutlinePage != null) {
3781 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3782 fOutlinePage.select(reference);
3783 fOutlineSelectionChangedListener.install(fOutlinePage);
3788 public synchronized void editingScriptStarted() {
3789 ++fIgnoreOutlinePageSelection;
3792 public synchronized void editingScriptEnded() {
3793 --fIgnoreOutlinePageSelection;
3796 public synchronized boolean isEditingScriptRunning() {
3797 return (fIgnoreOutlinePageSelection > 0);
3801 * The <code>PHPEditor</code> implementation of this
3802 * <code>AbstractTextEditor</code> method performs gets the java content
3803 * outline page if request is for a an outline page.
3805 public Object getAdapter(Class required) {
3807 if (IContentOutlinePage.class.equals(required)) {
3808 if (fOutlinePage == null)
3809 fOutlinePage = createOutlinePage();
3810 return fOutlinePage;
3813 if (IEncodingSupport.class.equals(required))
3814 return fEncodingSupport;
3816 if (required == IShowInTargetList.class) {
3817 return new IShowInTargetList() {
3818 public String[] getShowInTargetIds() {
3819 return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
3824 if (fProjectionSupport != null) {
3825 Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
3826 if (adapter != null)
3830 return super.getAdapter(required);
3833 // public Object getAdapter(Class required) {
3834 // if (IContentOutlinePage.class.equals(required)) {
3835 // if (fOutlinePage == null) {
3836 // fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
3837 // if (getEditorInput() != null)
3838 // fOutlinePage.setInput(getEditorInput());
3840 // return fOutlinePage;
3843 // if (IEncodingSupport.class.equals(required))
3844 // return fEncodingSupport;
3846 // return super.getAdapter(required);
3849 protected void doSelectionChanged(SelectionChangedEvent event) {
3850 ISourceReference reference = null;
3852 ISelection selection = event.getSelection();
3853 Iterator iter = ((IStructuredSelection) selection).iterator();
3854 while (iter.hasNext()) {
3855 Object o = iter.next();
3856 if (o instanceof ISourceReference) {
3857 reference = (ISourceReference) o;
3862 if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
3863 PHPeclipsePlugin.getActivePage().bringToTop(this);
3866 editingScriptStarted();
3867 setSelection(reference, !isActivePart());
3869 editingScriptEnded();
3874 * @see AbstractTextEditor#adjustHighlightRange(int, int)
3876 protected void adjustHighlightRange(int offset, int length) {
3880 IJavaElement element = getElementAt(offset);
3881 while (element instanceof ISourceReference) {
3882 ISourceRange range = ((ISourceReference) element).getSourceRange();
3883 if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) {
3885 ISourceViewer viewer = getSourceViewer();
3886 if (viewer instanceof ITextViewerExtension5) {
3887 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
3888 extension.exposeModelRange(new Region(range.getOffset(), range.getLength()));
3891 setHighlightRange(range.getOffset(), range.getLength(), true);
3892 if (fOutlinePage != null) {
3893 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3894 fOutlinePage.select((ISourceReference) element);
3895 fOutlineSelectionChangedListener.install(fOutlinePage);
3900 element = element.getParent();
3903 } catch (JavaModelException x) {
3904 PHPeclipsePlugin.log(x.getStatus());
3907 ISourceViewer viewer = getSourceViewer();
3908 if (viewer instanceof ITextViewerExtension5) {
3909 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
3910 extension.exposeModelRange(new Region(offset, length));
3912 resetHighlightRange();
3917 protected boolean isActivePart() {
3918 IWorkbenchWindow window = getSite().getWorkbenchWindow();
3919 IPartService service = window.getPartService();
3920 IWorkbenchPart part = service.getActivePart();
3921 return part != null && part.equals(this);
3924 // public void openContextHelp() {
3926 // this.getDocumentProvider().getDocument(this.getEditorInput());
3927 // ITextSelection selection = (ITextSelection)
3928 // this.getSelectionProvider().getSelection();
3929 // int pos = selection.getOffset();
3930 // String word = getFunctionName(doc, pos);
3931 // openContextHelp(word);
3934 // private void openContextHelp(String word) {
3938 // public static void open(String word) {
3939 // IHelp help = WorkbenchHelp.getHelpSupport();
3940 // if (help != null) {
3941 // IHelpResource helpResource = new PHPFunctionHelpResource(word);
3942 // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
3944 // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help
3945 // not available"), false); //$NON-NLS-1$
3949 // private String getFunctionName(IDocument doc, int pos) {
3950 // Point word = PHPWordExtractor.findWord(doc, pos);
3951 // if (word != null) {
3953 // return doc.get(word.x, word.y).replace('_', '-');
3954 // } catch (BadLocationException e) {
3961 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
3963 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
3967 ISourceViewer sourceViewer = getSourceViewer();
3968 if (sourceViewer == null)
3971 String property = event.getProperty();
3973 if (PreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
3974 Object value = event.getNewValue();
3975 if (value instanceof Integer) {
3976 sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
3977 } else if (value instanceof String) {
3979 sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
3980 } catch (NumberFormatException e) {
3981 // bug #1038071 - set default tab:
3982 sourceViewer.getTextWidget().setTabs(80);
3988 // if (OVERVIEW_RULER.equals(property)) {
3989 // if (isOverviewRulerVisible())
3990 // showOverviewRuler();
3992 // hideOverviewRuler();
3996 // if (LINE_NUMBER_RULER.equals(property)) {
3997 // if (isLineNumberRulerVisible())
3998 // showLineNumberRuler();
4000 // hideLineNumberRuler();
4004 // if (fLineNumberRulerColumn != null
4005 // && (LINE_NUMBER_COLOR.equals(property) ||
4006 // PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) ||
4007 // PREFERENCE_COLOR_BACKGROUND.equals(property))) {
4009 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4012 if (isJavaEditorHoverProperty(property))
4013 updateHoverBehavior();
4015 if (BROWSER_LIKE_LINKS.equals(property)) {
4016 if (isBrowserLikeLinks())
4017 enableBrowserLikeLinks();
4019 disableBrowserLikeLinks();
4023 if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) {
4024 if ((event.getNewValue() instanceof Boolean) && ((Boolean) event.getNewValue()).booleanValue())
4029 if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) {
4030 if (event.getNewValue() instanceof Boolean) {
4031 Boolean disable = (Boolean) event.getNewValue();
4032 enableOverwriteMode(!disable.booleanValue());
4037 // if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property))
4039 // if (event.getNewValue() instanceof Boolean) {
4040 // boolean markOccurrenceAnnotations=
4041 // ((Boolean)event.getNewValue()).booleanValue();
4042 // if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) {
4043 // fMarkOccurrenceAnnotations= markOccurrenceAnnotations;
4044 // if (!fMarkOccurrenceAnnotations)
4045 // uninstallOccurrencesFinder();
4047 // installOccurrencesFinder();
4052 // (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property))
4054 // if (event.getNewValue() instanceof Boolean) {
4055 // boolean stickyOccurrenceAnnotations=
4056 // ((Boolean)event.getNewValue()).booleanValue();
4057 // if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations)
4059 // fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations;
4060 // // if (!fMarkOccurrenceAnnotations)
4061 // // uninstallOccurrencesFinder();
4063 // // installOccurrencesFinder();
4068 ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
4070 // if (affectsOverrideIndicatorAnnotations(event)) {
4071 // if (isShowingOverrideIndicators()) {
4072 // if (fOverrideIndicatorManager == null)
4073 // installOverrideIndicator(true);
4075 // if (fOverrideIndicatorManager != null)
4076 // uninstallOverrideIndicator();
4081 if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
4082 if (sourceViewer instanceof ProjectionViewer) {
4083 ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer;
4084 if (fProjectionModelUpdater != null)
4085 fProjectionModelUpdater.uninstall();
4086 // either freshly enabled or provider changed
4087 fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
4088 if (fProjectionModelUpdater != null) {
4089 fProjectionModelUpdater.install(this, projectionViewer);
4095 super.handlePreferenceStoreChanged(event);
4101 // AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
4103 // protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
4107 // ISourceViewer sourceViewer = getSourceViewer();
4108 // if (sourceViewer == null)
4111 // String property = event.getProperty();
4114 // (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
4115 // // Object value= event.getNewValue();
4116 // // if (value instanceof Integer) {
4117 // // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
4118 // // } else if (value instanceof String) {
4119 // // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String)
4125 // if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
4126 // if (isLineNumberRulerVisible())
4127 // showLineNumberRuler();
4129 // hideLineNumberRuler();
4133 // if (fLineNumberRulerColumn != null
4134 // && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
4135 // || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
4136 // || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
4138 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4142 // super.handlePreferenceStoreChanged(event);
4146 // private boolean isJavaEditorHoverProperty(String property) {
4147 // return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
4148 // || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
4149 // || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
4150 // || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
4151 // || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
4152 // || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
4153 // || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
4154 // || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
4158 * Shows the line number ruler column.
4160 // private void showLineNumberRuler() {
4161 // IVerticalRuler v = getVerticalRuler();
4162 // if (v instanceof CompositeRuler) {
4163 // CompositeRuler c = (CompositeRuler) v;
4164 // c.addDecorator(1, createLineNumberRulerColumn());
4167 private boolean isJavaEditorHoverProperty(String property) {
4168 return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property);
4172 * Return whether the browser like links should be enabled according to the
4173 * preference store settings.
4175 * @return <code>true</code> if the browser like links should be enabled
4177 private boolean isBrowserLikeLinks() {
4178 IPreferenceStore store = getPreferenceStore();
4179 return store.getBoolean(BROWSER_LIKE_LINKS);
4183 * Enables browser like links.
4185 private void enableBrowserLikeLinks() {
4186 if (fMouseListener == null) {
4187 fMouseListener = new MouseClickListener();
4188 fMouseListener.install();
4193 * Disables browser like links.
4195 private void disableBrowserLikeLinks() {
4196 if (fMouseListener != null) {
4197 fMouseListener.uninstall();
4198 fMouseListener = null;
4203 * Handles a property change event describing a change of the java core's
4204 * preferences and updates the preference related editor properties.
4207 * the property change event
4209 protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
4210 if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
4211 ISourceViewer sourceViewer = getSourceViewer();
4212 if (sourceViewer != null
4213 && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event
4215 sourceViewer.invalidateTextPresentation();
4217 if (PreferenceConstants.EDITOR_WRAP_WORDS.equals(event.getProperty())) {
4223 * Return whether the line number ruler column should be visible according to
4224 * the preference store settings.
4226 * @return <code>true</code> if the line numbers should be visible
4228 // protected boolean isLineNumberRulerVisible() {
4229 // IPreferenceStore store = getPreferenceStore();
4230 // return store.getBoolean(LINE_NUMBER_RULER);
4233 * Hides the line number ruler column.
4235 // private void hideLineNumberRuler() {
4236 // IVerticalRuler v = getVerticalRuler();
4237 // if (v instanceof CompositeRuler) {
4238 // CompositeRuler c = (CompositeRuler) v;
4240 // c.removeDecorator(1);
4241 // } catch (Throwable e) {
4246 * @see AbstractTextEditor#handleCursorPositionChanged()
4248 // protected void handleCursorPositionChanged() {
4249 // super.handleCursorPositionChanged();
4250 // if (!isEditingScriptRunning() && fUpdater != null)
4254 * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced()
4256 protected void handleElementContentReplaced() {
4257 super.handleElementContentReplaced();
4258 if (fProjectionModelUpdater != null)
4259 fProjectionModelUpdater.initialize();
4263 * Initializes the given line number ruler column from the preference store.
4265 * @param rulerColumn
4266 * the ruler column to be initialized
4268 // protected void initializeLineNumberRulerColumn(LineNumberRulerColumn
4270 // JavaTextTools textTools =
4271 // PHPeclipsePlugin.getDefault().getJavaTextTools();
4272 // IColorManager manager = textTools.getColorManager();
4274 // IPreferenceStore store = getPreferenceStore();
4275 // if (store != null) {
4278 // // foreground color
4279 // if (store.contains(LINE_NUMBER_COLOR)) {
4280 // if (store.isDefault(LINE_NUMBER_COLOR))
4281 // rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
4283 // rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
4285 // rulerColumn.setForeground(manager.getColor(rgb));
4288 // // background color
4289 // if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
4290 // if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
4291 // if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
4292 // rgb = PreferenceConverter.getDefaultColor(store,
4293 // PREFERENCE_COLOR_BACKGROUND);
4295 // rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
4298 // rulerColumn.setBackground(manager.getColor(rgb));
4302 * Creates a new line number ruler column that is appropriately initialized.
4304 // protected IVerticalRulerColumn createLineNumberRulerColumn() {
4305 // fLineNumberRulerColumn = new LineNumberRulerColumn();
4306 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4307 // return fLineNumberRulerColumn;
4310 * @see AbstractTextEditor#createVerticalRuler()
4312 // protected IVerticalRuler createVerticalRuler() {
4313 // CompositeRuler ruler = new CompositeRuler();
4314 // ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
4315 // if (isLineNumberRulerVisible())
4316 // ruler.addDecorator(1, createLineNumberRulerColumn());
4319 // private static IRegion getSignedSelection(ITextViewer viewer) {
4321 // StyledText text = viewer.getTextWidget();
4322 // int caretOffset = text.getCaretOffset();
4323 // Point selection = text.getSelection();
4326 // int offset, length;
4327 // if (caretOffset == selection.x) {
4328 // offset = selection.y;
4329 // length = selection.x - selection.y;
4333 // offset = selection.x;
4334 // length = selection.y - selection.x;
4337 // return new Region(offset, length);
4339 protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
4340 StyledText text = sourceViewer.getTextWidget();
4341 Point selection = text.getSelectionRange();
4343 if (text.getCaretOffset() == selection.x) {
4344 selection.x = selection.x + selection.y;
4345 selection.y = -selection.y;
4348 selection.x = widgetOffset2ModelOffset(sourceViewer, selection.x);
4350 return new Region(selection.x, selection.y);
4353 /** Preference key for matching brackets */
4354 protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
4356 /** Preference key for matching brackets color */
4357 protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
4359 /** Preference key for highlighting current line */
4360 // protected final static String CURRENT_LINE =
4361 // PreferenceConstants.EDITOR_CURRENT_LINE;
4362 /** Preference key for highlight color of current line */
4363 // protected final static String CURRENT_LINE_COLOR =
4364 // PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
4365 /** Preference key for showing print marging ruler */
4366 // protected final static String PRINT_MARGIN =
4367 // PreferenceConstants.EDITOR_PRINT_MARGIN;
4368 /** Preference key for print margin ruler color */
4369 // protected final static String PRINT_MARGIN_COLOR =
4370 // PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
4371 /** Preference key for print margin ruler column */
4372 // protected final static String PRINT_MARGIN_COLUMN =
4373 // PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
4374 /** Preference key for error indication */
4375 // protected final static String ERROR_INDICATION =
4376 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
4377 /** Preference key for error color */
4378 // protected final static String ERROR_INDICATION_COLOR =
4379 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
4380 /** Preference key for warning indication */
4381 // protected final static String WARNING_INDICATION =
4382 // PreferenceConstants.EDITOR_WARNING_INDICATION;
4383 /** Preference key for warning color */
4384 // protected final static String WARNING_INDICATION_COLOR =
4385 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
4386 /** Preference key for task indication */
4387 protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
4389 /** Preference key for task color */
4390 protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
4392 /** Preference key for bookmark indication */
4393 protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
4395 /** Preference key for bookmark color */
4396 protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
4398 /** Preference key for search result indication */
4399 protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
4401 /** Preference key for search result color */
4402 protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
4404 /** Preference key for unknown annotation indication */
4405 protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
4407 /** Preference key for unknown annotation color */
4408 protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
4410 /** Preference key for shwoing the overview ruler */
4411 protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
4413 /** Preference key for error indication in overview ruler */
4414 protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
4416 /** Preference key for warning indication in overview ruler */
4417 protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
4419 /** Preference key for task indication in overview ruler */
4420 protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
4422 /** Preference key for bookmark indication in overview ruler */
4423 protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
4425 /** Preference key for search result indication in overview ruler */
4426 protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
4428 /** Preference key for unknown annotation indication in overview ruler */
4429 protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
4431 // /** Preference key for compiler task tags */
4432 // private final static String COMPILER_TASK_TAGS=
4433 // JavaCore.COMPILER_TASK_TAGS;
4434 /** Preference key for browser like links */
4435 private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS;
4437 /** Preference key for key modifier of browser like links */
4438 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER;
4441 * Preference key for key modifier mask of browser like links. The value is
4442 * only used if the value of <code>EDITOR_BROWSER_LIKE_LINKS</code> cannot
4443 * be resolved to valid SWT modifier bits.
4447 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
4449 private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
4451 private static boolean isBracket(char character) {
4452 for (int i = 0; i != BRACKETS.length; ++i)
4453 if (character == BRACKETS[i])
4458 private static boolean isSurroundedByBrackets(IDocument document, int offset) {
4459 if (offset == 0 || offset == document.getLength())
4463 return isBracket(document.getChar(offset - 1)) && isBracket(document.getChar(offset));
4465 } catch (BadLocationException e) {
4470 // protected void configureSourceViewerDecorationSupport() {
4472 // fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
4474 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4475 // AnnotationType.UNKNOWN,
4476 // UNKNOWN_INDICATION_COLOR,
4477 // UNKNOWN_INDICATION,
4478 // UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
4480 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4481 // AnnotationType.BOOKMARK,
4482 // BOOKMARK_INDICATION_COLOR,
4483 // BOOKMARK_INDICATION,
4484 // BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
4486 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4487 // AnnotationType.TASK,
4488 // TASK_INDICATION_COLOR,
4490 // TASK_INDICATION_IN_OVERVIEW_RULER,
4492 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4493 // AnnotationType.SEARCH,
4494 // SEARCH_RESULT_INDICATION_COLOR,
4495 // SEARCH_RESULT_INDICATION,
4496 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
4498 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4499 // AnnotationType.WARNING,
4500 // WARNING_INDICATION_COLOR,
4501 // WARNING_INDICATION,
4502 // WARNING_INDICATION_IN_OVERVIEW_RULER,
4504 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4505 // AnnotationType.ERROR,
4506 // ERROR_INDICATION_COLOR,
4507 // ERROR_INDICATION,
4508 // ERROR_INDICATION_IN_OVERVIEW_RULER,
4511 // fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE,
4512 // CURRENT_LINE_COLOR);
4513 // fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN,
4514 // PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
4515 // fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS,
4516 // MATCHING_BRACKETS_COLOR);
4518 // fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
4522 * Returns the Java element wrapped by this editors input.
4524 * @return the Java element wrapped by this editors input.
4527 abstract protected IJavaElement getInputJavaElement();
4529 protected void updateStatusLine() {
4530 ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
4531 Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength());
4532 setStatusLineErrorMessage(null);
4533 setStatusLineMessage(null);
4534 if (annotation != null) {
4536 fIsUpdatingAnnotationViews = true;
4537 updateAnnotationViews(annotation);
4539 fIsUpdatingAnnotationViews = false;
4541 if (annotation instanceof IJavaAnnotation && ((IJavaAnnotation) annotation).isProblem())
4542 setStatusLineMessage(annotation.getText());
4547 * Jumps to the matching bracket.
4549 public void gotoMatchingBracket() {
4551 ISourceViewer sourceViewer = getSourceViewer();
4552 IDocument document = sourceViewer.getDocument();
4553 if (document == null)
4556 IRegion selection = getSignedSelection(sourceViewer);
4558 int selectionLength = Math.abs(selection.getLength());
4559 if (selectionLength > 1) {
4560 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$
4561 sourceViewer.getTextWidget().getDisplay().beep();
4566 int sourceCaretOffset = selection.getOffset() + selection.getLength();
4567 if (isSurroundedByBrackets(document, sourceCaretOffset))
4568 sourceCaretOffset -= selection.getLength();
4570 IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
4571 if (region == null) {
4572 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$
4573 sourceViewer.getTextWidget().getDisplay().beep();
4577 int offset = region.getOffset();
4578 int length = region.getLength();
4583 int anchor = fBracketMatcher.getAnchor();
4584 int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
4586 boolean visible = false;
4587 if (sourceViewer instanceof ITextViewerExtension3) {
4588 ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
4589 visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
4591 IRegion visibleRegion = sourceViewer.getVisibleRegion();
4592 visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength());
4596 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$
4597 sourceViewer.getTextWidget().getDisplay().beep();
4601 if (selection.getLength() < 0)
4602 targetOffset -= selection.getLength();
4604 sourceViewer.setSelectedRange(targetOffset, selection.getLength());
4605 sourceViewer.revealRange(targetOffset, selection.getLength());
4609 * Ses the given message as error message to this editor's status line.
4614 protected void setStatusLineErrorMessage(String msg) {
4615 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
4616 if (statusLine != null)
4617 statusLine.setMessage(true, msg, null);
4621 * Sets the given message as message to this editor's status line.
4627 protected void setStatusLineMessage(String msg) {
4628 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
4629 if (statusLine != null)
4630 statusLine.setMessage(false, msg, null);
4634 * Returns the annotation closest to the given range respecting the given
4635 * direction. If an annotation is found, the annotations current position is
4636 * copied into the provided annotation position.
4643 * <code>true</code> for forwards, <code>false</code> for
4645 * @param annotationPosition
4646 * the position of the found annotation
4647 * @return the found annotation
4649 private Annotation getNextAnnotation(final int offset, final int length, boolean forward, Position annotationPosition) {
4651 Annotation nextAnnotation = null;
4652 Position nextAnnotationPosition = null;
4653 Annotation containingAnnotation = null;
4654 Position containingAnnotationPosition = null;
4655 boolean currentAnnotation = false;
4657 IDocument document = getDocumentProvider().getDocument(getEditorInput());
4658 int endOfDocument = document.getLength();
4659 int distance = Integer.MAX_VALUE;
4661 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
4662 Iterator e = new JavaAnnotationIterator(model, true, true);
4663 while (e.hasNext()) {
4664 Annotation a = (Annotation) e.next();
4665 if ((a instanceof IJavaAnnotation) && ((IJavaAnnotation) a).hasOverlay() || !isNavigationTarget(a))
4668 Position p = model.getPosition(a);
4672 if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {// ||
4673 // p.includes(offset))
4675 if (containingAnnotation == null
4676 || (forward && p.length >= containingAnnotationPosition.length || !forward
4677 && p.length >= containingAnnotationPosition.length)) {
4678 containingAnnotation = a;
4679 containingAnnotationPosition = p;
4680 currentAnnotation = p.length == length;
4683 int currentDistance = 0;
4686 currentDistance = p.getOffset() - offset;
4687 if (currentDistance < 0)
4688 currentDistance = endOfDocument + currentDistance;
4690 if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
4691 distance = currentDistance;
4693 nextAnnotationPosition = p;
4696 currentDistance = offset + length - (p.getOffset() + p.length);
4697 if (currentDistance < 0)
4698 currentDistance = endOfDocument + currentDistance;
4700 if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
4701 distance = currentDistance;
4703 nextAnnotationPosition = p;
4708 if (containingAnnotationPosition != null && (!currentAnnotation || nextAnnotation == null)) {
4709 annotationPosition.setOffset(containingAnnotationPosition.getOffset());
4710 annotationPosition.setLength(containingAnnotationPosition.getLength());
4711 return containingAnnotation;
4713 if (nextAnnotationPosition != null) {
4714 annotationPosition.setOffset(nextAnnotationPosition.getOffset());
4715 annotationPosition.setLength(nextAnnotationPosition.getLength());
4718 return nextAnnotation;
4722 * Returns the annotation overlapping with the given range or
4723 * <code>null</code>.
4729 * @return the found annotation or <code>null</code>
4732 private Annotation getAnnotation(int offset, int length) {
4733 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
4734 Iterator e = new JavaAnnotationIterator(model, true, true);
4735 while (e.hasNext()) {
4736 Annotation a = (Annotation) e.next();
4737 if (!isNavigationTarget(a))
4740 Position p = model.getPosition(a);
4741 if (p != null && p.overlapsWith(offset, length))
4749 * Returns whether the given annotation is configured as a target for the "Go
4750 * to Next/Previous Annotation" actions
4754 * @return <code>true</code> if this is a target, <code>false</code>
4758 private boolean isNavigationTarget(Annotation annotation) {
4759 Preferences preferences = EditorsUI.getPluginPreferences();
4760 AnnotationPreference preference = getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
4762 // String key= forward ? preference.getIsGoToNextNavigationTargetKey() :
4763 // preference.getIsGoToPreviousNavigationTargetKey();
4764 String key = preference == null ? null : preference.getIsGoToNextNavigationTargetKey();
4765 return (key != null && preferences.getBoolean(key));
4769 * Returns a segmentation of the line of the given document appropriate for
4770 * bidi rendering. The default implementation returns only the string literals
4771 * of a php code line as segments.
4776 * the offset of the line
4777 * @return the line's bidi segmentation
4778 * @throws BadLocationException
4779 * in case lineOffset is not valid in document
4781 public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException {
4783 IRegion line = document.getLineInformationOfOffset(lineOffset);
4784 ITypedRegion[] linePartitioning = document.computePartitioning(lineOffset, line.getLength());
4786 List segmentation = new ArrayList();
4787 for (int i = 0; i < linePartitioning.length; i++) {
4788 if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType()))
4789 segmentation.add(linePartitioning[i]);
4792 if (segmentation.size() == 0)
4795 int size = segmentation.size();
4796 int[] segments = new int[size * 2 + 1];
4799 for (int i = 0; i < size; i++) {
4800 ITypedRegion segment = (ITypedRegion) segmentation.get(i);
4805 int offset = segment.getOffset() - lineOffset;
4806 if (offset > segments[j - 1])
4807 segments[j++] = offset;
4809 if (offset + segment.getLength() >= line.getLength())
4812 segments[j++] = offset + segment.getLength();
4815 if (j < segments.length) {
4816 int[] result = new int[j];
4817 System.arraycopy(segments, 0, result, 0, j);
4825 * Returns a segmentation of the given line appropriate for bidi rendering.
4826 * The default implementation returns only the string literals of a php code
4830 * the offset of the line
4832 * the content of the line
4833 * @return the line's bidi segmentation
4835 protected int[] getBidiLineSegments(int lineOffset, String line) {
4836 IDocumentProvider provider = getDocumentProvider();
4837 if (provider != null && line != null && line.length() > 0) {
4838 IDocument document = provider.getDocument(getEditorInput());
4839 if (document != null)
4841 return getBidiLineSegments(document, lineOffset);
4842 } catch (BadLocationException x) {
4850 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4852 // protected final ISourceViewer createSourceViewer(
4853 // Composite parent,
4854 // IVerticalRuler ruler,
4856 // ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
4857 // StyledText text = viewer.getTextWidget();
4858 // text.addBidiSegmentListener(new BidiSegmentListener() {
4859 // public void lineGetSegments(BidiSegmentEvent event) {
4860 // event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
4863 // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
4866 public final ISourceViewer getViewer() {
4867 return getSourceViewer();
4870 // protected void showOverviewRuler() {
4871 // if (fOverviewRuler != null) {
4872 // if (getSourceViewer() instanceof ISourceViewerExtension) {
4873 // ((ISourceViewerExtension)
4874 // getSourceViewer()).showAnnotationsOverview(true);
4875 // fSourceViewerDecorationSupport.updateOverviewDecorations();
4880 // protected void hideOverviewRuler() {
4881 // if (getSourceViewer() instanceof ISourceViewerExtension) {
4882 // fSourceViewerDecorationSupport.hideAnnotationOverview();
4883 // ((ISourceViewerExtension)
4884 // getSourceViewer()).showAnnotationsOverview(false);
4888 // protected boolean isOverviewRulerVisible() {
4889 // IPreferenceStore store = getPreferenceStore();
4890 // return store.getBoolean(OVERVIEW_RULER);
4893 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4895 // protected ISourceViewer createJavaSourceViewer(
4896 // Composite parent,
4897 // IVerticalRuler ruler,
4898 // IOverviewRuler overviewRuler,
4899 // boolean isOverviewRulerVisible,
4901 // return new SourceViewer(parent, ruler, overviewRuler,
4902 // isOverviewRulerVisible(), styles);
4905 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4907 protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
4908 boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
4909 return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, store);
4913 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4915 protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {
4917 ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles,
4918 getPreferenceStore());
4920 StyledText text = viewer.getTextWidget();
4921 text.addBidiSegmentListener(new BidiSegmentListener() {
4922 public void lineGetSegments(BidiSegmentEvent event) {
4923 event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
4927 // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
4929 // ensure source viewer decoration support has been created and
4931 getSourceViewerDecorationSupport(viewer);
4937 * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
4939 protected boolean affectsTextPresentation(PropertyChangeEvent event) {
4940 return ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).affectsTextPresentation(event)
4941 || super.affectsTextPresentation(event);
4945 // protected boolean affectsTextPresentation(PropertyChangeEvent event) {
4946 // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
4947 // return textTools.affectsBehavior(event);
4950 * Creates and returns the preference store for this Java editor with the
4954 * The editor input for which to create the preference store
4955 * @return the preference store for this editor
4959 private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
4960 List stores = new ArrayList(3);
4962 IJavaProject project = EditorUtility.getJavaProject(input);
4963 if (project != null)
4964 stores.add(new OptionsAdapter(project.getOptions(false), PHPeclipsePlugin.getDefault().getMockupPreferenceStore(),
4965 new OptionsAdapter.IPropertyChangeEventFilter() {
4967 public boolean isFiltered(PropertyChangeEvent event) {
4968 IJavaElement inputJavaElement = getInputJavaElement();
4969 IJavaProject javaProject = inputJavaElement != null ? inputJavaElement.getJavaProject() : null;
4970 if (javaProject == null)
4973 return !javaProject.getProject().equals(event.getSource());
4978 stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore());
4979 stores.add(new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()));
4980 stores.add(EditorsUI.getPreferenceStore());
4982 return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
4986 * Jumps to the error next according to the given direction.
4988 public void gotoError(boolean forward) {
4990 ISelectionProvider provider = getSelectionProvider();
4992 ITextSelection s = (ITextSelection) provider.getSelection();
4993 Position errorPosition = new Position(0, 0);
4994 IJavaAnnotation nextError = getNextError(s.getOffset(), forward, errorPosition);
4996 if (nextError != null) {
4998 IMarker marker = null;
4999 if (nextError instanceof MarkerAnnotation)
5000 marker = ((MarkerAnnotation) nextError).getMarker();
5002 Iterator e = nextError.getOverlaidIterator();
5004 while (e.hasNext()) {
5005 Object o = e.next();
5006 if (o instanceof MarkerAnnotation) {
5007 marker = ((MarkerAnnotation) o).getMarker();
5014 if (marker != null) {
5015 IWorkbenchPage page = getSite().getPage();
5016 IViewPart view = view = page.findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
5017 if (view instanceof TaskList) {
5018 StructuredSelection ss = new StructuredSelection(marker);
5019 ((TaskList) view).setSelection(ss, true);
5023 selectAndReveal(errorPosition.getOffset(), errorPosition.getLength());
5024 // setStatusLineErrorMessage(nextError.getMessage());
5028 setStatusLineErrorMessage(null);
5033 private IJavaAnnotation getNextError(int offset, boolean forward, Position errorPosition) {
5035 IJavaAnnotation nextError = null;
5036 Position nextErrorPosition = null;
5038 IDocument document = getDocumentProvider().getDocument(getEditorInput());
5039 int endOfDocument = document.getLength();
5042 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
5043 Iterator e = new JavaAnnotationIterator(model, false);
5044 while (e.hasNext()) {
5046 IJavaAnnotation a = (IJavaAnnotation) e.next();
5047 if (a.hasOverlay() || !a.isProblem())
5050 Position p = model.getPosition((Annotation) a);
5051 if (!p.includes(offset)) {
5053 int currentDistance = 0;
5056 currentDistance = p.getOffset() - offset;
5057 if (currentDistance < 0)
5058 currentDistance = endOfDocument - offset + p.getOffset();
5060 currentDistance = offset - p.getOffset();
5061 if (currentDistance < 0)
5062 currentDistance = offset + endOfDocument - p.getOffset();
5065 if (nextError == null || currentDistance < distance) {
5066 distance = currentDistance;
5068 nextErrorPosition = p;
5073 if (nextErrorPosition != null) {
5074 errorPosition.setOffset(nextErrorPosition.getOffset());
5075 errorPosition.setLength(nextErrorPosition.getLength());
5081 void removeOccurrenceAnnotations() {
5082 IDocumentProvider documentProvider = getDocumentProvider();
5083 if (documentProvider == null)
5086 IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
5087 if (annotationModel == null || fOccurrenceAnnotations == null)
5090 synchronized (annotationModel) {
5091 if (annotationModel instanceof IAnnotationModelExtension) {
5092 ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
5094 for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++)
5095 annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
5097 fOccurrenceAnnotations = null;
5101 protected void uninstallOverrideIndicator() {
5102 // if (fOverrideIndicatorManager != null) {
5103 // fOverrideIndicatorManager.removeAnnotations();
5104 // fOverrideIndicatorManager= null;
5108 protected void installOverrideIndicator(boolean waitForReconcilation) {
5109 uninstallOverrideIndicator();
5110 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
5111 final IJavaElement inputElement = getInputJavaElement();
5113 if (model == null || inputElement == null)
5116 // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
5117 // inputElement, null);
5119 // if (provideAST) {
5121 // Job(JavaEditorMessages.getString("OverrideIndicatorManager.intallJob")) {
5125 // org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
5128 // protected IStatus run(IProgressMonitor monitor) {
5129 // CompilationUnit ast=
5130 // JavaPlugin.getDefault().getASTProvider().getAST(inputElement, true,
5132 // if (fOverrideIndicatorManager != null) // editor might have been closed
5134 // fOverrideIndicatorManager.reconciled(ast, true, monitor);
5135 // return Status.OK_STATUS;
5138 // job.setPriority(Job.DECORATE);
5139 // job.setSystem(true);
5145 * Tells whether override indicators are shown.
5147 * @return <code>true</code> if the override indicators are shown
5150 // protected boolean isShowingOverrideIndicators() {
5151 // AnnotationPreference preference=
5152 // getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
5153 // IPreferenceStore store= getPreferenceStore();
5154 // return getBoolean(store, preference.getHighlightPreferenceKey())
5155 // || getBoolean(store, preference.getVerticalRulerPreferenceKey())
5156 // || getBoolean(store, preference.getOverviewRulerPreferenceKey())
5157 // || getBoolean(store, preference.getTextPreferenceKey());
5160 * Returns the boolean preference for the given key.
5163 * the preference store
5165 * the preference key
5166 * @return <code>true</code> if the key exists in the store and its value is
5170 private boolean getBoolean(IPreferenceStore store, String key) {
5171 return key != null && store.getBoolean(key);
5174 protected boolean isPrefQuickDiffAlwaysOn() {
5175 return false; // never show change ruler for the non-editable java editor.
5176 // Overridden in subclasses like PHPUnitEditor
5180 * @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions()
5182 protected void createNavigationActions() {
5183 super.createNavigationActions();
5185 final StyledText textWidget = getSourceViewer().getTextWidget();
5187 IAction action = new SmartLineStartAction(textWidget, false);
5188 action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
5189 setAction(ITextEditorActionDefinitionIds.LINE_START, action);
5191 action = new SmartLineStartAction(textWidget, true);
5192 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
5193 setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);
5195 action = new NavigatePreviousSubWordAction();
5196 action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS);
5197 setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action);
5198 textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL);
5200 action = new NavigateNextSubWordAction();
5201 action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT);
5202 setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action);
5203 textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL);
5205 action = new SelectPreviousSubWordAction();
5206 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS);
5207 setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action);
5208 textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL);
5210 action = new SelectNextSubWordAction();
5211 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT);
5212 setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action);
5213 textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL);
5217 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createCompositeRuler()
5219 protected CompositeRuler createCompositeRuler() {
5220 if (!getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
5221 return super.createCompositeRuler();
5223 CompositeRuler ruler = new CompositeRuler();
5224 AnnotationRulerColumn column = new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess());
5225 column.setHover(new JavaExpandHover(ruler, getAnnotationAccess(), new IDoubleClickListener() {
5227 public void doubleClick(DoubleClickEvent event) {
5228 // for now: just invoke ruler double click action
5229 triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK);
5232 private void triggerAction(String actionID) {
5233 IAction action = getAction(actionID);
5234 if (action != null) {
5235 if (action instanceof IUpdate)
5236 ((IUpdate) action).update();
5237 // hack to propagate line change
5238 if (action instanceof ISelectionListener) {
5239 ((ISelectionListener) action).selectionChanged(null, null);
5241 if (action.isEnabled())
5247 ruler.addDecorator(0, column);
5249 if (isLineNumberRulerVisible())
5250 ruler.addDecorator(1, createLineNumberRulerColumn());
5251 else if (isPrefQuickDiffAlwaysOn())
5252 ruler.addDecorator(1, createChangeRulerColumn());
5258 * Returns the folding action group, or <code>null</code> if there is none.
5260 * @return the folding action group, or <code>null</code> if there is none
5263 protected FoldingActionGroup getFoldingActionGroup() {
5264 return fFoldingGroup;
5268 * @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert()
5270 protected void performRevert() {
5271 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
5272 projectionViewer.setRedraw(false);
5275 boolean projectionMode = projectionViewer.isProjectionMode();
5276 if (projectionMode) {
5277 projectionViewer.disableProjection();
5278 if (fProjectionModelUpdater != null)
5279 fProjectionModelUpdater.uninstall();
5282 super.performRevert();
5284 if (projectionMode) {
5285 if (fProjectionModelUpdater != null)
5286 fProjectionModelUpdater.install(this, projectionViewer);
5287 projectionViewer.enableProjection();
5291 projectionViewer.setRedraw(true);
5296 * React to changed selection.
5300 protected void selectionChanged() {
5301 if (getSelectionProvider() == null)
5303 ISourceReference element = computeHighlightRangeSourceReference();
5304 if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
5305 synchronizeOutlinePage(element);
5306 setSelection(element, false);
5310 private boolean isJavaOutlinePageActive() {
5311 IWorkbenchPart part = getActivePart();
5312 return part instanceof ContentOutline && ((ContentOutline) part).getCurrentPage() == fOutlinePage;
5315 private IWorkbenchPart getActivePart() {
5316 IWorkbenchWindow window = getSite().getWorkbenchWindow();
5317 IPartService service = window.getPartService();
5318 IWorkbenchPart part = service.getActivePart();
5323 * Computes and returns the source reference that includes the caret and
5324 * serves as provider for the outline page selection and the editor range
5327 * @return the computed source reference
5330 protected ISourceReference computeHighlightRangeSourceReference() {
5331 ISourceViewer sourceViewer = getSourceViewer();
5332 if (sourceViewer == null)
5335 StyledText styledText = sourceViewer.getTextWidget();
5336 if (styledText == null)
5340 if (sourceViewer instanceof ITextViewerExtension5) {
5341 ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
5342 caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
5344 int offset = sourceViewer.getVisibleRegion().getOffset();
5345 caret = offset + styledText.getCaretOffset();
5348 IJavaElement element = getElementAt(caret, false);
5350 if (!(element instanceof ISourceReference))
5353 if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) {
5355 IImportDeclaration declaration = (IImportDeclaration) element;
5356 IImportContainer container = (IImportContainer) declaration.getParent();
5357 ISourceRange srcRange = null;
5360 srcRange = container.getSourceRange();
5361 } catch (JavaModelException e) {
5364 if (srcRange != null && srcRange.getOffset() == caret)
5368 return (ISourceReference) element;
5372 * Returns the most narrow java element including the given offset.
5375 * the offset inside of the requested element
5377 * <code>true</code> if editor input should be reconciled in
5379 * @return the most narrow java element
5382 protected IJavaElement getElementAt(int offset, boolean reconcile) {
5383 return getElementAt(offset);
5386 public ShowInContext getShowInContext() {
5387 FileEditorInput fei = (FileEditorInput) getEditorInput();
5388 ShowInContext context = BrowserUtil.getShowInContext(fei.getFile(), false, "");
5389 if (context!=null) {
5392 return new ShowInContext(fei.getFile(), null);
5395 public String[] getShowInTargetIds() {
5396 return new String[] { BrowserView.ID_BROWSER };