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;
59 import org.eclipse.core.resources.IMarker;
60 import org.eclipse.core.resources.IResource;
61 import org.eclipse.core.runtime.CoreException;
62 import org.eclipse.core.runtime.IProgressMonitor;
63 import org.eclipse.core.runtime.IStatus;
64 import org.eclipse.core.runtime.Preferences;
65 import org.eclipse.core.runtime.Status;
66 import org.eclipse.core.runtime.jobs.Job;
67 import org.eclipse.jface.action.Action;
68 import org.eclipse.jface.action.GroupMarker;
69 import org.eclipse.jface.action.IAction;
70 import org.eclipse.jface.action.MenuManager;
71 import org.eclipse.jface.action.Separator;
72 import org.eclipse.jface.preference.IPreferenceStore;
73 import org.eclipse.jface.preference.PreferenceConverter;
74 import org.eclipse.jface.text.BadLocationException;
75 import org.eclipse.jface.text.DefaultInformationControl;
76 import org.eclipse.jface.text.DocumentEvent;
77 import org.eclipse.jface.text.IDocument;
78 import org.eclipse.jface.text.IDocumentListener;
79 import org.eclipse.jface.text.IInformationControl;
80 import org.eclipse.jface.text.IInformationControlCreator;
81 import org.eclipse.jface.text.IRegion;
82 import org.eclipse.jface.text.ISynchronizable;
83 import org.eclipse.jface.text.ITextHover;
84 import org.eclipse.jface.text.ITextInputListener;
85 import org.eclipse.jface.text.ITextPresentationListener;
86 import org.eclipse.jface.text.ITextSelection;
87 import org.eclipse.jface.text.ITextViewer;
88 import org.eclipse.jface.text.ITextViewerExtension2;
89 import org.eclipse.jface.text.ITextViewerExtension3;
90 import org.eclipse.jface.text.ITextViewerExtension4;
91 import org.eclipse.jface.text.ITextViewerExtension5;
92 import org.eclipse.jface.text.ITypedRegion;
93 import org.eclipse.jface.text.Position;
94 import org.eclipse.jface.text.Region;
95 import org.eclipse.jface.text.TextPresentation;
96 import org.eclipse.jface.text.TextSelection;
97 import org.eclipse.jface.text.TextUtilities;
98 import org.eclipse.jface.text.information.IInformationProvider;
99 import org.eclipse.jface.text.information.InformationPresenter;
100 import org.eclipse.jface.text.reconciler.IReconciler;
101 import org.eclipse.jface.text.source.Annotation;
102 import org.eclipse.jface.text.source.AnnotationRulerColumn;
103 import org.eclipse.jface.text.source.CompositeRuler;
104 import org.eclipse.jface.text.source.IAnnotationModel;
105 import org.eclipse.jface.text.source.IAnnotationModelExtension;
106 import org.eclipse.jface.text.source.IOverviewRuler;
107 import org.eclipse.jface.text.source.ISourceViewer;
108 import org.eclipse.jface.text.source.ISourceViewerExtension2;
109 import org.eclipse.jface.text.source.IVerticalRuler;
110 import org.eclipse.jface.text.source.OverviewRuler;
111 import org.eclipse.jface.text.source.SourceViewerConfiguration;
112 import org.eclipse.jface.text.source.projection.ProjectionSupport;
113 import org.eclipse.jface.text.source.projection.ProjectionViewer;
114 import org.eclipse.jface.util.IPropertyChangeListener;
115 import org.eclipse.jface.util.ListenerList;
116 import org.eclipse.jface.util.PropertyChangeEvent;
117 import org.eclipse.jface.viewers.DoubleClickEvent;
118 import org.eclipse.jface.viewers.IDoubleClickListener;
119 import org.eclipse.jface.viewers.IPostSelectionProvider;
120 import org.eclipse.jface.viewers.ISelection;
121 import org.eclipse.jface.viewers.ISelectionChangedListener;
122 import org.eclipse.jface.viewers.ISelectionProvider;
123 import org.eclipse.jface.viewers.IStructuredSelection;
124 import org.eclipse.jface.viewers.SelectionChangedEvent;
125 import org.eclipse.jface.viewers.StructuredSelection;
126 import org.eclipse.swt.SWT;
127 import org.eclipse.swt.custom.BidiSegmentEvent;
128 import org.eclipse.swt.custom.BidiSegmentListener;
129 import org.eclipse.swt.custom.ST;
130 import org.eclipse.swt.custom.StyleRange;
131 import org.eclipse.swt.custom.StyledText;
132 import org.eclipse.swt.events.FocusEvent;
133 import org.eclipse.swt.events.FocusListener;
134 import org.eclipse.swt.events.KeyEvent;
135 import org.eclipse.swt.events.KeyListener;
136 import org.eclipse.swt.events.MouseEvent;
137 import org.eclipse.swt.events.MouseListener;
138 import org.eclipse.swt.events.MouseMoveListener;
139 import org.eclipse.swt.events.PaintEvent;
140 import org.eclipse.swt.events.PaintListener;
141 import org.eclipse.swt.graphics.Color;
142 import org.eclipse.swt.graphics.Cursor;
143 import org.eclipse.swt.graphics.GC;
144 import org.eclipse.swt.graphics.Image;
145 import org.eclipse.swt.graphics.Point;
146 import org.eclipse.swt.graphics.RGB;
147 import org.eclipse.swt.widgets.Composite;
148 import org.eclipse.swt.widgets.Control;
149 import org.eclipse.swt.widgets.Display;
150 import org.eclipse.swt.widgets.Shell;
151 import org.eclipse.ui.IEditorInput;
152 import org.eclipse.ui.IPageLayout;
153 import org.eclipse.ui.IPartService;
154 import org.eclipse.ui.ISelectionListener;
155 import org.eclipse.ui.IViewPart;
156 import org.eclipse.ui.IWorkbenchPage;
157 import org.eclipse.ui.IWorkbenchPart;
158 import org.eclipse.ui.IWorkbenchWindow;
159 import org.eclipse.ui.actions.ActionContext;
160 import org.eclipse.ui.actions.ActionGroup;
161 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
162 import org.eclipse.ui.editors.text.EditorsUI;
163 import org.eclipse.ui.editors.text.IEncodingSupport;
164 import org.eclipse.ui.part.IShowInTargetList;
165 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
166 import org.eclipse.ui.texteditor.AnnotationPreference;
167 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
168 import org.eclipse.ui.texteditor.IDocumentProvider;
169 import org.eclipse.ui.texteditor.IEditorStatusLine;
170 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
171 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
172 import org.eclipse.ui.texteditor.IUpdate;
173 import org.eclipse.ui.texteditor.MarkerAnnotation;
174 import org.eclipse.ui.texteditor.ResourceAction;
175 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
176 import org.eclipse.ui.texteditor.TextEditorAction;
177 import org.eclipse.ui.texteditor.TextNavigationAction;
178 import org.eclipse.ui.texteditor.TextOperationAction;
179 import org.eclipse.ui.views.contentoutline.ContentOutline;
180 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
181 import org.eclipse.ui.views.tasklist.TaskList;
184 * PHP specific text editor.
186 public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider {
187 //extends StatusTextEditor implements IViewPartInputProvider { // extends
191 * Internal implementation class for a change listener.
195 protected abstract class AbstractSelectionChangedListener implements ISelectionChangedListener {
198 * Installs this selection changed listener with the given selection provider. If the selection provider is a post selection
199 * provider, post selection changed events are the preferred choice, otherwise normal selection changed events are requested.
201 * @param selectionProvider
203 public void install(ISelectionProvider selectionProvider) {
204 if (selectionProvider == null)
207 if (selectionProvider instanceof IPostSelectionProvider) {
208 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
209 provider.addPostSelectionChangedListener(this);
211 selectionProvider.addSelectionChangedListener(this);
216 * Removes this selection changed listener from the given selection provider.
218 * @param selectionProvider
219 * the selection provider
221 public void uninstall(ISelectionProvider selectionProvider) {
222 if (selectionProvider == null)
225 if (selectionProvider instanceof IPostSelectionProvider) {
226 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
227 provider.removePostSelectionChangedListener(this);
229 selectionProvider.removeSelectionChangedListener(this);
235 * Updates the Java outline page selection and this editor's range indicator.
239 private class EditorSelectionChangedListener extends AbstractSelectionChangedListener {
242 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
244 public void selectionChanged(SelectionChangedEvent event) {
245 // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161
246 PHPEditor.this.selectionChanged();
251 * "Smart" runnable for updating the outline page's selection.
253 // class OutlinePageSelectionUpdater implements Runnable {
255 // /** Has the runnable already been posted? */
256 // private boolean fPosted = false;
258 // public OutlinePageSelectionUpdater() {
262 // * @see Runnable#run()
264 // public void run() {
265 // synchronizeOutlinePageSelection();
270 // * Posts this runnable into the event queue.
272 // public void post() {
276 // Shell shell = getSite().getShell();
277 // if (shell != null & !shell.isDisposed()) {
279 // shell.getDisplay().asyncExec(this);
283 class SelectionChangedListener implements ISelectionChangedListener {
284 public void selectionChanged(SelectionChangedEvent event) {
285 doSelectionChanged(event);
290 * Adapts an options {@link java.util.Map}to {@link org.eclipse.jface.preference.IPreferenceStore}.
292 * This preference store is read-only i.e. write access throws an {@link java.lang.UnsupportedOperationException}.
297 private static class OptionsAdapter implements IPreferenceStore {
300 * A property change event filter.
302 public interface IPropertyChangeEventFilter {
305 * Should the given event be filtered?
308 * The property change event.
309 * @return <code>true</code> iff the given event should be filtered.
311 public boolean isFiltered(PropertyChangeEvent event);
316 * Property change listener. Listens for events in the options Map and fires a
317 * {@link org.eclipse.jface.util.PropertyChangeEvent}on this adapter with arguments from the received event.
319 private class PropertyChangeListener implements IPropertyChangeListener {
324 public void propertyChange(PropertyChangeEvent event) {
325 if (getFilter().isFiltered(event))
328 if (event.getNewValue() == null)
329 fOptions.remove(event.getProperty());
331 fOptions.put(event.getProperty(), event.getNewValue());
333 firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
337 /** Listeners on this adapter */
338 private ListenerList fListeners = new ListenerList();
340 /** Listener on the adapted options Map */
341 private IPropertyChangeListener fListener = new PropertyChangeListener();
343 /** Adapted options Map */
344 private Map fOptions;
346 /** Preference store through which events are received. */
347 private IPreferenceStore fMockupPreferenceStore;
349 /** Property event filter. */
350 private IPropertyChangeEventFilter fFilter;
353 * Initialize with the given options.
356 * The options to wrap
357 * @param mockupPreferenceStore
358 * the mock-up preference store
360 * the property change filter
362 public OptionsAdapter(Map options, IPreferenceStore mockupPreferenceStore, IPropertyChangeEventFilter filter) {
363 fMockupPreferenceStore = mockupPreferenceStore;
371 public void addPropertyChangeListener(IPropertyChangeListener listener) {
372 if (fListeners.size() == 0)
373 fMockupPreferenceStore.addPropertyChangeListener(fListener);
374 fListeners.add(listener);
380 public void removePropertyChangeListener(IPropertyChangeListener listener) {
381 fListeners.remove(listener);
382 if (fListeners.size() == 0)
383 fMockupPreferenceStore.removePropertyChangeListener(fListener);
389 public boolean contains(String name) {
390 return fOptions.containsKey(name);
396 public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
397 PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
398 Object[] listeners = fListeners.getListeners();
399 for (int i = 0; i < listeners.length; i++)
400 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
406 public boolean getBoolean(String name) {
407 boolean value = BOOLEAN_DEFAULT_DEFAULT;
408 String s = (String) fOptions.get(name);
410 value = s.equals(TRUE);
417 public boolean getDefaultBoolean(String name) {
418 return BOOLEAN_DEFAULT_DEFAULT;
424 public double getDefaultDouble(String name) {
425 return DOUBLE_DEFAULT_DEFAULT;
431 public float getDefaultFloat(String name) {
432 return FLOAT_DEFAULT_DEFAULT;
438 public int getDefaultInt(String name) {
439 return INT_DEFAULT_DEFAULT;
445 public long getDefaultLong(String name) {
446 return LONG_DEFAULT_DEFAULT;
452 public String getDefaultString(String name) {
453 return STRING_DEFAULT_DEFAULT;
459 public double getDouble(String name) {
460 double value = DOUBLE_DEFAULT_DEFAULT;
461 String s = (String) fOptions.get(name);
464 value = new Double(s).doubleValue();
465 } catch (NumberFormatException e) {
474 public float getFloat(String name) {
475 float value = FLOAT_DEFAULT_DEFAULT;
476 String s = (String) fOptions.get(name);
479 value = new Float(s).floatValue();
480 } catch (NumberFormatException e) {
489 public int getInt(String name) {
490 int value = INT_DEFAULT_DEFAULT;
491 String s = (String) fOptions.get(name);
494 value = new Integer(s).intValue();
495 } catch (NumberFormatException e) {
504 public long getLong(String name) {
505 long value = LONG_DEFAULT_DEFAULT;
506 String s = (String) fOptions.get(name);
509 value = new Long(s).longValue();
510 } catch (NumberFormatException e) {
519 public String getString(String name) {
520 String value = (String) fOptions.get(name);
522 value = STRING_DEFAULT_DEFAULT;
529 public boolean isDefault(String name) {
536 public boolean needsSaving() {
537 return !fOptions.isEmpty();
543 public void putValue(String name, String value) {
544 throw new UnsupportedOperationException();
550 public void setDefault(String name, double value) {
551 throw new UnsupportedOperationException();
557 public void setDefault(String name, float value) {
558 throw new UnsupportedOperationException();
564 public void setDefault(String name, int value) {
565 throw new UnsupportedOperationException();
571 public void setDefault(String name, long value) {
572 throw new UnsupportedOperationException();
578 public void setDefault(String name, String defaultObject) {
579 throw new UnsupportedOperationException();
585 public void setDefault(String name, boolean value) {
586 throw new UnsupportedOperationException();
592 public void setToDefault(String name) {
593 throw new UnsupportedOperationException();
599 public void setValue(String name, double value) {
600 throw new UnsupportedOperationException();
606 public void setValue(String name, float value) {
607 throw new UnsupportedOperationException();
613 public void setValue(String name, int value) {
614 throw new UnsupportedOperationException();
620 public void setValue(String name, long value) {
621 throw new UnsupportedOperationException();
627 public void setValue(String name, String value) {
628 throw new UnsupportedOperationException();
634 public void setValue(String name, boolean value) {
635 throw new UnsupportedOperationException();
639 * Returns the adapted options Map.
641 * @return Returns the adapted options Map.
643 public Map getOptions() {
648 * Returns the mock-up preference store, events are received through this preference store.
650 * @return Returns the mock-up preference store.
652 public IPreferenceStore getMockupPreferenceStore() {
653 return fMockupPreferenceStore;
657 * Set the event filter to the given filter.
662 public void setFilter(IPropertyChangeEventFilter filter) {
667 * Returns the event filter.
669 * @return The event filter.
671 public IPropertyChangeEventFilter getFilter() {
679 // class MouseClickListener implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener,
680 // IPropertyChangeListener, IDocumentListener, ITextInputListener {
682 // /** The session is active. */
683 // private boolean fActive;
685 // /** The currently active style range. */
686 // private IRegion fActiveRegion;
688 // /** The currently active style range as position. */
689 // private Position fRememberedPosition;
691 // /** The hand cursor. */
692 // private Cursor fCursor;
694 // /** The link color. */
695 // private Color fColor;
697 // /** The key modifier mask. */
698 // private int fKeyModifierMask;
700 // public void deactivate() {
701 // deactivate(false);
704 // public void deactivate(boolean redrawAll) {
708 // repairRepresentation(redrawAll);
712 // public void install() {
714 // ISourceViewer sourceViewer = getSourceViewer();
715 // if (sourceViewer == null)
718 // StyledText text = sourceViewer.getTextWidget();
719 // if (text == null || text.isDisposed())
722 // updateColor(sourceViewer);
724 // sourceViewer.addTextInputListener(this);
726 // IDocument document = sourceViewer.getDocument();
727 // if (document != null)
728 // document.addDocumentListener(this);
730 // text.addKeyListener(this);
731 // text.addMouseListener(this);
732 // text.addMouseMoveListener(this);
733 // text.addFocusListener(this);
734 // text.addPaintListener(this);
736 // updateKeyModifierMask();
738 // IPreferenceStore preferenceStore = getPreferenceStore();
739 // preferenceStore.addPropertyChangeListener(this);
742 // private void updateKeyModifierMask() {
743 // String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
744 // fKeyModifierMask = computeStateMask(modifiers);
745 // if (fKeyModifierMask == -1) {
746 // // Fallback to stored state mask
747 // fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
752 // private int computeStateMask(String modifiers) {
753 // if (modifiers == null)
756 // if (modifiers.length() == 0)
759 // int stateMask = 0;
760 // StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
761 // while (modifierTokenizer.hasMoreTokens()) {
762 // int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
763 // if (modifier == 0 || (stateMask & modifier) == modifier)
765 // stateMask = stateMask | modifier;
770 // public void uninstall() {
772 // if (fColor != null) {
777 // if (fCursor != null) {
778 // fCursor.dispose();
782 // ISourceViewer sourceViewer = getSourceViewer();
783 // if (sourceViewer == null)
786 // sourceViewer.removeTextInputListener(this);
788 // IDocument document = sourceViewer.getDocument();
789 // if (document != null)
790 // document.removeDocumentListener(this);
792 // IPreferenceStore preferenceStore = getPreferenceStore();
793 // if (preferenceStore != null)
794 // preferenceStore.removePropertyChangeListener(this);
796 // StyledText text = sourceViewer.getTextWidget();
797 // if (text == null || text.isDisposed())
800 // text.removeKeyListener(this);
801 // text.removeMouseListener(this);
802 // text.removeMouseMoveListener(this);
803 // text.removeFocusListener(this);
804 // text.removePaintListener(this);
808 // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
810 // public void propertyChange(PropertyChangeEvent event) {
811 // if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
812 // ISourceViewer viewer = getSourceViewer();
813 // if (viewer != null)
814 // updateColor(viewer);
815 // } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
816 // updateKeyModifierMask();
820 // private void updateColor(ISourceViewer viewer) {
821 // if (fColor != null)
824 // StyledText text = viewer.getTextWidget();
825 // if (text == null || text.isDisposed())
828 // Display display = text.getDisplay();
829 // fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
833 // * Creates a color from the information stored in the given preference store. Returns <code>null</code> if there is no such
834 // * information available.
836 // private Color createColor(IPreferenceStore store, String key, Display display) {
840 // if (store.contains(key)) {
842 // if (store.isDefault(key))
843 // rgb = PreferenceConverter.getDefaultColor(store, key);
845 // rgb = PreferenceConverter.getColor(store, key);
848 // return new Color(display, rgb);
854 // private void repairRepresentation() {
855 // repairRepresentation(false);
858 // private void repairRepresentation(boolean redrawAll) {
860 // if (fActiveRegion == null)
863 // ISourceViewer viewer = getSourceViewer();
864 // if (viewer != null) {
865 // resetCursor(viewer);
867 // int offset = fActiveRegion.getOffset();
868 // int length = fActiveRegion.getLength();
871 // if (!redrawAll && viewer instanceof ITextViewerExtension2)
872 // ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
874 // viewer.invalidateTextPresentation();
876 // // remove underline
877 // if (viewer instanceof ITextViewerExtension3) {
878 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
879 // offset = extension.modelOffset2WidgetOffset(offset);
881 // offset -= viewer.getVisibleRegion().getOffset();
884 // StyledText text = viewer.getTextWidget();
886 // text.redrawRange(offset, length, true);
887 // } catch (IllegalArgumentException x) {
888 // PHPeclipsePlugin.log(x);
892 // fActiveRegion = null;
895 // // will eventually be replaced by a method provided by jdt.core
896 // private IRegion selectWord(IDocument document, int anchor) {
899 // int offset = anchor;
902 // while (offset >= 0) {
903 // c = document.getChar(offset);
904 // if (!Character.isJavaIdentifierPart(c))
909 // int start = offset;
912 // int length = document.getLength();
914 // while (offset < length) {
915 // c = document.getChar(offset);
916 // if (!Character.isJavaIdentifierPart(c))
924 // return new Region(start, 0);
926 // return new Region(start + 1, end - start - 1);
928 // } catch (BadLocationException x) {
933 // IRegion getCurrentTextRegion(ISourceViewer viewer) {
935 // int offset = getCurrentTextOffset(viewer);
940 // // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
941 // // if (input == null)
946 // // IJavaElement[] elements= null;
947 // // synchronized (input) {
948 // // elements= ((ICodeAssist) input).codeSelect(offset, 0);
951 // // if (elements == null || elements.length == 0)
954 // // return selectWord(viewer.getDocument(), offset);
956 // // } catch (JavaModelException e) {
961 // private int getCurrentTextOffset(ISourceViewer viewer) {
964 // StyledText text = viewer.getTextWidget();
965 // if (text == null || text.isDisposed())
968 // Display display = text.getDisplay();
969 // Point absolutePosition = display.getCursorLocation();
970 // Point relativePosition = text.toControl(absolutePosition);
972 // int widgetOffset = text.getOffsetAtLocation(relativePosition);
973 // if (viewer instanceof ITextViewerExtension3) {
974 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
975 // return extension.widgetOffset2ModelOffset(widgetOffset);
977 // return widgetOffset + viewer.getVisibleRegion().getOffset();
980 // } catch (IllegalArgumentException e) {
985 // private void highlightRegion(ISourceViewer viewer, IRegion region) {
987 // if (region.equals(fActiveRegion))
990 // repairRepresentation();
992 // StyledText text = viewer.getTextWidget();
993 // if (text == null || text.isDisposed())
996 // // highlight region
1000 // if (viewer instanceof ITextViewerExtension3) {
1001 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1002 // IRegion widgetRange = extension.modelRange2WidgetRange(region);
1003 // if (widgetRange == null)
1006 // offset = widgetRange.getOffset();
1007 // length = widgetRange.getLength();
1010 // offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
1011 // length = region.getLength();
1014 // StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
1015 // Color foregroundColor = fColor;
1016 // Color backgroundColor = oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
1017 // StyleRange styleRange = new StyleRange(offset, length, foregroundColor, backgroundColor);
1018 // text.setStyleRange(styleRange);
1021 // text.redrawRange(offset, length, true);
1023 // fActiveRegion = region;
1026 // private void activateCursor(ISourceViewer viewer) {
1027 // StyledText text = viewer.getTextWidget();
1028 // if (text == null || text.isDisposed())
1030 // Display display = text.getDisplay();
1031 // if (fCursor == null)
1032 // fCursor = new Cursor(display, SWT.CURSOR_HAND);
1033 // text.setCursor(fCursor);
1036 // private void resetCursor(ISourceViewer viewer) {
1037 // StyledText text = viewer.getTextWidget();
1038 // if (text != null && !text.isDisposed())
1039 // text.setCursor(null);
1041 // if (fCursor != null) {
1042 // fCursor.dispose();
1048 // * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1050 // public void keyPressed(KeyEvent event) {
1057 // if (event.keyCode != fKeyModifierMask) {
1064 // // removed for #25871
1066 // // ISourceViewer viewer= getSourceViewer();
1067 // // if (viewer == null)
1070 // // IRegion region= getCurrentTextRegion(viewer);
1071 // // if (region == null)
1074 // // highlightRegion(viewer, region);
1075 // // activateCursor(viewer);
1079 // * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1081 // public void keyReleased(KeyEvent event) {
1090 // * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1092 // public void mouseDoubleClick(MouseEvent e) {
1096 // * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1098 // public void mouseDown(MouseEvent event) {
1103 // if (event.stateMask != fKeyModifierMask) {
1108 // if (event.button != 1) {
1115 // * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1117 // public void mouseUp(MouseEvent e) {
1122 // if (e.button != 1) {
1127 // boolean wasActive = fCursor != null;
1132 // IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1133 // if (action != null)
1139 // * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1141 // public void mouseMove(MouseEvent event) {
1143 // if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
1149 // if (event.stateMask != fKeyModifierMask)
1151 // // modifier was already pressed
1155 // ISourceViewer viewer = getSourceViewer();
1156 // if (viewer == null) {
1161 // StyledText text = viewer.getTextWidget();
1162 // if (text == null || text.isDisposed()) {
1167 // if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
1172 // IRegion region = getCurrentTextRegion(viewer);
1173 // if (region == null || region.getLength() == 0) {
1174 // repairRepresentation();
1178 // highlightRegion(viewer, region);
1179 // activateCursor(viewer);
1183 // * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1185 // public void focusGained(FocusEvent e) {
1189 // * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1191 // public void focusLost(FocusEvent event) {
1196 // * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1198 // public void documentAboutToBeChanged(DocumentEvent event) {
1199 // if (fActive && fActiveRegion != null) {
1200 // fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
1202 // event.getDocument().addPosition(fRememberedPosition);
1203 // } catch (BadLocationException x) {
1204 // fRememberedPosition = null;
1210 // * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1212 // public void documentChanged(DocumentEvent event) {
1213 // if (fRememberedPosition != null && !fRememberedPosition.isDeleted()) {
1214 // event.getDocument().removePosition(fRememberedPosition);
1215 // fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
1217 // fRememberedPosition = null;
1219 // ISourceViewer viewer = getSourceViewer();
1220 // if (viewer != null) {
1221 // StyledText widget = viewer.getTextWidget();
1222 // if (widget != null && !widget.isDisposed()) {
1223 // widget.getDisplay().asyncExec(new Runnable() {
1224 // public void run() {
1233 // * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
1234 // * org.eclipse.jface.text.IDocument)
1236 // public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
1237 // if (oldInput == null)
1240 // oldInput.removeDocumentListener(this);
1244 // * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
1245 // * org.eclipse.jface.text.IDocument)
1247 // public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
1248 // if (newInput == null)
1250 // newInput.addDocumentListener(this);
1254 // * @see PaintListener#paintControl(PaintEvent)
1256 // public void paintControl(PaintEvent event) {
1257 // if (fActiveRegion == null)
1260 // ISourceViewer viewer = getSourceViewer();
1261 // if (viewer == null)
1264 // StyledText text = viewer.getTextWidget();
1265 // if (text == null || text.isDisposed())
1271 // if (viewer instanceof ITextViewerExtension3) {
1273 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1274 // IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
1275 // if (widgetRange == null)
1278 // offset = widgetRange.getOffset();
1279 // length = widgetRange.getLength();
1283 // IRegion region = viewer.getVisibleRegion();
1284 // if (!includes(region, fActiveRegion))
1287 // offset = fActiveRegion.getOffset() - region.getOffset();
1288 // length = fActiveRegion.getLength();
1291 // // support for bidi
1292 // Point minLocation = getMinimumLocation(text, offset, length);
1293 // Point maxLocation = getMaximumLocation(text, offset, length);
1295 // int x1 = minLocation.x;
1296 // int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
1297 // int y = minLocation.y + text.getLineHeight() - 1;
1299 // GC gc = event.gc;
1300 // if (fColor != null && !fColor.isDisposed())
1301 // gc.setForeground(fColor);
1302 // gc.drawLine(x1, y, x2, y);
1305 // private boolean includes(IRegion region, IRegion position) {
1306 // return position.getOffset() >= region.getOffset()
1307 // && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
1310 // private Point getMinimumLocation(StyledText text, int offset, int length) {
1311 // Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
1313 // for (int i = 0; i <= length; i++) {
1314 // Point location = text.getLocationAtOffset(offset + i);
1316 // if (location.x < minLocation.x)
1317 // minLocation.x = location.x;
1318 // if (location.y < minLocation.y)
1319 // minLocation.y = location.y;
1322 // return minLocation;
1325 // private Point getMaximumLocation(StyledText text, int offset, int length) {
1326 // Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
1328 // for (int i = 0; i <= length; i++) {
1329 // Point location = text.getLocationAtOffset(offset + i);
1331 // if (location.x > maxLocation.x)
1332 // maxLocation.x = location.x;
1333 // if (location.y > maxLocation.y)
1334 // maxLocation.y = location.y;
1337 // return maxLocation;
1343 class MouseClickListener implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener,
1344 IPropertyChangeListener, IDocumentListener, ITextInputListener, ITextPresentationListener {
1346 /** The session is active. */
1347 private boolean fActive;
1349 /** The currently active style range. */
1350 private IRegion fActiveRegion;
1352 /** The currently active style range as position. */
1353 private Position fRememberedPosition;
1355 /** The hand cursor. */
1356 private Cursor fCursor;
1358 /** The link color. */
1359 private Color fColor;
1361 /** The key modifier mask. */
1362 private int fKeyModifierMask;
1364 public void deactivate() {
1368 public void deactivate(boolean redrawAll) {
1372 repairRepresentation(redrawAll);
1376 public void install() {
1377 ISourceViewer sourceViewer = getSourceViewer();
1378 if (sourceViewer == null)
1381 StyledText text = sourceViewer.getTextWidget();
1382 if (text == null || text.isDisposed())
1385 updateColor(sourceViewer);
1387 sourceViewer.addTextInputListener(this);
1389 IDocument document = sourceViewer.getDocument();
1390 if (document != null)
1391 document.addDocumentListener(this);
1393 text.addKeyListener(this);
1394 text.addMouseListener(this);
1395 text.addMouseMoveListener(this);
1396 text.addFocusListener(this);
1397 text.addPaintListener(this);
1399 ((ITextViewerExtension4) sourceViewer).addTextPresentationListener(this);
1401 updateKeyModifierMask();
1403 IPreferenceStore preferenceStore = getPreferenceStore();
1404 preferenceStore.addPropertyChangeListener(this);
1407 private void updateKeyModifierMask() {
1408 String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
1409 fKeyModifierMask = computeStateMask(modifiers);
1410 if (fKeyModifierMask == -1) {
1411 // Fall back to stored state mask
1412 fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
1416 private int computeStateMask(String modifiers) {
1417 if (modifiers == null)
1420 if (modifiers.length() == 0)
1424 StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
1425 while (modifierTokenizer.hasMoreTokens()) {
1426 int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
1427 if (modifier == 0 || (stateMask & modifier) == modifier)
1429 stateMask = stateMask | modifier;
1434 public void uninstall() {
1436 if (fColor != null) {
1441 if (fCursor != null) {
1446 ISourceViewer sourceViewer = getSourceViewer();
1447 if (sourceViewer != null)
1448 sourceViewer.removeTextInputListener(this);
1450 IDocumentProvider documentProvider = getDocumentProvider();
1451 if (documentProvider != null) {
1452 IDocument document = documentProvider.getDocument(getEditorInput());
1453 if (document != null)
1454 document.removeDocumentListener(this);
1457 IPreferenceStore preferenceStore = getPreferenceStore();
1458 if (preferenceStore != null)
1459 preferenceStore.removePropertyChangeListener(this);
1461 if (sourceViewer == null)
1464 StyledText text = sourceViewer.getTextWidget();
1465 if (text == null || text.isDisposed())
1468 text.removeKeyListener(this);
1469 text.removeMouseListener(this);
1470 text.removeMouseMoveListener(this);
1471 text.removeFocusListener(this);
1472 text.removePaintListener(this);
1474 ((ITextViewerExtension4) sourceViewer).removeTextPresentationListener(this);
1478 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
1480 public void propertyChange(PropertyChangeEvent event) {
1481 if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
1482 ISourceViewer viewer = getSourceViewer();
1484 updateColor(viewer);
1485 } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
1486 updateKeyModifierMask();
1490 private void updateColor(ISourceViewer viewer) {
1494 StyledText text = viewer.getTextWidget();
1495 if (text == null || text.isDisposed())
1498 Display display = text.getDisplay();
1499 fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
1503 * Creates a color from the information stored in the given preference store.
1506 * the preference store
1511 * @return the color or <code>null</code> if there is no such information available
1513 private Color createColor(IPreferenceStore store, String key, Display display) {
1517 if (store.contains(key)) {
1519 if (store.isDefault(key))
1520 rgb = PreferenceConverter.getDefaultColor(store, key);
1522 rgb = PreferenceConverter.getColor(store, key);
1525 return new Color(display, rgb);
1531 private void repairRepresentation() {
1532 repairRepresentation(false);
1535 private void repairRepresentation(boolean redrawAll) {
1537 if (fActiveRegion == null)
1540 int offset = fActiveRegion.getOffset();
1541 int length = fActiveRegion.getLength();
1542 fActiveRegion = null;
1544 ISourceViewer viewer = getSourceViewer();
1545 if (viewer != null) {
1547 resetCursor(viewer);
1549 // Invalidate ==> remove applied text presentation
1550 if (!redrawAll && viewer instanceof ITextViewerExtension2)
1551 ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
1553 viewer.invalidateTextPresentation();
1556 if (viewer instanceof ITextViewerExtension5) {
1557 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1558 offset = extension.modelOffset2WidgetOffset(offset);
1560 offset -= viewer.getVisibleRegion().getOffset();
1563 StyledText text = viewer.getTextWidget();
1565 text.redrawRange(offset, length, false);
1566 } catch (IllegalArgumentException x) {
1567 // JavaPlugin.log(x);
1572 // will eventually be replaced by a method provided by jdt.core
1573 private IRegion selectWord(IDocument document, int anchor) {
1576 int offset = anchor;
1579 while (offset >= 0) {
1580 c = document.getChar(offset);
1581 // if (!Character.isJavaIdentifierPart(c)&&c!='$')
1582 if (!Scanner.isPHPIdentifierPart(c) && c != '$')
1590 int length = document.getLength();
1592 while (offset < length) {
1593 c = document.getChar(offset);
1594 // if (!Character.isJavaIdentifierPart(c)&&c!='$')
1595 if (!Scanner.isPHPIdentifierPart(c) && c != '$')
1603 return new Region(start, 0);
1605 return new Region(start + 1, end - start - 1);
1607 } catch (BadLocationException x) {
1612 IRegion getCurrentTextRegion(ISourceViewer viewer) {
1614 int offset = getCurrentTextOffset(viewer);
1618 IJavaElement input = SelectionConverter.getInput(PHPEditor.this);
1624 // IJavaElement[] elements= null;
1625 // synchronized (input) {
1626 // elements= ((ICodeAssist) input).codeSelect(offset, 0);
1629 // if (elements == null || elements.length == 0)
1632 return selectWord(viewer.getDocument(), offset);
1634 // } catch (JavaModelException e) {
1639 private int getCurrentTextOffset(ISourceViewer viewer) {
1642 StyledText text = viewer.getTextWidget();
1643 if (text == null || text.isDisposed())
1646 Display display = text.getDisplay();
1647 Point absolutePosition = display.getCursorLocation();
1648 Point relativePosition = text.toControl(absolutePosition);
1650 int widgetOffset = text.getOffsetAtLocation(relativePosition);
1651 if (viewer instanceof ITextViewerExtension5) {
1652 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1653 return extension.widgetOffset2ModelOffset(widgetOffset);
1655 return widgetOffset + viewer.getVisibleRegion().getOffset();
1658 } catch (IllegalArgumentException e) {
1663 public void applyTextPresentation(TextPresentation textPresentation) {
1664 if (fActiveRegion == null)
1666 IRegion region = textPresentation.getExtent();
1667 if (fActiveRegion.getOffset() + fActiveRegion.getLength() >= region.getOffset()
1668 && region.getOffset() + region.getLength() > fActiveRegion.getOffset())
1669 textPresentation.mergeStyleRange(new StyleRange(fActiveRegion.getOffset(), fActiveRegion.getLength(), fColor, null));
1672 private void highlightRegion(ISourceViewer viewer, IRegion region) {
1674 if (region.equals(fActiveRegion))
1677 repairRepresentation();
1679 StyledText text = viewer.getTextWidget();
1680 if (text == null || text.isDisposed())
1686 if (viewer instanceof ITextViewerExtension5) {
1687 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1688 IRegion widgetRange = extension.modelRange2WidgetRange(region);
1689 if (widgetRange == null)
1692 offset = widgetRange.getOffset();
1693 length = widgetRange.getLength();
1696 offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
1697 length = region.getLength();
1699 text.redrawRange(offset, length, false);
1701 // Invalidate region ==> apply text presentation
1702 fActiveRegion = region;
1703 if (viewer instanceof ITextViewerExtension2)
1704 ((ITextViewerExtension2) viewer).invalidateTextPresentation(region.getOffset(), region.getLength());
1706 viewer.invalidateTextPresentation();
1709 private void activateCursor(ISourceViewer viewer) {
1710 StyledText text = viewer.getTextWidget();
1711 if (text == null || text.isDisposed())
1713 Display display = text.getDisplay();
1714 if (fCursor == null)
1715 fCursor = new Cursor(display, SWT.CURSOR_HAND);
1716 text.setCursor(fCursor);
1719 private void resetCursor(ISourceViewer viewer) {
1720 StyledText text = viewer.getTextWidget();
1721 if (text != null && !text.isDisposed())
1722 text.setCursor(null);
1724 if (fCursor != null) {
1731 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1733 public void keyPressed(KeyEvent event) {
1740 if (event.keyCode != fKeyModifierMask) {
1747 // removed for #25871
1749 // ISourceViewer viewer= getSourceViewer();
1750 // if (viewer == null)
1753 // IRegion region= getCurrentTextRegion(viewer);
1754 // if (region == null)
1757 // highlightRegion(viewer, region);
1758 // activateCursor(viewer);
1762 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1764 public void keyReleased(KeyEvent event) {
1773 * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1775 public void mouseDoubleClick(MouseEvent e) {
1779 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1781 public void mouseDown(MouseEvent event) {
1786 if (event.stateMask != fKeyModifierMask) {
1791 if (event.button != 1) {
1798 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1800 public void mouseUp(MouseEvent e) {
1805 if (e.button != 1) {
1810 boolean wasActive = fCursor != null;
1815 IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1822 * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1824 public void mouseMove(MouseEvent event) {
1826 if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
1832 if (event.stateMask != fKeyModifierMask)
1834 // modifier was already pressed
1838 ISourceViewer viewer = getSourceViewer();
1839 if (viewer == null) {
1844 StyledText text = viewer.getTextWidget();
1845 if (text == null || text.isDisposed()) {
1850 if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
1855 IRegion region = getCurrentTextRegion(viewer);
1856 if (region == null || region.getLength() == 0) {
1857 repairRepresentation();
1861 highlightRegion(viewer, region);
1862 activateCursor(viewer);
1866 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1868 public void focusGained(FocusEvent e) {
1872 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1874 public void focusLost(FocusEvent event) {
1879 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1881 public void documentAboutToBeChanged(DocumentEvent event) {
1882 if (fActive && fActiveRegion != null) {
1883 fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
1885 event.getDocument().addPosition(fRememberedPosition);
1886 } catch (BadLocationException x) {
1887 fRememberedPosition = null;
1893 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1895 public void documentChanged(DocumentEvent event) {
1896 if (fRememberedPosition != null) {
1897 if (!fRememberedPosition.isDeleted()) {
1899 event.getDocument().removePosition(fRememberedPosition);
1900 fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
1901 fRememberedPosition = null;
1903 ISourceViewer viewer = getSourceViewer();
1904 if (viewer != null) {
1905 StyledText widget = viewer.getTextWidget();
1906 if (widget != null && !widget.isDisposed()) {
1907 widget.getDisplay().asyncExec(new Runnable() {
1916 fActiveRegion = null;
1917 fRememberedPosition = null;
1924 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
1925 * org.eclipse.jface.text.IDocument)
1927 public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
1928 if (oldInput == null)
1931 oldInput.removeDocumentListener(this);
1935 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
1936 * org.eclipse.jface.text.IDocument)
1938 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
1939 if (newInput == null)
1941 newInput.addDocumentListener(this);
1945 * @see PaintListener#paintControl(PaintEvent)
1947 public void paintControl(PaintEvent event) {
1948 if (fActiveRegion == null)
1951 ISourceViewer viewer = getSourceViewer();
1955 StyledText text = viewer.getTextWidget();
1956 if (text == null || text.isDisposed())
1962 if (viewer instanceof ITextViewerExtension5) {
1964 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1965 IRegion widgetRange = extension.modelRange2WidgetRange(fActiveRegion);
1966 if (widgetRange == null)
1969 offset = widgetRange.getOffset();
1970 length = widgetRange.getLength();
1974 IRegion region = viewer.getVisibleRegion();
1975 if (!includes(region, fActiveRegion))
1978 offset = fActiveRegion.getOffset() - region.getOffset();
1979 length = fActiveRegion.getLength();
1983 Point minLocation = getMinimumLocation(text, offset, length);
1984 Point maxLocation = getMaximumLocation(text, offset, length);
1986 int x1 = minLocation.x;
1987 int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
1988 int y = minLocation.y + text.getLineHeight() - 1;
1991 if (fColor != null && !fColor.isDisposed())
1992 gc.setForeground(fColor);
1993 gc.drawLine(x1, y, x2, y);
1996 private boolean includes(IRegion region, IRegion position) {
1997 return position.getOffset() >= region.getOffset()
1998 && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
2001 private Point getMinimumLocation(StyledText text, int offset, int length) {
2002 Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
2004 for (int i = 0; i <= length; i++) {
2005 Point location = text.getLocationAtOffset(offset + i);
2007 if (location.x < minLocation.x)
2008 minLocation.x = location.x;
2009 if (location.y < minLocation.y)
2010 minLocation.y = location.y;
2016 private Point getMaximumLocation(StyledText text, int offset, int length) {
2017 Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
2019 for (int i = 0; i <= length; i++) {
2020 Point location = text.getLocationAtOffset(offset + i);
2022 if (location.x > maxLocation.x)
2023 maxLocation.x = location.x;
2024 if (location.y > maxLocation.y)
2025 maxLocation.y = location.y;
2033 * This action dispatches into two behaviours: If there is no current text hover, the javadoc is displayed using information
2034 * presenter. If there is a current text hover, it is converted into a information presenter in order to make it sticky.
2036 class InformationDispatchAction extends TextEditorAction {
2038 /** The wrapped text operation action. */
2039 private final TextOperationAction fTextOperationAction;
2042 * Creates a dispatch action.
2044 public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
2045 super(resourceBundle, prefix, PHPEditor.this);
2046 if (textOperationAction == null)
2047 throw new IllegalArgumentException();
2048 fTextOperationAction = textOperationAction;
2052 * @see org.eclipse.jface.action.IAction#run()
2056 ISourceViewer sourceViewer = getSourceViewer();
2057 if (sourceViewer == null) {
2058 fTextOperationAction.run();
2062 if (!(sourceViewer instanceof ITextViewerExtension2)) {
2063 fTextOperationAction.run();
2067 ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
2069 // does a text hover exist?
2070 ITextHover textHover = textViewerExtension2.getCurrentTextHover();
2071 if (textHover == null) {
2072 fTextOperationAction.run();
2076 Point hoverEventLocation = textViewerExtension2.getHoverEventLocation();
2077 int offset = computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
2079 fTextOperationAction.run();
2084 // get the text hover content
2085 IDocument document = sourceViewer.getDocument();
2086 String contentType = document.getContentType(offset);
2088 final IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
2089 if (hoverRegion == null)
2092 final String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);
2094 // with information provider
2095 IInformationProvider informationProvider = new IInformationProvider() {
2097 * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
2099 public IRegion getSubject(ITextViewer textViewer, int offset) {
2104 * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer,
2105 * org.eclipse.jface.text.IRegion)
2107 public String getInformation(ITextViewer textViewer, IRegion subject) {
2112 fInformationPresenter.setOffset(offset);
2113 fInformationPresenter.setInformationProvider(informationProvider, contentType);
2114 fInformationPresenter.showInformation();
2116 } catch (BadLocationException e) {
2120 // modified version from TextViewer
2121 private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
2123 StyledText styledText = textViewer.getTextWidget();
2124 IDocument document = textViewer.getDocument();
2126 if (document == null)
2130 int widgetLocation = styledText.getOffsetAtLocation(new Point(x, y));
2131 if (textViewer instanceof ITextViewerExtension3) {
2132 ITextViewerExtension3 extension = (ITextViewerExtension3) textViewer;
2133 return extension.widgetOffset2ModelOffset(widgetLocation);
2135 IRegion visibleRegion = textViewer.getVisibleRegion();
2136 return widgetLocation + visibleRegion.getOffset();
2138 } catch (IllegalArgumentException e) {
2146 * This action implements smart home.
2148 * Instead of going to the start of a line it does the following:
2149 * - if smart home/end is enabled and the caret is after the line's first non-whitespace then the caret is moved directly before
2150 * it, taking JavaDoc and multi-line comments into account. - if the caret is before the line's first non-whitespace the caret is
2151 * moved to the beginning of the line - if the caret is at the beginning of the line see first case.
2155 protected class SmartLineStartAction extends LineStartAction {
2158 * Creates a new smart line start action
2161 * the styled text widget
2163 * a boolean flag which tells if the text up to the beginning of the line should be selected
2165 public SmartLineStartAction(final StyledText textWidget, final boolean doSelect) {
2166 super(textWidget, doSelect);
2170 * @see org.eclipse.ui.texteditor.AbstractTextEditor.LineStartAction#getLineStartPosition(java.lang.String, int,
2173 protected int getLineStartPosition(final IDocument document, final String line, final int length, final int offset) {
2175 String type = IDocument.DEFAULT_CONTENT_TYPE;
2177 type = TextUtilities.getContentType(document, IPHPPartitions.PHP_PARTITIONING, offset, true);
2178 } catch (BadLocationException exception) {
2179 // Should not happen
2182 int index = super.getLineStartPosition(document, line, length, offset);
2183 if (type.equals(IPHPPartitions.PHP_PHPDOC_COMMENT) || type.equals(IPHPPartitions.PHP_MULTILINE_COMMENT)) {
2184 if (index < length - 1 && line.charAt(index) == '*' && line.charAt(index + 1) != '/') {
2187 } while (index < length && Character.isWhitespace(line.charAt(index)));
2190 if (index < length - 1 && line.charAt(index) == '/' && line.charAt(index + 1) == '/') {
2194 } while (index < length && Character.isWhitespace(line.charAt(index)));
2202 * Text navigation action to navigate to the next sub-word.
2206 protected abstract class NextSubWordAction extends TextNavigationAction {
2208 protected JavaWordIterator fIterator = new JavaWordIterator();
2211 * Creates a new next sub-word action.
2214 * Action code for the default operation. Must be an action code from
2215 * @see org.eclipse.swt.custom.ST.
2217 protected NextSubWordAction(int code) {
2218 super(getSourceViewer().getTextWidget(), code);
2222 * @see org.eclipse.jface.action.IAction#run()
2225 // Check whether we are in a java code partition and the preference is enabled
2226 final IPreferenceStore store = getPreferenceStore();
2227 if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
2232 final ISourceViewer viewer = getSourceViewer();
2233 final IDocument document = viewer.getDocument();
2234 fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document));
2235 int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2239 int next = findNextPosition(position);
2240 if (next != BreakIterator.DONE) {
2241 setCaretPosition(next);
2242 getTextWidget().showSelection();
2243 fireSelectionChanged();
2249 * Finds the next position after the given position.
2252 * the current position
2253 * @return the next position
2255 protected int findNextPosition(int position) {
2256 ISourceViewer viewer = getSourceViewer();
2258 while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize
2259 position = fIterator.following(position);
2260 if (position != BreakIterator.DONE)
2261 widget = modelOffset2WidgetOffset(viewer, position);
2267 * Sets the caret position to the sub-word boundary given with <code>position</code>.
2270 * Position where the action should move the caret
2272 protected abstract void setCaretPosition(int position);
2276 * Text navigation action to navigate to the next sub-word.
2280 protected class NavigateNextSubWordAction extends NextSubWordAction {
2283 * Creates a new navigate next sub-word action.
2285 public NavigateNextSubWordAction() {
2286 super(ST.WORD_NEXT);
2290 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2292 protected void setCaretPosition(final int position) {
2293 getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position));
2298 * Text operation action to delete the next sub-word.
2302 protected class DeleteNextSubWordAction extends NextSubWordAction implements IUpdate {
2305 * Creates a new delete next sub-word action.
2307 public DeleteNextSubWordAction() {
2308 super(ST.DELETE_WORD_NEXT);
2312 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2314 protected void setCaretPosition(final int position) {
2315 if (!validateEditorInputState())
2318 final ISourceViewer viewer = getSourceViewer();
2319 final int caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2322 viewer.getDocument().replace(caret, position - caret, ""); //$NON-NLS-1$
2323 } catch (BadLocationException exception) {
2324 // Should not happen
2329 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#findNextPosition(int)
2331 protected int findNextPosition(int position) {
2332 return fIterator.following(position);
2336 * @see org.eclipse.ui.texteditor.IUpdate#update()
2338 public void update() {
2339 setEnabled(isEditorInputModifiable());
2344 * Text operation action to select the next sub-word.
2348 protected class SelectNextSubWordAction extends NextSubWordAction {
2351 * Creates a new select next sub-word action.
2353 public SelectNextSubWordAction() {
2354 super(ST.SELECT_WORD_NEXT);
2358 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2360 protected void setCaretPosition(final int position) {
2361 final ISourceViewer viewer = getSourceViewer();
2363 final StyledText text = viewer.getTextWidget();
2364 if (text != null && !text.isDisposed()) {
2366 final Point selection = text.getSelection();
2367 final int caret = text.getCaretOffset();
2368 final int offset = modelOffset2WidgetOffset(viewer, position);
2370 if (caret == selection.x)
2371 text.setSelectionRange(selection.y, offset - selection.y);
2373 text.setSelectionRange(selection.x, offset - selection.x);
2379 * Text navigation action to navigate to the previous sub-word.
2383 protected abstract class PreviousSubWordAction extends TextNavigationAction {
2385 protected JavaWordIterator fIterator = new JavaWordIterator();
2388 * Creates a new previous sub-word action.
2391 * Action code for the default operation. Must be an action code from
2392 * @see org.eclipse.swt.custom.ST.
2394 protected PreviousSubWordAction(final int code) {
2395 super(getSourceViewer().getTextWidget(), code);
2399 * @see org.eclipse.jface.action.IAction#run()
2402 // Check whether we are in a java code partition and the preference is enabled
2403 final IPreferenceStore store = getPreferenceStore();
2404 if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
2409 final ISourceViewer viewer = getSourceViewer();
2410 final IDocument document = viewer.getDocument();
2411 fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document));
2412 int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2416 int previous = findPreviousPosition(position);
2417 if (previous != BreakIterator.DONE) {
2418 setCaretPosition(previous);
2419 getTextWidget().showSelection();
2420 fireSelectionChanged();
2426 * Finds the previous position before the given position.
2429 * the current position
2430 * @return the previous position
2432 protected int findPreviousPosition(int position) {
2433 ISourceViewer viewer = getSourceViewer();
2435 while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize
2436 position = fIterator.preceding(position);
2437 if (position != BreakIterator.DONE)
2438 widget = modelOffset2WidgetOffset(viewer, position);
2444 * Sets the caret position to the sub-word boundary given with <code>position</code>.
2447 * Position where the action should move the caret
2449 protected abstract void setCaretPosition(int position);
2453 * Text navigation action to navigate to the previous sub-word.
2457 protected class NavigatePreviousSubWordAction extends PreviousSubWordAction {
2460 * Creates a new navigate previous sub-word action.
2462 public NavigatePreviousSubWordAction() {
2463 super(ST.WORD_PREVIOUS);
2467 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2469 protected void setCaretPosition(final int position) {
2470 getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position));
2475 * Text operation action to delete the previous sub-word.
2479 protected class DeletePreviousSubWordAction extends PreviousSubWordAction implements IUpdate {
2482 * Creates a new delete previous sub-word action.
2484 public DeletePreviousSubWordAction() {
2485 super(ST.DELETE_WORD_PREVIOUS);
2489 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2491 protected void setCaretPosition(final int position) {
2492 if (!validateEditorInputState())
2495 final ISourceViewer viewer = getSourceViewer();
2496 final int caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset());
2499 viewer.getDocument().replace(position, caret - position, ""); //$NON-NLS-1$
2500 } catch (BadLocationException exception) {
2501 // Should not happen
2506 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#findPreviousPosition(int)
2508 protected int findPreviousPosition(int position) {
2509 return fIterator.preceding(position);
2513 * @see org.eclipse.ui.texteditor.IUpdate#update()
2515 public void update() {
2516 setEnabled(isEditorInputModifiable());
2521 * Text operation action to select the previous sub-word.
2525 protected class SelectPreviousSubWordAction extends PreviousSubWordAction {
2528 * Creates a new select previous sub-word action.
2530 public SelectPreviousSubWordAction() {
2531 super(ST.SELECT_WORD_PREVIOUS);
2535 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2537 protected void setCaretPosition(final int position) {
2538 final ISourceViewer viewer = getSourceViewer();
2540 final StyledText text = viewer.getTextWidget();
2541 if (text != null && !text.isDisposed()) {
2543 final Point selection = text.getSelection();
2544 final int caret = text.getCaretOffset();
2545 final int offset = modelOffset2WidgetOffset(viewer, position);
2547 if (caret == selection.x)
2548 text.setSelectionRange(selection.y, offset - selection.y);
2550 text.setSelectionRange(selection.x, offset - selection.x);
2555 // static protected class AnnotationAccess implements IAnnotationAccess {
2558 // org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
2560 // public Object getType(Annotation annotation) {
2561 // if (annotation instanceof IJavaAnnotation) {
2562 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
2563 // // if (javaAnnotation.isRelevant())
2564 // // return javaAnnotation.getAnnotationType();
2571 // org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
2573 // public boolean isMultiLine(Annotation annotation) {
2579 // org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
2581 // public boolean isTemporary(Annotation annotation) {
2582 // if (annotation instanceof IJavaAnnotation) {
2583 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
2584 // if (javaAnnotation.isRelevant())
2585 // return javaAnnotation.isTemporary();
2591 private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
2593 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
2595 public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
2596 handlePreferencePropertyChanged(event);
2601 * Finds and marks occurrence annotations.
2605 class OccurrencesFinderJob extends Job implements IDocumentListener {
2607 private IDocument fDocument;
2609 private boolean fCancelled = false;
2611 private IProgressMonitor fProgressMonitor;
2613 private Position[] fPositions;
2615 public OccurrencesFinderJob(IDocument document, Position[] positions) {
2616 super("Occurrences Marker"); //$NON-NLS-1$
2617 fDocument = document;
2618 fPositions = positions;
2619 fDocument.addDocumentListener(this);
2622 private boolean isCancelled() {
2623 return fCancelled || fProgressMonitor.isCanceled();
2627 * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
2629 public IStatus run(IProgressMonitor progressMonitor) {
2631 fProgressMonitor = progressMonitor;
2636 return Status.CANCEL_STATUS;
2638 ITextViewer textViewer = getViewer();
2639 if (textViewer == null)
2640 return Status.CANCEL_STATUS;
2642 IDocument document = textViewer.getDocument();
2643 if (document == null)
2644 return Status.CANCEL_STATUS;
2646 IDocumentProvider documentProvider = getDocumentProvider();
2647 if (documentProvider == null)
2648 return Status.CANCEL_STATUS;
2650 IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
2651 if (annotationModel == null)
2652 return Status.CANCEL_STATUS;
2654 // Add occurrence annotations
2655 int length = fPositions.length;
2656 Map annotationMap = new HashMap(length);
2657 for (int i = 0; i < length; i++) {
2660 return Status.CANCEL_STATUS;
2663 Position position = fPositions[i];
2665 // Create & add annotation
2667 message = document.get(position.offset, position.length);
2668 } catch (BadLocationException ex) {
2672 annotationMap.put(new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
2677 return Status.CANCEL_STATUS;
2679 synchronized (annotationModel) {
2680 if (annotationModel instanceof IAnnotationModelExtension) {
2681 ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
2683 removeOccurrenceAnnotations();
2684 Iterator iter = annotationMap.entrySet().iterator();
2685 while (iter.hasNext()) {
2686 Map.Entry mapEntry = (Map.Entry) iter.next();
2687 annotationModel.addAnnotation((Annotation) mapEntry.getKey(), (Position) mapEntry.getValue());
2690 fOccurrenceAnnotations = (Annotation[]) annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
2693 fDocument.removeDocumentListener(this);
2695 return Status.OK_STATUS;
2699 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
2701 public void documentAboutToBeChanged(DocumentEvent event) {
2706 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
2708 public void documentChanged(DocumentEvent event) {
2713 * Updates the selection in the editor's widget with the selection of the outline page.
2715 class OutlineSelectionChangedListener extends AbstractSelectionChangedListener {
2716 public void selectionChanged(SelectionChangedEvent event) {
2717 doSelectionChanged(event);
2722 * Holds the current occurrence annotations.
2726 private Annotation[] fOccurrenceAnnotations = null;
2728 private Job fOccurrencesFinderJob;
2730 /** Preference key for showing the line number ruler */
2731 // private final static String LINE_NUMBER_RULER =
2732 // PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
2733 /** Preference key for the foreground color of the line numbers */
2734 // private final static String LINE_NUMBER_COLOR =
2735 // PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
2736 /** Preference key for the link color */
2737 private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
2739 /** Preference key for compiler task tags */
2740 private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
2742 // protected PHPActionGroup fActionGroups;
2743 // /** The outline page */
2744 // private AbstractContentOutlinePage fOutlinePage;
2745 /** The outline page */
2746 protected JavaOutlinePage fOutlinePage;
2748 /** Outliner context menu Id */
2749 protected String fOutlinerContextMenuId;
2752 * Indicates whether this editor should react on outline page selection changes
2754 private int fIgnoreOutlinePageSelection;
2756 /** The outline page selection updater */
2757 // private OutlinePageSelectionUpdater fUpdater;
2758 // protected PHPSyntaxParserThread fValidationThread = null;
2759 // private IPreferenceStore fPHPPrefStore;
2760 /** The selection changed listener */
2761 // protected ISelectionChangedListener fSelectionChangedListener = new
2762 // SelectionChangedListener();
2764 * The editor selection changed listener.
2768 private EditorSelectionChangedListener fEditorSelectionChangedListener;
2770 /** The selection changed listener */
2771 protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener();
2773 /** The editor's bracket matcher */
2774 private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS);
2776 /** The line number ruler column */
2777 // private LineNumberRulerColumn fLineNumberRulerColumn;
2778 /** This editor's encoding support */
2779 private DefaultEncodingSupport fEncodingSupport;
2781 /** The mouse listener */
2782 private MouseClickListener fMouseListener;
2785 * Indicates whether this editor is about to update any annotation views.
2789 private boolean fIsUpdatingAnnotationViews = false;
2792 * The marker that served as last target for a goto marker request.
2796 private IMarker fLastMarkerTarget = null;
2798 protected CompositeActionGroup fActionGroups;
2800 protected CompositeActionGroup fContextMenuGroup;
2803 * This editor's projection support
2807 private ProjectionSupport fProjectionSupport;
2810 * This editor's projection model updater
2814 private IJavaFoldingStructureProvider fProjectionModelUpdater;
2817 * The override and implements indicator manager for this editor.
2821 // protected OverrideIndicatorManager fOverrideIndicatorManager;
2823 * The action group for folding.
2827 private FoldingActionGroup fFoldingGroup;
2829 /** The information presenter. */
2830 private InformationPresenter fInformationPresenter;
2832 /** The annotation access */
2833 // protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
2834 /** The overview ruler */
2835 protected OverviewRuler isOverviewRulerVisible;
2837 /** The source viewer decoration support */
2838 //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
2839 /** The overview ruler */
2840 //protected OverviewRuler fOverviewRuler;
2841 /** The preference property change listener for java core. */
2842 private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
2845 * Returns the most narrow java element including the given offset
2848 * the offset inside of the requested element
2850 abstract protected IJavaElement getElementAt(int offset);
2853 * Returns the java element of this editor's input corresponding to the given IJavaElement
2855 abstract protected IJavaElement getCorrespondingElement(IJavaElement element);
2858 * Sets the input of the editor's outline page.
2860 abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input);
2863 * Default constructor.
2865 public PHPEditor() {
2870 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
2872 protected void initializeKeyBindingScopes() {
2873 setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
2877 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
2879 protected void initializeEditor() {
2881 // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2882 // setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this, IPHPPartitions.PHP_PARTITIONING)); //,
2883 // IJavaPartitions.JAVA_PARTITIONING));
2884 IPreferenceStore store = createCombinedPreferenceStore(null);
2885 setPreferenceStore(store);
2886 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2887 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
2888 IPHPPartitions.PHP_PARTITIONING));
2889 // TODO changed in 3.x ?
2890 // setRangeIndicator(new DefaultRangeIndicator());
2891 // if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
2892 // fUpdater = new OutlinePageSelectionUpdater();
2895 // IPreferenceStore store= createCombinedPreferenceStore(null);
2896 // setPreferenceStore(store);
2897 // JavaTextTools textTools=
2898 // PHPeclipsePlugin.getDefault().getJavaTextTools();
2899 // setSourceViewerConfiguration(new
2900 // JavaSourceViewerConfiguration(textTools.getColorManager(), store,
2901 // this, IJavaPartitions.JAVA_PARTITIONING));
2902 // fMarkOccurrenceAnnotations=
2903 // store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
2904 // fStickyOccurrenceAnnotations=
2905 // store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
2906 // fMarkTypeOccurrences=
2907 // store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
2908 // fMarkMethodOccurrences=
2909 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
2910 // fMarkConstantOccurrences=
2911 // store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
2912 // fMarkFieldOccurrences=
2913 // store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
2914 // fMarkLocalVariableypeOccurrences=
2915 // store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
2916 // fMarkExceptionOccurrences=
2917 // store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
2918 // fMarkMethodExitPoints=
2919 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
2923 * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
2925 protected void updatePropertyDependentActions() {
2926 super.updatePropertyDependentActions();
2927 if (fEncodingSupport != null)
2928 fEncodingSupport.reset();
2932 * Update the hovering behavior depending on the preferences.
2934 private void updateHoverBehavior() {
2935 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
2936 String[] types = configuration.getConfiguredContentTypes(getSourceViewer());
2938 for (int i = 0; i < types.length; i++) {
2940 String t = types[i];
2942 int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
2944 ISourceViewer sourceViewer = getSourceViewer();
2945 if (sourceViewer instanceof ITextViewerExtension2) {
2946 if (stateMasks != null) {
2947 for (int j = 0; j < stateMasks.length; j++) {
2948 int stateMask = stateMasks[j];
2949 ITextHover textHover = configuration.getTextHover(sourceViewer, t, stateMask);
2950 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, stateMask);
2953 ITextHover textHover = configuration.getTextHover(sourceViewer, t);
2954 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
2957 sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t);
2961 public void updatedTitleImage(Image image) {
2962 setTitleImage(image);
2966 * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
2968 public Object getViewPartInput() {
2969 return getEditorInput().getAdapter(IResource.class);
2973 * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
2975 protected void doSetSelection(ISelection selection) {
2976 super.doSetSelection(selection);
2977 synchronizeOutlinePageSelection();
2980 boolean isFoldingEnabled() {
2981 return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
2985 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt. widgets.Composite)
2987 public void createPartControl(Composite parent) {
2988 super.createPartControl(parent);
2990 //fSourceViewerDecorationSupport.install(getPreferenceStore());
2992 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
2994 fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
2995 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
2996 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
2997 fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() {
2998 public IInformationControl createInformationControl(Shell shell) {
2999 return new CustomSourceInformationControl(shell, IDocument.DEFAULT_CONTENT_TYPE);
3002 fProjectionSupport.install();
3004 fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
3005 if (fProjectionModelUpdater != null)
3006 fProjectionModelUpdater.install(this, projectionViewer);
3008 if (isFoldingEnabled())
3009 projectionViewer.doOperation(ProjectionViewer.TOGGLE);
3010 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
3011 preferences.addPropertyChangeListener(fPropertyChangeListener);
3013 IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
3014 public IInformationControl createInformationControl(Shell parent) {
3015 boolean cutDown = false;
3016 int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
3017 return new DefaultInformationControl(parent, SWT.RESIZE, style, new HTMLTextPresenter(cutDown));
3021 fInformationPresenter = new InformationPresenter(informationControlCreator);
3022 fInformationPresenter.setSizeConstraints(60, 10, true, true);
3023 fInformationPresenter.install(getSourceViewer());
3025 fEditorSelectionChangedListener = new EditorSelectionChangedListener();
3026 fEditorSelectionChangedListener.install(getSelectionProvider());
3028 if (isBrowserLikeLinks())
3029 enableBrowserLikeLinks();
3031 if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE))
3032 enableOverwriteMode(false);
3035 // getEditorSite().getShell().addShellListener(fActivationListener);
3038 private void setWordWrap() {
3039 if (getSourceViewer() != null) {
3040 getSourceViewer().getTextWidget().setWordWrap(
3041 PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_WRAP_WORDS));
3045 protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
3047 support.setCharacterPairMatcher(fBracketMatcher);
3048 support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
3050 super.configureSourceViewerDecorationSupport(support);
3054 * @see org.eclipse.ui.texteditor.AbstractTextEditor#gotoMarker(org.eclipse.core.resources.IMarker)
3056 public void gotoMarker(IMarker marker) {
3057 fLastMarkerTarget = marker;
3058 if (!fIsUpdatingAnnotationViews) {
3059 super.gotoMarker(marker);
3064 * Jumps to the next enabled annotation according to the given direction. An annotation type is enabled if it is configured to be
3065 * in the Next/Previous tool bar drop down menu and if it is checked.
3068 * <code>true</code> if search direction is forward, <code>false</code> if backward
3070 public void gotoAnnotation(boolean forward) {
3071 ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
3072 Position position = new Position(0, 0);
3073 if (false /* delayed - see bug 18316 */) {
3074 getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
3075 selectAndReveal(position.getOffset(), position.getLength());
3076 } else /* no delay - see bug 18316 */{
3077 Annotation annotation = getNextAnnotation(selection.getOffset(), selection.getLength(), forward, position);
3078 setStatusLineErrorMessage(null);
3079 setStatusLineMessage(null);
3080 if (annotation != null) {
3081 updateAnnotationViews(annotation);
3082 selectAndReveal(position.getOffset(), position.getLength());
3083 setStatusLineMessage(annotation.getText());
3089 * Returns the lock object for the given annotation model.
3091 * @param annotationModel
3092 * the annotation model
3093 * @return the annotation model's lock object
3096 private Object getLockObject(IAnnotationModel annotationModel) {
3097 if (annotationModel instanceof ISynchronizable)
3098 return ((ISynchronizable) annotationModel).getLockObject();
3100 return annotationModel;
3104 * Updates the annotation views that show the given annotation.
3109 private void updateAnnotationViews(Annotation annotation) {
3110 IMarker marker = null;
3111 if (annotation instanceof MarkerAnnotation)
3112 marker = ((MarkerAnnotation) annotation).getMarker();
3113 else if (annotation instanceof IJavaAnnotation) {
3114 Iterator e = ((IJavaAnnotation) annotation).getOverlaidIterator();
3116 while (e.hasNext()) {
3117 Object o = e.next();
3118 if (o instanceof MarkerAnnotation) {
3119 marker = ((MarkerAnnotation) o).getMarker();
3126 if (marker != null && !marker.equals(fLastMarkerTarget)) {
3128 boolean isProblem = marker.isSubtypeOf(IMarker.PROBLEM);
3129 IWorkbenchPage page = getSite().getPage();
3130 IViewPart view = page.findView(isProblem ? IPageLayout.ID_PROBLEM_VIEW : IPageLayout.ID_TASK_LIST); //$NON-NLS-1$ //$NON-NLS-2$
3132 Method method = view.getClass().getMethod("setSelection", new Class[] { IStructuredSelection.class, boolean.class }); //$NON-NLS-1$
3133 method.invoke(view, new Object[] { new StructuredSelection(marker), Boolean.TRUE });
3135 } catch (CoreException x) {
3136 } catch (NoSuchMethodException x) {
3137 } catch (IllegalAccessException x) {
3138 } catch (InvocationTargetException x) {
3140 // ignore exceptions, don't update any of the lists, just set status line
3145 * Returns this document's complete text.
3147 * @return the document's complete text
3149 public String get() {
3150 IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
3155 * Sets the outliner's context menu ID.
3157 protected void setOutlinerContextMenuId(String menuId) {
3158 fOutlinerContextMenuId = menuId;
3162 * Returns the standard action group of this editor.
3164 protected ActionGroup getActionGroup() {
3165 return fActionGroups;
3168 // public JavaOutlinePage getfOutlinePage() {
3169 // return fOutlinePage;
3173 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method extend the actions to add those
3174 * specific to the receiver
3176 protected void createActions() {
3177 super.createActions();
3179 ActionGroup oeg, ovg, jsg, sg;
3180 fActionGroups = new CompositeActionGroup(new ActionGroup[] { oeg = new OpenEditorActionGroup(this),
3181 // sg= new ShowActionGroup(this),
3182 // ovg= new OpenViewActionGroup(this),
3183 // jsg= new JavaSearchActionGroup(this)
3185 fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { oeg });
3188 fFoldingGroup = new FoldingActionGroup(this, getViewer());
3190 ResourceAction resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
3191 "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
3192 resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(),
3193 "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
3194 resAction.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
3195 setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
3196 // WorkbenchHelp.setHelp(resAction,
3197 // IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
3199 Action action = new GotoMatchingBracketAction(this);
3200 action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
3201 setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
3204 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.",
3205 // this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
3206 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
3207 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action);
3208 //// WorkbenchHelp.setHelp(action,
3209 // IJavaHelpContextIds.SHOW_OUTLINE_ACTION);
3212 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.",
3213 // this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$
3214 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE);
3215 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE,
3217 //// WorkbenchHelp.setHelp(action,
3218 // IJavaHelpContextIds.OPEN_STRUCTURE_ACTION);
3221 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.",
3222 // this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
3223 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY);
3224 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY,
3226 //// WorkbenchHelp.setHelp(action,
3227 // IJavaHelpContextIds.OPEN_HIERARCHY_ACTION);
3229 fEncodingSupport = new DefaultEncodingSupport();
3230 fEncodingSupport.initialize(this);
3232 // fSelectionHistory= new SelectionHistory(this);
3234 // action= new StructureSelectEnclosingAction(this, fSelectionHistory);
3235 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
3236 // setAction(StructureSelectionAction.ENCLOSING, action);
3238 // action= new StructureSelectNextAction(this, fSelectionHistory);
3239 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
3240 // setAction(StructureSelectionAction.NEXT, action);
3242 // action= new StructureSelectPreviousAction(this, fSelectionHistory);
3243 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
3244 // setAction(StructureSelectionAction.PREVIOUS, action);
3246 // StructureSelectHistoryAction historyAction= new
3247 // StructureSelectHistoryAction(this, fSelectionHistory);
3248 // historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
3249 // setAction(StructureSelectionAction.HISTORY, historyAction);
3250 // fSelectionHistory.setHistoryAction(historyAction);
3252 // action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this);
3253 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
3254 // setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action);
3257 // GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this);
3258 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
3259 // setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
3261 // action= new QuickFormatAction();
3262 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT);
3263 // setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action);
3265 // action= new RemoveOccurrenceAnnotations(this);
3266 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
3267 // setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$
3269 // add annotation actions
3270 action = new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
3271 setAction("AnnotationAction", action); //$NON-NLS-1$
3274 private void internalDoSetInput(IEditorInput input) throws CoreException {
3275 super.doSetInput(input);
3277 if (getSourceViewer() instanceof JavaSourceViewer) {
3278 JavaSourceViewer viewer = (JavaSourceViewer) getSourceViewer();
3279 if (viewer.getReconciler() == null) {
3280 IReconciler reconciler = getSourceViewerConfiguration().getReconciler(viewer);
3281 if (reconciler != null) {
3282 reconciler.install(viewer);
3283 viewer.setReconciler(reconciler);
3288 if (fEncodingSupport != null)
3289 fEncodingSupport.reset();
3291 setOutlinePageInput(fOutlinePage, input);
3293 if (fProjectionModelUpdater != null)
3294 fProjectionModelUpdater.initialize();
3296 // if (isShowingOverrideIndicators())
3297 // installOverrideIndicator(false);
3301 * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)
3304 protected void setPreferenceStore(IPreferenceStore store) {
3305 super.setPreferenceStore(store);
3306 if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) {
3307 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
3308 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
3309 IPHPPartitions.PHP_PARTITIONING));
3311 if (getSourceViewer() instanceof JavaSourceViewer)
3312 ((JavaSourceViewer) getSourceViewer()).setPreferenceStore(store);
3316 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra disposal
3317 * actions required by the php editor.
3319 public void dispose() {
3320 if (fProjectionModelUpdater != null) {
3321 fProjectionModelUpdater.uninstall();
3322 fProjectionModelUpdater = null;
3325 if (fProjectionSupport != null) {
3326 fProjectionSupport.dispose();
3327 fProjectionSupport = null;
3329 // PHPEditorEnvironment.disconnect(this);
3330 if (fOutlinePage != null)
3331 fOutlinePage.setInput(null);
3333 if (fActionGroups != null)
3334 fActionGroups.dispose();
3336 if (isBrowserLikeLinks())
3337 disableBrowserLikeLinks();
3339 if (fEncodingSupport != null) {
3340 fEncodingSupport.dispose();
3341 fEncodingSupport = null;
3344 if (fPropertyChangeListener != null) {
3345 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
3346 preferences.removePropertyChangeListener(fPropertyChangeListener);
3347 fPropertyChangeListener = null;
3350 // if (fSourceViewerDecorationSupport != null) {
3351 // fSourceViewerDecorationSupport.dispose();
3352 // fSourceViewerDecorationSupport = null;
3355 if (fBracketMatcher != null) {
3356 fBracketMatcher.dispose();
3357 fBracketMatcher = null;
3360 if (fEditorSelectionChangedListener != null) {
3361 fEditorSelectionChangedListener.uninstall(getSelectionProvider());
3362 fEditorSelectionChangedListener = null;
3369 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra revert behavior
3370 * required by the php editor.
3372 // public void doRevertToSaved() {
3373 // super.doRevertToSaved();
3374 // if (fOutlinePage != null)
3375 // fOutlinePage.update();
3378 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra save behavior
3379 * required by the php editor.
3381 // public void doSave(IProgressMonitor monitor) {
3382 // super.doSave(monitor);
3383 // compile or not, according to the user preferences
3384 // IPreferenceStore store = getPreferenceStore();
3385 // the parse on save was changed to the eclipse "builders" concept
3386 // if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
3387 // IAction a = PHPParserAction.getInstance();
3391 // if (SWT.getPlatform().equals("win32")) {
3392 // IAction a = ShowExternalPreviewAction.getInstance();
3396 // if (fOutlinePage != null)
3397 // fOutlinePage.update();
3400 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra save as
3401 * behavior required by the php editor.
3403 // public void doSaveAs() {
3404 // super.doSaveAs();
3405 // if (fOutlinePage != null)
3406 // fOutlinePage.update();
3409 * @see StatusTextEditor#getStatusHeader(IStatus)
3411 protected String getStatusHeader(IStatus status) {
3412 if (fEncodingSupport != null) {
3413 String message = fEncodingSupport.getStatusHeader(status);
3414 if (message != null)
3417 return super.getStatusHeader(status);
3421 * @see StatusTextEditor#getStatusBanner(IStatus)
3423 protected String getStatusBanner(IStatus status) {
3424 if (fEncodingSupport != null) {
3425 String message = fEncodingSupport.getStatusBanner(status);
3426 if (message != null)
3429 return super.getStatusBanner(status);
3433 * @see StatusTextEditor#getStatusMessage(IStatus)
3435 protected String getStatusMessage(IStatus status) {
3436 if (fEncodingSupport != null) {
3437 String message = fEncodingSupport.getStatusMessage(status);
3438 if (message != null)
3441 return super.getStatusMessage(status);
3445 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs sets the input of the
3446 * outline page after AbstractTextEditor has set input.
3448 // protected void doSetInput(IEditorInput input) throws CoreException {
3449 // super.doSetInput(input);
3450 // if (fEncodingSupport != null)
3451 // fEncodingSupport.reset();
3452 // setOutlinePageInput(fOutlinePage, input);
3455 * @see AbstractTextEditor#doSetInput
3457 protected void doSetInput(IEditorInput input) throws CoreException {
3458 ISourceViewer sourceViewer = getSourceViewer();
3459 if (!(sourceViewer instanceof ISourceViewerExtension2)) {
3460 setPreferenceStore(createCombinedPreferenceStore(input));
3461 internalDoSetInput(input);
3465 // uninstall & unregister preference store listener
3466 if (isBrowserLikeLinks())
3467 disableBrowserLikeLinks();
3468 getSourceViewerDecorationSupport(sourceViewer).uninstall();
3469 ((ISourceViewerExtension2) sourceViewer).unconfigure();
3471 setPreferenceStore(createCombinedPreferenceStore(input));
3473 // install & register preference store listener
3474 sourceViewer.configure(getSourceViewerConfiguration());
3475 getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
3476 if (isBrowserLikeLinks())
3477 enableBrowserLikeLinks();
3479 internalDoSetInput(input);
3483 * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
3485 // public Object getViewPartInput() {
3486 // return getEditorInput().getAdapter(IFile.class);
3489 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method adds any PHPEditor specific
3492 public void editorContextMenuAboutToShow(MenuManager menu) {
3493 super.editorContextMenuAboutToShow(menu);
3494 menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, new Separator(IContextMenuConstants.GROUP_OPEN));
3495 menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));
3497 ActionContext context = new ActionContext(getSelectionProvider().getSelection());
3498 fContextMenuGroup.setContext(context);
3499 fContextMenuGroup.fillContextMenu(menu);
3500 fContextMenuGroup.setContext(null);
3501 // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format");
3504 // ActionContext context =
3505 // new ActionContext(getSelectionProvider().getSelection());
3506 // fContextMenuGroup.setContext(context);
3507 // fContextMenuGroup.fillContextMenu(menu);
3508 // fContextMenuGroup.setContext(null);
3512 * Creates the outline page used with this editor.
3514 protected JavaOutlinePage createOutlinePage() {
3515 JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this);
3516 fOutlineSelectionChangedListener.install(page);
3517 setOutlinePageInput(page, getEditorInput());
3522 * Informs the editor that its outliner has been closed.
3524 public void outlinePageClosed() {
3525 if (fOutlinePage != null) {
3526 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3527 fOutlinePage = null;
3528 resetHighlightRange();
3533 * Synchronizes the outliner selection with the given element position in the editor.
3536 * the java element to select
3538 protected void synchronizeOutlinePage(ISourceReference element) {
3539 synchronizeOutlinePage(element, true);
3543 * Synchronizes the outliner selection with the given element position in the editor.
3546 * the java element to select
3547 * @param checkIfOutlinePageActive
3548 * <code>true</code> if check for active outline page needs to be done
3550 protected void synchronizeOutlinePage(ISourceReference element, boolean checkIfOutlinePageActive) {
3551 if (fOutlinePage != null && element != null && !(checkIfOutlinePageActive && isJavaOutlinePageActive())) {
3552 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3553 fOutlinePage.select(element);
3554 fOutlineSelectionChangedListener.install(fOutlinePage);
3559 * Synchronizes the outliner selection with the actual cursor position in the editor.
3561 public void synchronizeOutlinePageSelection() {
3562 synchronizeOutlinePage(computeHighlightRangeSourceReference());
3564 // ISourceViewer sourceViewer = getSourceViewer();
3565 // if (sourceViewer == null || fOutlinePage == null)
3568 // StyledText styledText = sourceViewer.getTextWidget();
3569 // if (styledText == null)
3573 // if (sourceViewer instanceof ITextViewerExtension3) {
3574 // ITextViewerExtension3 extension = (ITextViewerExtension3)
3577 // extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
3579 // int offset = sourceViewer.getVisibleRegion().getOffset();
3580 // caret = offset + styledText.getCaretOffset();
3583 // IJavaElement element = getElementAt(caret);
3584 // if (element instanceof ISourceReference) {
3585 // fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
3586 // fOutlinePage.select((ISourceReference) element);
3587 // fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
3591 protected void setSelection(ISourceReference reference, boolean moveCursor) {
3593 ISelection selection = getSelectionProvider().getSelection();
3594 if (selection instanceof TextSelection) {
3595 TextSelection textSelection = (TextSelection) selection;
3596 if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
3597 markInNavigationHistory();
3600 if (reference != null) {
3602 StyledText textWidget = null;
3604 ISourceViewer sourceViewer = getSourceViewer();
3605 if (sourceViewer != null)
3606 textWidget = sourceViewer.getTextWidget();
3608 if (textWidget == null)
3613 ISourceRange range = reference.getSourceRange();
3617 int offset = range.getOffset();
3618 int length = range.getLength();
3620 if (offset < 0 || length < 0)
3623 textWidget.setRedraw(false);
3625 setHighlightRange(offset, length, moveCursor);
3633 if (reference instanceof IMember) {
3634 range = ((IMember) reference).getNameRange();
3635 if (range != null) {
3636 offset = range.getOffset();
3637 length = range.getLength();
3640 // else if (reference instanceof IImportDeclaration) {
3641 // String name= ((IImportDeclaration)
3642 // reference).getElementName();
3643 // if (name != null && name.length() > 0) {
3644 // String content= reference.getSource();
3645 // if (content != null) {
3646 // offset= range.getOffset() + content.indexOf(name);
3647 // length= name.length();
3650 // } else if (reference instanceof IPackageDeclaration) {
3651 // String name= ((IPackageDeclaration)
3652 // reference).getElementName();
3653 // if (name != null && name.length() > 0) {
3654 // String content= reference.getSource();
3655 // if (content != null) {
3656 // offset= range.getOffset() + content.indexOf(name);
3657 // length= name.length();
3662 if (offset > -1 && length > 0) {
3663 sourceViewer.revealRange(offset, length);
3664 sourceViewer.setSelectedRange(offset, length);
3667 } catch (JavaModelException x) {
3668 } catch (IllegalArgumentException x) {
3670 if (textWidget != null)
3671 textWidget.setRedraw(true);
3674 } else if (moveCursor) {
3675 resetHighlightRange();
3678 markInNavigationHistory();
3681 public void setSelection(IJavaElement element) {
3682 if (element == null || element instanceof ICompilationUnit) { // ||
3688 * If the element is an ICompilationUnit this unit is either the input of this editor or not being displayed. In both cases,
3689 * nothing should happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
3694 IJavaElement corresponding = getCorrespondingElement(element);
3695 if (corresponding instanceof ISourceReference) {
3696 ISourceReference reference = (ISourceReference) corresponding;
3697 // set highlight range
3698 setSelection(reference, true);
3699 // set outliner selection
3700 if (fOutlinePage != null) {
3701 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3702 fOutlinePage.select(reference);
3703 fOutlineSelectionChangedListener.install(fOutlinePage);
3708 public synchronized void editingScriptStarted() {
3709 ++fIgnoreOutlinePageSelection;
3712 public synchronized void editingScriptEnded() {
3713 --fIgnoreOutlinePageSelection;
3716 public synchronized boolean isEditingScriptRunning() {
3717 return (fIgnoreOutlinePageSelection > 0);
3721 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs gets the java content
3722 * outline page if request is for a an outline page.
3724 public Object getAdapter(Class required) {
3726 if (IContentOutlinePage.class.equals(required)) {
3727 if (fOutlinePage == null)
3728 fOutlinePage = createOutlinePage();
3729 return fOutlinePage;
3732 if (IEncodingSupport.class.equals(required))
3733 return fEncodingSupport;
3735 if (required == IShowInTargetList.class) {
3736 return new IShowInTargetList() {
3737 public String[] getShowInTargetIds() {
3738 return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
3743 if (fProjectionSupport != null) {
3744 Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
3745 if (adapter != null)
3749 return super.getAdapter(required);
3752 // public Object getAdapter(Class required) {
3753 // if (IContentOutlinePage.class.equals(required)) {
3754 // if (fOutlinePage == null) {
3755 // fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
3756 // if (getEditorInput() != null)
3757 // fOutlinePage.setInput(getEditorInput());
3759 // return fOutlinePage;
3762 // if (IEncodingSupport.class.equals(required))
3763 // return fEncodingSupport;
3765 // return super.getAdapter(required);
3768 protected void doSelectionChanged(SelectionChangedEvent event) {
3769 ISourceReference reference = null;
3771 ISelection selection = event.getSelection();
3772 Iterator iter = ((IStructuredSelection) selection).iterator();
3773 while (iter.hasNext()) {
3774 Object o = iter.next();
3775 if (o instanceof ISourceReference) {
3776 reference = (ISourceReference) o;
3781 if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
3782 PHPeclipsePlugin.getActivePage().bringToTop(this);
3785 editingScriptStarted();
3786 setSelection(reference, !isActivePart());
3788 editingScriptEnded();
3793 * @see AbstractTextEditor#adjustHighlightRange(int, int)
3795 protected void adjustHighlightRange(int offset, int length) {
3799 IJavaElement element = getElementAt(offset);
3800 while (element instanceof ISourceReference) {
3801 ISourceRange range = ((ISourceReference) element).getSourceRange();
3802 if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) {
3804 ISourceViewer viewer = getSourceViewer();
3805 if (viewer instanceof ITextViewerExtension5) {
3806 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
3807 extension.exposeModelRange(new Region(range.getOffset(), range.getLength()));
3810 setHighlightRange(range.getOffset(), range.getLength(), true);
3811 if (fOutlinePage != null) {
3812 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3813 fOutlinePage.select((ISourceReference) element);
3814 fOutlineSelectionChangedListener.install(fOutlinePage);
3819 element = element.getParent();
3822 } catch (JavaModelException x) {
3823 PHPeclipsePlugin.log(x.getStatus());
3826 ISourceViewer viewer = getSourceViewer();
3827 if (viewer instanceof ITextViewerExtension5) {
3828 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
3829 extension.exposeModelRange(new Region(offset, length));
3831 resetHighlightRange();
3836 protected boolean isActivePart() {
3837 IWorkbenchWindow window = getSite().getWorkbenchWindow();
3838 IPartService service = window.getPartService();
3839 IWorkbenchPart part = service.getActivePart();
3840 return part != null && part.equals(this);
3843 // public void openContextHelp() {
3845 // this.getDocumentProvider().getDocument(this.getEditorInput());
3846 // ITextSelection selection = (ITextSelection)
3847 // this.getSelectionProvider().getSelection();
3848 // int pos = selection.getOffset();
3849 // String word = getFunctionName(doc, pos);
3850 // openContextHelp(word);
3853 // private void openContextHelp(String word) {
3857 // public static void open(String word) {
3858 // IHelp help = WorkbenchHelp.getHelpSupport();
3859 // if (help != null) {
3860 // IHelpResource helpResource = new PHPFunctionHelpResource(word);
3861 // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
3863 // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help
3864 // not available"), false); //$NON-NLS-1$
3868 // private String getFunctionName(IDocument doc, int pos) {
3869 // Point word = PHPWordExtractor.findWord(doc, pos);
3870 // if (word != null) {
3872 // return doc.get(word.x, word.y).replace('_', '-');
3873 // } catch (BadLocationException e) {
3880 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
3882 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
3886 ISourceViewer sourceViewer = getSourceViewer();
3887 if (sourceViewer == null)
3890 String property = event.getProperty();
3892 if (PreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
3893 Object value = event.getNewValue();
3894 if (value instanceof Integer) {
3895 sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
3896 } else if (value instanceof String) {
3898 sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
3899 } catch (NumberFormatException e) {
3900 // bug #1038071 - set default tab:
3901 sourceViewer.getTextWidget().setTabs(80);
3907 // if (OVERVIEW_RULER.equals(property)) {
3908 // if (isOverviewRulerVisible())
3909 // showOverviewRuler();
3911 // hideOverviewRuler();
3915 // if (LINE_NUMBER_RULER.equals(property)) {
3916 // if (isLineNumberRulerVisible())
3917 // showLineNumberRuler();
3919 // hideLineNumberRuler();
3923 // if (fLineNumberRulerColumn != null
3924 // && (LINE_NUMBER_COLOR.equals(property) ||
3925 // PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) ||
3926 // PREFERENCE_COLOR_BACKGROUND.equals(property))) {
3928 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
3931 if (isJavaEditorHoverProperty(property))
3932 updateHoverBehavior();
3934 if (BROWSER_LIKE_LINKS.equals(property)) {
3935 if (isBrowserLikeLinks())
3936 enableBrowserLikeLinks();
3938 disableBrowserLikeLinks();
3942 if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) {
3943 if ((event.getNewValue() instanceof Boolean) && ((Boolean) event.getNewValue()).booleanValue())
3948 if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) {
3949 if (event.getNewValue() instanceof Boolean) {
3950 Boolean disable = (Boolean) event.getNewValue();
3951 enableOverwriteMode(!disable.booleanValue());
3956 // if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property))
3958 // if (event.getNewValue() instanceof Boolean) {
3959 // boolean markOccurrenceAnnotations=
3960 // ((Boolean)event.getNewValue()).booleanValue();
3961 // if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) {
3962 // fMarkOccurrenceAnnotations= markOccurrenceAnnotations;
3963 // if (!fMarkOccurrenceAnnotations)
3964 // uninstallOccurrencesFinder();
3966 // installOccurrencesFinder();
3971 // (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property))
3973 // if (event.getNewValue() instanceof Boolean) {
3974 // boolean stickyOccurrenceAnnotations=
3975 // ((Boolean)event.getNewValue()).booleanValue();
3976 // if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations)
3978 // fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations;
3979 //// if (!fMarkOccurrenceAnnotations)
3980 //// uninstallOccurrencesFinder();
3982 //// installOccurrencesFinder();
3987 ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event);
3989 // if (affectsOverrideIndicatorAnnotations(event)) {
3990 // if (isShowingOverrideIndicators()) {
3991 // if (fOverrideIndicatorManager == null)
3992 // installOverrideIndicator(true);
3994 // if (fOverrideIndicatorManager != null)
3995 // uninstallOverrideIndicator();
4000 if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
4001 if (sourceViewer instanceof ProjectionViewer) {
4002 ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer;
4003 if (fProjectionModelUpdater != null)
4004 fProjectionModelUpdater.uninstall();
4005 // either freshly enabled or provider changed
4006 fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
4007 if (fProjectionModelUpdater != null) {
4008 fProjectionModelUpdater.install(this, projectionViewer);
4014 super.handlePreferenceStoreChanged(event);
4020 // AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
4022 // protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
4026 // ISourceViewer sourceViewer = getSourceViewer();
4027 // if (sourceViewer == null)
4030 // String property = event.getProperty();
4033 // (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
4034 // // Object value= event.getNewValue();
4035 // // if (value instanceof Integer) {
4036 // // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
4037 // // } else if (value instanceof String) {
4038 // // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String)
4044 // if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
4045 // if (isLineNumberRulerVisible())
4046 // showLineNumberRuler();
4048 // hideLineNumberRuler();
4052 // if (fLineNumberRulerColumn != null
4053 // && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
4054 // || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
4055 // || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
4057 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4061 // super.handlePreferenceStoreChanged(event);
4065 // private boolean isJavaEditorHoverProperty(String property) {
4066 // return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
4067 // || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
4068 // || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
4069 // || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
4070 // || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
4071 // || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
4072 // || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
4073 // || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
4077 * Shows the line number ruler column.
4079 // private void showLineNumberRuler() {
4080 // IVerticalRuler v = getVerticalRuler();
4081 // if (v instanceof CompositeRuler) {
4082 // CompositeRuler c = (CompositeRuler) v;
4083 // c.addDecorator(1, createLineNumberRulerColumn());
4086 private boolean isJavaEditorHoverProperty(String property) {
4087 return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property);
4091 * Return whether the browser like links should be enabled according to the preference store settings.
4093 * @return <code>true</code> if the browser like links should be enabled
4095 private boolean isBrowserLikeLinks() {
4096 IPreferenceStore store = getPreferenceStore();
4097 return store.getBoolean(BROWSER_LIKE_LINKS);
4101 * Enables browser like links.
4103 private void enableBrowserLikeLinks() {
4104 if (fMouseListener == null) {
4105 fMouseListener = new MouseClickListener();
4106 fMouseListener.install();
4111 * Disables browser like links.
4113 private void disableBrowserLikeLinks() {
4114 if (fMouseListener != null) {
4115 fMouseListener.uninstall();
4116 fMouseListener = null;
4121 * Handles a property change event describing a change of the java core's preferences and updates the preference related editor
4125 * the property change event
4127 protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
4128 if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
4129 ISourceViewer sourceViewer = getSourceViewer();
4130 if (sourceViewer != null
4131 && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event
4133 sourceViewer.invalidateTextPresentation();
4135 if (PreferenceConstants.EDITOR_WRAP_WORDS.equals(event.getProperty())) {
4141 * Return whether the line number ruler column should be visible according to the preference store settings.
4143 * @return <code>true</code> if the line numbers should be visible
4145 // protected boolean isLineNumberRulerVisible() {
4146 // IPreferenceStore store = getPreferenceStore();
4147 // return store.getBoolean(LINE_NUMBER_RULER);
4150 * Hides the line number ruler column.
4152 // private void hideLineNumberRuler() {
4153 // IVerticalRuler v = getVerticalRuler();
4154 // if (v instanceof CompositeRuler) {
4155 // CompositeRuler c = (CompositeRuler) v;
4157 // c.removeDecorator(1);
4158 // } catch (Throwable e) {
4163 * @see AbstractTextEditor#handleCursorPositionChanged()
4165 // protected void handleCursorPositionChanged() {
4166 // super.handleCursorPositionChanged();
4167 // if (!isEditingScriptRunning() && fUpdater != null)
4171 * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced()
4173 protected void handleElementContentReplaced() {
4174 super.handleElementContentReplaced();
4175 if (fProjectionModelUpdater != null)
4176 fProjectionModelUpdater.initialize();
4180 * Initializes the given line number ruler column from the preference store.
4182 * @param rulerColumn
4183 * the ruler column to be initialized
4185 // protected void initializeLineNumberRulerColumn(LineNumberRulerColumn
4187 // JavaTextTools textTools =
4188 // PHPeclipsePlugin.getDefault().getJavaTextTools();
4189 // IColorManager manager = textTools.getColorManager();
4191 // IPreferenceStore store = getPreferenceStore();
4192 // if (store != null) {
4195 // // foreground color
4196 // if (store.contains(LINE_NUMBER_COLOR)) {
4197 // if (store.isDefault(LINE_NUMBER_COLOR))
4198 // rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
4200 // rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
4202 // rulerColumn.setForeground(manager.getColor(rgb));
4205 // // background color
4206 // if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
4207 // if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
4208 // if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
4209 // rgb = PreferenceConverter.getDefaultColor(store,
4210 // PREFERENCE_COLOR_BACKGROUND);
4212 // rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
4215 // rulerColumn.setBackground(manager.getColor(rgb));
4219 * Creates a new line number ruler column that is appropriately initialized.
4221 // protected IVerticalRulerColumn createLineNumberRulerColumn() {
4222 // fLineNumberRulerColumn = new LineNumberRulerColumn();
4223 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4224 // return fLineNumberRulerColumn;
4227 * @see AbstractTextEditor#createVerticalRuler()
4229 // protected IVerticalRuler createVerticalRuler() {
4230 // CompositeRuler ruler = new CompositeRuler();
4231 // ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
4232 // if (isLineNumberRulerVisible())
4233 // ruler.addDecorator(1, createLineNumberRulerColumn());
4236 // private static IRegion getSignedSelection(ITextViewer viewer) {
4238 // StyledText text = viewer.getTextWidget();
4239 // int caretOffset = text.getCaretOffset();
4240 // Point selection = text.getSelection();
4243 // int offset, length;
4244 // if (caretOffset == selection.x) {
4245 // offset = selection.y;
4246 // length = selection.x - selection.y;
4250 // offset = selection.x;
4251 // length = selection.y - selection.x;
4254 // return new Region(offset, length);
4256 protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
4257 StyledText text = sourceViewer.getTextWidget();
4258 Point selection = text.getSelectionRange();
4260 if (text.getCaretOffset() == selection.x) {
4261 selection.x = selection.x + selection.y;
4262 selection.y = -selection.y;
4265 selection.x = widgetOffset2ModelOffset(sourceViewer, selection.x);
4267 return new Region(selection.x, selection.y);
4270 /** Preference key for matching brackets */
4271 protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
4273 /** Preference key for matching brackets color */
4274 protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
4276 /** Preference key for highlighting current line */
4277 // protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
4278 /** Preference key for highlight color of current line */
4279 // protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
4280 /** Preference key for showing print marging ruler */
4281 // protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
4282 /** Preference key for print margin ruler color */
4283 // protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
4284 /** Preference key for print margin ruler column */
4285 // protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
4286 /** Preference key for error indication */
4287 // protected final static String ERROR_INDICATION =
4288 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
4289 /** Preference key for error color */
4290 // protected final static String ERROR_INDICATION_COLOR =
4291 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
4292 /** Preference key for warning indication */
4293 // protected final static String WARNING_INDICATION =
4294 // PreferenceConstants.EDITOR_WARNING_INDICATION;
4295 /** Preference key for warning color */
4296 // protected final static String WARNING_INDICATION_COLOR =
4297 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
4298 /** Preference key for task indication */
4299 protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
4301 /** Preference key for task color */
4302 protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
4304 /** Preference key for bookmark indication */
4305 protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
4307 /** Preference key for bookmark color */
4308 protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
4310 /** Preference key for search result indication */
4311 protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
4313 /** Preference key for search result color */
4314 protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
4316 /** Preference key for unknown annotation indication */
4317 protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
4319 /** Preference key for unknown annotation color */
4320 protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
4322 /** Preference key for shwoing the overview ruler */
4323 protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
4325 /** Preference key for error indication in overview ruler */
4326 protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
4328 /** Preference key for warning indication in overview ruler */
4329 protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
4331 /** Preference key for task indication in overview ruler */
4332 protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
4334 /** Preference key for bookmark indication in overview ruler */
4335 protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
4337 /** Preference key for search result indication in overview ruler */
4338 protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
4340 /** Preference key for unknown annotation indication in overview ruler */
4341 protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
4343 // /** Preference key for compiler task tags */
4344 // private final static String COMPILER_TASK_TAGS=
4345 // JavaCore.COMPILER_TASK_TAGS;
4346 /** Preference key for browser like links */
4347 private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS;
4349 /** Preference key for key modifier of browser like links */
4350 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER;
4353 * Preference key for key modifier mask of browser like links. The value is only used if the value of
4354 * <code>EDITOR_BROWSER_LIKE_LINKS</code> cannot be resolved to valid SWT modifier bits.
4358 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
4360 private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
4362 private static boolean isBracket(char character) {
4363 for (int i = 0; i != BRACKETS.length; ++i)
4364 if (character == BRACKETS[i])
4369 private static boolean isSurroundedByBrackets(IDocument document, int offset) {
4370 if (offset == 0 || offset == document.getLength())
4374 return isBracket(document.getChar(offset - 1)) && isBracket(document.getChar(offset));
4376 } catch (BadLocationException e) {
4381 // protected void configureSourceViewerDecorationSupport() {
4383 // fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
4385 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4386 // AnnotationType.UNKNOWN,
4387 // UNKNOWN_INDICATION_COLOR,
4388 // UNKNOWN_INDICATION,
4389 // UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
4391 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4392 // AnnotationType.BOOKMARK,
4393 // BOOKMARK_INDICATION_COLOR,
4394 // BOOKMARK_INDICATION,
4395 // BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
4397 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4398 // AnnotationType.TASK,
4399 // TASK_INDICATION_COLOR,
4401 // TASK_INDICATION_IN_OVERVIEW_RULER,
4403 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4404 // AnnotationType.SEARCH,
4405 // SEARCH_RESULT_INDICATION_COLOR,
4406 // SEARCH_RESULT_INDICATION,
4407 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
4409 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4410 // AnnotationType.WARNING,
4411 // WARNING_INDICATION_COLOR,
4412 // WARNING_INDICATION,
4413 // WARNING_INDICATION_IN_OVERVIEW_RULER,
4415 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4416 // AnnotationType.ERROR,
4417 // ERROR_INDICATION_COLOR,
4418 // ERROR_INDICATION,
4419 // ERROR_INDICATION_IN_OVERVIEW_RULER,
4422 // fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE,
4423 // CURRENT_LINE_COLOR);
4424 // fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN,
4425 // PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
4426 // fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS,
4427 // MATCHING_BRACKETS_COLOR);
4429 // fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
4433 * Returns the Java element wrapped by this editors input.
4435 * @return the Java element wrapped by this editors input.
4438 abstract protected IJavaElement getInputJavaElement();
4440 protected void updateStatusLine() {
4441 ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
4442 Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength());
4443 setStatusLineErrorMessage(null);
4444 setStatusLineMessage(null);
4445 if (annotation != null) {
4447 fIsUpdatingAnnotationViews = true;
4448 updateAnnotationViews(annotation);
4450 fIsUpdatingAnnotationViews = false;
4452 if (annotation instanceof IJavaAnnotation && ((IJavaAnnotation) annotation).isProblem())
4453 setStatusLineMessage(annotation.getText());
4458 * Jumps to the matching bracket.
4460 public void gotoMatchingBracket() {
4462 ISourceViewer sourceViewer = getSourceViewer();
4463 IDocument document = sourceViewer.getDocument();
4464 if (document == null)
4467 IRegion selection = getSignedSelection(sourceViewer);
4469 int selectionLength = Math.abs(selection.getLength());
4470 if (selectionLength > 1) {
4471 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$
4472 sourceViewer.getTextWidget().getDisplay().beep();
4477 int sourceCaretOffset = selection.getOffset() + selection.getLength();
4478 if (isSurroundedByBrackets(document, sourceCaretOffset))
4479 sourceCaretOffset -= selection.getLength();
4481 IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
4482 if (region == null) {
4483 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$
4484 sourceViewer.getTextWidget().getDisplay().beep();
4488 int offset = region.getOffset();
4489 int length = region.getLength();
4494 int anchor = fBracketMatcher.getAnchor();
4495 int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
4497 boolean visible = false;
4498 if (sourceViewer instanceof ITextViewerExtension3) {
4499 ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
4500 visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
4502 IRegion visibleRegion = sourceViewer.getVisibleRegion();
4503 visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength());
4507 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$
4508 sourceViewer.getTextWidget().getDisplay().beep();
4512 if (selection.getLength() < 0)
4513 targetOffset -= selection.getLength();
4515 sourceViewer.setSelectedRange(targetOffset, selection.getLength());
4516 sourceViewer.revealRange(targetOffset, selection.getLength());
4520 * Ses the given message as error message to this editor's status line.
4525 protected void setStatusLineErrorMessage(String msg) {
4526 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
4527 if (statusLine != null)
4528 statusLine.setMessage(true, msg, null);
4532 * Sets the given message as message to this editor's status line.
4538 protected void setStatusLineMessage(String msg) {
4539 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
4540 if (statusLine != null)
4541 statusLine.setMessage(false, msg, null);
4545 * Returns the annotation closest to the given range respecting the given direction. If an annotation is found, the annotations
4546 * current position is copied into the provided annotation position.
4553 * <code>true</code> for forwards, <code>false</code> for backward
4554 * @param annotationPosition
4555 * the position of the found annotation
4556 * @return the found annotation
4558 private Annotation getNextAnnotation(final int offset, final int length, boolean forward, Position annotationPosition) {
4560 Annotation nextAnnotation = null;
4561 Position nextAnnotationPosition = null;
4562 Annotation containingAnnotation = null;
4563 Position containingAnnotationPosition = null;
4564 boolean currentAnnotation = false;
4566 IDocument document = getDocumentProvider().getDocument(getEditorInput());
4567 int endOfDocument = document.getLength();
4568 int distance = Integer.MAX_VALUE;
4570 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
4571 Iterator e = new JavaAnnotationIterator(model, true, true);
4572 while (e.hasNext()) {
4573 Annotation a = (Annotation) e.next();
4574 if ((a instanceof IJavaAnnotation) && ((IJavaAnnotation) a).hasOverlay() || !isNavigationTarget(a))
4577 Position p = model.getPosition(a);
4581 if (forward && p.offset == offset || !forward && p.offset + p.getLength() == offset + length) {// || p.includes(offset)) {
4582 if (containingAnnotation == null
4583 || (forward && p.length >= containingAnnotationPosition.length || !forward
4584 && p.length >= containingAnnotationPosition.length)) {
4585 containingAnnotation = a;
4586 containingAnnotationPosition = p;
4587 currentAnnotation = p.length == length;
4590 int currentDistance = 0;
4593 currentDistance = p.getOffset() - offset;
4594 if (currentDistance < 0)
4595 currentDistance = endOfDocument + currentDistance;
4597 if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
4598 distance = currentDistance;
4600 nextAnnotationPosition = p;
4603 currentDistance = offset + length - (p.getOffset() + p.length);
4604 if (currentDistance < 0)
4605 currentDistance = endOfDocument + currentDistance;
4607 if (currentDistance < distance || currentDistance == distance && p.length < nextAnnotationPosition.length) {
4608 distance = currentDistance;
4610 nextAnnotationPosition = p;
4615 if (containingAnnotationPosition != null && (!currentAnnotation || nextAnnotation == null)) {
4616 annotationPosition.setOffset(containingAnnotationPosition.getOffset());
4617 annotationPosition.setLength(containingAnnotationPosition.getLength());
4618 return containingAnnotation;
4620 if (nextAnnotationPosition != null) {
4621 annotationPosition.setOffset(nextAnnotationPosition.getOffset());
4622 annotationPosition.setLength(nextAnnotationPosition.getLength());
4625 return nextAnnotation;
4629 * Returns the annotation overlapping with the given range or <code>null</code>.
4635 * @return the found annotation or <code>null</code>
4638 private Annotation getAnnotation(int offset, int length) {
4639 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
4640 Iterator e = new JavaAnnotationIterator(model, true, true);
4641 while (e.hasNext()) {
4642 Annotation a = (Annotation) e.next();
4643 if (!isNavigationTarget(a))
4646 Position p = model.getPosition(a);
4647 if (p != null && p.overlapsWith(offset, length))
4655 * Returns whether the given annotation is configured as a target for the "Go to Next/Previous Annotation" actions
4659 * @return <code>true</code> if this is a target, <code>false</code> otherwise
4662 private boolean isNavigationTarget(Annotation annotation) {
4663 Preferences preferences = EditorsUI.getPluginPreferences();
4664 AnnotationPreference preference = getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
4666 // String key= forward ? preference.getIsGoToNextNavigationTargetKey() : preference.getIsGoToPreviousNavigationTargetKey();
4667 String key = preference == null ? null : preference.getIsGoToNextNavigationTargetKey();
4668 return (key != null && preferences.getBoolean(key));
4672 * Returns a segmentation of the line of the given document appropriate for bidi rendering. The default implementation returns
4673 * only the string literals of a php code line as segments.
4678 * the offset of the line
4679 * @return the line's bidi segmentation
4680 * @throws BadLocationException
4681 * in case lineOffset is not valid in document
4683 public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException {
4685 IRegion line = document.getLineInformationOfOffset(lineOffset);
4686 ITypedRegion[] linePartitioning = document.computePartitioning(lineOffset, line.getLength());
4688 List segmentation = new ArrayList();
4689 for (int i = 0; i < linePartitioning.length; i++) {
4690 if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType()))
4691 segmentation.add(linePartitioning[i]);
4694 if (segmentation.size() == 0)
4697 int size = segmentation.size();
4698 int[] segments = new int[size * 2 + 1];
4701 for (int i = 0; i < size; i++) {
4702 ITypedRegion segment = (ITypedRegion) segmentation.get(i);
4707 int offset = segment.getOffset() - lineOffset;
4708 if (offset > segments[j - 1])
4709 segments[j++] = offset;
4711 if (offset + segment.getLength() >= line.getLength())
4714 segments[j++] = offset + segment.getLength();
4717 if (j < segments.length) {
4718 int[] result = new int[j];
4719 System.arraycopy(segments, 0, result, 0, j);
4727 * Returns a segmentation of the given line appropriate for bidi rendering. The default implementation returns only the string
4728 * literals of a php code line as segments.
4731 * the offset of the line
4733 * the content of the line
4734 * @return the line's bidi segmentation
4736 protected int[] getBidiLineSegments(int lineOffset, String line) {
4737 IDocumentProvider provider = getDocumentProvider();
4738 if (provider != null && line != null && line.length() > 0) {
4739 IDocument document = provider.getDocument(getEditorInput());
4740 if (document != null)
4742 return getBidiLineSegments(document, lineOffset);
4743 } catch (BadLocationException x) {
4751 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4753 // protected final ISourceViewer createSourceViewer(
4754 // Composite parent,
4755 // IVerticalRuler ruler,
4757 // ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
4758 // StyledText text = viewer.getTextWidget();
4759 // text.addBidiSegmentListener(new BidiSegmentListener() {
4760 // public void lineGetSegments(BidiSegmentEvent event) {
4761 // event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
4764 // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
4767 public final ISourceViewer getViewer() {
4768 return getSourceViewer();
4771 // protected void showOverviewRuler() {
4772 // if (fOverviewRuler != null) {
4773 // if (getSourceViewer() instanceof ISourceViewerExtension) {
4774 // ((ISourceViewerExtension)
4775 // getSourceViewer()).showAnnotationsOverview(true);
4776 // fSourceViewerDecorationSupport.updateOverviewDecorations();
4781 // protected void hideOverviewRuler() {
4782 // if (getSourceViewer() instanceof ISourceViewerExtension) {
4783 // fSourceViewerDecorationSupport.hideAnnotationOverview();
4784 // ((ISourceViewerExtension)
4785 // getSourceViewer()).showAnnotationsOverview(false);
4789 // protected boolean isOverviewRulerVisible() {
4790 // IPreferenceStore store = getPreferenceStore();
4791 // return store.getBoolean(OVERVIEW_RULER);
4794 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4796 // protected ISourceViewer createJavaSourceViewer(
4797 // Composite parent,
4798 // IVerticalRuler ruler,
4799 // IOverviewRuler overviewRuler,
4800 // boolean isOverviewRulerVisible,
4802 // return new SourceViewer(parent, ruler, overviewRuler,
4803 // isOverviewRulerVisible(), styles);
4806 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4808 protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
4809 boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
4810 return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, store);
4814 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
4816 protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {
4818 ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles,
4819 getPreferenceStore());
4821 StyledText text = viewer.getTextWidget();
4822 text.addBidiSegmentListener(new BidiSegmentListener() {
4823 public void lineGetSegments(BidiSegmentEvent event) {
4824 event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
4828 // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
4830 // ensure source viewer decoration support has been created and
4832 getSourceViewerDecorationSupport(viewer);
4838 * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
4840 protected boolean affectsTextPresentation(PropertyChangeEvent event) {
4841 return ((PHPSourceViewerConfiguration) getSourceViewerConfiguration()).affectsTextPresentation(event)
4842 || super.affectsTextPresentation(event);
4846 // protected boolean affectsTextPresentation(PropertyChangeEvent event) {
4847 // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
4848 // return textTools.affectsBehavior(event);
4851 * Creates and returns the preference store for this Java editor with the given input.
4854 * The editor input for which to create the preference store
4855 * @return the preference store for this editor
4859 private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
4860 List stores = new ArrayList(3);
4862 IJavaProject project = EditorUtility.getJavaProject(input);
4863 if (project != null)
4864 stores.add(new OptionsAdapter(project.getOptions(false), PHPeclipsePlugin.getDefault().getMockupPreferenceStore(),
4865 new OptionsAdapter.IPropertyChangeEventFilter() {
4867 public boolean isFiltered(PropertyChangeEvent event) {
4868 IJavaElement inputJavaElement = getInputJavaElement();
4869 IJavaProject javaProject = inputJavaElement != null ? inputJavaElement.getJavaProject() : null;
4870 if (javaProject == null)
4873 return !javaProject.getProject().equals(event.getSource());
4878 stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore());
4879 stores.add(new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()));
4880 stores.add(EditorsUI.getPreferenceStore());
4882 return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
4886 * Jumps to the error next according to the given direction.
4888 public void gotoError(boolean forward) {
4890 ISelectionProvider provider = getSelectionProvider();
4892 ITextSelection s = (ITextSelection) provider.getSelection();
4893 Position errorPosition = new Position(0, 0);
4894 IJavaAnnotation nextError = getNextError(s.getOffset(), forward, errorPosition);
4896 if (nextError != null) {
4898 IMarker marker = null;
4899 if (nextError instanceof MarkerAnnotation)
4900 marker = ((MarkerAnnotation) nextError).getMarker();
4902 Iterator e = nextError.getOverlaidIterator();
4904 while (e.hasNext()) {
4905 Object o = e.next();
4906 if (o instanceof MarkerAnnotation) {
4907 marker = ((MarkerAnnotation) o).getMarker();
4914 if (marker != null) {
4915 IWorkbenchPage page = getSite().getPage();
4916 IViewPart view = view = page.findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
4917 if (view instanceof TaskList) {
4918 StructuredSelection ss = new StructuredSelection(marker);
4919 ((TaskList) view).setSelection(ss, true);
4923 selectAndReveal(errorPosition.getOffset(), errorPosition.getLength());
4924 // setStatusLineErrorMessage(nextError.getMessage());
4928 setStatusLineErrorMessage(null);
4933 private IJavaAnnotation getNextError(int offset, boolean forward, Position errorPosition) {
4935 IJavaAnnotation nextError = null;
4936 Position nextErrorPosition = null;
4938 IDocument document = getDocumentProvider().getDocument(getEditorInput());
4939 int endOfDocument = document.getLength();
4942 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
4943 Iterator e = new JavaAnnotationIterator(model, false);
4944 while (e.hasNext()) {
4946 IJavaAnnotation a = (IJavaAnnotation) e.next();
4947 if (a.hasOverlay() || !a.isProblem())
4950 Position p = model.getPosition((Annotation) a);
4951 if (!p.includes(offset)) {
4953 int currentDistance = 0;
4956 currentDistance = p.getOffset() - offset;
4957 if (currentDistance < 0)
4958 currentDistance = endOfDocument - offset + p.getOffset();
4960 currentDistance = offset - p.getOffset();
4961 if (currentDistance < 0)
4962 currentDistance = offset + endOfDocument - p.getOffset();
4965 if (nextError == null || currentDistance < distance) {
4966 distance = currentDistance;
4968 nextErrorPosition = p;
4973 if (nextErrorPosition != null) {
4974 errorPosition.setOffset(nextErrorPosition.getOffset());
4975 errorPosition.setLength(nextErrorPosition.getLength());
4981 void removeOccurrenceAnnotations() {
4982 IDocumentProvider documentProvider = getDocumentProvider();
4983 if (documentProvider == null)
4986 IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
4987 if (annotationModel == null || fOccurrenceAnnotations == null)
4990 synchronized (annotationModel) {
4991 if (annotationModel instanceof IAnnotationModelExtension) {
4992 ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
4994 for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++)
4995 annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
4997 fOccurrenceAnnotations = null;
5001 protected void uninstallOverrideIndicator() {
5002 // if (fOverrideIndicatorManager != null) {
5003 // fOverrideIndicatorManager.removeAnnotations();
5004 // fOverrideIndicatorManager= null;
5008 protected void installOverrideIndicator(boolean waitForReconcilation) {
5009 uninstallOverrideIndicator();
5010 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
5011 final IJavaElement inputElement = getInputJavaElement();
5013 if (model == null || inputElement == null)
5016 // fOverrideIndicatorManager= new OverrideIndicatorManager(model, inputElement, null);
5018 // if (provideAST) {
5019 // Job job= new Job(JavaEditorMessages.getString("OverrideIndicatorManager.intallJob")) { //$NON-NLS-1$
5021 // * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
5024 // protected IStatus run(IProgressMonitor monitor) {
5025 // CompilationUnit ast= JavaPlugin.getDefault().getASTProvider().getAST(inputElement, true, null);
5026 // if (fOverrideIndicatorManager != null) // editor might have been closed in the meanwhile
5027 // fOverrideIndicatorManager.reconciled(ast, true, monitor);
5028 // return Status.OK_STATUS;
5031 // job.setPriority(Job.DECORATE);
5032 // job.setSystem(true);
5038 * Tells whether override indicators are shown.
5040 * @return <code>true</code> if the override indicators are shown
5043 // protected boolean isShowingOverrideIndicators() {
5044 // AnnotationPreference preference=
5045 // getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
5046 // IPreferenceStore store= getPreferenceStore();
5047 // return getBoolean(store, preference.getHighlightPreferenceKey())
5048 // || getBoolean(store, preference.getVerticalRulerPreferenceKey())
5049 // || getBoolean(store, preference.getOverviewRulerPreferenceKey())
5050 // || getBoolean(store, preference.getTextPreferenceKey());
5053 * Returns the boolean preference for the given key.
5056 * the preference store
5058 * the preference key
5059 * @return <code>true</code> if the key exists in the store and its value is <code>true</code>
5062 private boolean getBoolean(IPreferenceStore store, String key) {
5063 return key != null && store.getBoolean(key);
5066 protected boolean isPrefQuickDiffAlwaysOn() {
5067 return false; // never show change ruler for the non-editable java editor. Overridden in subclasses like PHPUnitEditor
5071 * @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions()
5073 protected void createNavigationActions() {
5074 super.createNavigationActions();
5076 final StyledText textWidget = getSourceViewer().getTextWidget();
5078 IAction action = new SmartLineStartAction(textWidget, false);
5079 action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
5080 setAction(ITextEditorActionDefinitionIds.LINE_START, action);
5082 action = new SmartLineStartAction(textWidget, true);
5083 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
5084 setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);
5086 action = new NavigatePreviousSubWordAction();
5087 action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS);
5088 setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action);
5089 textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL);
5091 action = new NavigateNextSubWordAction();
5092 action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT);
5093 setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action);
5094 textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL);
5096 action = new SelectPreviousSubWordAction();
5097 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS);
5098 setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action);
5099 textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL);
5101 action = new SelectNextSubWordAction();
5102 action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT);
5103 setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action);
5104 textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL);
5108 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createCompositeRuler()
5110 protected CompositeRuler createCompositeRuler() {
5111 if (!getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
5112 return super.createCompositeRuler();
5114 CompositeRuler ruler = new CompositeRuler();
5115 AnnotationRulerColumn column = new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess());
5116 column.setHover(new JavaExpandHover(ruler, getAnnotationAccess(), new IDoubleClickListener() {
5118 public void doubleClick(DoubleClickEvent event) {
5119 // for now: just invoke ruler double click action
5120 triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK);
5123 private void triggerAction(String actionID) {
5124 IAction action = getAction(actionID);
5125 if (action != null) {
5126 if (action instanceof IUpdate)
5127 ((IUpdate) action).update();
5128 // hack to propagate line change
5129 if (action instanceof ISelectionListener) {
5130 ((ISelectionListener) action).selectionChanged(null, null);
5132 if (action.isEnabled())
5138 ruler.addDecorator(0, column);
5140 if (isLineNumberRulerVisible())
5141 ruler.addDecorator(1, createLineNumberRulerColumn());
5142 else if (isPrefQuickDiffAlwaysOn())
5143 ruler.addDecorator(1, createChangeRulerColumn());
5149 * Returns the folding action group, or <code>null</code> if there is none.
5151 * @return the folding action group, or <code>null</code> if there is none
5154 protected FoldingActionGroup getFoldingActionGroup() {
5155 return fFoldingGroup;
5159 * @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert()
5161 protected void performRevert() {
5162 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
5163 projectionViewer.setRedraw(false);
5166 boolean projectionMode = projectionViewer.isProjectionMode();
5167 if (projectionMode) {
5168 projectionViewer.disableProjection();
5169 if (fProjectionModelUpdater != null)
5170 fProjectionModelUpdater.uninstall();
5173 super.performRevert();
5175 if (projectionMode) {
5176 if (fProjectionModelUpdater != null)
5177 fProjectionModelUpdater.install(this, projectionViewer);
5178 projectionViewer.enableProjection();
5182 projectionViewer.setRedraw(true);
5187 * React to changed selection.
5191 protected void selectionChanged() {
5192 if (getSelectionProvider() == null)
5194 ISourceReference element = computeHighlightRangeSourceReference();
5195 if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
5196 synchronizeOutlinePage(element);
5197 setSelection(element, false);
5201 private boolean isJavaOutlinePageActive() {
5202 IWorkbenchPart part = getActivePart();
5203 return part instanceof ContentOutline && ((ContentOutline) part).getCurrentPage() == fOutlinePage;
5206 private IWorkbenchPart getActivePart() {
5207 IWorkbenchWindow window = getSite().getWorkbenchWindow();
5208 IPartService service = window.getPartService();
5209 IWorkbenchPart part = service.getActivePart();
5214 * Computes and returns the source reference that includes the caret and serves as provider for the outline page selection and the
5215 * editor range indication.
5217 * @return the computed source reference
5220 protected ISourceReference computeHighlightRangeSourceReference() {
5221 ISourceViewer sourceViewer = getSourceViewer();
5222 if (sourceViewer == null)
5225 StyledText styledText = sourceViewer.getTextWidget();
5226 if (styledText == null)
5230 if (sourceViewer instanceof ITextViewerExtension5) {
5231 ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
5232 caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
5234 int offset = sourceViewer.getVisibleRegion().getOffset();
5235 caret = offset + styledText.getCaretOffset();
5238 IJavaElement element = getElementAt(caret, false);
5240 if (!(element instanceof ISourceReference))
5243 if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) {
5245 IImportDeclaration declaration = (IImportDeclaration) element;
5246 IImportContainer container = (IImportContainer) declaration.getParent();
5247 ISourceRange srcRange = null;
5250 srcRange = container.getSourceRange();
5251 } catch (JavaModelException e) {
5254 if (srcRange != null && srcRange.getOffset() == caret)
5258 return (ISourceReference) element;
5262 * Returns the most narrow java element including the given offset.
5265 * the offset inside of the requested element
5267 * <code>true</code> if editor input should be reconciled in advance
5268 * @return the most narrow java element
5271 protected IJavaElement getElementAt(int offset, boolean reconcile) {
5272 return getElementAt(offset);