1 package net.sourceforge.phpeclipse.phpeditor;
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.Iterator;
9 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
10 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
11 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
12 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
13 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
14 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
15 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags;
16 import net.sourceforge.phpdt.ui.PreferenceConstants;
17 import net.sourceforge.phpdt.ui.text.JavaTextTools;
18 import net.sourceforge.phpeclipse.PHPCore;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20 import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
22 import org.eclipse.core.resources.IFile;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.core.runtime.Preferences;
25 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
26 import org.eclipse.jface.action.IMenuManager;
27 import org.eclipse.jface.preference.IPreferenceStore;
28 import org.eclipse.jface.preference.PreferenceConverter;
29 import org.eclipse.jface.text.AbstractHoverInformationControlManager;
30 import org.eclipse.jface.text.BadLocationException;
31 import org.eclipse.jface.text.DocumentCommand;
32 import org.eclipse.jface.text.IDocument;
33 import org.eclipse.jface.text.ILineTracker;
34 import org.eclipse.jface.text.IRegion;
35 import org.eclipse.jface.text.ITextSelection;
36 import org.eclipse.jface.text.ITextViewerExtension;
37 import org.eclipse.jface.text.ITypedRegion;
38 import org.eclipse.jface.text.IWidgetTokenKeeper;
39 import org.eclipse.jface.text.contentassist.ContentAssistant;
40 import org.eclipse.jface.text.contentassist.IContentAssistant;
41 import org.eclipse.jface.text.source.IAnnotationModel;
42 import org.eclipse.jface.text.source.ISourceViewer;
43 import org.eclipse.jface.text.source.IVerticalRuler;
44 import org.eclipse.jface.text.source.SourceViewer;
45 import org.eclipse.jface.text.source.SourceViewerConfiguration;
46 import org.eclipse.jface.util.PropertyChangeEvent;
47 import org.eclipse.swt.SWT;
48 import org.eclipse.swt.custom.StyledText;
49 import org.eclipse.swt.custom.VerifyKeyListener;
50 import org.eclipse.swt.events.VerifyEvent;
51 import org.eclipse.swt.graphics.Color;
52 import org.eclipse.swt.graphics.Point;
53 import org.eclipse.swt.graphics.RGB;
54 import org.eclipse.swt.graphics.Rectangle;
55 import org.eclipse.swt.widgets.Composite;
56 import org.eclipse.swt.widgets.Control;
57 import org.eclipse.swt.widgets.Display;
58 import org.eclipse.swt.widgets.Layout;
59 import org.eclipse.ui.IEditorInput;
60 import org.eclipse.ui.IFileEditorInput;
61 import org.eclipse.ui.actions.ActionContext;
62 import org.eclipse.ui.help.WorkbenchHelp;
63 import org.eclipse.ui.texteditor.IDocumentProvider;
65 /**********************************************************************
66 Copyright (c) 2000, 2002 IBM Corp. and others.
67 All rights reserved. This program and the accompanying materials
68 are made available under the terms of the Common Public License v1.0
69 which accompanies this distribution, and is available at
70 http://www.eclipse.org/legal/cpl-v10.html
73 IBM Corporation - Initial implementation
74 Klaus Hartlage - www.eclipseproject.de
75 **********************************************************************/
77 * PHP specific text editor.
79 public class PHPUnitEditor extends PHPEditor {
80 interface ITextConverter {
81 void customizeDocumentCommand(IDocument document, DocumentCommand command);
84 class AdaptedRulerLayout extends Layout {
87 protected AdaptedSourceViewer fAdaptedSourceViewer;
89 protected AdaptedRulerLayout(int gap, AdaptedSourceViewer asv) {
91 fAdaptedSourceViewer = asv;
94 protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
95 Control[] children = composite.getChildren();
96 Point s = children[children.length - 1].computeSize(SWT.DEFAULT, SWT.DEFAULT, flushCache);
97 if (fAdaptedSourceViewer.isVerticalRulerVisible())
98 s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap;
102 protected void layout(Composite composite, boolean flushCache) {
103 Rectangle clArea = composite.getClientArea();
104 if (fAdaptedSourceViewer.isVerticalRulerVisible()) {
106 StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
107 Rectangle trim = textWidget.computeTrim(0, 0, 0, 0);
108 int scrollbarHeight = trim.height;
110 IVerticalRuler vr = fAdaptedSourceViewer.getVerticalRuler();
111 int vrWidth = vr.getWidth();
114 if (fAdaptedSourceViewer.isOverviewRulerVisible()) {
115 OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler();
116 orWidth = or.getWidth();
117 or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight, orWidth, clArea.height - 3 * scrollbarHeight);
120 textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth - 2 * fGap, clArea.height);
121 vr.getControl().setBounds(0, 0, vrWidth, clArea.height - scrollbarHeight);
124 StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
125 textWidget.setBounds(0, 0, clArea.width, clArea.height);
130 class AdaptedSourceViewer extends SourceViewer { // extends JavaCorrectionSourceViewer {
132 private List fTextConverters;
134 private OverviewRuler fOverviewRuler;
135 private boolean fIsOverviewRulerVisible;
136 /** The viewer's overview ruler hovering controller */
137 private AbstractHoverInformationControlManager fOverviewRulerHoveringController;
139 private boolean fIgnoreTextConverters = false;
141 private IVerticalRuler fCachedVerticalRuler;
142 private boolean fCachedIsVerticalRulerVisible;
144 public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
145 super(parent, ruler, styles); //, CompilationUnitEditor.this);
147 fCachedVerticalRuler = ruler;
148 fCachedIsVerticalRulerVisible = (ruler != null);
149 fOverviewRuler = new OverviewRuler(VERTICAL_RULER_WIDTH);
151 delayedCreateControl(parent, styles);
155 * @see ISourceViewer#showAnnotations(boolean)
157 public void showAnnotations(boolean show) {
158 fCachedIsVerticalRulerVisible = (show && fCachedVerticalRuler != null);
159 // super.showAnnotations(show);
162 public IContentAssistant getContentAssistant() {
163 return fContentAssistant;
167 * @see ITextOperationTarget#doOperation(int)
169 public void doOperation(int operation) {
171 if (getTextWidget() == null)
175 case CONTENTASSIST_PROPOSALS :
176 String msg = fContentAssistant.showPossibleCompletions();
177 setStatusLineErrorMessage(msg);
180 fIgnoreTextConverters = true;
183 fIgnoreTextConverters = true;
187 super.doOperation(operation);
190 public void insertTextConverter(ITextConverter textConverter, int index) {
191 throw new UnsupportedOperationException();
194 public void addTextConverter(ITextConverter textConverter) {
195 if (fTextConverters == null) {
196 fTextConverters = new ArrayList(1);
197 fTextConverters.add(textConverter);
198 } else if (!fTextConverters.contains(textConverter))
199 fTextConverters.add(textConverter);
202 public void removeTextConverter(ITextConverter textConverter) {
203 if (fTextConverters != null) {
204 fTextConverters.remove(textConverter);
205 if (fTextConverters.size() == 0)
206 fTextConverters = null;
211 * @see TextViewer#customizeDocumentCommand(DocumentCommand)
213 protected void customizeDocumentCommand(DocumentCommand command) {
214 super.customizeDocumentCommand(command);
215 if (!fIgnoreTextConverters && fTextConverters != null) {
216 for (Iterator e = fTextConverters.iterator(); e.hasNext();)
217 ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), command);
219 fIgnoreTextConverters = false;
222 public IVerticalRuler getVerticalRuler() {
223 return fCachedVerticalRuler;
226 public boolean isVerticalRulerVisible() {
227 return fCachedIsVerticalRulerVisible;
230 public OverviewRuler getOverviewRuler() {
231 return fOverviewRuler;
235 * @see TextViewer#createControl(Composite, int)
237 protected void createControl(Composite parent, int styles) {
241 protected void delayedCreateControl(Composite parent, int styles) {
243 super.createControl(parent, styles);
245 Control control = getControl();
246 if (control instanceof Composite) {
247 Composite composite = (Composite) control;
248 composite.setLayout(new AdaptedRulerLayout(GAP_SIZE, this));
249 fOverviewRuler.createControl(composite, this);
253 protected void ensureOverviewHoverManagerInstalled() {
254 if (fOverviewRulerHoveringController == null && fAnnotationHover != null && fHoverControlCreator != null) {
255 fOverviewRulerHoveringController =
256 new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover, fHoverControlCreator);
257 fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
261 public void hideOverviewRuler() {
262 fIsOverviewRulerVisible = false;
263 Control control = getControl();
264 if (control instanceof Composite) {
265 Composite composite = (Composite) control;
268 if (fOverviewRulerHoveringController != null) {
269 fOverviewRulerHoveringController.dispose();
270 fOverviewRulerHoveringController = null;
274 public void showOverviewRuler() {
275 fIsOverviewRulerVisible = true;
276 Control control = getControl();
277 if (control instanceof Composite) {
278 Composite composite = (Composite) control;
281 ensureOverviewHoverManagerInstalled();
284 public boolean isOverviewRulerVisible() {
285 return fIsOverviewRulerVisible;
289 * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
291 public void setDocument(
293 IAnnotationModel annotationModel,
294 int visibleRegionOffset,
295 int visibleRegionLength) {
296 super.setDocument(document, annotationModel, visibleRegionOffset, visibleRegionLength);
297 fOverviewRuler.setModel(annotationModel);
300 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
301 public void updateIndentationPrefixes() {
302 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
303 String[] types = configuration.getConfiguredContentTypes(this);
304 for (int i = 0; i < types.length; i++) {
305 String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
306 if (prefixes != null && prefixes.length > 0)
307 setIndentPrefixes(prefixes, types[i]);
312 * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
314 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
315 if (WorkbenchHelp.isContextHelpDisplayed())
317 return super.requestWidgetToken(requester);
321 * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
323 public void configure(SourceViewerConfiguration configuration) {
324 super.configure(configuration);
325 // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this), IDocument.DEFAULT_CONTENT_TYPE);
328 protected void handleDispose() {
329 fOverviewRuler = null;
331 if (fOverviewRulerHoveringController != null) {
332 fOverviewRulerHoveringController.dispose();
333 fOverviewRulerHoveringController = null;
336 super.handleDispose();
341 static class TabConverter implements ITextConverter {
343 private int fTabRatio;
344 private ILineTracker fLineTracker;
346 public TabConverter() {
349 public void setNumberOfSpacesPerTab(int ratio) {
353 public void setLineTracker(ILineTracker lineTracker) {
354 fLineTracker = lineTracker;
357 private int insertTabString(StringBuffer buffer, int offsetInLine) {
362 int remainder = offsetInLine % fTabRatio;
363 remainder = fTabRatio - remainder;
364 for (int i = 0; i < remainder; i++)
369 public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
370 String text = command.text;
374 int index = text.indexOf('\t');
377 StringBuffer buffer = new StringBuffer();
379 fLineTracker.set(command.text);
380 int lines = fLineTracker.getNumberOfLines();
384 for (int i = 0; i < lines; i++) {
386 int offset = fLineTracker.getLineOffset(i);
387 int endOffset = offset + fLineTracker.getLineLength(i);
388 String line = text.substring(offset, endOffset);
392 IRegion firstLine = document.getLineInformationOfOffset(command.offset);
393 position = command.offset - firstLine.getOffset();
396 int length = line.length();
397 for (int j = 0; j < length; j++) {
398 char c = line.charAt(j);
400 position += insertTabString(buffer, position);
409 command.text = buffer.toString();
411 } catch (BadLocationException x) {
417 private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
419 final char fExitCharacter;
421 public ExitPolicy(char exitCharacter) {
422 fExitCharacter = exitCharacter;
426 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager, org.eclipse.swt.events.VerifyEvent, int, int)
428 public ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event, int offset, int length) {
430 if (event.character == fExitCharacter) {
431 if (manager.anyPositionIncludes(offset, length))
432 return new ExitFlags(LinkedPositionUI.COMMIT | LinkedPositionUI.UPDATE_CARET, false);
434 return new ExitFlags(LinkedPositionUI.COMMIT, true);
437 switch (event.character) {
439 if (manager.getFirstPosition().length == 0)
440 return new ExitFlags(0, false);
446 return new ExitFlags(LinkedPositionUI.COMMIT, true);
454 private class BracketInserter implements VerifyKeyListener, LinkedPositionUI.ExitListener {
456 private boolean fCloseBracketsPHP = true;
457 private boolean fCloseStringsPHP = true;
458 private boolean fCloseBracketsHTML = true;
459 private boolean fCloseStringsHTML = true;
464 public void setCloseBracketsPHPEnabled(boolean enabled) {
465 fCloseBracketsPHP = enabled;
468 public void setCloseStringsPHPEnabled(boolean enabled) {
469 fCloseStringsPHP = enabled;
472 public void setCloseBracketsHTMLEnabled(boolean enabled) {
473 fCloseBracketsHTML = enabled;
476 public void setCloseStringsHTMLEnabled(boolean enabled) {
477 fCloseStringsHTML = enabled;
480 private boolean hasIdentifierToTheRight(IDocument document, int offset) {
483 IRegion endLine = document.getLineInformationOfOffset(end);
484 int maxEnd = endLine.getOffset() + endLine.getLength();
485 while (end != maxEnd && Character.isWhitespace(document.getChar(end)))
488 return end != maxEnd && Scanner.isPHPIdentifierPart(document.getChar(end));
490 } catch (BadLocationException e) {
496 private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
499 IRegion startLine = document.getLineInformationOfOffset(start);
500 int minStart = startLine.getOffset();
501 while (start != minStart && Character.isWhitespace(document.getChar(start - 1)))
504 return start != minStart && Scanner.isPHPIdentifierPart(document.getChar(start - 1));
506 } catch (BadLocationException e) {
511 private boolean hasCharacterToTheRight(IDocument document, int offset, char character) {
514 IRegion endLine = document.getLineInformationOfOffset(end);
515 int maxEnd = endLine.getOffset() + endLine.getLength();
516 while (end != maxEnd && Character.isWhitespace(document.getChar(end)))
519 return end != maxEnd && document.getChar(end) == character;
521 } catch (BadLocationException e) {
528 * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
530 public void verifyKey(VerifyEvent event) {
535 final ISourceViewer sourceViewer = getSourceViewer();
536 IDocument document = sourceViewer.getDocument();
538 final Point selection = sourceViewer.getSelectedRange();
539 final int offset = selection.x;
540 final int length = selection.y;
543 ITypedRegion partition = document.getPartition(offset);
544 String type = partition.getType();
545 if (type.equals(IPHPPartitionScannerConstants.PHP)) {
546 switch (event.character) {
548 if (hasCharacterToTheRight(document, offset + length, '('))
554 if (!fCloseBracketsPHP)
556 if (hasIdentifierToTheRight(document, offset + length))
562 if (event.character == '"') {
563 if (!fCloseStringsPHP)
565 // changed for statements like echo "" print ""
566 // if (hasIdentifierToTheLeft(document, offset) || hasIdentifierToTheRight(document, offset + length))
567 if (hasIdentifierToTheRight(document, offset + length))
571 // ITypedRegion partition= document.getPartition(offset);
572 // if (! IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) && (partition.getOffset() != offset))
575 final char character = event.character;
576 final char closingCharacter = getPeerCharacter(character);
577 final StringBuffer buffer = new StringBuffer();
578 buffer.append(character);
579 buffer.append(closingCharacter);
581 document.replace(offset, length, buffer.toString());
583 LinkedPositionManager manager = new LinkedPositionManager(document);
584 manager.addPosition(offset + 1, 0);
589 LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, manager);
590 editor.setCancelListener(this);
591 editor.setExitPolicy(new ExitPolicy(closingCharacter));
592 editor.setFinalCaretOffset(offset + 2);
595 IRegion newSelection = editor.getSelectedRegion();
596 sourceViewer.setSelectedRange(newSelection.getOffset(), newSelection.getLength());
600 } else if (type.equals(IPHPPartitionScannerConstants.HTML) || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
601 switch (event.character) {
603 if (hasCharacterToTheRight(document, offset + length, '('))
609 if (!fCloseBracketsHTML)
611 if (hasIdentifierToTheRight(document, offset + length))
617 if (event.character == '"') {
618 if (!fCloseStringsHTML)
621 if (hasIdentifierToTheLeft(document, offset) || hasIdentifierToTheRight(document, offset + length))
625 // ITypedRegion partition= document.getPartition(offset);
626 // if (! IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) && (partition.getOffset() != offset))
629 final char character = event.character;
630 final char closingCharacter = getPeerCharacter(character);
631 final StringBuffer buffer = new StringBuffer();
632 buffer.append(character);
633 buffer.append(closingCharacter);
635 document.replace(offset, length, buffer.toString());
637 LinkedPositionManager manager = new LinkedPositionManager(document);
638 manager.addPosition(offset + 1, 0);
643 LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, manager);
644 editor.setCancelListener(this);
645 editor.setExitPolicy(new ExitPolicy(closingCharacter));
646 editor.setFinalCaretOffset(offset + 2);
649 IRegion newSelection = editor.getSelectedRegion();
650 sourceViewer.setSelectedRange(newSelection.getOffset(), newSelection.getLength());
655 } catch (BadLocationException e) {
661 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean)
663 public void exit(boolean accept) {
669 final ISourceViewer sourceViewer = getSourceViewer();
670 IDocument document = sourceViewer.getDocument();
671 document.replace(fOffset, fLength, null);
672 } catch (BadLocationException e) {
677 /** The editor's paint manager */
678 private PaintManager fPaintManager;
679 /** The editor's bracket painter */
680 private BracketPainter fBracketPainter;
681 /** The editor's bracket matcher */
682 private PHPPairMatcher fBracketMatcher;
683 /** The editor's line painter */
684 private LinePainter fLinePainter;
685 /** The editor's print margin ruler painter */
686 private PrintMarginPainter fPrintMarginPainter;
687 /** The editor's problem painter */
688 private ProblemPainter fProblemPainter;
689 /** The editor's tab converter */
690 private TabConverter fTabConverter;
691 /** History for structure select action */
692 //private SelectionHistory fSelectionHistory;
694 /** The preference property change listener for php core. */
695 private IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
696 /** The remembered selection */
697 private ITextSelection fRememberedSelection;
698 /** The remembered php element offset */
699 private int fRememberedElementOffset;
700 /** The bracket inserter. */
701 private BracketInserter fBracketInserter = new BracketInserter();
703 private class PropertyChangeListener implements IPropertyChangeListener {
705 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
707 public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
708 handlePreferencePropertyChanged(event);
711 /* Preference key for code formatter tab size */
712 private final static String CODE_FORMATTER_TAB_SIZE = PHPCore.FORMATTER_TAB_SIZE;
713 /** Preference key for matching brackets */
714 private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
715 /** Preference key for matching brackets color */
716 private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
717 /** Preference key for highlighting current line */
718 private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
719 /** Preference key for highlight color of current line */
720 private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
721 /** Preference key for showing print marging ruler */
722 private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
723 /** Preference key for print margin ruler color */
724 private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
725 /** Preference key for print margin ruler column */
726 private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
727 /** Preference key for inserting spaces rather than tabs */
728 private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
729 /** Preference key for error indication */
730 private final static String ERROR_INDICATION = PreferenceConstants.EDITOR_PROBLEM_INDICATION;
731 /** Preference key for error color */
732 private final static String ERROR_INDICATION_COLOR = PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
733 /** Preference key for warning indication */
734 private final static String WARNING_INDICATION = PreferenceConstants.EDITOR_WARNING_INDICATION;
735 /** Preference key for warning color */
736 private final static String WARNING_INDICATION_COLOR = PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
737 /** Preference key for task indication */
738 private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
739 /** Preference key for task color */
740 private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
741 /** Preference key for bookmark indication */
742 private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
743 /** Preference key for bookmark color */
744 private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
745 /** Preference key for search result indication */
746 private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
747 /** Preference key for search result color */
748 private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
749 /** Preference key for unknown annotation indication */
750 private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
751 /** Preference key for unknown annotation color */
752 private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
753 /** Preference key for linked position color */
754 private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
755 /** Preference key for shwoing the overview ruler */
756 private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
758 /** Preference key for error indication in overview ruler */
759 private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
760 /** Preference key for warning indication in overview ruler */
761 private final static String WARNING_INDICATION_IN_OVERVIEW_RULER =
762 PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
763 /** Preference key for task indication in overview ruler */
764 private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
765 /** Preference key for bookmark indication in overview ruler */
766 private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER =
767 PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
768 /** Preference key for search result indication in overview ruler */
769 private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER =
770 PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
771 /** Preference key for unknown annotation indication in overview ruler */
772 private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER =
773 PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
774 /** Preference key for automatically closing strings */
775 private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP;
776 /** Preference key for automatically wrapping Java strings */
777 private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS;
778 /** Preference key for automatically closing brackets and parenthesis */
779 private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
780 /** Preference key for automatically closing phpdocs and comments */
781 private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
782 /** Preference key for automatically adding phpdoc tags */
783 private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
784 /** Preference key for automatically formatting phpdocs */
785 private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
786 /** Preference key for automatically closing strings */
787 private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
788 /** Preference key for automatically closing brackets and parenthesis */
789 private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
791 /** Preference key for smart paste */
792 private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
793 private final static class AnnotationInfo {
794 public String fColorPreference;
795 public String fOverviewRulerPreference;
796 public String fEditorPreference;
799 private final static Map ANNOTATION_MAP;
803 ANNOTATION_MAP = new HashMap();
805 info = new AnnotationInfo();
806 info.fColorPreference = TASK_INDICATION_COLOR;
807 info.fOverviewRulerPreference = TASK_INDICATION_IN_OVERVIEW_RULER;
808 info.fEditorPreference = TASK_INDICATION;
809 ANNOTATION_MAP.put(AnnotationType.TASK, info);
811 info = new AnnotationInfo();
812 info.fColorPreference = ERROR_INDICATION_COLOR;
813 info.fOverviewRulerPreference = ERROR_INDICATION_IN_OVERVIEW_RULER;
814 info.fEditorPreference = ERROR_INDICATION;
815 ANNOTATION_MAP.put(AnnotationType.ERROR, info);
817 info = new AnnotationInfo();
818 info.fColorPreference = WARNING_INDICATION_COLOR;
819 info.fOverviewRulerPreference = WARNING_INDICATION_IN_OVERVIEW_RULER;
820 info.fEditorPreference = WARNING_INDICATION;
821 ANNOTATION_MAP.put(AnnotationType.WARNING, info);
823 info = new AnnotationInfo();
824 info.fColorPreference = BOOKMARK_INDICATION_COLOR;
825 info.fOverviewRulerPreference = BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
826 info.fEditorPreference = BOOKMARK_INDICATION;
827 ANNOTATION_MAP.put(AnnotationType.BOOKMARK, info);
829 info = new AnnotationInfo();
830 info.fColorPreference = SEARCH_RESULT_INDICATION_COLOR;
831 info.fOverviewRulerPreference = SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
832 info.fEditorPreference = SEARCH_RESULT_INDICATION;
833 ANNOTATION_MAP.put(AnnotationType.SEARCH_RESULT, info);
835 info = new AnnotationInfo();
836 info.fColorPreference = UNKNOWN_INDICATION_COLOR;
837 info.fOverviewRulerPreference = UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
838 info.fEditorPreference = UNKNOWN_INDICATION;
839 ANNOTATION_MAP.put(AnnotationType.UNKNOWN, info);
842 private final static AnnotationType[] ANNOTATION_LAYERS =
843 new AnnotationType[] {
844 AnnotationType.UNKNOWN,
845 AnnotationType.BOOKMARK,
847 AnnotationType.SEARCH_RESULT,
848 AnnotationType.WARNING,
849 AnnotationType.ERROR };
851 * Creates a new php unit editor.
853 public PHPUnitEditor() {
855 setDocumentProvider(PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider());
856 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
857 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
861 public void createPartControl(Composite parent) {
862 super.createPartControl(parent);
864 fPaintManager = new PaintManager(getSourceViewer());
866 LinePainter linePainter;
867 linePainter = new LinePainter(getSourceViewer());
869 linePainter.setHighlightColor(new Color(Display.getCurrent(), 225, 235, 224));
871 fPaintManager.addPainter(linePainter);
873 if (isBracketHighlightingEnabled())
874 startBracketHighlighting();
875 if (isLineHighlightingEnabled())
876 startLineHighlighting();
877 if (isPrintMarginVisible())
880 Iterator e = ANNOTATION_MAP.keySet().iterator();
881 while (e.hasNext()) {
882 AnnotationType type = (AnnotationType) e.next();
883 if (isAnnotationIndicationEnabled(type))
884 startAnnotationIndication(type);
887 if (isTabConversionEnabled())
888 startTabConversion();
890 if (isOverviewRulerVisible())
893 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
894 preferences.addPropertyChangeListener(fPropertyChangeListener);
896 IPreferenceStore preferenceStore = getPreferenceStore();
897 boolean closeBracketsPHP = preferenceStore.getBoolean(CLOSE_BRACKETS_PHP);
898 boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP);
899 boolean closeBracketsHTML = preferenceStore.getBoolean(CLOSE_BRACKETS_HTML);
900 boolean closeStringsHTML = preferenceStore.getBoolean(CLOSE_STRINGS_HTML);
902 fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
903 fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP);
904 fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
905 fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
907 ISourceViewer sourceViewer = getSourceViewer();
908 if (sourceViewer instanceof ITextViewerExtension)
909 ((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter);
913 private static char getPeerCharacter(char character) {
931 throw new IllegalArgumentException();
936 * @see AbstractTextEditor#doSetInput(IEditorInput)
938 protected void doSetInput(IEditorInput input) throws CoreException {
939 super.doSetInput(input);
940 configureTabConverter();
943 private void startBracketHighlighting() {
944 if (fBracketPainter == null) {
945 ISourceViewer sourceViewer = getSourceViewer();
946 fBracketPainter = new BracketPainter(sourceViewer);
947 fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
948 fPaintManager.addPainter(fBracketPainter);
952 private void stopBracketHighlighting() {
953 if (fBracketPainter != null) {
954 fPaintManager.removePainter(fBracketPainter);
955 fBracketPainter.deactivate(true);
956 fBracketPainter.dispose();
957 fBracketPainter = null;
961 private boolean isBracketHighlightingEnabled() {
962 IPreferenceStore store = getPreferenceStore();
963 return store.getBoolean(MATCHING_BRACKETS);
966 private void startLineHighlighting() {
967 if (fLinePainter == null) {
968 ISourceViewer sourceViewer = getSourceViewer();
969 fLinePainter = new LinePainter(sourceViewer);
970 fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR));
971 fPaintManager.addPainter(fLinePainter);
975 private void stopLineHighlighting() {
976 if (fLinePainter != null) {
977 fPaintManager.removePainter(fLinePainter);
978 fLinePainter.deactivate(true);
979 fLinePainter.dispose();
984 private boolean isLineHighlightingEnabled() {
985 IPreferenceStore store = getPreferenceStore();
986 return store.getBoolean(CURRENT_LINE);
989 private void showPrintMargin() {
990 if (fPrintMarginPainter == null) {
991 fPrintMarginPainter = new PrintMarginPainter(getSourceViewer());
992 fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
993 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN));
994 fPaintManager.addPainter(fPrintMarginPainter);
998 private void hidePrintMargin() {
999 if (fPrintMarginPainter != null) {
1000 fPaintManager.removePainter(fPrintMarginPainter);
1001 fPrintMarginPainter.deactivate(true);
1002 fPrintMarginPainter.dispose();
1003 fPrintMarginPainter = null;
1007 private boolean isPrintMarginVisible() {
1008 IPreferenceStore store = getPreferenceStore();
1009 return store.getBoolean(PRINT_MARGIN);
1012 private void startAnnotationIndication(AnnotationType annotationType) {
1013 if (fProblemPainter == null) {
1014 fProblemPainter = new ProblemPainter(this, getSourceViewer());
1015 fPaintManager.addPainter(fProblemPainter);
1017 fProblemPainter.setColor(annotationType, getColor(annotationType));
1018 fProblemPainter.paintAnnotations(annotationType, true);
1019 fProblemPainter.paint(IPainter.CONFIGURATION);
1022 private void shutdownAnnotationIndication() {
1023 if (fProblemPainter != null) {
1025 if (!fProblemPainter.isPaintingAnnotations()) {
1026 fPaintManager.removePainter(fProblemPainter);
1027 fProblemPainter.deactivate(true);
1028 fProblemPainter.dispose();
1029 fProblemPainter = null;
1031 fProblemPainter.paint(IPainter.CONFIGURATION);
1036 private void stopAnnotationIndication(AnnotationType annotationType) {
1037 if (fProblemPainter != null) {
1038 fProblemPainter.paintAnnotations(annotationType, false);
1039 shutdownAnnotationIndication();
1043 private boolean isAnnotationIndicationEnabled(AnnotationType annotationType) {
1044 IPreferenceStore store = getPreferenceStore();
1045 AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType);
1047 return store.getBoolean(info.fEditorPreference);
1051 private boolean isAnnotationIndicationInOverviewRulerEnabled(AnnotationType annotationType) {
1052 IPreferenceStore store = getPreferenceStore();
1053 AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType);
1055 return store.getBoolean(info.fOverviewRulerPreference);
1059 private void showAnnotationIndicationInOverviewRuler(AnnotationType annotationType, boolean show) {
1060 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1061 OverviewRuler ruler = asv.getOverviewRuler();
1062 if (ruler != null) {
1063 ruler.setColor(annotationType, getColor(annotationType));
1064 ruler.showAnnotation(annotationType, show);
1069 private void setColorInOverviewRuler(AnnotationType annotationType, Color color) {
1070 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1071 OverviewRuler ruler = asv.getOverviewRuler();
1072 if (ruler != null) {
1073 ruler.setColor(annotationType, color);
1078 private void configureTabConverter() {
1079 if (fTabConverter != null) {
1080 IDocumentProvider provider = getDocumentProvider();
1081 if (provider instanceof PHPDocumentProvider) {
1082 PHPDocumentProvider cup = (PHPDocumentProvider) provider;
1083 fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
1088 private int getTabSize() {
1089 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
1090 return preferences.getInt(CODE_FORMATTER_TAB_SIZE);
1093 private void startTabConversion() {
1094 if (fTabConverter == null) {
1095 fTabConverter = new TabConverter();
1096 configureTabConverter();
1097 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1098 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1099 asv.addTextConverter(fTabConverter);
1100 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1101 asv.updateIndentationPrefixes();
1105 private void stopTabConversion() {
1106 if (fTabConverter != null) {
1107 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1108 asv.removeTextConverter(fTabConverter);
1109 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1110 asv.updateIndentationPrefixes();
1111 fTabConverter = null;
1115 private boolean isTabConversionEnabled() {
1116 IPreferenceStore store = getPreferenceStore();
1117 return store.getBoolean(SPACES_FOR_TABS);
1120 private void showOverviewRuler() {
1121 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1122 asv.showOverviewRuler();
1124 OverviewRuler overviewRuler = asv.getOverviewRuler();
1125 if (overviewRuler != null) {
1126 for (int i = 0; i < ANNOTATION_LAYERS.length; i++) {
1127 AnnotationType type = ANNOTATION_LAYERS[i];
1128 overviewRuler.setLayer(type, i);
1129 if (isAnnotationIndicationInOverviewRulerEnabled(type))
1130 showAnnotationIndicationInOverviewRuler(type, true);
1135 private void hideOverviewRuler() {
1136 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1137 asv.hideOverviewRuler();
1140 private boolean isOverviewRulerVisible() {
1141 IPreferenceStore store = getPreferenceStore();
1142 return store.getBoolean(OVERVIEW_RULER);
1145 private Color getColor(String key) {
1146 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
1147 return getColor(rgb);
1150 private Color getColor(RGB rgb) {
1151 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1152 return textTools.getColorManager().getColor(rgb);
1155 private Color getColor(AnnotationType annotationType) {
1156 AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType);
1158 return getColor(info.fColorPreference);
1162 public void dispose() {
1163 ISourceViewer sourceViewer = getSourceViewer();
1164 if (sourceViewer instanceof ITextViewerExtension)
1165 ((ITextViewerExtension) sourceViewer).removeVerifyKeyListener(fBracketInserter);
1167 if (fPropertyChangeListener != null) {
1168 Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences();
1169 preferences.removePropertyChangeListener(fPropertyChangeListener);
1170 fPropertyChangeListener = null;
1173 // if (fJavaEditorErrorTickUpdater != null) {
1174 // fJavaEditorErrorTickUpdater.dispose();
1175 // fJavaEditorErrorTickUpdater= null;
1178 // if (fSelectionHistory != null)
1179 // fSelectionHistory.dispose();
1181 if (fPaintManager != null) {
1182 fPaintManager.dispose();
1183 fPaintManager = null;
1186 if (fActionGroups != null)
1187 fActionGroups.dispose();
1192 protected AnnotationType getAnnotationType(String preferenceKey) {
1193 Iterator e = ANNOTATION_MAP.keySet().iterator();
1194 while (e.hasNext()) {
1195 AnnotationType type = (AnnotationType) e.next();
1196 AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1198 if (preferenceKey.equals(info.fColorPreference)
1199 || preferenceKey.equals(info.fEditorPreference)
1200 || preferenceKey.equals(info.fOverviewRulerPreference))
1208 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1210 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1214 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1217 String p = event.getProperty();
1219 if (CLOSE_BRACKETS_PHP.equals(p)) {
1220 fBracketInserter.setCloseBracketsPHPEnabled(getPreferenceStore().getBoolean(p));
1224 if (CLOSE_STRINGS_PHP.equals(p)) {
1225 fBracketInserter.setCloseStringsPHPEnabled(getPreferenceStore().getBoolean(p));
1229 if (CLOSE_BRACKETS_HTML.equals(p)) {
1230 fBracketInserter.setCloseBracketsHTMLEnabled(getPreferenceStore().getBoolean(p));
1234 if (CLOSE_STRINGS_HTML.equals(p)) {
1235 fBracketInserter.setCloseStringsHTMLEnabled(getPreferenceStore().getBoolean(p));
1239 if (SPACES_FOR_TABS.equals(p)) {
1240 if (isTabConversionEnabled())
1241 startTabConversion();
1243 stopTabConversion();
1247 if (MATCHING_BRACKETS.equals(p)) {
1248 if (isBracketHighlightingEnabled())
1249 startBracketHighlighting();
1251 stopBracketHighlighting();
1255 if (MATCHING_BRACKETS_COLOR.equals(p)) {
1256 if (fBracketPainter != null)
1257 fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1261 if (CURRENT_LINE.equals(p)) {
1262 if (isLineHighlightingEnabled())
1263 startLineHighlighting();
1265 stopLineHighlighting();
1269 if (CURRENT_LINE_COLOR.equals(p)) {
1270 if (fLinePainter != null) {
1271 stopLineHighlighting();
1272 startLineHighlighting();
1277 if (PRINT_MARGIN.equals(p)) {
1278 if (isPrintMarginVisible())
1285 if (PRINT_MARGIN_COLOR.equals(p)) {
1286 if (fPrintMarginPainter != null)
1287 fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1291 if (PRINT_MARGIN_COLUMN.equals(p)) {
1292 if (fPrintMarginPainter != null)
1293 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN));
1297 if (OVERVIEW_RULER.equals(p)) {
1298 if (isOverviewRulerVisible())
1299 showOverviewRuler();
1301 hideOverviewRuler();
1305 AnnotationType type = getAnnotationType(p);
1308 AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1309 if (info.fColorPreference.equals(p)) {
1310 Color color = getColor(type);
1311 if (fProblemPainter != null) {
1312 fProblemPainter.setColor(type, color);
1313 fProblemPainter.paint(IPainter.CONFIGURATION);
1315 setColorInOverviewRuler(type, color);
1319 if (info.fEditorPreference.equals(p)) {
1320 if (isAnnotationIndicationEnabled(type))
1321 startAnnotationIndication(type);
1323 stopAnnotationIndication(type);
1327 if (info.fOverviewRulerPreference.equals(p)) {
1328 if (isAnnotationIndicationInOverviewRulerEnabled(type))
1329 showAnnotationIndicationInOverviewRuler(type, true);
1331 showAnnotationIndicationInOverviewRuler(type, false);
1336 IContentAssistant c = asv.getContentAssistant();
1337 if (c instanceof ContentAssistant)
1338 ContentAssistPreference.changeConfiguration((ContentAssistant) c, getPreferenceStore(), event);
1342 super.handlePreferenceStoreChanged(event);
1347 * Handles a property change event describing a change
1348 * of the php core's preferences and updates the preference
1349 * related editor properties.
1351 * @param event the property change event
1353 protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1354 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1356 String p = event.getProperty();
1357 if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1358 asv.updateIndentationPrefixes();
1359 if (fTabConverter != null)
1360 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1366 * @see PHPEditor#createJavaSourceViewer(Composite, IVerticalRuler, int)
1368 protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
1369 return new AdaptedSourceViewer(parent, ruler, styles);
1372 private boolean isValidSelection(int offset, int length) {
1373 IDocumentProvider provider = getDocumentProvider();
1374 if (provider != null) {
1375 IDocument document = provider.getDocument(getEditorInput());
1376 if (document != null) {
1377 int end = offset + length;
1378 int documentLength = document.getLength();
1379 return 0 <= offset && offset <= documentLength && 0 <= end && end <= documentLength;
1386 * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput)
1388 protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) {
1390 String oldExtension = ""; //$NON-NLS-1$
1391 if (originalElement instanceof IFileEditorInput) {
1392 IFile file = ((IFileEditorInput) originalElement).getFile();
1394 String ext = file.getFileExtension();
1400 String newExtension = ""; //$NON-NLS-1$
1401 if (movedElement instanceof IFileEditorInput) {
1402 IFile file = ((IFileEditorInput) movedElement).getFile();
1404 newExtension = file.getFileExtension();
1407 return oldExtension.equals(newExtension);
1411 * @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager)
1413 public void editorContextMenuAboutToShow(IMenuManager menu) {
1414 super.editorContextMenuAboutToShow(menu);
1416 ActionContext context= new ActionContext(getSelectionProvider().getSelection());
1417 fContextMenuGroup.setContext(context);
1418 fContextMenuGroup.fillContextMenu(menu);
1419 fContextMenuGroup.setContext(null);