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
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.Iterator;
17 import java.util.List;
19 import java.util.ResourceBundle;
20 import java.util.StringTokenizer;
22 import net.sourceforge.phpdt.core.ICompilationUnit;
23 import net.sourceforge.phpdt.core.IImportContainer;
24 import net.sourceforge.phpdt.core.IImportDeclaration;
25 import net.sourceforge.phpdt.core.IJavaElement;
26 import net.sourceforge.phpdt.core.IJavaProject;
27 import net.sourceforge.phpdt.core.IMember;
28 import net.sourceforge.phpdt.core.ISourceRange;
29 import net.sourceforge.phpdt.core.ISourceReference;
30 import net.sourceforge.phpdt.core.JavaCore;
31 import net.sourceforge.phpdt.core.JavaModelException;
32 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
33 import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
34 import net.sourceforge.phpdt.internal.ui.text.CustomSourceInformationControl;
35 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
36 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
37 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
38 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
39 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
40 import net.sourceforge.phpdt.ui.IContextMenuConstants;
41 import net.sourceforge.phpdt.ui.JavaUI;
42 import net.sourceforge.phpdt.ui.PreferenceConstants;
43 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
44 import net.sourceforge.phpdt.ui.text.JavaTextTools;
45 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
46 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
47 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
49 import org.eclipse.core.resources.IMarker;
50 import org.eclipse.core.resources.IResource;
51 import org.eclipse.core.runtime.CoreException;
52 import org.eclipse.core.runtime.IProgressMonitor;
53 import org.eclipse.core.runtime.IStatus;
54 import org.eclipse.core.runtime.Preferences;
55 import org.eclipse.core.runtime.Status;
56 import org.eclipse.core.runtime.jobs.Job;
57 import org.eclipse.jface.action.Action;
58 import org.eclipse.jface.action.GroupMarker;
59 import org.eclipse.jface.action.IAction;
60 import org.eclipse.jface.action.MenuManager;
61 import org.eclipse.jface.action.Separator;
62 import org.eclipse.jface.preference.IPreferenceStore;
63 import org.eclipse.jface.preference.PreferenceConverter;
64 import org.eclipse.jface.text.BadLocationException;
65 import org.eclipse.jface.text.DefaultInformationControl;
66 import org.eclipse.jface.text.DocumentEvent;
67 import org.eclipse.jface.text.IDocument;
68 import org.eclipse.jface.text.IDocumentListener;
69 import org.eclipse.jface.text.IInformationControl;
70 import org.eclipse.jface.text.IInformationControlCreator;
71 import org.eclipse.jface.text.IRegion;
72 import org.eclipse.jface.text.ITextHover;
73 import org.eclipse.jface.text.ITextInputListener;
74 import org.eclipse.jface.text.ITextSelection;
75 import org.eclipse.jface.text.ITextViewer;
76 import org.eclipse.jface.text.ITextViewerExtension2;
77 import org.eclipse.jface.text.ITextViewerExtension3;
78 import org.eclipse.jface.text.ITextViewerExtension5;
79 import org.eclipse.jface.text.ITypedRegion;
80 import org.eclipse.jface.text.Position;
81 import org.eclipse.jface.text.Region;
82 import org.eclipse.jface.text.TextSelection;
83 import org.eclipse.jface.text.information.IInformationProvider;
84 import org.eclipse.jface.text.information.InformationPresenter;
85 import org.eclipse.jface.text.reconciler.IReconciler;
86 import org.eclipse.jface.text.source.Annotation;
87 import org.eclipse.jface.text.source.IAnnotationModel;
88 import org.eclipse.jface.text.source.IAnnotationModelExtension;
89 import org.eclipse.jface.text.source.IOverviewRuler;
90 import org.eclipse.jface.text.source.ISourceViewer;
91 import org.eclipse.jface.text.source.IVerticalRuler;
92 import org.eclipse.jface.text.source.OverviewRuler;
93 import org.eclipse.jface.text.source.SourceViewerConfiguration;
94 import org.eclipse.jface.text.source.projection.ProjectionSupport;
95 import org.eclipse.jface.text.source.projection.ProjectionViewer;
96 import org.eclipse.jface.util.IPropertyChangeListener;
97 import org.eclipse.jface.util.ListenerList;
98 import org.eclipse.jface.util.PropertyChangeEvent;
99 import org.eclipse.jface.viewers.IPostSelectionProvider;
100 import org.eclipse.jface.viewers.ISelection;
101 import org.eclipse.jface.viewers.ISelectionChangedListener;
102 import org.eclipse.jface.viewers.ISelectionProvider;
103 import org.eclipse.jface.viewers.IStructuredSelection;
104 import org.eclipse.jface.viewers.SelectionChangedEvent;
105 import org.eclipse.jface.viewers.StructuredSelection;
106 import org.eclipse.swt.SWT;
107 import org.eclipse.swt.custom.BidiSegmentEvent;
108 import org.eclipse.swt.custom.BidiSegmentListener;
109 import org.eclipse.swt.custom.StyleRange;
110 import org.eclipse.swt.custom.StyledText;
111 import org.eclipse.swt.events.FocusEvent;
112 import org.eclipse.swt.events.FocusListener;
113 import org.eclipse.swt.events.KeyEvent;
114 import org.eclipse.swt.events.KeyListener;
115 import org.eclipse.swt.events.MouseEvent;
116 import org.eclipse.swt.events.MouseListener;
117 import org.eclipse.swt.events.MouseMoveListener;
118 import org.eclipse.swt.events.PaintEvent;
119 import org.eclipse.swt.events.PaintListener;
120 import org.eclipse.swt.graphics.Color;
121 import org.eclipse.swt.graphics.Cursor;
122 import org.eclipse.swt.graphics.GC;
123 import org.eclipse.swt.graphics.Image;
124 import org.eclipse.swt.graphics.Point;
125 import org.eclipse.swt.graphics.RGB;
126 import org.eclipse.swt.widgets.Composite;
127 import org.eclipse.swt.widgets.Control;
128 import org.eclipse.swt.widgets.Display;
129 import org.eclipse.swt.widgets.Shell;
130 import org.eclipse.ui.IEditorInput;
131 import org.eclipse.ui.IPageLayout;
132 import org.eclipse.ui.IPartService;
133 import org.eclipse.ui.IViewPart;
134 import org.eclipse.ui.IWorkbenchPage;
135 import org.eclipse.ui.IWorkbenchPart;
136 import org.eclipse.ui.IWorkbenchWindow;
137 import org.eclipse.ui.actions.ActionContext;
138 import org.eclipse.ui.actions.ActionGroup;
139 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
140 import org.eclipse.ui.editors.text.EditorsUI;
141 import org.eclipse.ui.editors.text.IEncodingSupport;
142 import org.eclipse.ui.part.IShowInTargetList;
143 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
144 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
145 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
146 import org.eclipse.ui.texteditor.IDocumentProvider;
147 import org.eclipse.ui.texteditor.IEditorStatusLine;
148 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
149 import org.eclipse.ui.texteditor.MarkerAnnotation;
150 import org.eclipse.ui.texteditor.ResourceAction;
151 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
152 import org.eclipse.ui.texteditor.TextEditorAction;
153 import org.eclipse.ui.texteditor.TextOperationAction;
154 import org.eclipse.ui.views.contentoutline.ContentOutline;
155 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
156 import org.eclipse.ui.views.tasklist.TaskList;
159 * PHP specific text editor.
161 public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider {
162 //extends StatusTextEditor implements IViewPartInputProvider { // extends
166 * Internal implementation class for a change listener.
170 protected abstract class AbstractSelectionChangedListener implements ISelectionChangedListener {
173 * Installs this selection changed listener with the given selection provider. If the selection provider is a post selection
174 * provider, post selection changed events are the preferred choice, otherwise normal selection changed events are requested.
176 * @param selectionProvider
178 public void install(ISelectionProvider selectionProvider) {
179 if (selectionProvider == null)
182 if (selectionProvider instanceof IPostSelectionProvider) {
183 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
184 provider.addPostSelectionChangedListener(this);
186 selectionProvider.addSelectionChangedListener(this);
191 * Removes this selection changed listener from the given selection provider.
193 * @param selectionProvider
194 * the selection provider
196 public void uninstall(ISelectionProvider selectionProvider) {
197 if (selectionProvider == null)
200 if (selectionProvider instanceof IPostSelectionProvider) {
201 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
202 provider.removePostSelectionChangedListener(this);
204 selectionProvider.removeSelectionChangedListener(this);
210 * Updates the Java outline page selection and this editor's range indicator.
214 private class EditorSelectionChangedListener extends AbstractSelectionChangedListener {
217 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
219 public void selectionChanged(SelectionChangedEvent event) {
220 // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161
221 PHPEditor.this.selectionChanged();
226 * "Smart" runnable for updating the outline page's selection.
228 class OutlinePageSelectionUpdater implements Runnable {
230 /** Has the runnable already been posted? */
231 private boolean fPosted = false;
233 public OutlinePageSelectionUpdater() {
237 * @see Runnable#run()
240 synchronizeOutlinePageSelection();
245 * Posts this runnable into the event queue.
251 Shell shell = getSite().getShell();
252 if (shell != null & !shell.isDisposed()) {
254 shell.getDisplay().asyncExec(this);
259 class SelectionChangedListener implements ISelectionChangedListener {
260 public void selectionChanged(SelectionChangedEvent event) {
261 doSelectionChanged(event);
266 * Adapts an options {@link java.util.Map}to {@link org.eclipse.jface.preference.IPreferenceStore}.
268 * This preference store is read-only i.e. write access throws an {@link java.lang.UnsupportedOperationException}.
273 private static class OptionsAdapter implements IPreferenceStore {
276 * A property change event filter.
278 public interface IPropertyChangeEventFilter {
281 * Should the given event be filtered?
284 * The property change event.
285 * @return <code>true</code> iff the given event should be filtered.
287 public boolean isFiltered(PropertyChangeEvent event);
292 * Property change listener. Listens for events in the options Map and fires a
293 * {@link org.eclipse.jface.util.PropertyChangeEvent}on this adapter with arguments from the received event.
295 private class PropertyChangeListener implements IPropertyChangeListener {
300 public void propertyChange(PropertyChangeEvent event) {
301 if (getFilter().isFiltered(event))
304 if (event.getNewValue() == null)
305 fOptions.remove(event.getProperty());
307 fOptions.put(event.getProperty(), event.getNewValue());
309 firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
313 /** Listeners on this adapter */
314 private ListenerList fListeners = new ListenerList();
316 /** Listener on the adapted options Map */
317 private IPropertyChangeListener fListener = new PropertyChangeListener();
319 /** Adapted options Map */
320 private Map fOptions;
322 /** Preference store through which events are received. */
323 private IPreferenceStore fMockupPreferenceStore;
325 /** Property event filter. */
326 private IPropertyChangeEventFilter fFilter;
329 * Initialize with the given options.
332 * The options to wrap
333 * @param mockupPreferenceStore
334 * the mock-up preference store
336 * the property change filter
338 public OptionsAdapter(Map options, IPreferenceStore mockupPreferenceStore, IPropertyChangeEventFilter filter) {
339 fMockupPreferenceStore = mockupPreferenceStore;
347 public void addPropertyChangeListener(IPropertyChangeListener listener) {
348 if (fListeners.size() == 0)
349 fMockupPreferenceStore.addPropertyChangeListener(fListener);
350 fListeners.add(listener);
356 public void removePropertyChangeListener(IPropertyChangeListener listener) {
357 fListeners.remove(listener);
358 if (fListeners.size() == 0)
359 fMockupPreferenceStore.removePropertyChangeListener(fListener);
365 public boolean contains(String name) {
366 return fOptions.containsKey(name);
372 public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
373 PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
374 Object[] listeners = fListeners.getListeners();
375 for (int i = 0; i < listeners.length; i++)
376 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
382 public boolean getBoolean(String name) {
383 boolean value = BOOLEAN_DEFAULT_DEFAULT;
384 String s = (String) fOptions.get(name);
386 value = s.equals(TRUE);
393 public boolean getDefaultBoolean(String name) {
394 return BOOLEAN_DEFAULT_DEFAULT;
400 public double getDefaultDouble(String name) {
401 return DOUBLE_DEFAULT_DEFAULT;
407 public float getDefaultFloat(String name) {
408 return FLOAT_DEFAULT_DEFAULT;
414 public int getDefaultInt(String name) {
415 return INT_DEFAULT_DEFAULT;
421 public long getDefaultLong(String name) {
422 return LONG_DEFAULT_DEFAULT;
428 public String getDefaultString(String name) {
429 return STRING_DEFAULT_DEFAULT;
435 public double getDouble(String name) {
436 double value = DOUBLE_DEFAULT_DEFAULT;
437 String s = (String) fOptions.get(name);
440 value = new Double(s).doubleValue();
441 } catch (NumberFormatException e) {
450 public float getFloat(String name) {
451 float value = FLOAT_DEFAULT_DEFAULT;
452 String s = (String) fOptions.get(name);
455 value = new Float(s).floatValue();
456 } catch (NumberFormatException e) {
465 public int getInt(String name) {
466 int value = INT_DEFAULT_DEFAULT;
467 String s = (String) fOptions.get(name);
470 value = new Integer(s).intValue();
471 } catch (NumberFormatException e) {
480 public long getLong(String name) {
481 long value = LONG_DEFAULT_DEFAULT;
482 String s = (String) fOptions.get(name);
485 value = new Long(s).longValue();
486 } catch (NumberFormatException e) {
495 public String getString(String name) {
496 String value = (String) fOptions.get(name);
498 value = STRING_DEFAULT_DEFAULT;
505 public boolean isDefault(String name) {
512 public boolean needsSaving() {
513 return !fOptions.isEmpty();
519 public void putValue(String name, String value) {
520 throw new UnsupportedOperationException();
526 public void setDefault(String name, double value) {
527 throw new UnsupportedOperationException();
533 public void setDefault(String name, float value) {
534 throw new UnsupportedOperationException();
540 public void setDefault(String name, int value) {
541 throw new UnsupportedOperationException();
547 public void setDefault(String name, long value) {
548 throw new UnsupportedOperationException();
554 public void setDefault(String name, String defaultObject) {
555 throw new UnsupportedOperationException();
561 public void setDefault(String name, boolean value) {
562 throw new UnsupportedOperationException();
568 public void setToDefault(String name) {
569 throw new UnsupportedOperationException();
575 public void setValue(String name, double value) {
576 throw new UnsupportedOperationException();
582 public void setValue(String name, float value) {
583 throw new UnsupportedOperationException();
589 public void setValue(String name, int value) {
590 throw new UnsupportedOperationException();
596 public void setValue(String name, long value) {
597 throw new UnsupportedOperationException();
603 public void setValue(String name, String value) {
604 throw new UnsupportedOperationException();
610 public void setValue(String name, boolean value) {
611 throw new UnsupportedOperationException();
615 * Returns the adapted options Map.
617 * @return Returns the adapted options Map.
619 public Map getOptions() {
624 * Returns the mock-up preference store, events are received through this preference store.
626 * @return Returns the mock-up preference store.
628 public IPreferenceStore getMockupPreferenceStore() {
629 return fMockupPreferenceStore;
633 * Set the event filter to the given filter.
638 public void setFilter(IPropertyChangeEventFilter filter) {
643 * Returns the event filter.
645 * @return The event filter.
647 public IPropertyChangeEventFilter getFilter() {
655 class MouseClickListener implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener,
656 IPropertyChangeListener, IDocumentListener, ITextInputListener {
658 /** The session is active. */
659 private boolean fActive;
661 /** The currently active style range. */
662 private IRegion fActiveRegion;
664 /** The currently active style range as position. */
665 private Position fRememberedPosition;
667 /** The hand cursor. */
668 private Cursor fCursor;
670 /** The link color. */
671 private Color fColor;
673 /** The key modifier mask. */
674 private int fKeyModifierMask;
676 public void deactivate() {
680 public void deactivate(boolean redrawAll) {
684 repairRepresentation(redrawAll);
688 public void install() {
690 ISourceViewer sourceViewer = getSourceViewer();
691 if (sourceViewer == null)
694 StyledText text = sourceViewer.getTextWidget();
695 if (text == null || text.isDisposed())
698 updateColor(sourceViewer);
700 sourceViewer.addTextInputListener(this);
702 IDocument document = sourceViewer.getDocument();
703 if (document != null)
704 document.addDocumentListener(this);
706 text.addKeyListener(this);
707 text.addMouseListener(this);
708 text.addMouseMoveListener(this);
709 text.addFocusListener(this);
710 text.addPaintListener(this);
712 updateKeyModifierMask();
714 IPreferenceStore preferenceStore = getPreferenceStore();
715 preferenceStore.addPropertyChangeListener(this);
718 private void updateKeyModifierMask() {
719 String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
720 fKeyModifierMask = computeStateMask(modifiers);
721 if (fKeyModifierMask == -1) {
722 // Fallback to stored state mask
723 fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
728 private int computeStateMask(String modifiers) {
729 if (modifiers == null)
732 if (modifiers.length() == 0)
736 StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
737 while (modifierTokenizer.hasMoreTokens()) {
738 int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
739 if (modifier == 0 || (stateMask & modifier) == modifier)
741 stateMask = stateMask | modifier;
746 public void uninstall() {
748 if (fColor != null) {
753 if (fCursor != null) {
758 ISourceViewer sourceViewer = getSourceViewer();
759 if (sourceViewer == null)
762 sourceViewer.removeTextInputListener(this);
764 IDocument document = sourceViewer.getDocument();
765 if (document != null)
766 document.removeDocumentListener(this);
768 IPreferenceStore preferenceStore = getPreferenceStore();
769 if (preferenceStore != null)
770 preferenceStore.removePropertyChangeListener(this);
772 StyledText text = sourceViewer.getTextWidget();
773 if (text == null || text.isDisposed())
776 text.removeKeyListener(this);
777 text.removeMouseListener(this);
778 text.removeMouseMoveListener(this);
779 text.removeFocusListener(this);
780 text.removePaintListener(this);
784 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
786 public void propertyChange(PropertyChangeEvent event) {
787 if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
788 ISourceViewer viewer = getSourceViewer();
791 } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
792 updateKeyModifierMask();
796 private void updateColor(ISourceViewer viewer) {
800 StyledText text = viewer.getTextWidget();
801 if (text == null || text.isDisposed())
804 Display display = text.getDisplay();
805 fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
809 * Creates a color from the information stored in the given preference store. Returns <code>null</code> if there is no such
810 * information available.
812 private Color createColor(IPreferenceStore store, String key, Display display) {
816 if (store.contains(key)) {
818 if (store.isDefault(key))
819 rgb = PreferenceConverter.getDefaultColor(store, key);
821 rgb = PreferenceConverter.getColor(store, key);
824 return new Color(display, rgb);
830 private void repairRepresentation() {
831 repairRepresentation(false);
834 private void repairRepresentation(boolean redrawAll) {
836 if (fActiveRegion == null)
839 ISourceViewer viewer = getSourceViewer();
840 if (viewer != null) {
843 int offset = fActiveRegion.getOffset();
844 int length = fActiveRegion.getLength();
847 if (!redrawAll && viewer instanceof ITextViewerExtension2)
848 ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
850 viewer.invalidateTextPresentation();
853 if (viewer instanceof ITextViewerExtension3) {
854 ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
855 offset = extension.modelOffset2WidgetOffset(offset);
857 offset -= viewer.getVisibleRegion().getOffset();
860 StyledText text = viewer.getTextWidget();
862 text.redrawRange(offset, length, true);
863 } catch (IllegalArgumentException x) {
864 PHPeclipsePlugin.log(x);
868 fActiveRegion = null;
871 // will eventually be replaced by a method provided by jdt.core
872 private IRegion selectWord(IDocument document, int anchor) {
878 while (offset >= 0) {
879 c = document.getChar(offset);
880 if (!Character.isJavaIdentifierPart(c))
888 int length = document.getLength();
890 while (offset < length) {
891 c = document.getChar(offset);
892 if (!Character.isJavaIdentifierPart(c))
900 return new Region(start, 0);
902 return new Region(start + 1, end - start - 1);
904 } catch (BadLocationException x) {
909 IRegion getCurrentTextRegion(ISourceViewer viewer) {
911 int offset = getCurrentTextOffset(viewer);
916 // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
917 // if (input == null)
922 // IJavaElement[] elements= null;
923 // synchronized (input) {
924 // elements= ((ICodeAssist) input).codeSelect(offset, 0);
927 // if (elements == null || elements.length == 0)
930 // return selectWord(viewer.getDocument(), offset);
932 // } catch (JavaModelException e) {
937 private int getCurrentTextOffset(ISourceViewer viewer) {
940 StyledText text = viewer.getTextWidget();
941 if (text == null || text.isDisposed())
944 Display display = text.getDisplay();
945 Point absolutePosition = display.getCursorLocation();
946 Point relativePosition = text.toControl(absolutePosition);
948 int widgetOffset = text.getOffsetAtLocation(relativePosition);
949 if (viewer instanceof ITextViewerExtension3) {
950 ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
951 return extension.widgetOffset2ModelOffset(widgetOffset);
953 return widgetOffset + viewer.getVisibleRegion().getOffset();
956 } catch (IllegalArgumentException e) {
961 private void highlightRegion(ISourceViewer viewer, IRegion region) {
963 if (region.equals(fActiveRegion))
966 repairRepresentation();
968 StyledText text = viewer.getTextWidget();
969 if (text == null || text.isDisposed())
976 if (viewer instanceof ITextViewerExtension3) {
977 ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
978 IRegion widgetRange = extension.modelRange2WidgetRange(region);
979 if (widgetRange == null)
982 offset = widgetRange.getOffset();
983 length = widgetRange.getLength();
986 offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
987 length = region.getLength();
990 StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
991 Color foregroundColor = fColor;
992 Color backgroundColor = oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
993 StyleRange styleRange = new StyleRange(offset, length, foregroundColor, backgroundColor);
994 text.setStyleRange(styleRange);
997 text.redrawRange(offset, length, true);
999 fActiveRegion = region;
1002 private void activateCursor(ISourceViewer viewer) {
1003 StyledText text = viewer.getTextWidget();
1004 if (text == null || text.isDisposed())
1006 Display display = text.getDisplay();
1007 if (fCursor == null)
1008 fCursor = new Cursor(display, SWT.CURSOR_HAND);
1009 text.setCursor(fCursor);
1012 private void resetCursor(ISourceViewer viewer) {
1013 StyledText text = viewer.getTextWidget();
1014 if (text != null && !text.isDisposed())
1015 text.setCursor(null);
1017 if (fCursor != null) {
1024 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1026 public void keyPressed(KeyEvent event) {
1033 if (event.keyCode != fKeyModifierMask) {
1040 // removed for #25871
1042 // ISourceViewer viewer= getSourceViewer();
1043 // if (viewer == null)
1046 // IRegion region= getCurrentTextRegion(viewer);
1047 // if (region == null)
1050 // highlightRegion(viewer, region);
1051 // activateCursor(viewer);
1055 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1057 public void keyReleased(KeyEvent event) {
1066 * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1068 public void mouseDoubleClick(MouseEvent e) {
1072 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1074 public void mouseDown(MouseEvent event) {
1079 if (event.stateMask != fKeyModifierMask) {
1084 if (event.button != 1) {
1091 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1093 public void mouseUp(MouseEvent e) {
1098 if (e.button != 1) {
1103 boolean wasActive = fCursor != null;
1108 IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1115 * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1117 public void mouseMove(MouseEvent event) {
1119 if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
1125 if (event.stateMask != fKeyModifierMask)
1127 // modifier was already pressed
1131 ISourceViewer viewer = getSourceViewer();
1132 if (viewer == null) {
1137 StyledText text = viewer.getTextWidget();
1138 if (text == null || text.isDisposed()) {
1143 if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
1148 IRegion region = getCurrentTextRegion(viewer);
1149 if (region == null || region.getLength() == 0) {
1150 repairRepresentation();
1154 highlightRegion(viewer, region);
1155 activateCursor(viewer);
1159 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1161 public void focusGained(FocusEvent e) {
1165 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1167 public void focusLost(FocusEvent event) {
1172 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1174 public void documentAboutToBeChanged(DocumentEvent event) {
1175 if (fActive && fActiveRegion != null) {
1176 fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
1178 event.getDocument().addPosition(fRememberedPosition);
1179 } catch (BadLocationException x) {
1180 fRememberedPosition = null;
1186 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1188 public void documentChanged(DocumentEvent event) {
1189 if (fRememberedPosition != null && !fRememberedPosition.isDeleted()) {
1190 event.getDocument().removePosition(fRememberedPosition);
1191 fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
1193 fRememberedPosition = null;
1195 ISourceViewer viewer = getSourceViewer();
1196 if (viewer != null) {
1197 StyledText widget = viewer.getTextWidget();
1198 if (widget != null && !widget.isDisposed()) {
1199 widget.getDisplay().asyncExec(new Runnable() {
1209 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
1210 * org.eclipse.jface.text.IDocument)
1212 public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
1213 if (oldInput == null)
1216 oldInput.removeDocumentListener(this);
1220 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
1221 * org.eclipse.jface.text.IDocument)
1223 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
1224 if (newInput == null)
1226 newInput.addDocumentListener(this);
1230 * @see PaintListener#paintControl(PaintEvent)
1232 public void paintControl(PaintEvent event) {
1233 if (fActiveRegion == null)
1236 ISourceViewer viewer = getSourceViewer();
1240 StyledText text = viewer.getTextWidget();
1241 if (text == null || text.isDisposed())
1247 if (viewer instanceof ITextViewerExtension3) {
1249 ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1250 IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
1251 if (widgetRange == null)
1254 offset = widgetRange.getOffset();
1255 length = widgetRange.getLength();
1259 IRegion region = viewer.getVisibleRegion();
1260 if (!includes(region, fActiveRegion))
1263 offset = fActiveRegion.getOffset() - region.getOffset();
1264 length = fActiveRegion.getLength();
1268 Point minLocation = getMinimumLocation(text, offset, length);
1269 Point maxLocation = getMaximumLocation(text, offset, length);
1271 int x1 = minLocation.x;
1272 int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
1273 int y = minLocation.y + text.getLineHeight() - 1;
1276 if (fColor != null && !fColor.isDisposed())
1277 gc.setForeground(fColor);
1278 gc.drawLine(x1, y, x2, y);
1281 private boolean includes(IRegion region, IRegion position) {
1282 return position.getOffset() >= region.getOffset()
1283 && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
1286 private Point getMinimumLocation(StyledText text, int offset, int length) {
1287 Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
1289 for (int i = 0; i <= length; i++) {
1290 Point location = text.getLocationAtOffset(offset + i);
1292 if (location.x < minLocation.x)
1293 minLocation.x = location.x;
1294 if (location.y < minLocation.y)
1295 minLocation.y = location.y;
1301 private Point getMaximumLocation(StyledText text, int offset, int length) {
1302 Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
1304 for (int i = 0; i <= length; i++) {
1305 Point location = text.getLocationAtOffset(offset + i);
1307 if (location.x > maxLocation.x)
1308 maxLocation.x = location.x;
1309 if (location.y > maxLocation.y)
1310 maxLocation.y = location.y;
1318 * This action dispatches into two behaviours: If there is no current text hover, the javadoc is displayed using information
1319 * presenter. If there is a current text hover, it is converted into a information presenter in order to make it sticky.
1321 class InformationDispatchAction extends TextEditorAction {
1323 /** The wrapped text operation action. */
1324 private final TextOperationAction fTextOperationAction;
1327 * Creates a dispatch action.
1329 public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
1330 super(resourceBundle, prefix, PHPEditor.this);
1331 if (textOperationAction == null)
1332 throw new IllegalArgumentException();
1333 fTextOperationAction = textOperationAction;
1337 * @see org.eclipse.jface.action.IAction#run()
1341 ISourceViewer sourceViewer = getSourceViewer();
1342 if (sourceViewer == null) {
1343 fTextOperationAction.run();
1347 if (!(sourceViewer instanceof ITextViewerExtension2)) {
1348 fTextOperationAction.run();
1352 ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
1354 // does a text hover exist?
1355 ITextHover textHover = textViewerExtension2.getCurrentTextHover();
1356 if (textHover == null) {
1357 fTextOperationAction.run();
1361 Point hoverEventLocation = textViewerExtension2.getHoverEventLocation();
1362 int offset = computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
1364 fTextOperationAction.run();
1369 // get the text hover content
1370 IDocument document = sourceViewer.getDocument();
1371 String contentType = document.getContentType(offset);
1373 final IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
1374 if (hoverRegion == null)
1377 final String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);
1379 // with information provider
1380 IInformationProvider informationProvider = new IInformationProvider() {
1382 * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
1384 public IRegion getSubject(ITextViewer textViewer, int offset) {
1389 * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer,
1390 * org.eclipse.jface.text.IRegion)
1392 public String getInformation(ITextViewer textViewer, IRegion subject) {
1397 fInformationPresenter.setOffset(offset);
1398 fInformationPresenter.setInformationProvider(informationProvider, contentType);
1399 fInformationPresenter.showInformation();
1401 } catch (BadLocationException e) {
1405 // modified version from TextViewer
1406 private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
1408 StyledText styledText = textViewer.getTextWidget();
1409 IDocument document = textViewer.getDocument();
1411 if (document == null)
1415 int widgetLocation = styledText.getOffsetAtLocation(new Point(x, y));
1416 if (textViewer instanceof ITextViewerExtension3) {
1417 ITextViewerExtension3 extension = (ITextViewerExtension3) textViewer;
1418 return extension.widgetOffset2ModelOffset(widgetLocation);
1420 IRegion visibleRegion = textViewer.getVisibleRegion();
1421 return widgetLocation + visibleRegion.getOffset();
1423 } catch (IllegalArgumentException e) {
1430 // static protected class AnnotationAccess implements IAnnotationAccess {
1433 // org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
1435 // public Object getType(Annotation annotation) {
1436 // if (annotation instanceof IJavaAnnotation) {
1437 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
1438 // // if (javaAnnotation.isRelevant())
1439 // // return javaAnnotation.getAnnotationType();
1446 // org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
1448 // public boolean isMultiLine(Annotation annotation) {
1454 // org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
1456 // public boolean isTemporary(Annotation annotation) {
1457 // if (annotation instanceof IJavaAnnotation) {
1458 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
1459 // if (javaAnnotation.isRelevant())
1460 // return javaAnnotation.isTemporary();
1466 private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
1468 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
1470 public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1471 handlePreferencePropertyChanged(event);
1476 * Finds and marks occurrence annotations.
1480 class OccurrencesFinderJob extends Job implements IDocumentListener {
1482 private IDocument fDocument;
1484 private boolean fCancelled = false;
1486 private IProgressMonitor fProgressMonitor;
1488 private Position[] fPositions;
1490 public OccurrencesFinderJob(IDocument document, Position[] positions) {
1491 super("Occurrences Marker"); //$NON-NLS-1$
1492 fDocument = document;
1493 fPositions = positions;
1494 fDocument.addDocumentListener(this);
1497 private boolean isCancelled() {
1498 return fCancelled || fProgressMonitor.isCanceled();
1502 * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
1504 public IStatus run(IProgressMonitor progressMonitor) {
1506 fProgressMonitor = progressMonitor;
1511 return Status.CANCEL_STATUS;
1513 ITextViewer textViewer = getViewer();
1514 if (textViewer == null)
1515 return Status.CANCEL_STATUS;
1517 IDocument document = textViewer.getDocument();
1518 if (document == null)
1519 return Status.CANCEL_STATUS;
1521 IDocumentProvider documentProvider = getDocumentProvider();
1522 if (documentProvider == null)
1523 return Status.CANCEL_STATUS;
1525 IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
1526 if (annotationModel == null)
1527 return Status.CANCEL_STATUS;
1529 // Add occurrence annotations
1530 int length = fPositions.length;
1531 Map annotationMap = new HashMap(length);
1532 for (int i = 0; i < length; i++) {
1535 return Status.CANCEL_STATUS;
1538 Position position = fPositions[i];
1540 // Create & add annotation
1542 message = document.get(position.offset, position.length);
1543 } catch (BadLocationException ex) {
1547 annotationMap.put(new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
1552 return Status.CANCEL_STATUS;
1554 synchronized (annotationModel) {
1555 if (annotationModel instanceof IAnnotationModelExtension) {
1556 ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
1558 removeOccurrenceAnnotations();
1559 Iterator iter = annotationMap.entrySet().iterator();
1560 while (iter.hasNext()) {
1561 Map.Entry mapEntry = (Map.Entry) iter.next();
1562 annotationModel.addAnnotation((Annotation) mapEntry.getKey(), (Position) mapEntry.getValue());
1565 fOccurrenceAnnotations = (Annotation[]) annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
1568 fDocument.removeDocumentListener(this);
1570 return Status.OK_STATUS;
1574 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1576 public void documentAboutToBeChanged(DocumentEvent event) {
1581 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1583 public void documentChanged(DocumentEvent event) {
1588 * Updates the selection in the editor's widget with the selection of the outline page.
1590 class OutlineSelectionChangedListener extends AbstractSelectionChangedListener {
1591 public void selectionChanged(SelectionChangedEvent event) {
1592 doSelectionChanged(event);
1597 * Holds the current occurrence annotations.
1601 private Annotation[] fOccurrenceAnnotations = null;
1603 private Job fOccurrencesFinderJob;
1605 /** Preference key for showing the line number ruler */
1606 // private final static String LINE_NUMBER_RULER =
1607 // PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
1608 /** Preference key for the foreground color of the line numbers */
1609 // private final static String LINE_NUMBER_COLOR =
1610 // PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
1611 /** Preference key for the link color */
1612 private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
1614 /** Preference key for compiler task tags */
1615 private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
1617 // protected PHPActionGroup fActionGroups;
1618 // /** The outline page */
1619 // private AbstractContentOutlinePage fOutlinePage;
1620 /** The outline page */
1621 protected JavaOutlinePage fOutlinePage;
1623 /** Outliner context menu Id */
1624 protected String fOutlinerContextMenuId;
1627 * The editor selection changed listener.
1631 // private EditorSelectionChangedListener fEditorSelectionChangedListener;
1633 * Indicates whether this editor should react on outline page selection changes
1635 private int fIgnoreOutlinePageSelection;
1637 /** The outline page selection updater */
1638 private OutlinePageSelectionUpdater fUpdater;
1640 // protected PHPSyntaxParserThread fValidationThread = null;
1642 // private IPreferenceStore fPHPPrefStore;
1643 /** The selection changed listener */
1644 // protected ISelectionChangedListener fSelectionChangedListener = new
1645 // SelectionChangedListener();
1647 * The editor selection changed listener.
1651 private EditorSelectionChangedListener fEditorSelectionChangedListener;
1653 /** The selection changed listener */
1654 protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener();
1656 /** The editor's bracket matcher */
1657 private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS);
1659 /** The line number ruler column */
1660 // private LineNumberRulerColumn fLineNumberRulerColumn;
1661 /** This editor's encoding support */
1662 private DefaultEncodingSupport fEncodingSupport;
1664 /** The mouse listener */
1665 private MouseClickListener fMouseListener;
1667 protected CompositeActionGroup fActionGroups;
1669 protected CompositeActionGroup fContextMenuGroup;
1672 * This editor's projection support
1676 private ProjectionSupport fProjectionSupport;
1679 * This editor's projection model updater
1683 private IJavaFoldingStructureProvider fProjectionModelUpdater;
1686 * The action group for folding.
1690 private FoldingActionGroup fFoldingGroup;
1692 /** The information presenter. */
1693 private InformationPresenter fInformationPresenter;
1695 /** The annotation access */
1696 // protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
1697 /** The overview ruler */
1698 protected OverviewRuler isOverviewRulerVisible;
1700 /** The source viewer decoration support */
1701 //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
1702 /** The overview ruler */
1703 //protected OverviewRuler fOverviewRuler;
1704 /** The preference property change listener for java core. */
1705 private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
1708 * Returns the most narrow java element including the given offset
1711 * the offset inside of the requested element
1713 abstract protected IJavaElement getElementAt(int offset);
1716 * Returns the java element of this editor's input corresponding to the given IJavaElement
1718 abstract protected IJavaElement getCorrespondingElement(IJavaElement element);
1721 * Sets the input of the editor's outline page.
1723 abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input);
1726 * Default constructor.
1728 public PHPEditor() {
1733 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
1735 protected void initializeKeyBindingScopes() {
1736 setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
1740 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
1742 protected void initializeEditor() {
1744 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1745 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this, IPHPPartitions.PHP_PARTITIONING)); //, IJavaPartitions.JAVA_PARTITIONING));
1746 setRangeIndicator(new DefaultRangeIndicator());
1747 // IPreferenceStore store=
1748 // PHPeclipsePlugin.getDefault().getPreferenceStore();
1749 // setPreferenceStore(store);
1750 IPreferenceStore store = createCombinedPreferenceStore(null);
1751 setPreferenceStore(store);
1753 // TODO changed in 3.x ?
1754 if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
1755 fUpdater = new OutlinePageSelectionUpdater();
1758 // IPreferenceStore store= createCombinedPreferenceStore(null);
1759 // setPreferenceStore(store);
1760 // JavaTextTools textTools=
1761 // PHPeclipsePlugin.getDefault().getJavaTextTools();
1762 // setSourceViewerConfiguration(new
1763 // JavaSourceViewerConfiguration(textTools.getColorManager(), store,
1764 // this, IJavaPartitions.JAVA_PARTITIONING));
1765 // fMarkOccurrenceAnnotations=
1766 // store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
1767 // fStickyOccurrenceAnnotations=
1768 // store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
1769 // fMarkTypeOccurrences=
1770 // store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
1771 // fMarkMethodOccurrences=
1772 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
1773 // fMarkConstantOccurrences=
1774 // store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
1775 // fMarkFieldOccurrences=
1776 // store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
1777 // fMarkLocalVariableypeOccurrences=
1778 // store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
1779 // fMarkExceptionOccurrences=
1780 // store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
1781 // fMarkMethodExitPoints=
1782 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
1786 * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
1788 protected void updatePropertyDependentActions() {
1789 super.updatePropertyDependentActions();
1790 if (fEncodingSupport != null)
1791 fEncodingSupport.reset();
1795 * Update the hovering behavior depending on the preferences.
1797 private void updateHoverBehavior() {
1798 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
1799 String[] types = configuration.getConfiguredContentTypes(getSourceViewer());
1801 for (int i = 0; i < types.length; i++) {
1803 String t = types[i];
1805 int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
1807 ISourceViewer sourceViewer = getSourceViewer();
1808 if (sourceViewer instanceof ITextViewerExtension2) {
1809 if (stateMasks != null) {
1810 for (int j = 0; j < stateMasks.length; j++) {
1811 int stateMask = stateMasks[j];
1812 ITextHover textHover = configuration.getTextHover(sourceViewer, t, stateMask);
1813 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, stateMask);
1816 ITextHover textHover = configuration.getTextHover(sourceViewer, t);
1817 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
1820 sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t);
1824 public void updatedTitleImage(Image image) {
1825 setTitleImage(image);
1829 * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
1831 public Object getViewPartInput() {
1832 return getEditorInput().getAdapter(IResource.class);
1836 * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
1838 protected void doSetSelection(ISelection selection) {
1839 super.doSetSelection(selection);
1840 synchronizeOutlinePageSelection();
1843 boolean isFoldingEnabled() {
1844 return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
1848 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt. widgets.Composite)
1850 public void createPartControl(Composite parent) {
1851 super.createPartControl(parent);
1853 //fSourceViewerDecorationSupport.install(getPreferenceStore());
1855 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
1857 fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
1858 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
1859 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
1860 fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() {
1861 public IInformationControl createInformationControl(Shell shell) {
1862 return new CustomSourceInformationControl(shell, IDocument.DEFAULT_CONTENT_TYPE);
1865 fProjectionSupport.install();
1867 fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
1868 if (fProjectionModelUpdater != null)
1869 fProjectionModelUpdater.install(this, projectionViewer);
1871 if (isFoldingEnabled())
1872 projectionViewer.doOperation(ProjectionViewer.TOGGLE);
1873 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
1874 preferences.addPropertyChangeListener(fPropertyChangeListener);
1876 IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
1877 public IInformationControl createInformationControl(Shell parent) {
1878 boolean cutDown = false;
1879 int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
1880 return new DefaultInformationControl(parent, SWT.RESIZE, style, new HTMLTextPresenter(cutDown));
1884 fInformationPresenter = new InformationPresenter(informationControlCreator);
1885 fInformationPresenter.setSizeConstraints(60, 10, true, true);
1886 fInformationPresenter.install(getSourceViewer());
1888 fEditorSelectionChangedListener = new EditorSelectionChangedListener();
1889 fEditorSelectionChangedListener.install(getSelectionProvider());
1891 if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE))
1892 enableOverwriteMode(false);
1894 // getEditorSite().getShell().addShellListener(fActivationListener);
1897 protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
1899 support.setCharacterPairMatcher(fBracketMatcher);
1900 support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
1902 super.configureSourceViewerDecorationSupport(support);
1906 * Returns this document's complete text.
1908 * @return the document's complete text
1910 public String get() {
1911 IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
1916 * Sets the outliner's context menu ID.
1918 protected void setOutlinerContextMenuId(String menuId) {
1919 fOutlinerContextMenuId = menuId;
1923 * Returns the standard action group of this editor.
1925 protected ActionGroup getActionGroup() {
1926 return fActionGroups;
1929 // public JavaOutlinePage getfOutlinePage() {
1930 // return fOutlinePage;
1934 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method extend the actions to add those
1935 * specific to the receiver
1937 protected void createActions() {
1938 super.createActions();
1940 fFoldingGroup = new FoldingActionGroup(this, getViewer());
1942 ResourceAction resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1943 "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
1944 resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(),
1945 "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
1946 resAction.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
1947 setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
1948 // WorkbenchHelp.setHelp(resAction,
1949 // IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
1951 Action action = new GotoMatchingBracketAction(this);
1952 action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
1953 setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
1956 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.",
1957 // this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
1958 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
1959 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action);
1960 //// WorkbenchHelp.setHelp(action,
1961 // IJavaHelpContextIds.SHOW_OUTLINE_ACTION);
1964 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.",
1965 // this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$
1966 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE);
1967 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE,
1969 //// WorkbenchHelp.setHelp(action,
1970 // IJavaHelpContextIds.OPEN_STRUCTURE_ACTION);
1973 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.",
1974 // this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
1975 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY);
1976 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY,
1978 //// WorkbenchHelp.setHelp(action,
1979 // IJavaHelpContextIds.OPEN_HIERARCHY_ACTION);
1981 fEncodingSupport = new DefaultEncodingSupport();
1982 fEncodingSupport.initialize(this);
1984 // fSelectionHistory= new SelectionHistory(this);
1986 // action= new StructureSelectEnclosingAction(this, fSelectionHistory);
1987 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
1988 // setAction(StructureSelectionAction.ENCLOSING, action);
1990 // action= new StructureSelectNextAction(this, fSelectionHistory);
1991 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
1992 // setAction(StructureSelectionAction.NEXT, action);
1994 // action= new StructureSelectPreviousAction(this, fSelectionHistory);
1995 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
1996 // setAction(StructureSelectionAction.PREVIOUS, action);
1998 // StructureSelectHistoryAction historyAction= new
1999 // StructureSelectHistoryAction(this, fSelectionHistory);
2000 // historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
2001 // setAction(StructureSelectionAction.HISTORY, historyAction);
2002 // fSelectionHistory.setHistoryAction(historyAction);
2004 // action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this);
2005 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
2006 // setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action);
2009 // GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this);
2010 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
2011 // setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
2013 // action= new QuickFormatAction();
2014 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT);
2015 // setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action);
2017 // action= new RemoveOccurrenceAnnotations(this);
2018 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
2019 // setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$
2021 // add annotation actions
2022 action = new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
2023 setAction("AnnotationAction", action); //$NON-NLS-1$
2026 private void internalDoSetInput(IEditorInput input) throws CoreException {
2027 super.doSetInput(input);
2029 if (getSourceViewer() instanceof JavaSourceViewer) {
2030 JavaSourceViewer viewer= (JavaSourceViewer)getSourceViewer();
2031 if (viewer.getReconciler() == null) {
2032 IReconciler reconciler= getSourceViewerConfiguration().getReconciler(viewer);
2033 if (reconciler != null) {
2034 reconciler.install(viewer);
2035 viewer.setReconciler(reconciler);
2040 if (fEncodingSupport != null)
2041 fEncodingSupport.reset();
2043 setOutlinePageInput(fOutlinePage, input);
2045 if (fProjectionModelUpdater != null)
2046 fProjectionModelUpdater.initialize();
2048 // if (isShowingOverrideIndicators())
2049 // installOverrideIndicator(false);
2053 * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)
2056 protected void setPreferenceStore(IPreferenceStore store) {
2057 super.setPreferenceStore(store);
2058 if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) {
2059 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2060 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this,
2061 IPHPPartitions.PHP_PARTITIONING));
2063 if (getSourceViewer() instanceof JavaSourceViewer)
2064 ((JavaSourceViewer) getSourceViewer()).setPreferenceStore(store);
2068 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra disposal
2069 * actions required by the php editor.
2071 public void dispose() {
2072 if (fProjectionModelUpdater != null) {
2073 fProjectionModelUpdater.uninstall();
2074 fProjectionModelUpdater = null;
2077 if (fProjectionSupport != null) {
2078 fProjectionSupport.dispose();
2079 fProjectionSupport = null;
2081 // PHPEditorEnvironment.disconnect(this);
2082 if (fOutlinePage != null)
2083 fOutlinePage.setInput(null);
2085 if (fActionGroups != null)
2086 fActionGroups.dispose();
2088 if (isBrowserLikeLinks())
2089 disableBrowserLikeLinks();
2091 if (fEncodingSupport != null) {
2092 fEncodingSupport.dispose();
2093 fEncodingSupport = null;
2096 if (fPropertyChangeListener != null) {
2097 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
2098 preferences.removePropertyChangeListener(fPropertyChangeListener);
2099 fPropertyChangeListener = null;
2102 // if (fSourceViewerDecorationSupport != null) {
2103 // fSourceViewerDecorationSupport.dispose();
2104 // fSourceViewerDecorationSupport = null;
2107 if (fBracketMatcher != null) {
2108 fBracketMatcher.dispose();
2109 fBracketMatcher = null;
2112 if (fEditorSelectionChangedListener != null) {
2113 fEditorSelectionChangedListener.uninstall(getSelectionProvider());
2114 fEditorSelectionChangedListener = null;
2121 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra revert behavior
2122 * required by the php editor.
2124 // public void doRevertToSaved() {
2125 // super.doRevertToSaved();
2126 // if (fOutlinePage != null)
2127 // fOutlinePage.update();
2130 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra save behavior
2131 * required by the php editor.
2133 // public void doSave(IProgressMonitor monitor) {
2134 // super.doSave(monitor);
2135 // compile or not, according to the user preferences
2136 // IPreferenceStore store = getPreferenceStore();
2137 // the parse on save was changed to the eclipse "builders" concept
2138 // if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
2139 // IAction a = PHPParserAction.getInstance();
2143 // if (SWT.getPlatform().equals("win32")) {
2144 // IAction a = ShowExternalPreviewAction.getInstance();
2148 // if (fOutlinePage != null)
2149 // fOutlinePage.update();
2152 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs any extra save as
2153 * behavior required by the php editor.
2155 // public void doSaveAs() {
2156 // super.doSaveAs();
2157 // if (fOutlinePage != null)
2158 // fOutlinePage.update();
2161 * @see StatusTextEditor#getStatusHeader(IStatus)
2163 protected String getStatusHeader(IStatus status) {
2164 if (fEncodingSupport != null) {
2165 String message = fEncodingSupport.getStatusHeader(status);
2166 if (message != null)
2169 return super.getStatusHeader(status);
2173 * @see StatusTextEditor#getStatusBanner(IStatus)
2175 protected String getStatusBanner(IStatus status) {
2176 if (fEncodingSupport != null) {
2177 String message = fEncodingSupport.getStatusBanner(status);
2178 if (message != null)
2181 return super.getStatusBanner(status);
2185 * @see StatusTextEditor#getStatusMessage(IStatus)
2187 protected String getStatusMessage(IStatus status) {
2188 if (fEncodingSupport != null) {
2189 String message = fEncodingSupport.getStatusMessage(status);
2190 if (message != null)
2193 return super.getStatusMessage(status);
2197 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs sets the input of the
2198 * outline page after AbstractTextEditor has set input.
2200 // protected void doSetInput(IEditorInput input) throws CoreException {
2201 // super.doSetInput(input);
2203 // if (fEncodingSupport != null)
2204 // fEncodingSupport.reset();
2205 // if (fOutlinePage != null)
2206 // fOutlinePage.setInput(input);
2207 // // setOutlinePageInput(fOutlinePage, input);
2209 protected void doSetInput(IEditorInput input) throws CoreException {
2210 super.doSetInput(input);
2211 if (fEncodingSupport != null)
2212 fEncodingSupport.reset();
2213 setOutlinePageInput(fOutlinePage, input);
2217 * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
2219 // public Object getViewPartInput() {
2220 // return getEditorInput().getAdapter(IFile.class);
2223 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method adds any PHPEditor specific
2226 public void editorContextMenuAboutToShow(MenuManager menu) {
2227 super.editorContextMenuAboutToShow(menu);
2228 menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, new Separator(IContextMenuConstants.GROUP_OPEN));
2229 menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));
2231 ActionContext context = new ActionContext(getSelectionProvider().getSelection());
2232 fContextMenuGroup.setContext(context);
2233 fContextMenuGroup.fillContextMenu(menu);
2234 fContextMenuGroup.setContext(null);
2235 // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format");
2238 // ActionContext context =
2239 // new ActionContext(getSelectionProvider().getSelection());
2240 // fContextMenuGroup.setContext(context);
2241 // fContextMenuGroup.fillContextMenu(menu);
2242 // fContextMenuGroup.setContext(null);
2246 * Creates the outline page used with this editor.
2248 protected JavaOutlinePage createOutlinePage() {
2249 JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this);
2250 fOutlineSelectionChangedListener.install(page);
2251 setOutlinePageInput(page, getEditorInput());
2256 * Informs the editor that its outliner has been closed.
2258 public void outlinePageClosed() {
2259 if (fOutlinePage != null) {
2260 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
2261 fOutlinePage = null;
2262 resetHighlightRange();
2267 * Synchronizes the outliner selection with the given element position in the editor.
2270 * the java element to select
2272 protected void synchronizeOutlinePage(ISourceReference element) {
2273 synchronizeOutlinePage(element, true);
2277 * Synchronizes the outliner selection with the given element position in the editor.
2280 * the java element to select
2281 * @param checkIfOutlinePageActive
2282 * <code>true</code> if check for active outline page needs to be done
2284 protected void synchronizeOutlinePage(ISourceReference element, boolean checkIfOutlinePageActive) {
2285 if (fOutlinePage != null && element != null && !(checkIfOutlinePageActive && isJavaOutlinePageActive())) {
2286 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
2287 fOutlinePage.select(element);
2288 fOutlineSelectionChangedListener.install(fOutlinePage);
2293 * Synchronizes the outliner selection with the actual cursor position in the editor.
2295 public void synchronizeOutlinePageSelection() {
2296 synchronizeOutlinePage(computeHighlightRangeSourceReference());
2298 // ISourceViewer sourceViewer = getSourceViewer();
2299 // if (sourceViewer == null || fOutlinePage == null)
2302 // StyledText styledText = sourceViewer.getTextWidget();
2303 // if (styledText == null)
2307 // if (sourceViewer instanceof ITextViewerExtension3) {
2308 // ITextViewerExtension3 extension = (ITextViewerExtension3)
2311 // extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
2313 // int offset = sourceViewer.getVisibleRegion().getOffset();
2314 // caret = offset + styledText.getCaretOffset();
2317 // IJavaElement element = getElementAt(caret);
2318 // if (element instanceof ISourceReference) {
2319 // fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
2320 // fOutlinePage.select((ISourceReference) element);
2321 // fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
2325 protected void setSelection(ISourceReference reference, boolean moveCursor) {
2327 ISelection selection = getSelectionProvider().getSelection();
2328 if (selection instanceof TextSelection) {
2329 TextSelection textSelection = (TextSelection) selection;
2330 if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
2331 markInNavigationHistory();
2334 if (reference != null) {
2336 StyledText textWidget = null;
2338 ISourceViewer sourceViewer = getSourceViewer();
2339 if (sourceViewer != null)
2340 textWidget = sourceViewer.getTextWidget();
2342 if (textWidget == null)
2347 ISourceRange range = reference.getSourceRange();
2351 int offset = range.getOffset();
2352 int length = range.getLength();
2354 if (offset < 0 || length < 0)
2357 textWidget.setRedraw(false);
2359 setHighlightRange(offset, length, moveCursor);
2367 if (reference instanceof IMember) {
2368 range = ((IMember) reference).getNameRange();
2369 if (range != null) {
2370 offset = range.getOffset();
2371 length = range.getLength();
2374 // else if (reference instanceof IImportDeclaration) {
2375 // String name= ((IImportDeclaration)
2376 // reference).getElementName();
2377 // if (name != null && name.length() > 0) {
2378 // String content= reference.getSource();
2379 // if (content != null) {
2380 // offset= range.getOffset() + content.indexOf(name);
2381 // length= name.length();
2384 // } else if (reference instanceof IPackageDeclaration) {
2385 // String name= ((IPackageDeclaration)
2386 // reference).getElementName();
2387 // if (name != null && name.length() > 0) {
2388 // String content= reference.getSource();
2389 // if (content != null) {
2390 // offset= range.getOffset() + content.indexOf(name);
2391 // length= name.length();
2396 if (offset > -1 && length > 0) {
2397 sourceViewer.revealRange(offset, length);
2398 sourceViewer.setSelectedRange(offset, length);
2401 } catch (JavaModelException x) {
2402 } catch (IllegalArgumentException x) {
2404 if (textWidget != null)
2405 textWidget.setRedraw(true);
2408 } else if (moveCursor) {
2409 resetHighlightRange();
2412 markInNavigationHistory();
2415 public void setSelection(IJavaElement element) {
2416 if (element == null || element instanceof ICompilationUnit) { // ||
2422 * If the element is an ICompilationUnit this unit is either the input of this editor or not being displayed. In both cases,
2423 * nothing should happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
2428 IJavaElement corresponding = getCorrespondingElement(element);
2429 if (corresponding instanceof ISourceReference) {
2430 ISourceReference reference = (ISourceReference) corresponding;
2431 // set highlight range
2432 setSelection(reference, true);
2433 // set outliner selection
2434 if (fOutlinePage != null) {
2435 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
2436 fOutlinePage.select(reference);
2437 fOutlineSelectionChangedListener.install(fOutlinePage);
2442 public synchronized void editingScriptStarted() {
2443 ++fIgnoreOutlinePageSelection;
2446 public synchronized void editingScriptEnded() {
2447 --fIgnoreOutlinePageSelection;
2450 public synchronized boolean isEditingScriptRunning() {
2451 return (fIgnoreOutlinePageSelection > 0);
2455 * The <code>PHPEditor</code> implementation of this <code>AbstractTextEditor</code> method performs gets the java content
2456 * outline page if request is for a an outline page.
2458 public Object getAdapter(Class required) {
2460 if (IContentOutlinePage.class.equals(required)) {
2461 if (fOutlinePage == null)
2462 fOutlinePage = createOutlinePage();
2463 return fOutlinePage;
2466 if (IEncodingSupport.class.equals(required))
2467 return fEncodingSupport;
2469 if (required == IShowInTargetList.class) {
2470 return new IShowInTargetList() {
2471 public String[] getShowInTargetIds() {
2472 return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
2477 if (fProjectionSupport != null) {
2478 Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
2479 if (adapter != null)
2483 return super.getAdapter(required);
2486 // public Object getAdapter(Class required) {
2487 // if (IContentOutlinePage.class.equals(required)) {
2488 // if (fOutlinePage == null) {
2489 // fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
2490 // if (getEditorInput() != null)
2491 // fOutlinePage.setInput(getEditorInput());
2493 // return fOutlinePage;
2496 // if (IEncodingSupport.class.equals(required))
2497 // return fEncodingSupport;
2499 // return super.getAdapter(required);
2502 protected void doSelectionChanged(SelectionChangedEvent event) {
2503 ISourceReference reference = null;
2505 ISelection selection = event.getSelection();
2506 Iterator iter = ((IStructuredSelection) selection).iterator();
2507 while (iter.hasNext()) {
2508 Object o = iter.next();
2509 if (o instanceof ISourceReference) {
2510 reference = (ISourceReference) o;
2515 if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
2516 PHPeclipsePlugin.getActivePage().bringToTop(this);
2519 editingScriptStarted();
2520 setSelection(reference, !isActivePart());
2522 editingScriptEnded();
2527 * @see AbstractTextEditor#adjustHighlightRange(int, int)
2529 protected void adjustHighlightRange(int offset, int length) {
2533 IJavaElement element = getElementAt(offset);
2534 while (element instanceof ISourceReference) {
2535 ISourceRange range = ((ISourceReference) element).getSourceRange();
2536 if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) {
2538 ISourceViewer viewer = getSourceViewer();
2539 if (viewer instanceof ITextViewerExtension5) {
2540 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
2541 extension.exposeModelRange(new Region(range.getOffset(), range.getLength()));
2544 setHighlightRange(range.getOffset(), range.getLength(), true);
2545 if (fOutlinePage != null) {
2546 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
2547 fOutlinePage.select((ISourceReference) element);
2548 fOutlineSelectionChangedListener.install(fOutlinePage);
2553 element = element.getParent();
2556 } catch (JavaModelException x) {
2557 PHPeclipsePlugin.log(x.getStatus());
2560 ISourceViewer viewer = getSourceViewer();
2561 if (viewer instanceof ITextViewerExtension5) {
2562 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
2563 extension.exposeModelRange(new Region(offset, length));
2565 resetHighlightRange();
2570 protected boolean isActivePart() {
2571 IWorkbenchWindow window = getSite().getWorkbenchWindow();
2572 IPartService service = window.getPartService();
2573 IWorkbenchPart part = service.getActivePart();
2574 return part != null && part.equals(this);
2577 // public void openContextHelp() {
2579 // this.getDocumentProvider().getDocument(this.getEditorInput());
2580 // ITextSelection selection = (ITextSelection)
2581 // this.getSelectionProvider().getSelection();
2582 // int pos = selection.getOffset();
2583 // String word = getFunctionName(doc, pos);
2584 // openContextHelp(word);
2587 // private void openContextHelp(String word) {
2591 // public static void open(String word) {
2592 // IHelp help = WorkbenchHelp.getHelpSupport();
2593 // if (help != null) {
2594 // IHelpResource helpResource = new PHPFunctionHelpResource(word);
2595 // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
2597 // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help
2598 // not available"), false); //$NON-NLS-1$
2602 // private String getFunctionName(IDocument doc, int pos) {
2603 // Point word = PHPWordExtractor.findWord(doc, pos);
2604 // if (word != null) {
2606 // return doc.get(word.x, word.y).replace('_', '-');
2607 // } catch (BadLocationException e) {
2614 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
2616 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
2620 ISourceViewer sourceViewer = getSourceViewer();
2621 if (sourceViewer == null)
2624 String property = event.getProperty();
2626 if (PreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
2627 Object value = event.getNewValue();
2628 if (value instanceof Integer) {
2629 sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
2630 } else if (value instanceof String) {
2631 sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
2636 // if (OVERVIEW_RULER.equals(property)) {
2637 // if (isOverviewRulerVisible())
2638 // showOverviewRuler();
2640 // hideOverviewRuler();
2644 // if (LINE_NUMBER_RULER.equals(property)) {
2645 // if (isLineNumberRulerVisible())
2646 // showLineNumberRuler();
2648 // hideLineNumberRuler();
2652 // if (fLineNumberRulerColumn != null
2653 // && (LINE_NUMBER_COLOR.equals(property) ||
2654 // PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) ||
2655 // PREFERENCE_COLOR_BACKGROUND.equals(property))) {
2657 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
2660 if (isJavaEditorHoverProperty(property))
2661 updateHoverBehavior();
2663 if (BROWSER_LIKE_LINKS.equals(property)) {
2664 if (isBrowserLikeLinks())
2665 enableBrowserLikeLinks();
2667 disableBrowserLikeLinks();
2672 // (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property))
2674 // if ((event.getNewValue() instanceof Boolean) &&
2675 // ((Boolean)event.getNewValue()).booleanValue())
2676 // fEditorSelectionChangedListener.selectionChanged();
2680 if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) {
2681 if (event.getNewValue() instanceof Boolean) {
2682 Boolean disable = (Boolean) event.getNewValue();
2683 enableOverwriteMode(!disable.booleanValue());
2688 // if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property))
2690 // if (event.getNewValue() instanceof Boolean) {
2691 // boolean markOccurrenceAnnotations=
2692 // ((Boolean)event.getNewValue()).booleanValue();
2693 // if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) {
2694 // fMarkOccurrenceAnnotations= markOccurrenceAnnotations;
2695 // if (!fMarkOccurrenceAnnotations)
2696 // uninstallOccurrencesFinder();
2698 // installOccurrencesFinder();
2703 // (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property))
2705 // if (event.getNewValue() instanceof Boolean) {
2706 // boolean stickyOccurrenceAnnotations=
2707 // ((Boolean)event.getNewValue()).booleanValue();
2708 // if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations)
2710 // fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations;
2711 //// if (!fMarkOccurrenceAnnotations)
2712 //// uninstallOccurrencesFinder();
2714 //// installOccurrencesFinder();
2718 if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
2719 if (sourceViewer instanceof ProjectionViewer) {
2720 ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer;
2721 if (fProjectionModelUpdater != null)
2722 fProjectionModelUpdater.uninstall();
2723 // either freshly enabled or provider changed
2724 fProjectionModelUpdater = PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
2725 if (fProjectionModelUpdater != null) {
2726 fProjectionModelUpdater.install(this, projectionViewer);
2732 super.handlePreferenceStoreChanged(event);
2738 // AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
2740 // protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
2744 // ISourceViewer sourceViewer = getSourceViewer();
2745 // if (sourceViewer == null)
2748 // String property = event.getProperty();
2751 // (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
2752 // // Object value= event.getNewValue();
2753 // // if (value instanceof Integer) {
2754 // // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
2755 // // } else if (value instanceof String) {
2756 // // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String)
2762 // if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
2763 // if (isLineNumberRulerVisible())
2764 // showLineNumberRuler();
2766 // hideLineNumberRuler();
2770 // if (fLineNumberRulerColumn != null
2771 // && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
2772 // || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
2773 // || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
2775 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
2779 // super.handlePreferenceStoreChanged(event);
2783 // private boolean isJavaEditorHoverProperty(String property) {
2784 // return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
2785 // || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
2786 // || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
2787 // || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
2788 // || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
2789 // || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
2790 // || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
2791 // || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
2795 * Shows the line number ruler column.
2797 // private void showLineNumberRuler() {
2798 // IVerticalRuler v = getVerticalRuler();
2799 // if (v instanceof CompositeRuler) {
2800 // CompositeRuler c = (CompositeRuler) v;
2801 // c.addDecorator(1, createLineNumberRulerColumn());
2804 private boolean isJavaEditorHoverProperty(String property) {
2805 return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property);
2809 * Return whether the browser like links should be enabled according to the preference store settings.
2811 * @return <code>true</code> if the browser like links should be enabled
2813 private boolean isBrowserLikeLinks() {
2814 IPreferenceStore store = getPreferenceStore();
2815 return store.getBoolean(BROWSER_LIKE_LINKS);
2819 * Enables browser like links.
2821 private void enableBrowserLikeLinks() {
2822 if (fMouseListener == null) {
2823 fMouseListener = new MouseClickListener();
2824 fMouseListener.install();
2829 * Disables browser like links.
2831 private void disableBrowserLikeLinks() {
2832 if (fMouseListener != null) {
2833 fMouseListener.uninstall();
2834 fMouseListener = null;
2839 * Handles a property change event describing a change of the java core's preferences and updates the preference related editor
2843 * the property change event
2845 protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
2846 if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
2847 ISourceViewer sourceViewer = getSourceViewer();
2848 if (sourceViewer != null
2849 && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event
2851 sourceViewer.invalidateTextPresentation();
2856 * Return whether the line number ruler column should be visible according to the preference store settings.
2858 * @return <code>true</code> if the line numbers should be visible
2860 // protected boolean isLineNumberRulerVisible() {
2861 // IPreferenceStore store = getPreferenceStore();
2862 // return store.getBoolean(LINE_NUMBER_RULER);
2865 * Hides the line number ruler column.
2867 // private void hideLineNumberRuler() {
2868 // IVerticalRuler v = getVerticalRuler();
2869 // if (v instanceof CompositeRuler) {
2870 // CompositeRuler c = (CompositeRuler) v;
2872 // c.removeDecorator(1);
2873 // } catch (Throwable e) {
2878 * @see AbstractTextEditor#handleCursorPositionChanged()
2880 protected void handleCursorPositionChanged() {
2881 super.handleCursorPositionChanged();
2882 if (!isEditingScriptRunning() && fUpdater != null)
2887 * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced()
2889 protected void handleElementContentReplaced() {
2890 super.handleElementContentReplaced();
2891 if (fProjectionModelUpdater != null)
2892 fProjectionModelUpdater.initialize();
2896 * Initializes the given line number ruler column from the preference store.
2898 * @param rulerColumn
2899 * the ruler column to be initialized
2901 // protected void initializeLineNumberRulerColumn(LineNumberRulerColumn
2903 // JavaTextTools textTools =
2904 // PHPeclipsePlugin.getDefault().getJavaTextTools();
2905 // IColorManager manager = textTools.getColorManager();
2907 // IPreferenceStore store = getPreferenceStore();
2908 // if (store != null) {
2911 // // foreground color
2912 // if (store.contains(LINE_NUMBER_COLOR)) {
2913 // if (store.isDefault(LINE_NUMBER_COLOR))
2914 // rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
2916 // rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
2918 // rulerColumn.setForeground(manager.getColor(rgb));
2921 // // background color
2922 // if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
2923 // if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
2924 // if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
2925 // rgb = PreferenceConverter.getDefaultColor(store,
2926 // PREFERENCE_COLOR_BACKGROUND);
2928 // rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
2931 // rulerColumn.setBackground(manager.getColor(rgb));
2935 * Creates a new line number ruler column that is appropriately initialized.
2937 // protected IVerticalRulerColumn createLineNumberRulerColumn() {
2938 // fLineNumberRulerColumn = new LineNumberRulerColumn();
2939 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
2940 // return fLineNumberRulerColumn;
2943 * @see AbstractTextEditor#createVerticalRuler()
2945 // protected IVerticalRuler createVerticalRuler() {
2946 // CompositeRuler ruler = new CompositeRuler();
2947 // ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
2948 // if (isLineNumberRulerVisible())
2949 // ruler.addDecorator(1, createLineNumberRulerColumn());
2952 // private static IRegion getSignedSelection(ITextViewer viewer) {
2954 // StyledText text = viewer.getTextWidget();
2955 // int caretOffset = text.getCaretOffset();
2956 // Point selection = text.getSelection();
2959 // int offset, length;
2960 // if (caretOffset == selection.x) {
2961 // offset = selection.y;
2962 // length = selection.x - selection.y;
2966 // offset = selection.x;
2967 // length = selection.y - selection.x;
2970 // return new Region(offset, length);
2972 protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
2973 StyledText text= sourceViewer.getTextWidget();
2974 Point selection= text.getSelectionRange();
2976 if (text.getCaretOffset() == selection.x) {
2977 selection.x= selection.x + selection.y;
2978 selection.y= -selection.y;
2981 selection.x= widgetOffset2ModelOffset(sourceViewer, selection.x);
2983 return new Region(selection.x, selection.y);
2985 /** Preference key for matching brackets */
2986 protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
2988 /** Preference key for matching brackets color */
2989 protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
2991 /** Preference key for highlighting current line */
2992 protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
2994 /** Preference key for highlight color of current line */
2995 protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
2997 /** Preference key for showing print marging ruler */
2998 protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
3000 /** Preference key for print margin ruler color */
3001 protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
3003 /** Preference key for print margin ruler column */
3004 protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
3006 /** Preference key for error indication */
3007 // protected final static String ERROR_INDICATION =
3008 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
3009 /** Preference key for error color */
3010 // protected final static String ERROR_INDICATION_COLOR =
3011 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
3012 /** Preference key for warning indication */
3013 // protected final static String WARNING_INDICATION =
3014 // PreferenceConstants.EDITOR_WARNING_INDICATION;
3015 /** Preference key for warning color */
3016 // protected final static String WARNING_INDICATION_COLOR =
3017 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
3018 /** Preference key for task indication */
3019 protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
3021 /** Preference key for task color */
3022 protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
3024 /** Preference key for bookmark indication */
3025 protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
3027 /** Preference key for bookmark color */
3028 protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
3030 /** Preference key for search result indication */
3031 protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
3033 /** Preference key for search result color */
3034 protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
3036 /** Preference key for unknown annotation indication */
3037 protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
3039 /** Preference key for unknown annotation color */
3040 protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
3042 /** Preference key for shwoing the overview ruler */
3043 protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
3045 /** Preference key for error indication in overview ruler */
3046 protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
3048 /** Preference key for warning indication in overview ruler */
3049 protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
3051 /** Preference key for task indication in overview ruler */
3052 protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
3054 /** Preference key for bookmark indication in overview ruler */
3055 protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
3057 /** Preference key for search result indication in overview ruler */
3058 protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
3060 /** Preference key for unknown annotation indication in overview ruler */
3061 protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
3063 // /** Preference key for compiler task tags */
3064 // private final static String COMPILER_TASK_TAGS=
3065 // JavaCore.COMPILER_TASK_TAGS;
3066 /** Preference key for browser like links */
3067 private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS;
3069 /** Preference key for key modifier of browser like links */
3070 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER;
3073 * Preference key for key modifier mask of browser like links. The value is only used if the value of
3074 * <code>EDITOR_BROWSER_LIKE_LINKS</code> cannot be resolved to valid SWT modifier bits.
3078 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
3080 private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
3082 private static boolean isBracket(char character) {
3083 for (int i = 0; i != BRACKETS.length; ++i)
3084 if (character == BRACKETS[i])
3089 private static boolean isSurroundedByBrackets(IDocument document, int offset) {
3090 if (offset == 0 || offset == document.getLength())
3094 return isBracket(document.getChar(offset - 1)) && isBracket(document.getChar(offset));
3096 } catch (BadLocationException e) {
3101 // protected void configureSourceViewerDecorationSupport() {
3103 // fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
3105 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
3106 // AnnotationType.UNKNOWN,
3107 // UNKNOWN_INDICATION_COLOR,
3108 // UNKNOWN_INDICATION,
3109 // UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
3111 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
3112 // AnnotationType.BOOKMARK,
3113 // BOOKMARK_INDICATION_COLOR,
3114 // BOOKMARK_INDICATION,
3115 // BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
3117 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
3118 // AnnotationType.TASK,
3119 // TASK_INDICATION_COLOR,
3121 // TASK_INDICATION_IN_OVERVIEW_RULER,
3123 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
3124 // AnnotationType.SEARCH,
3125 // SEARCH_RESULT_INDICATION_COLOR,
3126 // SEARCH_RESULT_INDICATION,
3127 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
3129 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
3130 // AnnotationType.WARNING,
3131 // WARNING_INDICATION_COLOR,
3132 // WARNING_INDICATION,
3133 // WARNING_INDICATION_IN_OVERVIEW_RULER,
3135 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
3136 // AnnotationType.ERROR,
3137 // ERROR_INDICATION_COLOR,
3138 // ERROR_INDICATION,
3139 // ERROR_INDICATION_IN_OVERVIEW_RULER,
3142 // fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE,
3143 // CURRENT_LINE_COLOR);
3144 // fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN,
3145 // PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
3146 // fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS,
3147 // MATCHING_BRACKETS_COLOR);
3149 // fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
3153 * Returns the Java element wrapped by this editors input.
3155 * @return the Java element wrapped by this editors input.
3158 abstract protected IJavaElement getInputJavaElement();
3161 * Jumps to the matching bracket.
3163 public void gotoMatchingBracket() {
3165 ISourceViewer sourceViewer = getSourceViewer();
3166 IDocument document = sourceViewer.getDocument();
3167 if (document == null)
3170 IRegion selection = getSignedSelection(sourceViewer);
3172 int selectionLength = Math.abs(selection.getLength());
3173 if (selectionLength > 1) {
3174 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$
3175 sourceViewer.getTextWidget().getDisplay().beep();
3180 int sourceCaretOffset = selection.getOffset() + selection.getLength();
3181 if (isSurroundedByBrackets(document, sourceCaretOffset))
3182 sourceCaretOffset -= selection.getLength();
3184 IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
3185 if (region == null) {
3186 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$
3187 sourceViewer.getTextWidget().getDisplay().beep();
3191 int offset = region.getOffset();
3192 int length = region.getLength();
3197 int anchor = fBracketMatcher.getAnchor();
3198 int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
3200 boolean visible = false;
3201 if (sourceViewer instanceof ITextViewerExtension3) {
3202 ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
3203 visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
3205 IRegion visibleRegion = sourceViewer.getVisibleRegion();
3206 visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength());
3210 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$
3211 sourceViewer.getTextWidget().getDisplay().beep();
3215 if (selection.getLength() < 0)
3216 targetOffset -= selection.getLength();
3218 sourceViewer.setSelectedRange(targetOffset, selection.getLength());
3219 sourceViewer.revealRange(targetOffset, selection.getLength());
3223 * Ses the given message as error message to this editor's status line.
3228 protected void setStatusLineErrorMessage(String msg) {
3229 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
3230 if (statusLine != null)
3231 statusLine.setMessage(true, msg, null);
3235 * Returns a segmentation of the line of the given document appropriate for bidi rendering. The default implementation returns
3236 * only the string literals of a php code line as segments.
3241 * the offset of the line
3242 * @return the line's bidi segmentation
3243 * @throws BadLocationException
3244 * in case lineOffset is not valid in document
3246 public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException {
3248 IRegion line = document.getLineInformationOfOffset(lineOffset);
3249 ITypedRegion[] linePartitioning = document.computePartitioning(lineOffset, line.getLength());
3251 List segmentation = new ArrayList();
3252 for (int i = 0; i < linePartitioning.length; i++) {
3253 if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType()))
3254 segmentation.add(linePartitioning[i]);
3257 if (segmentation.size() == 0)
3260 int size = segmentation.size();
3261 int[] segments = new int[size * 2 + 1];
3264 for (int i = 0; i < size; i++) {
3265 ITypedRegion segment = (ITypedRegion) segmentation.get(i);
3270 int offset = segment.getOffset() - lineOffset;
3271 if (offset > segments[j - 1])
3272 segments[j++] = offset;
3274 if (offset + segment.getLength() >= line.getLength())
3277 segments[j++] = offset + segment.getLength();
3280 if (j < segments.length) {
3281 int[] result = new int[j];
3282 System.arraycopy(segments, 0, result, 0, j);
3290 * Returns a segmentation of the given line appropriate for bidi rendering. The default implementation returns only the string
3291 * literals of a php code line as segments.
3294 * the offset of the line
3296 * the content of the line
3297 * @return the line's bidi segmentation
3299 protected int[] getBidiLineSegments(int lineOffset, String line) {
3300 IDocumentProvider provider = getDocumentProvider();
3301 if (provider != null && line != null && line.length() > 0) {
3302 IDocument document = provider.getDocument(getEditorInput());
3303 if (document != null)
3305 return getBidiLineSegments(document, lineOffset);
3306 } catch (BadLocationException x) {
3314 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3316 // protected final ISourceViewer createSourceViewer(
3317 // Composite parent,
3318 // IVerticalRuler ruler,
3320 // ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
3321 // StyledText text = viewer.getTextWidget();
3322 // text.addBidiSegmentListener(new BidiSegmentListener() {
3323 // public void lineGetSegments(BidiSegmentEvent event) {
3324 // event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
3327 // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
3330 public final ISourceViewer getViewer() {
3331 return getSourceViewer();
3334 // protected void showOverviewRuler() {
3335 // if (fOverviewRuler != null) {
3336 // if (getSourceViewer() instanceof ISourceViewerExtension) {
3337 // ((ISourceViewerExtension)
3338 // getSourceViewer()).showAnnotationsOverview(true);
3339 // fSourceViewerDecorationSupport.updateOverviewDecorations();
3344 // protected void hideOverviewRuler() {
3345 // if (getSourceViewer() instanceof ISourceViewerExtension) {
3346 // fSourceViewerDecorationSupport.hideAnnotationOverview();
3347 // ((ISourceViewerExtension)
3348 // getSourceViewer()).showAnnotationsOverview(false);
3352 // protected boolean isOverviewRulerVisible() {
3353 // IPreferenceStore store = getPreferenceStore();
3354 // return store.getBoolean(OVERVIEW_RULER);
3357 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3359 // protected ISourceViewer createJavaSourceViewer(
3360 // Composite parent,
3361 // IVerticalRuler ruler,
3362 // IOverviewRuler overviewRuler,
3363 // boolean isOverviewRulerVisible,
3365 // return new SourceViewer(parent, ruler, overviewRuler,
3366 // isOverviewRulerVisible(), styles);
3369 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3371 protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
3372 boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
3373 return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, store);
3377 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3379 protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {
3381 ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles,
3382 getPreferenceStore());
3384 StyledText text = viewer.getTextWidget();
3385 text.addBidiSegmentListener(new BidiSegmentListener() {
3386 public void lineGetSegments(BidiSegmentEvent event) {
3387 event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
3391 // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
3393 // ensure source viewer decoration support has been created and
3395 getSourceViewerDecorationSupport(viewer);
3401 * Creates and returns the preference store for this Java editor with the given input.
3404 * The editor input for which to create the preference store
3405 * @return the preference store for this editor
3409 private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
3410 List stores = new ArrayList(3);
3412 IJavaProject project = EditorUtility.getJavaProject(input);
3413 if (project != null)
3414 stores.add(new OptionsAdapter(project.getOptions(false), PHPeclipsePlugin.getDefault().getMockupPreferenceStore(),
3415 new OptionsAdapter.IPropertyChangeEventFilter() {
3417 public boolean isFiltered(PropertyChangeEvent event) {
3418 IJavaElement inputJavaElement = getInputJavaElement();
3419 IJavaProject javaProject = inputJavaElement != null ? inputJavaElement.getJavaProject() : null;
3420 if (javaProject == null)
3423 return !javaProject.getProject().equals(event.getSource());
3428 stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore());
3429 stores.add(new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()));
3430 stores.add(EditorsUI.getPreferenceStore());
3432 return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
3436 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3438 // protected ISourceViewer createJavaSourceViewer(Composite parent,
3439 // IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean
3440 // isOverviewRulerVisible, int styles) {
3441 // return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(),
3442 // isOverviewRulerVisible(), styles);
3445 * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
3447 protected boolean affectsTextPresentation(PropertyChangeEvent event) {
3448 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
3449 return textTools.affectsBehavior(event);
3453 * Jumps to the error next according to the given direction.
3455 public void gotoError(boolean forward) {
3457 ISelectionProvider provider = getSelectionProvider();
3459 ITextSelection s = (ITextSelection) provider.getSelection();
3460 Position errorPosition = new Position(0, 0);
3461 IJavaAnnotation nextError = getNextError(s.getOffset(), forward, errorPosition);
3463 if (nextError != null) {
3465 IMarker marker = null;
3466 if (nextError instanceof MarkerAnnotation)
3467 marker = ((MarkerAnnotation) nextError).getMarker();
3469 Iterator e = nextError.getOverlaidIterator();
3471 while (e.hasNext()) {
3472 Object o = e.next();
3473 if (o instanceof MarkerAnnotation) {
3474 marker = ((MarkerAnnotation) o).getMarker();
3481 if (marker != null) {
3482 IWorkbenchPage page = getSite().getPage();
3483 IViewPart view = view = page.findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
3484 if (view instanceof TaskList) {
3485 StructuredSelection ss = new StructuredSelection(marker);
3486 ((TaskList) view).setSelection(ss, true);
3490 selectAndReveal(errorPosition.getOffset(), errorPosition.getLength());
3491 // setStatusLineErrorMessage(nextError.getMessage());
3495 setStatusLineErrorMessage(null);
3500 private IJavaAnnotation getNextError(int offset, boolean forward, Position errorPosition) {
3502 IJavaAnnotation nextError = null;
3503 Position nextErrorPosition = null;
3505 IDocument document = getDocumentProvider().getDocument(getEditorInput());
3506 int endOfDocument = document.getLength();
3509 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
3510 Iterator e = new JavaAnnotationIterator(model, false);
3511 while (e.hasNext()) {
3513 IJavaAnnotation a = (IJavaAnnotation) e.next();
3514 if (a.hasOverlay() || !a.isProblem())
3517 Position p = model.getPosition((Annotation) a);
3518 if (!p.includes(offset)) {
3520 int currentDistance = 0;
3523 currentDistance = p.getOffset() - offset;
3524 if (currentDistance < 0)
3525 currentDistance = endOfDocument - offset + p.getOffset();
3527 currentDistance = offset - p.getOffset();
3528 if (currentDistance < 0)
3529 currentDistance = offset + endOfDocument - p.getOffset();
3532 if (nextError == null || currentDistance < distance) {
3533 distance = currentDistance;
3535 nextErrorPosition = p;
3540 if (nextErrorPosition != null) {
3541 errorPosition.setOffset(nextErrorPosition.getOffset());
3542 errorPosition.setLength(nextErrorPosition.getLength());
3548 void removeOccurrenceAnnotations() {
3549 IDocumentProvider documentProvider = getDocumentProvider();
3550 if (documentProvider == null)
3553 IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
3554 if (annotationModel == null || fOccurrenceAnnotations == null)
3557 synchronized (annotationModel) {
3558 if (annotationModel instanceof IAnnotationModelExtension) {
3559 ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
3561 for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++)
3562 annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
3564 fOccurrenceAnnotations = null;
3568 // protected void uninstallOverrideIndicator() {
3569 // if (fOverrideIndicatorManager != null) {
3570 // fOverrideIndicatorManager.removeAnnotations();
3571 // fOverrideIndicatorManager= null;
3575 protected void installOverrideIndicator(boolean waitForReconcilation) {
3576 // uninstallOverrideIndicator();
3577 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
3578 // IJavaElement inputElement= getInputJavaElement();
3580 // if (model == null || inputElement == null)
3583 // CompilationUnit ast=
3584 // PHPeclipsePlugin.getDefault().getASTProvider().getAST(inputElement,
3586 // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
3587 // inputElement, ast);
3591 * Tells whether override indicators are shown.
3593 * @return <code>true</code> if the override indicators are shown
3596 // protected boolean isShowingOverrideIndicators() {
3597 // AnnotationPreference preference= getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
3598 // IPreferenceStore store= getPreferenceStore();
3599 // return getBoolean(store, preference.getHighlightPreferenceKey())
3600 // || getBoolean(store, preference.getVerticalRulerPreferenceKey())
3601 // || getBoolean(store, preference.getOverviewRulerPreferenceKey())
3602 // || getBoolean(store, preference.getTextPreferenceKey());
3605 * Returns the boolean preference for the given key.
3608 * the preference store
3610 * the preference key
3611 * @return <code>true</code> if the key exists in the store and its value is <code>true</code>
3614 private boolean getBoolean(IPreferenceStore store, String key) {
3615 return key != null && store.getBoolean(key);
3619 * Returns the folding action group, or <code>null</code> if there is none.
3621 * @return the folding action group, or <code>null</code> if there is none
3624 protected FoldingActionGroup getFoldingActionGroup() {
3625 return fFoldingGroup;
3629 * React to changed selection.
3633 protected void selectionChanged() {
3634 if (getSelectionProvider() == null)
3636 ISourceReference element = computeHighlightRangeSourceReference();
3637 if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
3638 synchronizeOutlinePage(element);
3639 setSelection(element, false);
3640 // updateStatusLine();
3643 private boolean isJavaOutlinePageActive() {
3644 IWorkbenchPart part = getActivePart();
3645 return part instanceof ContentOutline && ((ContentOutline) part).getCurrentPage() == fOutlinePage;
3648 private IWorkbenchPart getActivePart() {
3649 IWorkbenchWindow window = getSite().getWorkbenchWindow();
3650 IPartService service = window.getPartService();
3651 IWorkbenchPart part = service.getActivePart();
3656 * Computes and returns the source reference that includes the caret and serves as provider for the outline page selection and the
3657 * editor range indication.
3659 * @return the computed source reference
3662 protected ISourceReference computeHighlightRangeSourceReference() {
3663 ISourceViewer sourceViewer = getSourceViewer();
3664 if (sourceViewer == null)
3667 StyledText styledText = sourceViewer.getTextWidget();
3668 if (styledText == null)
3672 if (sourceViewer instanceof ITextViewerExtension5) {
3673 ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
3674 caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
3676 int offset = sourceViewer.getVisibleRegion().getOffset();
3677 caret = offset + styledText.getCaretOffset();
3680 IJavaElement element = getElementAt(caret, false);
3682 if (!(element instanceof ISourceReference))
3685 if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) {
3687 IImportDeclaration declaration = (IImportDeclaration) element;
3688 IImportContainer container = (IImportContainer) declaration.getParent();
3689 ISourceRange srcRange = null;
3692 srcRange = container.getSourceRange();
3693 } catch (JavaModelException e) {
3696 if (srcRange != null && srcRange.getOffset() == caret)
3700 return (ISourceReference) element;
3704 * Returns the most narrow java element including the given offset.
3707 * the offset inside of the requested element
3709 * <code>true</code> if editor input should be reconciled in advance
3710 * @return the most narrow java element
3713 protected IJavaElement getElementAt(int offset, boolean reconcile) {
3714 return getElementAt(offset);