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.IJavaElement;
24 import net.sourceforge.phpdt.core.IJavaProject;
25 import net.sourceforge.phpdt.core.IMember;
26 import net.sourceforge.phpdt.core.ISourceRange;
27 import net.sourceforge.phpdt.core.ISourceReference;
28 import net.sourceforge.phpdt.core.JavaCore;
29 import net.sourceforge.phpdt.core.JavaModelException;
30 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
31 import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
32 import net.sourceforge.phpdt.internal.ui.text.CustomSourceInformationControl;
33 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
34 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
35 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
36 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
37 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
38 import net.sourceforge.phpdt.ui.IContextMenuConstants;
39 import net.sourceforge.phpdt.ui.JavaUI;
40 import net.sourceforge.phpdt.ui.PreferenceConstants;
41 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
42 import net.sourceforge.phpdt.ui.text.JavaTextTools;
43 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
44 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
46 import org.eclipse.core.resources.IMarker;
47 import org.eclipse.core.resources.IResource;
48 import org.eclipse.core.runtime.CoreException;
49 import org.eclipse.core.runtime.IProgressMonitor;
50 import org.eclipse.core.runtime.IStatus;
51 import org.eclipse.core.runtime.Preferences;
52 import org.eclipse.core.runtime.Status;
53 import org.eclipse.core.runtime.jobs.Job;
54 import org.eclipse.jface.action.Action;
55 import org.eclipse.jface.action.GroupMarker;
56 import org.eclipse.jface.action.IAction;
57 import org.eclipse.jface.action.MenuManager;
58 import org.eclipse.jface.action.Separator;
59 import org.eclipse.jface.preference.IPreferenceStore;
60 import org.eclipse.jface.preference.PreferenceConverter;
61 import org.eclipse.jface.text.BadLocationException;
62 import org.eclipse.jface.text.DefaultInformationControl;
63 import org.eclipse.jface.text.DocumentEvent;
64 import org.eclipse.jface.text.IDocument;
65 import org.eclipse.jface.text.IDocumentListener;
66 import org.eclipse.jface.text.IInformationControl;
67 import org.eclipse.jface.text.IInformationControlCreator;
68 import org.eclipse.jface.text.IRegion;
69 import org.eclipse.jface.text.ITextHover;
70 import org.eclipse.jface.text.ITextInputListener;
71 import org.eclipse.jface.text.ITextSelection;
72 import org.eclipse.jface.text.ITextViewer;
73 import org.eclipse.jface.text.ITextViewerExtension2;
74 import org.eclipse.jface.text.ITextViewerExtension3;
75 import org.eclipse.jface.text.ITypedRegion;
76 import org.eclipse.jface.text.Position;
77 import org.eclipse.jface.text.Region;
78 import org.eclipse.jface.text.TextSelection;
79 import org.eclipse.jface.text.information.IInformationProvider;
80 import org.eclipse.jface.text.information.InformationPresenter;
81 import org.eclipse.jface.text.source.Annotation;
82 import org.eclipse.jface.text.source.IAnnotationModel;
83 import org.eclipse.jface.text.source.IAnnotationModelExtension;
84 import org.eclipse.jface.text.source.IOverviewRuler;
85 import org.eclipse.jface.text.source.ISourceViewer;
86 import org.eclipse.jface.text.source.IVerticalRuler;
87 import org.eclipse.jface.text.source.OverviewRuler;
88 import org.eclipse.jface.text.source.SourceViewerConfiguration;
89 import org.eclipse.jface.text.source.projection.ProjectionSupport;
90 import org.eclipse.jface.text.source.projection.ProjectionViewer;
91 import org.eclipse.jface.util.IPropertyChangeListener;
92 import org.eclipse.jface.util.ListenerList;
93 import org.eclipse.jface.util.PropertyChangeEvent;
94 import org.eclipse.jface.viewers.ISelection;
95 import org.eclipse.jface.viewers.ISelectionChangedListener;
96 import org.eclipse.jface.viewers.ISelectionProvider;
97 import org.eclipse.jface.viewers.IStructuredSelection;
98 import org.eclipse.jface.viewers.SelectionChangedEvent;
99 import org.eclipse.jface.viewers.StructuredSelection;
100 import org.eclipse.swt.SWT;
101 import org.eclipse.swt.custom.BidiSegmentEvent;
102 import org.eclipse.swt.custom.BidiSegmentListener;
103 import org.eclipse.swt.custom.StyleRange;
104 import org.eclipse.swt.custom.StyledText;
105 import org.eclipse.swt.events.FocusEvent;
106 import org.eclipse.swt.events.FocusListener;
107 import org.eclipse.swt.events.KeyEvent;
108 import org.eclipse.swt.events.KeyListener;
109 import org.eclipse.swt.events.MouseEvent;
110 import org.eclipse.swt.events.MouseListener;
111 import org.eclipse.swt.events.MouseMoveListener;
112 import org.eclipse.swt.events.PaintEvent;
113 import org.eclipse.swt.events.PaintListener;
114 import org.eclipse.swt.graphics.Color;
115 import org.eclipse.swt.graphics.Cursor;
116 import org.eclipse.swt.graphics.GC;
117 import org.eclipse.swt.graphics.Image;
118 import org.eclipse.swt.graphics.Point;
119 import org.eclipse.swt.graphics.RGB;
120 import org.eclipse.swt.widgets.Composite;
121 import org.eclipse.swt.widgets.Control;
122 import org.eclipse.swt.widgets.Display;
123 import org.eclipse.swt.widgets.Shell;
124 import org.eclipse.ui.IEditorInput;
125 import org.eclipse.ui.IPageLayout;
126 import org.eclipse.ui.IPartService;
127 import org.eclipse.ui.IViewPart;
128 import org.eclipse.ui.IWorkbenchPage;
129 import org.eclipse.ui.IWorkbenchPart;
130 import org.eclipse.ui.IWorkbenchWindow;
131 import org.eclipse.ui.actions.ActionContext;
132 import org.eclipse.ui.actions.ActionGroup;
133 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
134 import org.eclipse.ui.editors.text.EditorsUI;
135 import org.eclipse.ui.editors.text.IEncodingSupport;
136 import org.eclipse.ui.part.IShowInTargetList;
137 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
138 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
139 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
140 import org.eclipse.ui.texteditor.IDocumentProvider;
141 import org.eclipse.ui.texteditor.IEditorStatusLine;
142 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
143 import org.eclipse.ui.texteditor.MarkerAnnotation;
144 import org.eclipse.ui.texteditor.ResourceAction;
145 import org.eclipse.ui.texteditor.TextEditorAction;
146 import org.eclipse.ui.texteditor.TextOperationAction;
147 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
148 import org.eclipse.ui.views.tasklist.TaskList;
151 * PHP specific text editor.
153 public abstract class PHPEditor extends AbstractDecoratedTextEditor implements IViewPartInputProvider {
154 //extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor {
156 * "Smart" runnable for updating the outline page's selection.
158 class OutlinePageSelectionUpdater implements Runnable {
160 /** Has the runnable already been posted? */
161 private boolean fPosted = false;
163 public OutlinePageSelectionUpdater() {
167 * @see Runnable#run()
170 synchronizeOutlinePageSelection();
175 * Posts this runnable into the event queue.
181 Shell shell = getSite().getShell();
182 if (shell != null & !shell.isDisposed()) {
184 shell.getDisplay().asyncExec(this);
188 class SelectionChangedListener implements ISelectionChangedListener {
189 public void selectionChanged(SelectionChangedEvent event) {
190 doSelectionChanged(event);
195 * Adapts an options {@link java.util.Map} to {@link org.eclipse.jface.preference.IPreferenceStore}.
197 * This preference store is read-only i.e. write access
198 * throws an {@link java.lang.UnsupportedOperationException}.
203 private static class OptionsAdapter implements IPreferenceStore {
207 * A property change event filter.
209 public interface IPropertyChangeEventFilter {
212 * Should the given event be filtered?
213 * @param event The property change event.
214 * @return <code>true</code> iff the given event should be filtered.
216 public boolean isFiltered(PropertyChangeEvent event);
220 * Property change listener. Listens for events in the options Map and
221 * fires a {@link org.eclipse.jface.util.PropertyChangeEvent}
222 * on this adapter with arguments from the received event.
224 private class PropertyChangeListener implements IPropertyChangeListener {
229 public void propertyChange(PropertyChangeEvent event) {
230 if (getFilter().isFiltered(event))
233 if (event.getNewValue() == null)
234 fOptions.remove(event.getProperty());
236 fOptions.put(event.getProperty(), event.getNewValue());
238 firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
242 /** Listeners on this adapter */
243 private ListenerList fListeners= new ListenerList();
245 /** Listener on the adapted options Map */
246 private IPropertyChangeListener fListener= new PropertyChangeListener();
248 /** Adapted options Map */
249 private Map fOptions;
251 /** Preference store through which events are received. */
252 private IPreferenceStore fMockupPreferenceStore;
254 /** Property event filter. */
255 private IPropertyChangeEventFilter fFilter;
258 * Initialize with the given options.
260 * @param options The options to wrap
261 * @param mockupPreferenceStore the mock-up preference store
262 * @param filter the property change filter
264 public OptionsAdapter(Map options, IPreferenceStore mockupPreferenceStore, IPropertyChangeEventFilter filter) {
265 fMockupPreferenceStore= mockupPreferenceStore;
273 public void addPropertyChangeListener(IPropertyChangeListener listener) {
274 if (fListeners.size() == 0)
275 fMockupPreferenceStore.addPropertyChangeListener(fListener);
276 fListeners.add(listener);
282 public void removePropertyChangeListener(IPropertyChangeListener listener) {
283 fListeners.remove(listener);
284 if (fListeners.size() == 0)
285 fMockupPreferenceStore.removePropertyChangeListener(fListener);
291 public boolean contains(String name) {
292 return fOptions.containsKey(name);
298 public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
299 PropertyChangeEvent event= new PropertyChangeEvent(this, name, oldValue, newValue);
300 Object[] listeners= fListeners.getListeners();
301 for (int i= 0; i < listeners.length; i++)
302 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
308 public boolean getBoolean(String name) {
309 boolean value= BOOLEAN_DEFAULT_DEFAULT;
310 String s= (String) fOptions.get(name);
312 value= s.equals(TRUE);
319 public boolean getDefaultBoolean(String name) {
320 return BOOLEAN_DEFAULT_DEFAULT;
326 public double getDefaultDouble(String name) {
327 return DOUBLE_DEFAULT_DEFAULT;
333 public float getDefaultFloat(String name) {
334 return FLOAT_DEFAULT_DEFAULT;
340 public int getDefaultInt(String name) {
341 return INT_DEFAULT_DEFAULT;
347 public long getDefaultLong(String name) {
348 return LONG_DEFAULT_DEFAULT;
354 public String getDefaultString(String name) {
355 return STRING_DEFAULT_DEFAULT;
361 public double getDouble(String name) {
362 double value= DOUBLE_DEFAULT_DEFAULT;
363 String s= (String) fOptions.get(name);
366 value= new Double(s).doubleValue();
367 } catch (NumberFormatException e) {
376 public float getFloat(String name) {
377 float value= FLOAT_DEFAULT_DEFAULT;
378 String s= (String) fOptions.get(name);
381 value= new Float(s).floatValue();
382 } catch (NumberFormatException e) {
391 public int getInt(String name) {
392 int value= INT_DEFAULT_DEFAULT;
393 String s= (String) fOptions.get(name);
396 value= new Integer(s).intValue();
397 } catch (NumberFormatException e) {
406 public long getLong(String name) {
407 long value= LONG_DEFAULT_DEFAULT;
408 String s= (String) fOptions.get(name);
411 value= new Long(s).longValue();
412 } catch (NumberFormatException e) {
421 public String getString(String name) {
422 String value= (String) fOptions.get(name);
424 value= STRING_DEFAULT_DEFAULT;
431 public boolean isDefault(String name) {
438 public boolean needsSaving() {
439 return !fOptions.isEmpty();
445 public void putValue(String name, String value) {
446 throw new UnsupportedOperationException();
452 public void setDefault(String name, double value) {
453 throw new UnsupportedOperationException();
459 public void setDefault(String name, float value) {
460 throw new UnsupportedOperationException();
466 public void setDefault(String name, int value) {
467 throw new UnsupportedOperationException();
473 public void setDefault(String name, long value) {
474 throw new UnsupportedOperationException();
480 public void setDefault(String name, String defaultObject) {
481 throw new UnsupportedOperationException();
487 public void setDefault(String name, boolean value) {
488 throw new UnsupportedOperationException();
494 public void setToDefault(String name) {
495 throw new UnsupportedOperationException();
501 public void setValue(String name, double value) {
502 throw new UnsupportedOperationException();
508 public void setValue(String name, float value) {
509 throw new UnsupportedOperationException();
515 public void setValue(String name, int value) {
516 throw new UnsupportedOperationException();
522 public void setValue(String name, long value) {
523 throw new UnsupportedOperationException();
529 public void setValue(String name, String value) {
530 throw new UnsupportedOperationException();
536 public void setValue(String name, boolean value) {
537 throw new UnsupportedOperationException();
541 * Returns the adapted options Map.
543 * @return Returns the adapted options Map.
545 public Map getOptions() {
550 * Returns the mock-up preference store, events are received through this preference store.
551 * @return Returns the mock-up preference store.
553 public IPreferenceStore getMockupPreferenceStore() {
554 return fMockupPreferenceStore;
558 * Set the event filter to the given filter.
560 * @param filter The new filter.
562 public void setFilter(IPropertyChangeEventFilter filter) {
567 * Returns the event filter.
569 * @return The event filter.
571 public IPropertyChangeEventFilter getFilter() {
578 class MouseClickListener
579 implements KeyListener, MouseListener, MouseMoveListener, FocusListener, PaintListener, IPropertyChangeListener, IDocumentListener, ITextInputListener {
581 /** The session is active. */
582 private boolean fActive;
584 /** The currently active style range. */
585 private IRegion fActiveRegion;
586 /** The currently active style range as position. */
587 private Position fRememberedPosition;
588 /** The hand cursor. */
589 private Cursor fCursor;
591 /** The link color. */
592 private Color fColor;
593 /** The key modifier mask. */
594 private int fKeyModifierMask;
596 public void deactivate() {
600 public void deactivate(boolean redrawAll) {
604 repairRepresentation(redrawAll);
608 public void install() {
610 ISourceViewer sourceViewer = getSourceViewer();
611 if (sourceViewer == null)
614 StyledText text = sourceViewer.getTextWidget();
615 if (text == null || text.isDisposed())
618 updateColor(sourceViewer);
620 sourceViewer.addTextInputListener(this);
622 IDocument document = sourceViewer.getDocument();
623 if (document != null)
624 document.addDocumentListener(this);
626 text.addKeyListener(this);
627 text.addMouseListener(this);
628 text.addMouseMoveListener(this);
629 text.addFocusListener(this);
630 text.addPaintListener(this);
632 updateKeyModifierMask();
634 IPreferenceStore preferenceStore = getPreferenceStore();
635 preferenceStore.addPropertyChangeListener(this);
638 private void updateKeyModifierMask() {
639 String modifiers = getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
640 fKeyModifierMask = computeStateMask(modifiers);
641 if (fKeyModifierMask == -1) {
642 // Fallback to stored state mask
643 fKeyModifierMask = getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
647 private int computeStateMask(String modifiers) {
648 if (modifiers == null)
651 if (modifiers.length() == 0)
655 StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
656 while (modifierTokenizer.hasMoreTokens()) {
657 int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
658 if (modifier == 0 || (stateMask & modifier) == modifier)
660 stateMask = stateMask | modifier;
665 public void uninstall() {
667 if (fColor != null) {
672 if (fCursor != null) {
677 ISourceViewer sourceViewer = getSourceViewer();
678 if (sourceViewer == null)
681 sourceViewer.removeTextInputListener(this);
683 IDocument document = sourceViewer.getDocument();
684 if (document != null)
685 document.removeDocumentListener(this);
687 IPreferenceStore preferenceStore = getPreferenceStore();
688 if (preferenceStore != null)
689 preferenceStore.removePropertyChangeListener(this);
691 StyledText text = sourceViewer.getTextWidget();
692 if (text == null || text.isDisposed())
695 text.removeKeyListener(this);
696 text.removeMouseListener(this);
697 text.removeMouseMoveListener(this);
698 text.removeFocusListener(this);
699 text.removePaintListener(this);
703 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
705 public void propertyChange(PropertyChangeEvent event) {
706 if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
707 ISourceViewer viewer = getSourceViewer();
710 } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
711 updateKeyModifierMask();
715 private void updateColor(ISourceViewer viewer) {
719 StyledText text = viewer.getTextWidget();
720 if (text == null || text.isDisposed())
723 Display display = text.getDisplay();
724 fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR, display);
728 * Creates a color from the information stored in the given preference store.
729 * Returns <code>null</code> if there is no such information available.
731 private Color createColor(IPreferenceStore store, String key, Display display) {
735 if (store.contains(key)) {
737 if (store.isDefault(key))
738 rgb = PreferenceConverter.getDefaultColor(store, key);
740 rgb = PreferenceConverter.getColor(store, key);
743 return new Color(display, rgb);
749 private void repairRepresentation() {
750 repairRepresentation(false);
753 private void repairRepresentation(boolean redrawAll) {
755 if (fActiveRegion == null)
758 ISourceViewer viewer = getSourceViewer();
759 if (viewer != null) {
762 int offset = fActiveRegion.getOffset();
763 int length = fActiveRegion.getLength();
766 if (!redrawAll && viewer instanceof ITextViewerExtension2)
767 ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
769 viewer.invalidateTextPresentation();
772 if (viewer instanceof ITextViewerExtension3) {
773 ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
774 offset = extension.modelOffset2WidgetOffset(offset);
776 offset -= viewer.getVisibleRegion().getOffset();
779 StyledText text = viewer.getTextWidget();
781 text.redrawRange(offset, length, true);
782 } catch (IllegalArgumentException x) {
783 PHPeclipsePlugin.log(x);
787 fActiveRegion = null;
790 // will eventually be replaced by a method provided by jdt.core
791 private IRegion selectWord(IDocument document, int anchor) {
797 while (offset >= 0) {
798 c = document.getChar(offset);
799 if (!Character.isJavaIdentifierPart(c))
807 int length = document.getLength();
809 while (offset < length) {
810 c = document.getChar(offset);
811 if (!Character.isJavaIdentifierPart(c))
819 return new Region(start, 0);
821 return new Region(start + 1, end - start - 1);
823 } catch (BadLocationException x) {
828 IRegion getCurrentTextRegion(ISourceViewer viewer) {
830 int offset = getCurrentTextOffset(viewer);
835 // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
836 // if (input == null)
841 // IJavaElement[] elements= null;
842 // synchronized (input) {
843 // elements= ((ICodeAssist) input).codeSelect(offset, 0);
846 // if (elements == null || elements.length == 0)
849 // return selectWord(viewer.getDocument(), offset);
851 // } catch (JavaModelException e) {
856 private int getCurrentTextOffset(ISourceViewer viewer) {
859 StyledText text = viewer.getTextWidget();
860 if (text == null || text.isDisposed())
863 Display display = text.getDisplay();
864 Point absolutePosition = display.getCursorLocation();
865 Point relativePosition = text.toControl(absolutePosition);
867 int widgetOffset = text.getOffsetAtLocation(relativePosition);
868 if (viewer instanceof ITextViewerExtension3) {
869 ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
870 return extension.widgetOffset2ModelOffset(widgetOffset);
872 return widgetOffset + viewer.getVisibleRegion().getOffset();
875 } catch (IllegalArgumentException e) {
880 private void highlightRegion(ISourceViewer viewer, IRegion region) {
882 if (region.equals(fActiveRegion))
885 repairRepresentation();
887 StyledText text = viewer.getTextWidget();
888 if (text == null || text.isDisposed())
895 if (viewer instanceof ITextViewerExtension3) {
896 ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
897 IRegion widgetRange = extension.modelRange2WidgetRange(region);
898 if (widgetRange == null)
901 offset = widgetRange.getOffset();
902 length = widgetRange.getLength();
905 offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
906 length = region.getLength();
909 StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
910 Color foregroundColor = fColor;
911 Color backgroundColor = oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
912 StyleRange styleRange = new StyleRange(offset, length, foregroundColor, backgroundColor);
913 text.setStyleRange(styleRange);
916 text.redrawRange(offset, length, true);
918 fActiveRegion = region;
921 private void activateCursor(ISourceViewer viewer) {
922 StyledText text = viewer.getTextWidget();
923 if (text == null || text.isDisposed())
925 Display display = text.getDisplay();
927 fCursor = new Cursor(display, SWT.CURSOR_HAND);
928 text.setCursor(fCursor);
931 private void resetCursor(ISourceViewer viewer) {
932 StyledText text = viewer.getTextWidget();
933 if (text != null && !text.isDisposed())
934 text.setCursor(null);
936 if (fCursor != null) {
943 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
945 public void keyPressed(KeyEvent event) {
952 if (event.keyCode != fKeyModifierMask) {
959 // removed for #25871
961 // ISourceViewer viewer= getSourceViewer();
962 // if (viewer == null)
965 // IRegion region= getCurrentTextRegion(viewer);
966 // if (region == null)
969 // highlightRegion(viewer, region);
970 // activateCursor(viewer);
974 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
976 public void keyReleased(KeyEvent event) {
985 * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
987 public void mouseDoubleClick(MouseEvent e) {
990 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
992 public void mouseDown(MouseEvent event) {
997 if (event.stateMask != fKeyModifierMask) {
1002 if (event.button != 1) {
1009 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1011 public void mouseUp(MouseEvent e) {
1016 if (e.button != 1) {
1021 boolean wasActive = fCursor != null;
1026 IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1033 * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1035 public void mouseMove(MouseEvent event) {
1037 if (event.widget instanceof Control && !((Control) event.widget).isFocusControl()) {
1043 if (event.stateMask != fKeyModifierMask)
1045 // modifier was already pressed
1049 ISourceViewer viewer = getSourceViewer();
1050 if (viewer == null) {
1055 StyledText text = viewer.getTextWidget();
1056 if (text == null || text.isDisposed()) {
1061 if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() != 0) {
1066 IRegion region = getCurrentTextRegion(viewer);
1067 if (region == null || region.getLength() == 0) {
1068 repairRepresentation();
1072 highlightRegion(viewer, region);
1073 activateCursor(viewer);
1077 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1079 public void focusGained(FocusEvent e) {
1083 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1085 public void focusLost(FocusEvent event) {
1090 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1092 public void documentAboutToBeChanged(DocumentEvent event) {
1093 if (fActive && fActiveRegion != null) {
1094 fRememberedPosition = new Position(fActiveRegion.getOffset(), fActiveRegion.getLength());
1096 event.getDocument().addPosition(fRememberedPosition);
1097 } catch (BadLocationException x) {
1098 fRememberedPosition = null;
1104 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1106 public void documentChanged(DocumentEvent event) {
1107 if (fRememberedPosition != null && !fRememberedPosition.isDeleted()) {
1108 event.getDocument().removePosition(fRememberedPosition);
1109 fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength());
1111 fRememberedPosition = null;
1113 ISourceViewer viewer = getSourceViewer();
1114 if (viewer != null) {
1115 StyledText widget = viewer.getTextWidget();
1116 if (widget != null && !widget.isDisposed()) {
1117 widget.getDisplay().asyncExec(new Runnable() {
1127 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
1129 public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
1130 if (oldInput == null)
1133 oldInput.removeDocumentListener(this);
1137 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
1139 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
1140 if (newInput == null)
1142 newInput.addDocumentListener(this);
1146 * @see PaintListener#paintControl(PaintEvent)
1148 public void paintControl(PaintEvent event) {
1149 if (fActiveRegion == null)
1152 ISourceViewer viewer = getSourceViewer();
1156 StyledText text = viewer.getTextWidget();
1157 if (text == null || text.isDisposed())
1163 if (viewer instanceof ITextViewerExtension3) {
1165 ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1166 IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
1167 if (widgetRange == null)
1170 offset = widgetRange.getOffset();
1171 length = widgetRange.getLength();
1175 IRegion region = viewer.getVisibleRegion();
1176 if (!includes(region, fActiveRegion))
1179 offset = fActiveRegion.getOffset() - region.getOffset();
1180 length = fActiveRegion.getLength();
1184 Point minLocation = getMinimumLocation(text, offset, length);
1185 Point maxLocation = getMaximumLocation(text, offset, length);
1187 int x1 = minLocation.x;
1188 int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
1189 int y = minLocation.y + text.getLineHeight() - 1;
1192 if (fColor != null && !fColor.isDisposed())
1193 gc.setForeground(fColor);
1194 gc.drawLine(x1, y, x2, y);
1197 private boolean includes(IRegion region, IRegion position) {
1198 return position.getOffset() >= region.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
1201 private Point getMinimumLocation(StyledText text, int offset, int length) {
1202 Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
1204 for (int i = 0; i <= length; i++) {
1205 Point location = text.getLocationAtOffset(offset + i);
1207 if (location.x < minLocation.x)
1208 minLocation.x = location.x;
1209 if (location.y < minLocation.y)
1210 minLocation.y = location.y;
1216 private Point getMaximumLocation(StyledText text, int offset, int length) {
1217 Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
1219 for (int i = 0; i <= length; i++) {
1220 Point location = text.getLocationAtOffset(offset + i);
1222 if (location.x > maxLocation.x)
1223 maxLocation.x = location.x;
1224 if (location.y > maxLocation.y)
1225 maxLocation.y = location.y;
1233 * This action dispatches into two behaviours: If there is no current text
1234 * hover, the javadoc is displayed using information presenter. If there is
1235 * a current text hover, it is converted into a information presenter in
1236 * order to make it sticky.
1238 class InformationDispatchAction extends TextEditorAction {
1240 /** The wrapped text operation action. */
1241 private final TextOperationAction fTextOperationAction;
1244 * Creates a dispatch action.
1246 public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
1247 super(resourceBundle, prefix, PHPEditor.this);
1248 if (textOperationAction == null)
1249 throw new IllegalArgumentException();
1250 fTextOperationAction = textOperationAction;
1254 * @see org.eclipse.jface.action.IAction#run()
1258 ISourceViewer sourceViewer = getSourceViewer();
1259 if (sourceViewer == null) {
1260 fTextOperationAction.run();
1264 if (!(sourceViewer instanceof ITextViewerExtension2)) {
1265 fTextOperationAction.run();
1269 ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
1271 // does a text hover exist?
1272 ITextHover textHover = textViewerExtension2.getCurrentTextHover();
1273 if (textHover == null) {
1274 fTextOperationAction.run();
1278 Point hoverEventLocation = textViewerExtension2.getHoverEventLocation();
1279 int offset = computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
1281 fTextOperationAction.run();
1286 // get the text hover content
1287 IDocument document = sourceViewer.getDocument();
1288 String contentType = document.getContentType(offset);
1290 final IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
1291 if (hoverRegion == null)
1294 final String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);
1296 // with information provider
1297 IInformationProvider informationProvider = new IInformationProvider() {
1299 * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
1301 public IRegion getSubject(ITextViewer textViewer, int offset) {
1305 * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
1307 public String getInformation(ITextViewer textViewer, IRegion subject) {
1312 fInformationPresenter.setOffset(offset);
1313 fInformationPresenter.setInformationProvider(informationProvider, contentType);
1314 fInformationPresenter.showInformation();
1316 } catch (BadLocationException e) {
1320 // modified version from TextViewer
1321 private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
1323 StyledText styledText = textViewer.getTextWidget();
1324 IDocument document = textViewer.getDocument();
1326 if (document == null)
1330 int widgetLocation = styledText.getOffsetAtLocation(new Point(x, y));
1331 if (textViewer instanceof ITextViewerExtension3) {
1332 ITextViewerExtension3 extension = (ITextViewerExtension3) textViewer;
1333 return extension.widgetOffset2ModelOffset(widgetLocation);
1335 IRegion visibleRegion = textViewer.getVisibleRegion();
1336 return widgetLocation + visibleRegion.getOffset();
1338 } catch (IllegalArgumentException e) {
1345 // static protected class AnnotationAccess implements IAnnotationAccess {
1347 // * @see org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
1349 // public Object getType(Annotation annotation) {
1350 // if (annotation instanceof IJavaAnnotation) {
1351 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
1352 // // if (javaAnnotation.isRelevant())
1353 // // return javaAnnotation.getAnnotationType();
1359 // * @see org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
1361 // public boolean isMultiLine(Annotation annotation) {
1366 // * @see org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
1368 // public boolean isTemporary(Annotation annotation) {
1369 // if (annotation instanceof IJavaAnnotation) {
1370 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
1371 // if (javaAnnotation.isRelevant())
1372 // return javaAnnotation.isTemporary();
1378 private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
1380 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
1382 public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1383 handlePreferencePropertyChanged(event);
1388 * Finds and marks occurrence annotations.
1392 class OccurrencesFinderJob extends Job implements IDocumentListener {
1394 private IDocument fDocument;
1395 private boolean fCancelled= false;
1396 private IProgressMonitor fProgressMonitor;
1397 private Position[] fPositions;
1399 public OccurrencesFinderJob(IDocument document, Position[] positions) {
1400 super("Occurrences Marker"); //$NON-NLS-1$
1401 fDocument= document;
1402 fPositions= positions;
1403 fDocument.addDocumentListener(this);
1406 private boolean isCancelled() {
1407 return fCancelled || fProgressMonitor.isCanceled();
1411 * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
1413 public IStatus run(IProgressMonitor progressMonitor) {
1415 fProgressMonitor= progressMonitor;
1420 return Status.CANCEL_STATUS;
1422 ITextViewer textViewer= getViewer();
1423 if (textViewer == null)
1424 return Status.CANCEL_STATUS;
1426 IDocument document= textViewer.getDocument();
1427 if (document == null)
1428 return Status.CANCEL_STATUS;
1430 IDocumentProvider documentProvider= getDocumentProvider();
1431 if (documentProvider == null)
1432 return Status.CANCEL_STATUS;
1434 IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput());
1435 if (annotationModel == null)
1436 return Status.CANCEL_STATUS;
1438 // Add occurrence annotations
1439 int length= fPositions.length;
1440 Map annotationMap= new HashMap(length);
1441 for (int i= 0; i < length; i++) {
1444 return Status.CANCEL_STATUS;
1447 Position position= fPositions[i];
1449 // Create & add annotation
1451 message= document.get(position.offset, position.length);
1452 } catch (BadLocationException ex) {
1457 new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
1462 return Status.CANCEL_STATUS;
1464 synchronized (annotationModel) {
1465 if (annotationModel instanceof IAnnotationModelExtension) {
1466 ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
1468 removeOccurrenceAnnotations();
1469 Iterator iter= annotationMap.entrySet().iterator();
1470 while (iter.hasNext()) {
1471 Map.Entry mapEntry= (Map.Entry)iter.next();
1472 annotationModel.addAnnotation((Annotation)mapEntry.getKey(), (Position)mapEntry.getValue());
1475 fOccurrenceAnnotations= (Annotation[])annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
1478 fDocument.removeDocumentListener(this);
1480 return Status.OK_STATUS;
1484 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1486 public void documentAboutToBeChanged(DocumentEvent event) {
1491 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1493 public void documentChanged(DocumentEvent event) {
1499 * Holds the current occurrence annotations.
1502 private Annotation[] fOccurrenceAnnotations= null;
1504 private Job fOccurrencesFinderJob;
1506 /** Preference key for showing the line number ruler */
1507 // private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER;
1508 /** Preference key for the foreground color of the line numbers */
1509 // private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR;
1510 /** Preference key for the link color */
1511 private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
1512 /** Preference key for compiler task tags */
1513 private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
1515 // protected PHPActionGroup fActionGroups;
1516 // /** The outline page */
1517 // private AbstractContentOutlinePage fOutlinePage;
1518 /** The outline page */
1519 protected JavaOutlinePage fOutlinePage;
1520 /** Outliner context menu Id */
1521 protected String fOutlinerContextMenuId;
1523 * The editor selection changed listener.
1527 // private EditorSelectionChangedListener fEditorSelectionChangedListener;
1528 /** Indicates whether this editor should react on outline page selection changes */
1529 private int fIgnoreOutlinePageSelection;
1531 /** The outline page selection updater */
1532 private OutlinePageSelectionUpdater fUpdater;
1533 // protected PHPSyntaxParserThread fValidationThread = null;
1535 // private IPreferenceStore fPHPPrefStore;
1536 /** The selection changed listener */
1537 protected ISelectionChangedListener fSelectionChangedListener = new SelectionChangedListener();
1539 /** The editor's bracket matcher */
1540 private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS);
1543 /** The line number ruler column */
1544 // private LineNumberRulerColumn fLineNumberRulerColumn;
1545 /** This editor's encoding support */
1546 private DefaultEncodingSupport fEncodingSupport;
1547 /** The mouse listener */
1548 private MouseClickListener fMouseListener;
1550 protected CompositeActionGroup fActionGroups;
1551 protected CompositeActionGroup fContextMenuGroup;
1554 * This editor's projection support
1557 private ProjectionSupport fProjectionSupport;
1559 * This editor's projection model updater
1562 private IJavaFoldingStructureProvider fProjectionModelUpdater;
1564 * The action group for folding.
1568 private FoldingActionGroup fFoldingGroup;
1570 /** The information presenter. */
1571 private InformationPresenter fInformationPresenter;
1572 /** The annotation access */
1573 // protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
1574 /** The overview ruler */
1575 protected OverviewRuler isOverviewRulerVisible;
1576 /** The source viewer decoration support */
1577 //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
1578 /** The overview ruler */
1579 //protected OverviewRuler fOverviewRuler;
1581 /** The preference property change listener for java core. */
1582 private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
1584 * Returns the most narrow java element including the given offset
1586 * @param offset the offset inside of the requested element
1588 abstract protected IJavaElement getElementAt(int offset);
1591 * Returns the java element of this editor's input corresponding to the given IJavaElement
1593 abstract protected IJavaElement getCorrespondingElement(IJavaElement element);
1595 * Sets the input of the editor's outline page.
1597 abstract protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input);
1600 * Default constructor.
1602 public PHPEditor() {
1608 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
1610 protected void initializeKeyBindingScopes() {
1611 setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
1615 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
1617 protected void initializeEditor() {
1619 JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
1620 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this)); //, IJavaPartitions.JAVA_PARTITIONING));
1621 setRangeIndicator(new DefaultRangeIndicator());
1622 // IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore();
1623 // setPreferenceStore(store);
1624 IPreferenceStore store= createCombinedPreferenceStore(null);
1625 setPreferenceStore(store);
1627 // TODO changed in 3.x ?
1628 if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
1629 fUpdater= new OutlinePageSelectionUpdater();
1632 // IPreferenceStore store= createCombinedPreferenceStore(null);
1633 // setPreferenceStore(store);
1634 // JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
1635 // setSourceViewerConfiguration(new JavaSourceViewerConfiguration(textTools.getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING));
1636 // fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
1637 // fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
1638 // fMarkTypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
1639 // fMarkMethodOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
1640 // fMarkConstantOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
1641 // fMarkFieldOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
1642 // fMarkLocalVariableypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
1643 // fMarkExceptionOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
1644 // fMarkMethodExitPoints= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
1647 * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
1649 protected void updatePropertyDependentActions() {
1650 super.updatePropertyDependentActions();
1651 if (fEncodingSupport != null)
1652 fEncodingSupport.reset();
1656 * Update the hovering behavior depending on the preferences.
1658 private void updateHoverBehavior() {
1659 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
1660 String[] types = configuration.getConfiguredContentTypes(getSourceViewer());
1662 for (int i = 0; i < types.length; i++) {
1664 String t = types[i];
1666 int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
1668 ISourceViewer sourceViewer = getSourceViewer();
1669 if (sourceViewer instanceof ITextViewerExtension2) {
1670 if (stateMasks != null) {
1671 for (int j = 0; j < stateMasks.length; j++) {
1672 int stateMask = stateMasks[j];
1673 ITextHover textHover = configuration.getTextHover(sourceViewer, t, stateMask);
1674 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, stateMask);
1677 ITextHover textHover = configuration.getTextHover(sourceViewer, t);
1678 ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
1681 sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t);
1685 public void updatedTitleImage(Image image) {
1686 setTitleImage(image);
1689 * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
1691 public Object getViewPartInput() {
1692 return getEditorInput().getAdapter(IResource.class);
1695 * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
1697 protected void doSetSelection(ISelection selection) {
1698 super.doSetSelection(selection);
1699 synchronizeOutlinePageSelection();
1701 boolean isFoldingEnabled() {
1702 return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
1705 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.
1706 * widgets.Composite)
1708 public void createPartControl(Composite parent) {
1709 super.createPartControl(parent);
1711 //fSourceViewerDecorationSupport.install(getPreferenceStore());
1713 ProjectionViewer projectionViewer= (ProjectionViewer) getSourceViewer();
1715 fProjectionSupport= new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
1716 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
1717 fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
1718 fProjectionSupport.setHoverControlCreator(new IInformationControlCreator() {
1719 public IInformationControl createInformationControl(Shell shell) {
1720 return new CustomSourceInformationControl(shell, IDocument.DEFAULT_CONTENT_TYPE);
1723 fProjectionSupport.install();
1725 fProjectionModelUpdater= PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
1726 if (fProjectionModelUpdater != null)
1727 fProjectionModelUpdater.install(this, projectionViewer);
1729 if (isFoldingEnabled())
1730 projectionViewer.doOperation(ProjectionViewer.TOGGLE);
1731 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
1732 preferences.addPropertyChangeListener(fPropertyChangeListener);
1734 IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
1735 public IInformationControl createInformationControl(Shell parent) {
1736 boolean cutDown = false;
1737 int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
1738 return new DefaultInformationControl(parent, SWT.RESIZE, style, new HTMLTextPresenter(cutDown));
1742 fInformationPresenter = new InformationPresenter(informationControlCreator);
1743 fInformationPresenter.setSizeConstraints(60, 10, true, true);
1744 fInformationPresenter.install(getSourceViewer());
1749 * Returns this document's complete text.
1751 * @return the document's complete text
1753 public String get() {
1754 IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
1759 * Sets the outliner's context menu ID.
1761 protected void setOutlinerContextMenuId(String menuId) {
1762 fOutlinerContextMenuId = menuId;
1766 * Returns the standard action group of this editor.
1768 protected ActionGroup getActionGroup() {
1769 return fActionGroups;
1772 // public JavaOutlinePage getfOutlinePage() {
1773 // return fOutlinePage;
1776 /** The <code>PHPEditor</code> implementation of this
1777 * <code>AbstractTextEditor</code> method extend the
1778 * actions to add those specific to the receiver
1780 protected void createActions() {
1781 super.createActions();
1783 fFoldingGroup= new FoldingActionGroup(this, getViewer());
1785 ResourceAction resAction= new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
1786 resAction= new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
1787 resAction.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
1788 setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
1789 // WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
1791 Action action= new GotoMatchingBracketAction(this);
1792 action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
1793 setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
1795 // action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.", this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
1796 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
1797 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action);
1798 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.SHOW_OUTLINE_ACTION);
1800 // action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.", this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$
1801 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE);
1802 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE, action);
1803 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.OPEN_STRUCTURE_ACTION);
1805 // action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.", this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
1806 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY);
1807 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY, action);
1808 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.OPEN_HIERARCHY_ACTION);
1810 fEncodingSupport= new DefaultEncodingSupport();
1811 fEncodingSupport.initialize(this);
1813 // fSelectionHistory= new SelectionHistory(this);
1815 // action= new StructureSelectEnclosingAction(this, fSelectionHistory);
1816 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
1817 // setAction(StructureSelectionAction.ENCLOSING, action);
1819 // action= new StructureSelectNextAction(this, fSelectionHistory);
1820 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
1821 // setAction(StructureSelectionAction.NEXT, action);
1823 // action= new StructureSelectPreviousAction(this, fSelectionHistory);
1824 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
1825 // setAction(StructureSelectionAction.PREVIOUS, action);
1827 // StructureSelectHistoryAction historyAction= new StructureSelectHistoryAction(this, fSelectionHistory);
1828 // historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
1829 // setAction(StructureSelectionAction.HISTORY, historyAction);
1830 // fSelectionHistory.setHistoryAction(historyAction);
1832 // action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this);
1833 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
1834 // setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action);
1836 // action= GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this);
1837 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
1838 // setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
1840 // action= new QuickFormatAction();
1841 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT);
1842 // setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action);
1844 // action= new RemoveOccurrenceAnnotations(this);
1845 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
1846 // setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$
1848 // add annotation actions
1849 action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
1850 setAction("AnnotationAction", action); //$NON-NLS-1$
1853 private void internalDoSetInput(IEditorInput input) throws CoreException {
1854 super.doSetInput(input);
1856 if (fEncodingSupport != null)
1857 fEncodingSupport.reset();
1859 setOutlinePageInput(fOutlinePage, input);
1861 if (fProjectionModelUpdater != null)
1862 fProjectionModelUpdater.initialize();
1864 // if (isShowingOverrideIndicators())
1865 // installOverrideIndicator(true);
1869 * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)
1872 protected void setPreferenceStore(IPreferenceStore store) {
1873 super.setPreferenceStore(store);
1874 if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) {
1875 JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
1876 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools.getColorManager(), store, this, IPHPPartitions.PHP_PARTITIONING));
1878 if (getSourceViewer() instanceof JavaSourceViewer)
1879 ((JavaSourceViewer)getSourceViewer()).setPreferenceStore(store);
1881 /** The <code>PHPEditor</code> implementation of this
1882 * <code>AbstractTextEditor</code> method performs any extra
1883 * disposal actions required by the php editor.
1885 public void dispose() {
1886 if (fProjectionModelUpdater != null) {
1887 fProjectionModelUpdater.uninstall();
1888 fProjectionModelUpdater= null;
1891 if (fProjectionSupport != null) {
1892 fProjectionSupport.dispose();
1893 fProjectionSupport= null;
1895 // PHPEditorEnvironment.disconnect(this);
1896 if (fOutlinePage != null)
1897 fOutlinePage.setInput(null);
1899 if (fActionGroups != null)
1900 fActionGroups.dispose();
1902 if (isBrowserLikeLinks())
1903 disableBrowserLikeLinks();
1905 if (fEncodingSupport != null) {
1906 fEncodingSupport.dispose();
1907 fEncodingSupport = null;
1910 if (fPropertyChangeListener != null) {
1911 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
1912 preferences.removePropertyChangeListener(fPropertyChangeListener);
1913 fPropertyChangeListener = null;
1916 // if (fSourceViewerDecorationSupport != null) {
1917 // fSourceViewerDecorationSupport.dispose();
1918 // fSourceViewerDecorationSupport = null;
1921 if (fBracketMatcher != null) {
1922 fBracketMatcher.dispose();
1923 fBracketMatcher = null;
1928 /** The <code>PHPEditor</code> implementation of this
1929 * <code>AbstractTextEditor</code> method performs any extra
1930 * revert behavior required by the php editor.
1932 // public void doRevertToSaved() {
1933 // super.doRevertToSaved();
1934 // if (fOutlinePage != null)
1935 // fOutlinePage.update();
1938 /** The <code>PHPEditor</code> implementation of this
1939 * <code>AbstractTextEditor</code> method performs any extra
1940 * save behavior required by the php editor.
1942 // public void doSave(IProgressMonitor monitor) {
1943 // super.doSave(monitor);
1944 // compile or not, according to the user preferences
1945 // IPreferenceStore store = getPreferenceStore();
1947 // the parse on save was changed to the eclipse "builders" concept
1948 // if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
1949 // IAction a = PHPParserAction.getInstance();
1954 // if (SWT.getPlatform().equals("win32")) {
1955 // IAction a = ShowExternalPreviewAction.getInstance();
1959 // if (fOutlinePage != null)
1960 // fOutlinePage.update();
1963 /** The <code>PHPEditor</code> implementation of this
1964 * <code>AbstractTextEditor</code> method performs any extra
1965 * save as behavior required by the php editor.
1967 // public void doSaveAs() {
1968 // super.doSaveAs();
1969 // if (fOutlinePage != null)
1970 // fOutlinePage.update();
1973 * @see StatusTextEditor#getStatusHeader(IStatus)
1975 protected String getStatusHeader(IStatus status) {
1976 if (fEncodingSupport != null) {
1977 String message = fEncodingSupport.getStatusHeader(status);
1978 if (message != null)
1981 return super.getStatusHeader(status);
1985 * @see StatusTextEditor#getStatusBanner(IStatus)
1987 protected String getStatusBanner(IStatus status) {
1988 if (fEncodingSupport != null) {
1989 String message = fEncodingSupport.getStatusBanner(status);
1990 if (message != null)
1993 return super.getStatusBanner(status);
1997 * @see StatusTextEditor#getStatusMessage(IStatus)
1999 protected String getStatusMessage(IStatus status) {
2000 if (fEncodingSupport != null) {
2001 String message = fEncodingSupport.getStatusMessage(status);
2002 if (message != null)
2005 return super.getStatusMessage(status);
2007 /** The <code>PHPEditor</code> implementation of this
2008 * <code>AbstractTextEditor</code> method performs sets the
2009 * input of the outline page after AbstractTextEditor has set input.
2011 // protected void doSetInput(IEditorInput input) throws CoreException {
2012 // super.doSetInput(input);
2014 // if (fEncodingSupport != null)
2015 // fEncodingSupport.reset();
2016 // if (fOutlinePage != null)
2017 // fOutlinePage.setInput(input);
2018 // // setOutlinePageInput(fOutlinePage, input);
2020 protected void doSetInput(IEditorInput input) throws CoreException {
2021 super.doSetInput(input);
2022 if (fEncodingSupport != null)
2023 fEncodingSupport.reset();
2024 setOutlinePageInput(fOutlinePage, input);
2027 * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
2029 // public Object getViewPartInput() {
2030 // return getEditorInput().getAdapter(IFile.class);
2033 /** The <code>PHPEditor</code> implementation of this
2034 * <code>AbstractTextEditor</code> method adds any
2035 * PHPEditor specific entries.
2037 public void editorContextMenuAboutToShow(MenuManager menu) {
2038 super.editorContextMenuAboutToShow(menu);
2039 menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, new Separator(IContextMenuConstants.GROUP_OPEN));
2040 menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));
2042 ActionContext context = new ActionContext(getSelectionProvider().getSelection());
2043 fContextMenuGroup.setContext(context);
2044 fContextMenuGroup.fillContextMenu(menu);
2045 fContextMenuGroup.setContext(null);
2046 // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$
2048 // ActionContext context =
2049 // new ActionContext(getSelectionProvider().getSelection());
2050 // fContextMenuGroup.setContext(context);
2051 // fContextMenuGroup.fillContextMenu(menu);
2052 // fContextMenuGroup.setContext(null);
2056 * Creates the outline page used with this editor.
2058 protected JavaOutlinePage createOutlinePage() {
2060 // AbstractContentOutlinePage page = new PHPContentOutlinePage(getDocumentProvider(), this);
2062 // page.addSelectionChangedListener(fSelectionChangedListener);
2063 // // setOutlinePageInput(page, getEditorInput());
2064 // if (getEditorInput() != null)
2065 // fOutlinePage.setInput(getEditorInput());
2068 JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this);
2070 page.addSelectionChangedListener(fSelectionChangedListener);
2071 setOutlinePageInput(page, getEditorInput());
2077 * Informs the editor that its outliner has been closed.
2079 public void outlinePageClosed() {
2080 if (fOutlinePage != null) {
2081 fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
2082 fOutlinePage = null;
2083 resetHighlightRange();
2087 * Synchronizes the outliner selection with the actual cursor
2088 * position in the editor.
2090 public void synchronizeOutlinePageSelection() {
2092 // if (isEditingScriptRunning())
2095 ISourceViewer sourceViewer = getSourceViewer();
2096 if (sourceViewer == null || fOutlinePage == null)
2099 StyledText styledText = sourceViewer.getTextWidget();
2100 if (styledText == null)
2104 if (sourceViewer instanceof ITextViewerExtension3) {
2105 ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
2106 caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
2108 int offset = sourceViewer.getVisibleRegion().getOffset();
2109 caret = offset + styledText.getCaretOffset();
2112 IJavaElement element = getElementAt(caret);
2113 if (element instanceof ISourceReference) {
2114 fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
2115 fOutlinePage.select((ISourceReference) element);
2116 fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
2120 protected void setSelection(ISourceReference reference, boolean moveCursor) {
2122 ISelection selection = getSelectionProvider().getSelection();
2123 if (selection instanceof TextSelection) {
2124 TextSelection textSelection = (TextSelection) selection;
2125 if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
2126 markInNavigationHistory();
2129 if (reference != null) {
2131 StyledText textWidget = null;
2133 ISourceViewer sourceViewer = getSourceViewer();
2134 if (sourceViewer != null)
2135 textWidget = sourceViewer.getTextWidget();
2137 if (textWidget == null)
2142 ISourceRange range = reference.getSourceRange();
2146 int offset = range.getOffset();
2147 int length = range.getLength();
2149 if (offset < 0 || length < 0)
2152 textWidget.setRedraw(false);
2154 setHighlightRange(offset, length, moveCursor);
2162 if (reference instanceof IMember) {
2163 range = ((IMember) reference).getNameRange();
2164 if (range != null) {
2165 offset = range.getOffset();
2166 length = range.getLength();
2169 // else if (reference instanceof IImportDeclaration) {
2170 // String name= ((IImportDeclaration) reference).getElementName();
2171 // if (name != null && name.length() > 0) {
2172 // String content= reference.getSource();
2173 // if (content != null) {
2174 // offset= range.getOffset() + content.indexOf(name);
2175 // length= name.length();
2178 // } else if (reference instanceof IPackageDeclaration) {
2179 // String name= ((IPackageDeclaration) reference).getElementName();
2180 // if (name != null && name.length() > 0) {
2181 // String content= reference.getSource();
2182 // if (content != null) {
2183 // offset= range.getOffset() + content.indexOf(name);
2184 // length= name.length();
2189 if (offset > -1 && length > 0) {
2190 sourceViewer.revealRange(offset, length);
2191 sourceViewer.setSelectedRange(offset, length);
2194 } catch (JavaModelException x) {
2195 } catch (IllegalArgumentException x) {
2197 if (textWidget != null)
2198 textWidget.setRedraw(true);
2201 } else if (moveCursor) {
2202 resetHighlightRange();
2205 markInNavigationHistory();
2208 public void setSelection(IJavaElement element) {
2210 if (element == null || element instanceof ICompilationUnit) { // || element instanceof IClassFile) {
2212 * If the element is an ICompilationUnit this unit is either the input
2213 * of this editor or not being displayed. In both cases, nothing should
2214 * happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
2219 IJavaElement corresponding = getCorrespondingElement(element);
2220 if (corresponding instanceof ISourceReference) {
2221 ISourceReference reference = (ISourceReference) corresponding;
2222 // set hightlight range
2223 setSelection(reference, true);
2224 // set outliner selection
2225 if (fOutlinePage != null) {
2226 fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
2227 fOutlinePage.select(reference);
2228 fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
2233 public synchronized void editingScriptStarted() {
2234 ++ fIgnoreOutlinePageSelection;
2237 public synchronized void editingScriptEnded() {
2238 -- fIgnoreOutlinePageSelection;
2241 public synchronized boolean isEditingScriptRunning() {
2242 return (fIgnoreOutlinePageSelection > 0);
2245 /** The <code>PHPEditor</code> implementation of this
2246 * <code>AbstractTextEditor</code> method performs gets
2247 * the java content outline page if request is for a an
2250 public Object getAdapter(Class required) {
2252 if (IContentOutlinePage.class.equals(required)) {
2253 if (fOutlinePage == null)
2254 fOutlinePage = createOutlinePage();
2255 return fOutlinePage;
2258 if (IEncodingSupport.class.equals(required))
2259 return fEncodingSupport;
2261 if (required == IShowInTargetList.class) {
2262 return new IShowInTargetList() {
2263 public String[] getShowInTargetIds() {
2264 return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
2269 if (fProjectionSupport != null) {
2270 Object adapter= fProjectionSupport.getAdapter(getSourceViewer(), required);
2271 if (adapter != null)
2275 return super.getAdapter(required);
2277 // public Object getAdapter(Class required) {
2278 // if (IContentOutlinePage.class.equals(required)) {
2279 // if (fOutlinePage == null) {
2280 // fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
2281 // if (getEditorInput() != null)
2282 // fOutlinePage.setInput(getEditorInput());
2284 // return fOutlinePage;
2287 // if (IEncodingSupport.class.equals(required))
2288 // return fEncodingSupport;
2290 // return super.getAdapter(required);
2293 protected void doSelectionChanged(SelectionChangedEvent event) {
2294 ISourceReference reference = null;
2296 ISelection selection = event.getSelection();
2297 Iterator iter = ((IStructuredSelection) selection).iterator();
2298 while (iter.hasNext()) {
2299 Object o = iter.next();
2300 if (o instanceof ISourceReference) {
2301 reference = (ISourceReference) o;
2306 if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
2307 PHPeclipsePlugin.getActivePage().bringToTop(this);
2310 editingScriptStarted();
2311 setSelection(reference, !isActivePart());
2313 editingScriptEnded();
2317 * @see AbstractTextEditor#adjustHighlightRange(int, int)
2319 protected void adjustHighlightRange(int offset, int length) {
2323 IJavaElement element = getElementAt(offset);
2324 while (element instanceof ISourceReference) {
2325 ISourceRange range = ((ISourceReference) element).getSourceRange();
2326 if (offset < range.getOffset() + range.getLength() && range.getOffset() < offset + length) {
2327 setHighlightRange(range.getOffset(), range.getLength(), true);
2328 if (fOutlinePage != null) {
2329 fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
2330 fOutlinePage.select((ISourceReference) element);
2331 fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
2335 element = element.getParent();
2338 } catch (JavaModelException x) {
2339 PHPeclipsePlugin.log(x.getStatus());
2342 resetHighlightRange();
2344 protected boolean isActivePart() {
2345 IWorkbenchWindow window = getSite().getWorkbenchWindow();
2346 IPartService service = window.getPartService();
2347 IWorkbenchPart part = service.getActivePart();
2348 return part != null && part.equals(this);
2352 // public void openContextHelp() {
2353 // IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
2354 // ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
2355 // int pos = selection.getOffset();
2356 // String word = getFunctionName(doc, pos);
2357 // openContextHelp(word);
2360 // private void openContextHelp(String word) {
2364 // public static void open(String word) {
2365 // IHelp help = WorkbenchHelp.getHelpSupport();
2366 // if (help != null) {
2367 // IHelpResource helpResource = new PHPFunctionHelpResource(word);
2368 // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
2370 // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
2374 // private String getFunctionName(IDocument doc, int pos) {
2375 // Point word = PHPWordExtractor.findWord(doc, pos);
2376 // if (word != null) {
2378 // return doc.get(word.x, word.y).replace('_', '-');
2379 // } catch (BadLocationException e) {
2386 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
2388 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
2392 ISourceViewer sourceViewer = getSourceViewer();
2393 if (sourceViewer == null)
2396 String property = event.getProperty();
2398 if (PreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
2399 Object value = event.getNewValue();
2400 if (value instanceof Integer) {
2401 sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
2402 } else if (value instanceof String) {
2403 sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
2408 // if (OVERVIEW_RULER.equals(property)) {
2409 // if (isOverviewRulerVisible())
2410 // showOverviewRuler();
2412 // hideOverviewRuler();
2416 // if (LINE_NUMBER_RULER.equals(property)) {
2417 // if (isLineNumberRulerVisible())
2418 // showLineNumberRuler();
2420 // hideLineNumberRuler();
2424 // if (fLineNumberRulerColumn != null
2425 // && (LINE_NUMBER_COLOR.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
2427 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
2430 if (isJavaEditorHoverProperty(property))
2431 updateHoverBehavior();
2433 if (BROWSER_LIKE_LINKS.equals(property)) {
2434 if (isBrowserLikeLinks())
2435 enableBrowserLikeLinks();
2437 disableBrowserLikeLinks();
2441 // if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) {
2442 // if ((event.getNewValue() instanceof Boolean) && ((Boolean)event.getNewValue()).booleanValue())
2443 // fEditorSelectionChangedListener.selectionChanged();
2447 if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) {
2448 if (event.getNewValue() instanceof Boolean) {
2449 Boolean disable= (Boolean) event.getNewValue();
2450 enableOverwriteMode(!disable.booleanValue());
2455 // if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) {
2456 // if (event.getNewValue() instanceof Boolean) {
2457 // boolean markOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue();
2458 // if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) {
2459 // fMarkOccurrenceAnnotations= markOccurrenceAnnotations;
2460 // if (!fMarkOccurrenceAnnotations)
2461 // uninstallOccurrencesFinder();
2463 // installOccurrencesFinder();
2467 // if (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) {
2468 // if (event.getNewValue() instanceof Boolean) {
2469 // boolean stickyOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue();
2470 // if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations) {
2471 // fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations;
2472 //// if (!fMarkOccurrenceAnnotations)
2473 //// uninstallOccurrencesFinder();
2475 //// installOccurrencesFinder();
2479 if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
2480 if (sourceViewer instanceof ProjectionViewer) {
2481 ProjectionViewer projectionViewer= (ProjectionViewer) sourceViewer;
2482 if (fProjectionModelUpdater != null)
2483 fProjectionModelUpdater.uninstall();
2484 // either freshly enabled or provider changed
2485 fProjectionModelUpdater= PHPeclipsePlugin.getDefault().getFoldingStructureProviderRegistry().getCurrentFoldingProvider();
2486 if (fProjectionModelUpdater != null) {
2487 fProjectionModelUpdater.install(this, projectionViewer);
2493 super.handlePreferenceStoreChanged(event);
2498 // * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
2500 // protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
2504 // ISourceViewer sourceViewer = getSourceViewer();
2505 // if (sourceViewer == null)
2508 // String property = event.getProperty();
2510 // // if (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
2511 // // Object value= event.getNewValue();
2512 // // if (value instanceof Integer) {
2513 // // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
2514 // // } else if (value instanceof String) {
2515 // // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
2520 // if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
2521 // if (isLineNumberRulerVisible())
2522 // showLineNumberRuler();
2524 // hideLineNumberRuler();
2528 // if (fLineNumberRulerColumn != null
2529 // && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
2530 // || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
2531 // || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
2533 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
2537 // super.handlePreferenceStoreChanged(event);
2541 // private boolean isJavaEditorHoverProperty(String property) {
2542 // return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
2543 // || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
2544 // || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
2545 // || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
2546 // || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
2547 // || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
2548 // || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
2549 // || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
2553 * Shows the line number ruler column.
2555 // private void showLineNumberRuler() {
2556 // IVerticalRuler v = getVerticalRuler();
2557 // if (v instanceof CompositeRuler) {
2558 // CompositeRuler c = (CompositeRuler) v;
2559 // c.addDecorator(1, createLineNumberRulerColumn());
2562 private boolean isJavaEditorHoverProperty(String property) {
2563 return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property);
2567 * Return whether the browser like links should be enabled
2568 * according to the preference store settings.
2569 * @return <code>true</code> if the browser like links should be enabled
2571 private boolean isBrowserLikeLinks() {
2572 IPreferenceStore store = getPreferenceStore();
2573 return store.getBoolean(BROWSER_LIKE_LINKS);
2577 * Enables browser like links.
2579 private void enableBrowserLikeLinks() {
2580 if (fMouseListener == null) {
2581 fMouseListener = new MouseClickListener();
2582 fMouseListener.install();
2587 * Disables browser like links.
2589 private void disableBrowserLikeLinks() {
2590 if (fMouseListener != null) {
2591 fMouseListener.uninstall();
2592 fMouseListener = null;
2596 * Handles a property change event describing a change
2597 * of the java core's preferences and updates the preference
2598 * related editor properties.
2600 * @param event the property change event
2602 protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
2603 if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
2604 ISourceViewer sourceViewer = getSourceViewer();
2605 if (sourceViewer != null
2606 && affectsTextPresentation(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue())))
2607 sourceViewer.invalidateTextPresentation();
2612 * Return whether the line number ruler column should be
2613 * visible according to the preference store settings.
2614 * @return <code>true</code> if the line numbers should be visible
2616 // protected boolean isLineNumberRulerVisible() {
2617 // IPreferenceStore store = getPreferenceStore();
2618 // return store.getBoolean(LINE_NUMBER_RULER);
2621 * Hides the line number ruler column.
2623 // private void hideLineNumberRuler() {
2624 // IVerticalRuler v = getVerticalRuler();
2625 // if (v instanceof CompositeRuler) {
2626 // CompositeRuler c = (CompositeRuler) v;
2628 // c.removeDecorator(1);
2629 // } catch (Throwable e) {
2635 * @see AbstractTextEditor#handleCursorPositionChanged()
2637 protected void handleCursorPositionChanged() {
2638 super.handleCursorPositionChanged();
2639 if (!isEditingScriptRunning() && fUpdater != null)
2643 * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced()
2645 protected void handleElementContentReplaced() {
2646 super.handleElementContentReplaced();
2647 if (fProjectionModelUpdater != null)
2648 fProjectionModelUpdater.initialize();
2651 * Initializes the given line number ruler column from the preference store.
2652 * @param rulerColumn the ruler column to be initialized
2654 // protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) {
2655 // JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
2656 // IColorManager manager = textTools.getColorManager();
2658 // IPreferenceStore store = getPreferenceStore();
2659 // if (store != null) {
2662 // // foreground color
2663 // if (store.contains(LINE_NUMBER_COLOR)) {
2664 // if (store.isDefault(LINE_NUMBER_COLOR))
2665 // rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
2667 // rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
2669 // rulerColumn.setForeground(manager.getColor(rgb));
2672 // // background color
2673 // if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
2674 // if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
2675 // if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
2676 // rgb = PreferenceConverter.getDefaultColor(store, PREFERENCE_COLOR_BACKGROUND);
2678 // rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
2681 // rulerColumn.setBackground(manager.getColor(rgb));
2686 * Creates a new line number ruler column that is appropriately initialized.
2688 // protected IVerticalRulerColumn createLineNumberRulerColumn() {
2689 // fLineNumberRulerColumn = new LineNumberRulerColumn();
2690 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
2691 // return fLineNumberRulerColumn;
2695 * @see AbstractTextEditor#createVerticalRuler()
2697 // protected IVerticalRuler createVerticalRuler() {
2698 // CompositeRuler ruler = new CompositeRuler();
2699 // ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
2700 // if (isLineNumberRulerVisible())
2701 // ruler.addDecorator(1, createLineNumberRulerColumn());
2705 private static IRegion getSignedSelection(ITextViewer viewer) {
2707 StyledText text = viewer.getTextWidget();
2708 int caretOffset = text.getCaretOffset();
2709 Point selection = text.getSelection();
2713 if (caretOffset == selection.x) {
2714 offset = selection.y;
2715 length = selection.x - selection.y;
2719 offset = selection.x;
2720 length = selection.y - selection.x;
2723 return new Region(offset, length);
2726 /** Preference key for matching brackets */
2727 protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
2728 /** Preference key for matching brackets color */
2729 protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
2730 /** Preference key for highlighting current line */
2731 protected final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
2732 /** Preference key for highlight color of current line */
2733 protected final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
2734 /** Preference key for showing print marging ruler */
2735 protected final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
2736 /** Preference key for print margin ruler color */
2737 protected final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
2738 /** Preference key for print margin ruler column */
2739 protected final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
2740 /** Preference key for error indication */
2741 // protected final static String ERROR_INDICATION = PreferenceConstants.EDITOR_PROBLEM_INDICATION;
2742 /** Preference key for error color */
2743 // protected final static String ERROR_INDICATION_COLOR = PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
2744 /** Preference key for warning indication */
2745 // protected final static String WARNING_INDICATION = PreferenceConstants.EDITOR_WARNING_INDICATION;
2746 /** Preference key for warning color */
2747 // protected final static String WARNING_INDICATION_COLOR = PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
2748 /** Preference key for task indication */
2749 protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
2750 /** Preference key for task color */
2751 protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
2752 /** Preference key for bookmark indication */
2753 protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
2754 /** Preference key for bookmark color */
2755 protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
2756 /** Preference key for search result indication */
2757 protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
2758 /** Preference key for search result color */
2759 protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
2760 /** Preference key for unknown annotation indication */
2761 protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
2762 /** Preference key for unknown annotation color */
2763 protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
2764 /** Preference key for shwoing the overview ruler */
2765 protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
2766 /** Preference key for error indication in overview ruler */
2767 protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
2768 /** Preference key for warning indication in overview ruler */
2769 protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
2770 /** Preference key for task indication in overview ruler */
2771 protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
2772 /** Preference key for bookmark indication in overview ruler */
2773 protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
2774 /** Preference key for search result indication in overview ruler */
2775 protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
2776 /** Preference key for unknown annotation indication in overview ruler */
2777 protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
2778 // /** Preference key for compiler task tags */
2779 // private final static String COMPILER_TASK_TAGS= JavaCore.COMPILER_TASK_TAGS;
2780 /** Preference key for browser like links */
2781 private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS;
2782 /** Preference key for key modifier of browser like links */
2783 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER;
2785 * Preference key for key modifier mask of browser like links.
2786 * The value is only used if the value of <code>EDITOR_BROWSER_LIKE_LINKS</code>
2787 * cannot be resolved to valid SWT modifier bits.
2791 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
2793 private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
2795 private static boolean isBracket(char character) {
2796 for (int i = 0; i != BRACKETS.length; ++i)
2797 if (character == BRACKETS[i])
2802 private static boolean isSurroundedByBrackets(IDocument document, int offset) {
2803 if (offset == 0 || offset == document.getLength())
2807 return isBracket(document.getChar(offset - 1)) && isBracket(document.getChar(offset));
2809 } catch (BadLocationException e) {
2814 // protected void configureSourceViewerDecorationSupport() {
2816 // fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
2818 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2819 // AnnotationType.UNKNOWN,
2820 // UNKNOWN_INDICATION_COLOR,
2821 // UNKNOWN_INDICATION,
2822 // UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
2824 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2825 // AnnotationType.BOOKMARK,
2826 // BOOKMARK_INDICATION_COLOR,
2827 // BOOKMARK_INDICATION,
2828 // BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
2830 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2831 // AnnotationType.TASK,
2832 // TASK_INDICATION_COLOR,
2834 // TASK_INDICATION_IN_OVERVIEW_RULER,
2836 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2837 // AnnotationType.SEARCH,
2838 // SEARCH_RESULT_INDICATION_COLOR,
2839 // SEARCH_RESULT_INDICATION,
2840 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
2842 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2843 // AnnotationType.WARNING,
2844 // WARNING_INDICATION_COLOR,
2845 // WARNING_INDICATION,
2846 // WARNING_INDICATION_IN_OVERVIEW_RULER,
2848 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
2849 // AnnotationType.ERROR,
2850 // ERROR_INDICATION_COLOR,
2851 // ERROR_INDICATION,
2852 // ERROR_INDICATION_IN_OVERVIEW_RULER,
2855 // fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR);
2856 // fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
2857 // fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
2859 // fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
2863 * Returns the Java element wrapped by this editors input.
2865 * @return the Java element wrapped by this editors input.
2868 abstract protected IJavaElement getInputJavaElement();
2871 * Jumps to the matching bracket.
2873 public void gotoMatchingBracket() {
2875 ISourceViewer sourceViewer = getSourceViewer();
2876 IDocument document = sourceViewer.getDocument();
2877 if (document == null)
2880 IRegion selection = getSignedSelection(sourceViewer);
2882 int selectionLength = Math.abs(selection.getLength());
2883 if (selectionLength > 1) {
2884 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$
2885 sourceViewer.getTextWidget().getDisplay().beep();
2890 int sourceCaretOffset = selection.getOffset() + selection.getLength();
2891 if (isSurroundedByBrackets(document, sourceCaretOffset))
2892 sourceCaretOffset -= selection.getLength();
2894 IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
2895 if (region == null) {
2896 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$
2897 sourceViewer.getTextWidget().getDisplay().beep();
2901 int offset = region.getOffset();
2902 int length = region.getLength();
2907 int anchor = fBracketMatcher.getAnchor();
2908 int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
2910 boolean visible = false;
2911 if (sourceViewer instanceof ITextViewerExtension3) {
2912 ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
2913 visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
2915 IRegion visibleRegion = sourceViewer.getVisibleRegion();
2916 visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength());
2920 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$
2921 sourceViewer.getTextWidget().getDisplay().beep();
2925 if (selection.getLength() < 0)
2926 targetOffset -= selection.getLength();
2928 sourceViewer.setSelectedRange(targetOffset, selection.getLength());
2929 sourceViewer.revealRange(targetOffset, selection.getLength());
2932 * Ses the given message as error message to this editor's status line.
2933 * @param msg message to be set
2935 protected void setStatusLineErrorMessage(String msg) {
2936 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
2937 if (statusLine != null)
2938 statusLine.setMessage(true, msg, null);
2942 * Returns a segmentation of the line of the given document appropriate for bidi rendering.
2943 * The default implementation returns only the string literals of a php code line as segments.
2945 * @param document the document
2946 * @param lineOffset the offset of the line
2947 * @return the line's bidi segmentation
2948 * @throws BadLocationException in case lineOffset is not valid in document
2950 public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException {
2952 IRegion line = document.getLineInformationOfOffset(lineOffset);
2953 ITypedRegion[] linePartitioning = document.computePartitioning(lineOffset, line.getLength());
2955 List segmentation = new ArrayList();
2956 for (int i = 0; i < linePartitioning.length; i++) {
2957 if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType()))
2958 segmentation.add(linePartitioning[i]);
2961 if (segmentation.size() == 0)
2964 int size = segmentation.size();
2965 int[] segments = new int[size * 2 + 1];
2968 for (int i = 0; i < size; i++) {
2969 ITypedRegion segment = (ITypedRegion) segmentation.get(i);
2974 int offset = segment.getOffset() - lineOffset;
2975 if (offset > segments[j - 1])
2976 segments[j++] = offset;
2978 if (offset + segment.getLength() >= line.getLength())
2981 segments[j++] = offset + segment.getLength();
2984 if (j < segments.length) {
2985 int[] result = new int[j];
2986 System.arraycopy(segments, 0, result, 0, j);
2993 * Returns a segmentation of the given line appropriate for bidi rendering. The default
2994 * implementation returns only the string literals of a php code line as segments.
2996 * @param lineOffset the offset of the line
2997 * @param line the content of the line
2998 * @return the line's bidi segmentation
3000 protected int[] getBidiLineSegments(int lineOffset, String line) {
3001 IDocumentProvider provider = getDocumentProvider();
3002 if (provider != null && line != null && line.length() > 0) {
3003 IDocument document = provider.getDocument(getEditorInput());
3004 if (document != null)
3006 return getBidiLineSegments(document, lineOffset);
3007 } catch (BadLocationException x) {
3015 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3017 // protected final ISourceViewer createSourceViewer(
3018 // Composite parent,
3019 // IVerticalRuler ruler,
3021 // ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
3022 // StyledText text = viewer.getTextWidget();
3023 // text.addBidiSegmentListener(new BidiSegmentListener() {
3024 // public void lineGetSegments(BidiSegmentEvent event) {
3025 // event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
3028 // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
3032 public final ISourceViewer getViewer() {
3033 return getSourceViewer();
3037 // protected void showOverviewRuler() {
3038 // if (fOverviewRuler != null) {
3039 // if (getSourceViewer() instanceof ISourceViewerExtension) {
3040 // ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(true);
3041 // fSourceViewerDecorationSupport.updateOverviewDecorations();
3046 // protected void hideOverviewRuler() {
3047 // if (getSourceViewer() instanceof ISourceViewerExtension) {
3048 // fSourceViewerDecorationSupport.hideAnnotationOverview();
3049 // ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(false);
3053 // protected boolean isOverviewRulerVisible() {
3054 // IPreferenceStore store = getPreferenceStore();
3055 // return store.getBoolean(OVERVIEW_RULER);
3058 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3060 // protected ISourceViewer createJavaSourceViewer(
3061 // Composite parent,
3062 // IVerticalRuler ruler,
3063 // IOverviewRuler overviewRuler,
3064 // boolean isOverviewRulerVisible,
3066 // return new SourceViewer(parent, ruler, overviewRuler, isOverviewRulerVisible(), styles);
3069 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3071 protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
3072 return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, store);
3075 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3077 protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) {
3079 ISourceViewer viewer= createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles, getPreferenceStore());
3081 StyledText text= viewer.getTextWidget();
3082 text.addBidiSegmentListener(new BidiSegmentListener() {
3083 public void lineGetSegments(BidiSegmentEvent event) {
3084 event.segments= getBidiLineSegments(event.lineOffset, event.lineText);
3088 // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
3090 // ensure source viewer decoration support has been created and configured
3091 getSourceViewerDecorationSupport(viewer);
3096 * Creates and returns the preference store for this Java editor with the given input.
3098 * @param input The editor input for which to create the preference store
3099 * @return the preference store for this editor
3103 private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
3104 List stores= new ArrayList(3);
3106 IJavaProject project= EditorUtility.getJavaProject(input);
3107 if (project != null)
3108 stores.add(new OptionsAdapter(project.getOptions(false), PHPeclipsePlugin.getDefault().getMockupPreferenceStore(), new OptionsAdapter.IPropertyChangeEventFilter() {
3110 public boolean isFiltered(PropertyChangeEvent event) {
3111 IJavaElement inputJavaElement= getInputJavaElement();
3112 IJavaProject javaProject= inputJavaElement != null ? inputJavaElement.getJavaProject() : null;
3113 if (javaProject == null)
3116 return !javaProject.getProject().equals(event.getSource());
3121 stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore());
3122 stores.add(new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()));
3123 stores.add(EditorsUI.getPreferenceStore());
3125 return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
3128 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
3130 // protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles) {
3131 // return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles);
3134 * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
3136 protected boolean affectsTextPresentation(PropertyChangeEvent event) {
3137 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
3138 return textTools.affectsBehavior(event);
3142 * Jumps to the error next according to the given direction.
3144 public void gotoError(boolean forward) {
3146 ISelectionProvider provider = getSelectionProvider();
3148 ITextSelection s = (ITextSelection) provider.getSelection();
3149 Position errorPosition = new Position(0, 0);
3150 IJavaAnnotation nextError = getNextError(s.getOffset(), forward, errorPosition);
3152 if (nextError != null) {
3154 IMarker marker = null;
3155 if (nextError instanceof MarkerAnnotation)
3156 marker = ((MarkerAnnotation) nextError).getMarker();
3158 Iterator e = nextError.getOverlaidIterator();
3160 while (e.hasNext()) {
3161 Object o = e.next();
3162 if (o instanceof MarkerAnnotation) {
3163 marker = ((MarkerAnnotation) o).getMarker();
3170 if (marker != null) {
3171 IWorkbenchPage page = getSite().getPage();
3172 IViewPart view = view = page.findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
3173 if (view instanceof TaskList) {
3174 StructuredSelection ss = new StructuredSelection(marker);
3175 ((TaskList) view).setSelection(ss, true);
3179 selectAndReveal(errorPosition.getOffset(), errorPosition.getLength());
3180 // setStatusLineErrorMessage(nextError.getMessage());
3184 setStatusLineErrorMessage(null);
3189 private IJavaAnnotation getNextError(int offset, boolean forward, Position errorPosition) {
3191 IJavaAnnotation nextError = null;
3192 Position nextErrorPosition = null;
3194 IDocument document = getDocumentProvider().getDocument(getEditorInput());
3195 int endOfDocument = document.getLength();
3198 IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
3199 Iterator e = new JavaAnnotationIterator(model, false);
3200 while (e.hasNext()) {
3202 IJavaAnnotation a = (IJavaAnnotation) e.next();
3203 if (a.hasOverlay() || !a.isProblem())
3206 Position p = model.getPosition((Annotation) a);
3207 if (!p.includes(offset)) {
3209 int currentDistance = 0;
3212 currentDistance = p.getOffset() - offset;
3213 if (currentDistance < 0)
3214 currentDistance = endOfDocument - offset + p.getOffset();
3216 currentDistance = offset - p.getOffset();
3217 if (currentDistance < 0)
3218 currentDistance = offset + endOfDocument - p.getOffset();
3221 if (nextError == null || currentDistance < distance) {
3222 distance = currentDistance;
3224 nextErrorPosition = p;
3229 if (nextErrorPosition != null) {
3230 errorPosition.setOffset(nextErrorPosition.getOffset());
3231 errorPosition.setLength(nextErrorPosition.getLength());
3236 void removeOccurrenceAnnotations() {
3237 IDocumentProvider documentProvider= getDocumentProvider();
3238 if (documentProvider == null)
3241 IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput());
3242 if (annotationModel == null || fOccurrenceAnnotations == null)
3245 synchronized (annotationModel) {
3246 if (annotationModel instanceof IAnnotationModelExtension) {
3247 ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null);
3249 for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++)
3250 annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
3252 fOccurrenceAnnotations= null;
3255 // protected void uninstallOverrideIndicator() {
3256 // if (fOverrideIndicatorManager != null) {
3257 // fOverrideIndicatorManager.removeAnnotations();
3258 // fOverrideIndicatorManager= null;
3262 protected void installOverrideIndicator(boolean waitForReconcilation) {
3263 // uninstallOverrideIndicator();
3264 IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput());
3265 // IJavaElement inputElement= getInputJavaElement();
3267 // if (model == null || inputElement == null)
3270 // CompilationUnit ast= PHPeclipsePlugin.getDefault().getASTProvider().getAST(inputElement, true, null);
3271 // fOverrideIndicatorManager= new OverrideIndicatorManager(model, inputElement, ast);
3275 * Tells whether override indicators are shown.
3277 * @return <code>true</code> if the override indicators are shown
3280 //protected boolean isShowingOverrideIndicators() {
3281 // AnnotationPreference preference= getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
3282 // IPreferenceStore store= getPreferenceStore();
3283 // return getBoolean(store, preference.getHighlightPreferenceKey())
3284 // || getBoolean(store, preference.getVerticalRulerPreferenceKey())
3285 // || getBoolean(store, preference.getOverviewRulerPreferenceKey())
3286 // || getBoolean(store, preference.getTextPreferenceKey());
3290 * Returns the boolean preference for the given key.
3292 * @param store the preference store
3293 * @param key the preference key
3294 * @return <code>true</code> if the key exists in the store and its value is <code>true</code>
3297 private boolean getBoolean(IPreferenceStore store, String key) {
3298 return key != null && store.getBoolean(key);
3302 * Returns the folding action group, or <code>null</code> if there is none.
3304 * @return the folding action group, or <code>null</code> if there is none
3307 protected FoldingActionGroup getFoldingActionGroup() {
3308 return fFoldingGroup;