1 package net.sourceforge.phpeclipse.phpeditor;
3 import java.text.MessageFormat;
4 import java.util.ArrayList;
5 import java.util.Iterator;
8 import net.sourceforge.phpdt.core.ICompilationUnit;
9 import net.sourceforge.phpdt.core.IJavaElement;
10 import net.sourceforge.phpdt.core.ISourceRange;
11 import net.sourceforge.phpdt.core.ISourceReference;
12 import net.sourceforge.phpdt.core.JavaCore;
13 import net.sourceforge.phpdt.core.JavaModelException;
14 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
15 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
16 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
17 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
18 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
19 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
20 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
21 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags;
22 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
23 import net.sourceforge.phpdt.ui.PreferenceConstants;
24 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
25 import net.sourceforge.phpdt.ui.text.JavaTextTools;
26 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
28 import org.eclipse.core.resources.IFile;
29 import org.eclipse.core.resources.IWorkspaceRoot;
30 import org.eclipse.core.resources.ResourcesPlugin;
31 import org.eclipse.core.runtime.CoreException;
32 import org.eclipse.core.runtime.IPath;
33 import org.eclipse.core.runtime.IProgressMonitor;
34 import org.eclipse.core.runtime.IStatus;
35 import org.eclipse.core.runtime.Preferences;
36 import org.eclipse.jface.action.Action;
37 import org.eclipse.jface.action.IAction;
38 import org.eclipse.jface.action.IMenuManager;
39 import org.eclipse.jface.dialogs.ErrorDialog;
40 import org.eclipse.jface.dialogs.IMessageProvider;
41 import org.eclipse.jface.dialogs.MessageDialog;
42 import org.eclipse.jface.preference.IPreferenceStore;
43 import org.eclipse.jface.preference.PreferenceConverter;
44 import org.eclipse.jface.text.BadLocationException;
45 import org.eclipse.jface.text.DocumentCommand;
46 import org.eclipse.jface.text.IDocument;
47 import org.eclipse.jface.text.ILineTracker;
48 import org.eclipse.jface.text.IRegion;
49 import org.eclipse.jface.text.ITextOperationTarget;
50 import org.eclipse.jface.text.ITextSelection;
51 import org.eclipse.jface.text.ITextViewerExtension;
52 import org.eclipse.jface.text.ITypedRegion;
53 import org.eclipse.jface.text.IWidgetTokenKeeper;
54 import org.eclipse.jface.text.contentassist.ContentAssistant;
55 import org.eclipse.jface.text.contentassist.IContentAssistant;
56 import org.eclipse.jface.text.source.IOverviewRuler;
57 import org.eclipse.jface.text.source.ISourceViewer;
58 import org.eclipse.jface.text.source.IVerticalRuler;
59 import org.eclipse.jface.text.source.SourceViewerConfiguration;
60 import org.eclipse.jface.util.PropertyChangeEvent;
61 import org.eclipse.jface.viewers.ISelectionProvider;
62 import org.eclipse.jface.window.Window;
63 import org.eclipse.swt.SWT;
64 import org.eclipse.swt.custom.VerifyKeyListener;
65 import org.eclipse.swt.events.VerifyEvent;
66 import org.eclipse.swt.graphics.Color;
67 import org.eclipse.swt.graphics.Point;
68 import org.eclipse.swt.graphics.RGB;
69 import org.eclipse.swt.widgets.Composite;
70 import org.eclipse.swt.widgets.Display;
71 import org.eclipse.swt.widgets.Shell;
72 import org.eclipse.ui.IEditorInput;
73 import org.eclipse.ui.IFileEditorInput;
74 import org.eclipse.ui.actions.ActionContext;
75 import org.eclipse.ui.actions.ActionGroup;
76 import org.eclipse.ui.dialogs.SaveAsDialog;
77 import org.eclipse.ui.editors.text.IStorageDocumentProvider;
78 import org.eclipse.ui.help.WorkbenchHelp;
79 import org.eclipse.ui.part.FileEditorInput;
80 import org.eclipse.ui.texteditor.ContentAssistAction;
81 import org.eclipse.ui.texteditor.IDocumentProvider;
82 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
83 import org.eclipse.ui.texteditor.TextOperationAction;
85 /*******************************************************************************
86 * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
87 * program and the accompanying materials are made available under the terms of
88 * the Common Public License v1.0 which accompanies this distribution, and is
89 * available at http://www.eclipse.org/legal/cpl-v10.html
91 * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
92 * www.eclipseproject.de
93 ******************************************************************************/
95 * PHP specific text editor.
97 public class PHPUnitEditor extends PHPEditor { //implements
98 // IJavaReconcilingListener {
99 interface ITextConverter {
100 void customizeDocumentCommand(IDocument document, DocumentCommand command);
103 // class AdaptedRulerLayout extends Layout {
105 // protected int fGap;
106 // protected AdaptedSourceViewer fAdaptedSourceViewer;
108 // protected AdaptedRulerLayout(int gap, AdaptedSourceViewer asv) {
110 // fAdaptedSourceViewer = asv;
113 // protected Point computeSize(Composite composite, int wHint, int hHint,
114 // boolean flushCache) {
115 // Control[] children = composite.getChildren();
116 // Point s = children[children.length - 1].computeSize(SWT.DEFAULT,
117 // SWT.DEFAULT, flushCache);
118 // if (fAdaptedSourceViewer.isVerticalRulerVisible())
119 // s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap;
123 // protected void layout(Composite composite, boolean flushCache) {
124 // Rectangle clArea = composite.getClientArea();
125 // if (fAdaptedSourceViewer.isVerticalRulerVisible()) {
127 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
128 // Rectangle trim = textWidget.computeTrim(0, 0, 0, 0);
129 // int scrollbarHeight = trim.height;
131 // IVerticalRuler vr = fAdaptedSourceViewer.getVerticalRuler();
132 // int vrWidth = vr.getWidth();
135 // if (fAdaptedSourceViewer.isOverviewRulerVisible()) {
136 // OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler();
137 // orWidth = or.getWidth();
138 // or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight,
139 // orWidth, clArea.height - 3 * scrollbarHeight);
142 // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth
144 // 2 * fGap, clArea.height);
145 // vr.getControl().setBounds(0, 0, vrWidth, clArea.height -
149 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
150 // textWidget.setBounds(0, 0, clArea.width, clArea.height);
155 // class AdaptedSourceViewer extends SourceViewer { // extends
156 // JavaCorrectionSourceViewer {
158 // private List fTextConverters;
160 // private OverviewRuler fOverviewRuler;
161 // private boolean fIsOverviewRulerVisible;
162 // /** The viewer's overview ruler hovering controller */
163 // private AbstractHoverInformationControlManager
164 // fOverviewRulerHoveringController;
166 // private boolean fIgnoreTextConverters = false;
168 // private IVerticalRuler fCachedVerticalRuler;
169 // private boolean fCachedIsVerticalRulerVisible;
171 // public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int
173 // super(parent, ruler, styles); //, CompilationUnitEditor.this);
175 // fCachedVerticalRuler = ruler;
176 // fCachedIsVerticalRulerVisible = (ruler != null);
177 // fOverviewRuler = new OverviewRuler(VERTICAL_RULER_WIDTH);
179 // delayedCreateControl(parent, styles);
183 // * @see ISourceViewer#showAnnotations(boolean)
185 // public void showAnnotations(boolean show) {
186 // fCachedIsVerticalRulerVisible = (show && fCachedVerticalRuler != null);
187 // // super.showAnnotations(show);
190 // public IContentAssistant getContentAssistant() {
191 // return fContentAssistant;
195 // * @see ITextOperationTarget#doOperation(int)
197 // public void doOperation(int operation) {
199 // if (getTextWidget() == null)
202 // switch (operation) {
203 // case CONTENTASSIST_PROPOSALS :
204 // String msg = fContentAssistant.showPossibleCompletions();
205 // setStatusLineErrorMessage(msg);
208 // fIgnoreTextConverters = true;
211 // fIgnoreTextConverters = true;
215 // super.doOperation(operation);
218 // public void insertTextConverter(ITextConverter textConverter, int index)
220 // throw new UnsupportedOperationException();
223 // public void addTextConverter(ITextConverter textConverter) {
224 // if (fTextConverters == null) {
225 // fTextConverters = new ArrayList(1);
226 // fTextConverters.add(textConverter);
227 // } else if (!fTextConverters.contains(textConverter))
228 // fTextConverters.add(textConverter);
231 // public void removeTextConverter(ITextConverter textConverter) {
232 // if (fTextConverters != null) {
233 // fTextConverters.remove(textConverter);
234 // if (fTextConverters.size() == 0)
235 // fTextConverters = null;
240 // * @see TextViewer#customizeDocumentCommand(DocumentCommand)
242 // protected void customizeDocumentCommand(DocumentCommand command) {
243 // super.customizeDocumentCommand(command);
244 // if (!fIgnoreTextConverters && fTextConverters != null) {
245 // for (Iterator e = fTextConverters.iterator(); e.hasNext();)
246 // ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(),
249 // fIgnoreTextConverters = false;
252 // public IVerticalRuler getVerticalRuler() {
253 // return fCachedVerticalRuler;
256 // public boolean isVerticalRulerVisible() {
257 // return fCachedIsVerticalRulerVisible;
260 // public OverviewRuler getOverviewRuler() {
261 // return fOverviewRuler;
265 // * @see TextViewer#createControl(Composite, int)
267 // protected void createControl(Composite parent, int styles) {
268 // // do nothing here
271 // protected void delayedCreateControl(Composite parent, int styles) {
272 // //create the viewer
273 // super.createControl(parent, styles);
275 // Control control = getControl();
276 // if (control instanceof Composite) {
277 // Composite composite = (Composite) control;
278 // composite.setLayout(new AdaptedRulerLayout(GAP_SIZE, this));
279 // fOverviewRuler.createControl(composite, this);
282 // protected void ensureOverviewHoverManagerInstalled() {
283 // if (fOverviewRulerHoveringController == null && fAnnotationHover != null
284 // && fHoverControlCreator != null) {
285 // fOverviewRulerHoveringController =
286 // new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover,
287 // fHoverControlCreator);
288 // fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
292 // public void hideOverviewRuler() {
293 // fIsOverviewRulerVisible = false;
294 // Control control = getControl();
295 // if (control instanceof Composite) {
296 // Composite composite = (Composite) control;
297 // composite.layout();
299 // if (fOverviewRulerHoveringController != null) {
300 // fOverviewRulerHoveringController.dispose();
301 // fOverviewRulerHoveringController = null;
305 // public void showOverviewRuler() {
306 // fIsOverviewRulerVisible = true;
307 // Control control = getControl();
308 // if (control instanceof Composite) {
309 // Composite composite = (Composite) control;
310 // composite.layout();
312 // ensureOverviewHoverManagerInstalled();
315 // public boolean isOverviewRulerVisible() {
316 // return fIsOverviewRulerVisible;
320 // * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
322 // public void setDocument(
323 // IDocument document,
324 // IAnnotationModel annotationModel,
325 // int visibleRegionOffset,
326 // int visibleRegionLength) {
327 // super.setDocument(document, annotationModel, visibleRegionOffset,
328 // visibleRegionLength);
329 // fOverviewRuler.setModel(annotationModel);
332 // // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
333 // public void updateIndentationPrefixes() {
334 // SourceViewerConfiguration configuration = getSourceViewerConfiguration();
335 // String[] types = configuration.getConfiguredContentTypes(this);
336 // for (int i = 0; i < types.length; i++) {
337 // String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
338 // if (prefixes != null && prefixes.length > 0)
339 // setIndentPrefixes(prefixes, types[i]);
344 // * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
346 // public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
347 // if (WorkbenchHelp.isContextHelpDisplayed())
349 // return super.requestWidgetToken(requester);
354 // org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
356 // public void configure(SourceViewerConfiguration configuration) {
357 // super.configure(configuration);
358 // // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
359 // IDocument.DEFAULT_CONTENT_TYPE);
362 // protected void handleDispose() {
363 // fOverviewRuler = null;
365 // if (fOverviewRulerHoveringController != null) {
366 // fOverviewRulerHoveringController.dispose();
367 // fOverviewRulerHoveringController = null;
370 // super.handleDispose();
374 class AdaptedSourceViewer extends JavaSourceViewer {
375 private List fTextConverters;
377 private boolean fIgnoreTextConverters = false;
379 // private JavaCorrectionAssistant fCorrectionAssistant;
380 public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler,
381 IOverviewRuler overviewRuler, boolean showAnnotationsOverview,
382 int styles, IPreferenceStore store) {
383 super(parent, verticalRuler, overviewRuler, showAnnotationsOverview,
387 // public AdaptedSourceViewer(Composite parent,
388 // IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
389 // boolean showAnnotationsOverview, int styles) {
390 // super(parent, verticalRuler, overviewRuler,
391 // showAnnotationsOverview, styles);
393 public IContentAssistant getContentAssistant() {
394 return fContentAssistant;
398 * @see ITextOperationTarget#doOperation(int)
400 public void doOperation(int operation) {
401 if (getTextWidget() == null)
404 case CONTENTASSIST_PROPOSALS:
405 String msg = fContentAssistant.showPossibleCompletions();
406 setStatusLineErrorMessage(msg);
408 // case CORRECTIONASSIST_PROPOSALS:
409 // fCorrectionAssistant.showPossibleCompletions();
412 fIgnoreTextConverters = true;
415 fIgnoreTextConverters = true;
418 super.doOperation(operation);
422 * @see ITextOperationTarget#canDoOperation(int)
424 public boolean canDoOperation(int operation) {
425 // if (operation == CORRECTIONASSIST_PROPOSALS)
426 // return isEditable();
427 return super.canDoOperation(operation);
431 * @see TextViewer#handleDispose()
433 protected void handleDispose() {
434 // if (fCorrectionAssistant != null) {
435 // fCorrectionAssistant.uninstall();
436 // fCorrectionAssistant= null;
438 super.handleDispose();
441 public void insertTextConverter(ITextConverter textConverter, int index) {
442 throw new UnsupportedOperationException();
445 public void addTextConverter(ITextConverter textConverter) {
446 if (fTextConverters == null) {
447 fTextConverters = new ArrayList(1);
448 fTextConverters.add(textConverter);
449 } else if (!fTextConverters.contains(textConverter))
450 fTextConverters.add(textConverter);
453 public void removeTextConverter(ITextConverter textConverter) {
454 if (fTextConverters != null) {
455 fTextConverters.remove(textConverter);
456 if (fTextConverters.size() == 0)
457 fTextConverters = null;
462 * @see TextViewer#customizeDocumentCommand(DocumentCommand)
464 protected void customizeDocumentCommand(DocumentCommand command) {
465 super.customizeDocumentCommand(command);
466 if (!fIgnoreTextConverters && fTextConverters != null) {
467 for (Iterator e = fTextConverters.iterator(); e.hasNext();)
468 ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(),
471 fIgnoreTextConverters = false;
474 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
475 public void updateIndentationPrefixes() {
476 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
477 String[] types = configuration.getConfiguredContentTypes(this);
478 for (int i = 0; i < types.length; i++) {
479 String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
480 if (prefixes != null && prefixes.length > 0)
481 setIndentPrefixes(prefixes, types[i]);
486 * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
488 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
489 if (WorkbenchHelp.isContextHelpDisplayed())
491 return super.requestWidgetToken(requester);
495 * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
497 public void configure(SourceViewerConfiguration configuration) {
498 super.configure(configuration);
499 // fCorrectionAssistant= new
500 // JavaCorrectionAssistant(CompilationUnitEditor.this);
501 // fCorrectionAssistant.install(this);
502 //TODO install SmartBracesAutoEditStrategy
503 // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
504 // IDocument.DEFAULT_CONTENT_TYPE);
508 static class TabConverter implements ITextConverter {
509 private int fTabRatio;
511 private ILineTracker fLineTracker;
513 public TabConverter() {
516 public void setNumberOfSpacesPerTab(int ratio) {
520 public void setLineTracker(ILineTracker lineTracker) {
521 fLineTracker = lineTracker;
524 private int insertTabString(StringBuffer buffer, int offsetInLine) {
527 int remainder = offsetInLine % fTabRatio;
528 remainder = fTabRatio - remainder;
529 for (int i = 0; i < remainder; i++)
534 public void customizeDocumentCommand(IDocument document,
535 DocumentCommand command) {
536 String text = command.text;
539 int index = text.indexOf('\t');
541 StringBuffer buffer = new StringBuffer();
542 fLineTracker.set(command.text);
543 int lines = fLineTracker.getNumberOfLines();
545 for (int i = 0; i < lines; i++) {
546 int offset = fLineTracker.getLineOffset(i);
547 int endOffset = offset + fLineTracker.getLineLength(i);
548 String line = text.substring(offset, endOffset);
551 IRegion firstLine = document
552 .getLineInformationOfOffset(command.offset);
553 position = command.offset - firstLine.getOffset();
555 int length = line.length();
556 for (int j = 0; j < length; j++) {
557 char c = line.charAt(j);
559 position += insertTabString(buffer, position);
566 command.text = buffer.toString();
567 } catch (BadLocationException x) {
573 private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
574 final char fExitCharacter;
576 public ExitPolicy(char exitCharacter) {
577 fExitCharacter = exitCharacter;
581 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager,
582 * org.eclipse.swt.events.VerifyEvent, int, int)
584 public ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event,
585 int offset, int length) {
586 if (event.character == fExitCharacter) {
587 if (manager.anyPositionIncludes(offset, length))
588 return new ExitFlags(LinkedPositionUI.COMMIT
589 | LinkedPositionUI.UPDATE_CARET, false);
591 return new ExitFlags(LinkedPositionUI.COMMIT, true);
593 switch (event.character) {
595 if (manager.getFirstPosition().length == 0)
596 return new ExitFlags(0, false);
601 return new ExitFlags(LinkedPositionUI.COMMIT, true);
608 private static class BracketLevel {
613 LinkedPositionManager fManager;
615 LinkedPositionUI fEditor;
618 private class BracketInserter implements VerifyKeyListener,
619 LinkedPositionUI.ExitListener {
620 private boolean fCloseBracketsPHP = true;
622 private boolean fCloseStringsPHP = true;
624 private boolean fCloseBracketsHTML = true;
626 private boolean fCloseStringsHTML = true;
632 public void setCloseBracketsPHPEnabled(boolean enabled) {
633 fCloseBracketsPHP = enabled;
636 public void setCloseStringsPHPEnabled(boolean enabled) {
637 fCloseStringsPHP = enabled;
640 public void setCloseBracketsHTMLEnabled(boolean enabled) {
641 fCloseBracketsHTML = enabled;
644 public void setCloseStringsHTMLEnabled(boolean enabled) {
645 fCloseStringsHTML = enabled;
648 private boolean hasIdentifierToTheRight(IDocument document, int offset) {
651 IRegion endLine = document.getLineInformationOfOffset(end);
652 int maxEnd = endLine.getOffset() + endLine.getLength();
653 while (end != maxEnd && Character.isWhitespace(document.getChar(end)))
656 && Scanner.isPHPIdentifierPart(document.getChar(end));
657 } catch (BadLocationException e) {
663 private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
666 IRegion startLine = document.getLineInformationOfOffset(start);
667 int minStart = startLine.getOffset();
668 while (start != minStart
669 && Character.isWhitespace(document.getChar(start - 1)))
671 return start != minStart
672 && Scanner.isPHPIdentifierPart(document.getChar(start - 1));
673 } catch (BadLocationException e) {
678 private boolean hasCharacterToTheRight(IDocument document, int offset,
682 IRegion endLine = document.getLineInformationOfOffset(end);
683 int maxEnd = endLine.getOffset() + endLine.getLength();
684 while (end != maxEnd && Character.isWhitespace(document.getChar(end)))
686 return end != maxEnd && document.getChar(end) == character;
687 } catch (BadLocationException e) {
694 * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
696 public void verifyKey(VerifyEvent event) {
699 final ISourceViewer sourceViewer = getSourceViewer();
700 IDocument document = sourceViewer.getDocument();
701 final Point selection = sourceViewer.getSelectedRange();
702 final int offset = selection.x;
703 final int length = selection.y;
705 ITypedRegion partition = document.getPartition(offset);
706 String type = partition.getType();
707 if (type.equals(IPHPPartitions.PHP_PARTITIONING)) {
708 switch (event.character) {
710 if (hasCharacterToTheRight(document, offset + length, '('))
714 if (!fCloseBracketsPHP)
716 if (hasIdentifierToTheRight(document, offset + length))
720 if (event.character == '"') {
721 if (!fCloseStringsPHP)
723 // changed for statements like echo "" print ""
724 // if (hasIdentifierToTheLeft(document, offset)
726 // hasIdentifierToTheRight(document, offset +
728 if (hasIdentifierToTheRight(document, offset + length))
731 // ITypedRegion partition=
732 // document.getPartition(offset);
734 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
736 // (partition.getOffset() != offset))
738 final char character = event.character;
739 final char closingCharacter = getPeerCharacter(character);
740 final StringBuffer buffer = new StringBuffer();
741 buffer.append(character);
742 buffer.append(closingCharacter);
743 document.replace(offset, length, buffer.toString());
744 LinkedPositionManager manager = new LinkedPositionManager(document);
745 manager.addPosition(offset + 1, 0);
748 LinkedPositionUI editor = new LinkedPositionUI(sourceViewer,
750 editor.setCancelListener(this);
751 editor.setExitPolicy(new ExitPolicy(closingCharacter));
752 editor.setFinalCaretOffset(offset + 2);
754 IRegion newSelection = editor.getSelectedRegion();
755 sourceViewer.setSelectedRange(newSelection.getOffset(),
756 newSelection.getLength());
759 } else if (type.equals(IPHPPartitions.HTML)
760 || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
761 switch (event.character) {
763 if (hasCharacterToTheRight(document, offset + length, '('))
767 if (!fCloseBracketsHTML)
769 if (hasIdentifierToTheRight(document, offset + length))
773 if (event.character == '"') {
774 if (!fCloseStringsHTML)
776 if (hasIdentifierToTheLeft(document, offset)
777 || hasIdentifierToTheRight(document, offset + length))
780 // ITypedRegion partition=
781 // document.getPartition(offset);
783 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
785 // (partition.getOffset() != offset))
787 final char character = event.character;
788 final char closingCharacter = getPeerCharacter(character);
789 final StringBuffer buffer = new StringBuffer();
790 buffer.append(character);
791 buffer.append(closingCharacter);
792 document.replace(offset, length, buffer.toString());
793 LinkedPositionManager manager = new LinkedPositionManager(document);
794 manager.addPosition(offset + 1, 0);
797 LinkedPositionUI editor = new LinkedPositionUI(sourceViewer,
799 editor.setCancelListener(this);
800 editor.setExitPolicy(new ExitPolicy(closingCharacter));
801 editor.setFinalCaretOffset(offset + 2);
803 IRegion newSelection = editor.getSelectedRegion();
804 sourceViewer.setSelectedRange(newSelection.getOffset(),
805 newSelection.getLength());
809 } catch (BadLocationException e) {
814 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean)
816 public void exit(boolean accept) {
821 final ISourceViewer sourceViewer = getSourceViewer();
822 IDocument document = sourceViewer.getDocument();
823 document.replace(fOffset, fLength, null);
824 } catch (BadLocationException e) {
829 /** The editor's save policy */
830 protected ISavePolicy fSavePolicy;
833 * Listener to annotation model changes that updates the error tick in the tab
836 private JavaEditorErrorTickUpdater fJavaEditorErrorTickUpdater;
838 /** The editor's paint manager */
839 // private PaintManager fPaintManager;
840 /** The editor's bracket painter */
841 private BracketPainter fBracketPainter;
843 /** The editor's bracket matcher */
844 private PHPPairMatcher fBracketMatcher;
846 /** The editor's line painter */
847 private LinePainter fLinePainter;
849 /** The editor's print margin ruler painter */
850 private PrintMarginPainter fPrintMarginPainter;
852 /** The editor's problem painter */
853 // private ProblemPainter fProblemPainter;
854 /** The editor's tab converter */
855 private TabConverter fTabConverter;
857 /** History for structure select action */
858 //private SelectionHistory fSelectionHistory;
859 /** The preference property change listener for php core. */
860 // private IPropertyChangeListener fPropertyChangeListener = new
861 // PropertyChangeListener();
862 /** The remembered java element */
863 private IJavaElement fRememberedElement;
865 /** The remembered selection */
866 private ITextSelection fRememberedSelection;
868 /** The remembered php element offset */
869 private int fRememberedElementOffset;
871 /** The bracket inserter. */
872 private BracketInserter fBracketInserter = new BracketInserter();
874 /** The standard action groups added to the menu */
875 private GenerateActionGroup fGenerateActionGroup;
877 private CompositeActionGroup fContextMenuGroup;
879 // private class PropertyChangeListener implements IPropertyChangeListener {
881 // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
884 // propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
886 // handlePreferencePropertyChanged(event);
889 /* Preference key for code formatter tab size */
890 private final static String CODE_FORMATTER_TAB_SIZE = JavaCore.FORMATTER_TAB_SIZE;
892 /** Preference key for matching brackets */
893 private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
895 /** Preference key for matching brackets color */
896 private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
898 /** Preference key for highlighting current line */
899 private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
901 /** Preference key for highlight color of current line */
902 private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
904 /** Preference key for showing print marging ruler */
905 private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
907 /** Preference key for print margin ruler color */
908 private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
910 /** Preference key for print margin ruler column */
911 private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
913 /** Preference key for inserting spaces rather than tabs */
914 private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
916 /** Preference key for error indication */
917 // private final static String ERROR_INDICATION =
918 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
919 /** Preference key for error color */
920 // private final static String ERROR_INDICATION_COLOR =
921 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
922 /** Preference key for warning indication */
923 // private final static String WARNING_INDICATION =
924 // PreferenceConstants.EDITOR_WARNING_INDICATION;
925 /** Preference key for warning color */
926 // private final static String WARNING_INDICATION_COLOR =
927 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
928 /** Preference key for task indication */
929 private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
931 /** Preference key for task color */
932 private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
934 /** Preference key for bookmark indication */
935 private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
937 /** Preference key for bookmark color */
938 private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
940 /** Preference key for search result indication */
941 private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
943 /** Preference key for search result color */
944 private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
946 /** Preference key for unknown annotation indication */
947 private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
949 /** Preference key for unknown annotation color */
950 private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
952 /** Preference key for linked position color */
953 private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
955 /** Preference key for shwoing the overview ruler */
956 private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
958 /** Preference key for error indication in overview ruler */
959 private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
961 /** Preference key for warning indication in overview ruler */
962 private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
964 /** Preference key for task indication in overview ruler */
965 private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
967 /** Preference key for bookmark indication in overview ruler */
968 private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
970 /** Preference key for search result indication in overview ruler */
971 private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
973 /** Preference key for unknown annotation indication in overview ruler */
974 private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
976 /** Preference key for automatically closing strings */
977 private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP;
979 /** Preference key for automatically wrapping Java strings */
980 private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS;
982 /** Preference key for automatically closing brackets and parenthesis */
983 private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
985 /** Preference key for automatically closing phpdocs and comments */
986 private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
988 /** Preference key for automatically adding phpdoc tags */
989 private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
991 /** Preference key for automatically formatting phpdocs */
992 private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
994 /** Preference key for automatically closing strings */
995 private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
997 /** Preference key for automatically closing brackets and parenthesis */
998 private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
1000 /** Preference key for smart paste */
1001 private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
1003 // private final static class AnnotationInfo {
1004 // public String fColorPreference;
1005 // public String fOverviewRulerPreference;
1006 // public String fEditorPreference;
1008 // private final static Map ANNOTATION_MAP;
1011 // AnnotationInfo info;
1012 // ANNOTATION_MAP = new HashMap();
1014 // info = new AnnotationInfo();
1015 // info.fColorPreference = TASK_INDICATION_COLOR;
1016 // info.fOverviewRulerPreference = TASK_INDICATION_IN_OVERVIEW_RULER;
1017 // info.fEditorPreference = TASK_INDICATION;
1018 // ANNOTATION_MAP.put(AnnotationType.TASK, info);
1020 // info = new AnnotationInfo();
1021 // info.fColorPreference = ERROR_INDICATION_COLOR;
1022 // info.fOverviewRulerPreference = ERROR_INDICATION_IN_OVERVIEW_RULER;
1023 // info.fEditorPreference = ERROR_INDICATION;
1024 // ANNOTATION_MAP.put(AnnotationType.ERROR, info);
1026 // info = new AnnotationInfo();
1027 // info.fColorPreference = WARNING_INDICATION_COLOR;
1028 // info.fOverviewRulerPreference = WARNING_INDICATION_IN_OVERVIEW_RULER;
1029 // info.fEditorPreference = WARNING_INDICATION;
1030 // ANNOTATION_MAP.put(AnnotationType.WARNING, info);
1032 // info = new AnnotationInfo();
1033 // info.fColorPreference = BOOKMARK_INDICATION_COLOR;
1034 // info.fOverviewRulerPreference = BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
1035 // info.fEditorPreference = BOOKMARK_INDICATION;
1036 // ANNOTATION_MAP.put(AnnotationType.BOOKMARK, info);
1038 // info = new AnnotationInfo();
1039 // info.fColorPreference = SEARCH_RESULT_INDICATION_COLOR;
1040 // info.fOverviewRulerPreference =
1041 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
1042 // info.fEditorPreference = SEARCH_RESULT_INDICATION;
1043 // ANNOTATION_MAP.put(AnnotationType.SEARCH, info);
1045 // info = new AnnotationInfo();
1046 // info.fColorPreference = UNKNOWN_INDICATION_COLOR;
1047 // info.fOverviewRulerPreference = UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
1048 // info.fEditorPreference = UNKNOWN_INDICATION;
1049 // ANNOTATION_MAP.put(AnnotationType.UNKNOWN, info);
1052 // private final static AnnotationType[] ANNOTATION_LAYERS =
1053 // new AnnotationType[] {
1054 // AnnotationType.UNKNOWN,
1055 // AnnotationType.BOOKMARK,
1056 // AnnotationType.TASK,
1057 // AnnotationType.SEARCH,
1058 // AnnotationType.WARNING,
1059 // AnnotationType.ERROR };
1061 * Creates a new php unit editor.
1063 public PHPUnitEditor() {
1065 setDocumentProvider(PHPeclipsePlugin.getDefault()
1066 .getCompilationUnitDocumentProvider());
1067 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
1068 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
1069 setOutlinerContextMenuId("#PHPOutlinerContext"); //$NON-NLS-1$
1070 // don't set help contextId, we install our own help context
1072 fJavaEditorErrorTickUpdater = new JavaEditorErrorTickUpdater(this);
1076 * @see AbstractTextEditor#createActions()
1078 protected void createActions() {
1079 super.createActions();
1081 // Action action= new
1082 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1083 // "CorrectionAssistProposal.", this, CORRECTIONASSIST_PROPOSALS);
1085 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
1086 // setAction("CorrectionAssistProposal", action); //$NON-NLS-1$
1087 // markAsStateDependentAction("CorrectionAssistProposal", true);
1089 //// WorkbenchHelp.setHelp(action,
1090 // IJavaHelpContextIds.QUICK_FIX_ACTION);
1091 action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(),
1092 "ContentAssistProposal.", this); //$NON-NLS-1$
1094 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
1095 setAction("ContentAssistProposal", action); //$NON-NLS-1$
1096 markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
1097 // WorkbenchHelp.setHelp(action,
1098 // IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
1099 // action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1100 // "ContentAssistContextInformation.", this,
1101 // ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$
1103 // .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
1104 // setAction("ContentAssistContextInformation", action); //$NON-NLS-1$
1105 // markAsStateDependentAction("ContentAssistContextInformation", true);
1107 // WorkbenchHelp.setHelp(action,
1108 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1110 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1111 // "ContentAssistCompletePrefix.", this, CONTENTASSIST_COMPLETE_PREFIX);
1113 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_COMPLETE_PREFIX);
1114 // setAction("ContentAssistCompletePrefix", action); //$NON-NLS-1$
1115 // markAsStateDependentAction("ContentAssistCompletePrefix", true);
1117 //// WorkbenchHelp.setHelp(action,
1118 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1119 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1120 "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
1121 action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
1122 setAction("Comment", action); //$NON-NLS-1$
1123 markAsStateDependentAction("Comment", true); //$NON-NLS-1$
1124 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
1125 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1126 "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
1127 action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
1128 setAction("Uncomment", action); //$NON-NLS-1$
1129 markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
1130 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
1132 action = new ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1133 "ToggleComment.", this); //$NON-NLS-1$
1134 action.setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1135 setAction("ToggleComment", action); //$NON-NLS-1$
1136 markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1137 //WorkbenchHelp.setHelp(action,
1138 // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1139 configureToggleCommentAction();
1141 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1142 "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
1143 action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
1144 setAction("Format", action); //$NON-NLS-1$
1145 markAsStateDependentAction("Format", true); //$NON-NLS-1$
1146 markAsSelectionDependentAction("Format", true); //$NON-NLS-1$
1147 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
1149 // action = new AddBlockCommentAction(PHPEditorMessages.getResourceBundle(),
1150 // "AddBlockComment.", this); //$NON-NLS-1$
1152 // .setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
1153 // setAction("AddBlockComment", action); //$NON-NLS-1$
1154 // markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
1155 // markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
1156 // // WorkbenchHelp.setHelp(action,
1157 // // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1158 // action = new RemoveBlockCommentAction(
1159 // PHPEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
1161 // .setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
1162 // setAction("RemoveBlockComment", action); //$NON-NLS-1$
1163 // markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1164 // markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1165 // WorkbenchHelp.setHelp(action,
1166 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1167 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1168 // "Indent.", this, false); //$NON-NLS-1$
1169 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT);
1170 // setAction("Indent", action); //$NON-NLS-1$
1171 // markAsStateDependentAction("Indent", true); //$NON-NLS-1$
1172 // markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
1173 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION);
1175 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1176 // "Indent.", this, true); //$NON-NLS-1$
1177 // setAction("IndentOnTab", action); //$NON-NLS-1$
1178 // markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
1179 // markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$
1181 if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_TAB)) {
1182 // don't replace Shift Right - have to make sure their enablement is
1183 // mutually exclusive
1184 // removeActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT);
1185 setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$
1187 fGenerateActionGroup = new GenerateActionGroup(this,
1188 ITextEditorActionConstants.GROUP_EDIT);
1189 fActionGroups = new CompositeActionGroup(
1190 new ActionGroup[] { fGenerateActionGroup });
1191 // We have to keep the context menu group separate to have better
1194 fContextMenuGroup = new CompositeActionGroup(
1195 new ActionGroup[] { fGenerateActionGroup });
1197 // new LocalHistoryActionGroup(this,
1198 // ITextEditorActionConstants.GROUP_EDIT)});
1203 * @see JavaEditor#getElementAt(int)
1205 protected IJavaElement getElementAt(int offset) {
1206 return getElementAt(offset, true);
1210 * Returns the most narrow element including the given offset. If
1211 * <code>reconcile</code> is <code>true</code> the editor's input element
1212 * is reconciled in advance. If it is <code>false</code> this method only
1213 * returns a result if the editor's input element does not need to be
1217 * the offset included by the retrieved element
1219 * <code>true</code> if working copy should be reconciled
1221 protected IJavaElement getElementAt(int offset, boolean reconcile) {
1222 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1223 .getWorkingCopyManager();
1224 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1228 synchronized (unit) {
1231 return unit.getElementAt(offset);
1232 } else if (unit.isConsistent())
1233 return unit.getElementAt(offset);
1234 } catch (JavaModelException x) {
1235 PHPeclipsePlugin.log(x.getStatus());
1236 // nothing found, be tolerant and go on
1243 * @see JavaEditor#getCorrespondingElement(IJavaElement)
1245 protected IJavaElement getCorrespondingElement(IJavaElement element) {
1247 return EditorUtility.getWorkingCopy(element, true);
1248 } catch (JavaModelException x) {
1249 PHPeclipsePlugin.log(x.getStatus());
1250 // nothing found, be tolerant and go on
1255 public void createPartControl(Composite parent) {
1256 super.createPartControl(parent);
1257 // fPaintManager = new PaintManager(getSourceViewer());
1258 LinePainter linePainter;
1259 linePainter = new LinePainter(getSourceViewer());
1261 .setHighlightColor(new Color(Display.getCurrent(), 225, 235, 224));
1262 // fPaintManager.addPainter(linePainter);
1263 if (isBracketHighlightingEnabled())
1264 startBracketHighlighting();
1265 if (isLineHighlightingEnabled())
1266 startLineHighlighting();
1267 if (isPrintMarginVisible())
1269 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1270 // while (e.hasNext()) {
1271 // AnnotationType type = (AnnotationType) e.next();
1272 // if (isAnnotationIndicationEnabled(type))
1273 // startAnnotationIndication(type);
1275 if (isTabConversionEnabled())
1276 startTabConversion();
1277 // if (isOverviewRulerVisible())
1278 // showOverviewRuler();
1280 // Preferences preferences =
1281 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1282 // preferences.addPropertyChangeListener(fPropertyChangeListener);
1283 IPreferenceStore preferenceStore = getPreferenceStore();
1284 boolean closeBracketsPHP = preferenceStore.getBoolean(CLOSE_BRACKETS_PHP);
1285 boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP);
1286 boolean closeBracketsHTML = preferenceStore.getBoolean(CLOSE_BRACKETS_HTML);
1287 boolean closeStringsHTML = preferenceStore.getBoolean(CLOSE_STRINGS_HTML);
1288 fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
1289 fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP);
1290 fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
1291 fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
1292 ISourceViewer sourceViewer = getSourceViewer();
1293 if (sourceViewer instanceof ITextViewerExtension)
1294 ((ITextViewerExtension) sourceViewer)
1295 .prependVerifyKeyListener(fBracketInserter);
1298 private static char getPeerCharacter(char character) {
1299 switch (character) {
1311 throw new IllegalArgumentException();
1315 private void startBracketHighlighting() {
1316 if (fBracketPainter == null) {
1317 ISourceViewer sourceViewer = getSourceViewer();
1318 fBracketPainter = new BracketPainter(sourceViewer);
1319 fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1320 // fPaintManager.addPainter(fBracketPainter);
1324 private void stopBracketHighlighting() {
1325 if (fBracketPainter != null) {
1326 // fPaintManager.removePainter(fBracketPainter);
1327 fBracketPainter.deactivate(true);
1328 fBracketPainter.dispose();
1329 fBracketPainter = null;
1333 private boolean isBracketHighlightingEnabled() {
1334 IPreferenceStore store = getPreferenceStore();
1335 return store.getBoolean(MATCHING_BRACKETS);
1338 private void startLineHighlighting() {
1339 if (fLinePainter == null) {
1340 ISourceViewer sourceViewer = getSourceViewer();
1341 fLinePainter = new LinePainter(sourceViewer);
1342 fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR));
1343 // fPaintManager.addPainter(fLinePainter);
1347 private void stopLineHighlighting() {
1348 if (fLinePainter != null) {
1349 // fPaintManager.removePainter(fLinePainter);
1350 fLinePainter.deactivate(true);
1351 fLinePainter.dispose();
1352 fLinePainter = null;
1356 private boolean isLineHighlightingEnabled() {
1357 IPreferenceStore store = getPreferenceStore();
1358 return store.getBoolean(CURRENT_LINE);
1361 private void showPrintMargin() {
1362 if (fPrintMarginPainter == null) {
1363 fPrintMarginPainter = new PrintMarginPainter(getSourceViewer());
1364 fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1365 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(
1366 PRINT_MARGIN_COLUMN));
1367 // fPaintManager.addPainter(fPrintMarginPainter);
1371 private void hidePrintMargin() {
1372 if (fPrintMarginPainter != null) {
1373 // fPaintManager.removePainter(fPrintMarginPainter);
1374 fPrintMarginPainter.deactivate(true);
1375 fPrintMarginPainter.dispose();
1376 fPrintMarginPainter = null;
1380 private boolean isPrintMarginVisible() {
1381 IPreferenceStore store = getPreferenceStore();
1382 return store.getBoolean(PRINT_MARGIN);
1385 // private void startAnnotationIndication(AnnotationType annotationType) {
1386 // if (fProblemPainter == null) {
1387 // fProblemPainter = new ProblemPainter(this, getSourceViewer());
1388 //// fPaintManager.addPainter(fProblemPainter);
1390 // fProblemPainter.setColor(annotationType, getColor(annotationType));
1391 // fProblemPainter.paintAnnotations(annotationType, true);
1392 // fProblemPainter.paint(IPainter.CONFIGURATION);
1395 // private void shutdownAnnotationIndication() {
1396 // if (fProblemPainter != null) {
1398 // if (!fProblemPainter.isPaintingAnnotations()) {
1399 //// fPaintManager.removePainter(fProblemPainter);
1400 // fProblemPainter.deactivate(true);
1401 // fProblemPainter.dispose();
1402 // fProblemPainter = null;
1404 // fProblemPainter.paint(IPainter.CONFIGURATION);
1409 // private void stopAnnotationIndication(AnnotationType annotationType) {
1410 // if (fProblemPainter != null) {
1411 // fProblemPainter.paintAnnotations(annotationType, false);
1412 // shutdownAnnotationIndication();
1416 // private boolean isAnnotationIndicationEnabled(AnnotationType
1417 // annotationType) {
1418 // IPreferenceStore store = getPreferenceStore();
1419 // AnnotationInfo info = (AnnotationInfo)
1420 // ANNOTATION_MAP.get(annotationType);
1421 // if (info != null)
1422 // return store.getBoolean(info.fEditorPreference);
1427 // isAnnotationIndicationInOverviewRulerEnabled(AnnotationType
1428 // annotationType) {
1429 // IPreferenceStore store = getPreferenceStore();
1430 // AnnotationInfo info = (AnnotationInfo)
1431 // ANNOTATION_MAP.get(annotationType);
1432 // if (info != null)
1433 // return store.getBoolean(info.fOverviewRulerPreference);
1437 // private void showAnnotationIndicationInOverviewRuler(AnnotationType
1438 // annotationType, boolean show) {
1439 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1440 // OverviewRuler ruler = asv.getOverviewRuler();
1441 // if (ruler != null) {
1442 // ruler.setColor(annotationType, getColor(annotationType));
1443 // ruler.showAnnotation(annotationType, show);
1448 // private void setColorInOverviewRuler(AnnotationType annotationType, Color
1450 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1451 // OverviewRuler ruler = asv.getOverviewRuler();
1452 // if (ruler != null) {
1453 // ruler.setColor(annotationType, color);
1458 private int getTabSize() {
1459 Preferences preferences = PHPeclipsePlugin.getDefault()
1460 .getPluginPreferences();
1461 return preferences.getInt(CODE_FORMATTER_TAB_SIZE);
1464 private boolean isTabConversionEnabled() {
1465 IPreferenceStore store = getPreferenceStore();
1466 return store.getBoolean(SPACES_FOR_TABS);
1469 // private void showOverviewRuler() {
1470 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1471 // asv.showOverviewRuler();
1473 // OverviewRuler overviewRuler = asv.getOverviewRuler();
1474 // if (overviewRuler != null) {
1475 // for (int i = 0; i < ANNOTATION_LAYERS.length; i++) {
1476 // AnnotationType type = ANNOTATION_LAYERS[i];
1477 // overviewRuler.setLayer(type, i);
1478 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1479 // showAnnotationIndicationInOverviewRuler(type, true);
1484 // private void hideOverviewRuler() {
1485 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1486 // asv.hideOverviewRuler();
1489 // private boolean isOverviewRulerVisible() {
1490 // IPreferenceStore store = getPreferenceStore();
1491 // return store.getBoolean(OVERVIEW_RULER);
1493 private Color getColor(String key) {
1494 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
1495 return getColor(rgb);
1498 private Color getColor(RGB rgb) {
1499 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1500 return textTools.getColorManager().getColor(rgb);
1503 // private Color getColor(AnnotationType annotationType) {
1504 // AnnotationInfo info = (AnnotationInfo)
1505 // ANNOTATION_MAP.get(annotationType);
1506 // if (info != null)
1507 // return getColor(info.fColorPreference);
1510 public void dispose() {
1511 ISourceViewer sourceViewer = getSourceViewer();
1512 if (sourceViewer instanceof ITextViewerExtension)
1513 ((ITextViewerExtension) sourceViewer)
1514 .removeVerifyKeyListener(fBracketInserter);
1515 // if (fPropertyChangeListener != null) {
1516 // Preferences preferences =
1517 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1518 // preferences.removePropertyChangeListener(fPropertyChangeListener);
1519 // fPropertyChangeListener = null;
1521 if (fJavaEditorErrorTickUpdater != null) {
1522 fJavaEditorErrorTickUpdater.dispose();
1523 fJavaEditorErrorTickUpdater = null;
1525 // if (fSelectionHistory != null)
1526 // fSelectionHistory.dispose();
1527 // if (fPaintManager != null) {
1528 // fPaintManager.dispose();
1529 // fPaintManager = null;
1531 if (fActionGroups != null) {
1532 fActionGroups.dispose();
1533 fActionGroups = null;
1538 // protected AnnotationType getAnnotationType(String preferenceKey) {
1539 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1540 // while (e.hasNext()) {
1541 // AnnotationType type = (AnnotationType) e.next();
1542 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1543 // if (info != null) {
1544 // if (preferenceKey.equals(info.fColorPreference)
1545 // || preferenceKey.equals(info.fEditorPreference)
1546 // || preferenceKey.equals(info.fOverviewRulerPreference))
1553 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1555 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1557 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1559 String p = event.getProperty();
1560 if (CLOSE_BRACKETS_PHP.equals(p)) {
1561 fBracketInserter.setCloseBracketsPHPEnabled(getPreferenceStore()
1565 if (CLOSE_STRINGS_PHP.equals(p)) {
1566 fBracketInserter.setCloseStringsPHPEnabled(getPreferenceStore()
1570 if (CLOSE_BRACKETS_HTML.equals(p)) {
1571 fBracketInserter.setCloseBracketsHTMLEnabled(getPreferenceStore()
1575 if (CLOSE_STRINGS_HTML.equals(p)) {
1576 fBracketInserter.setCloseStringsHTMLEnabled(getPreferenceStore()
1580 if (SPACES_FOR_TABS.equals(p)) {
1581 if (isTabConversionEnabled())
1582 startTabConversion();
1584 stopTabConversion();
1587 if (MATCHING_BRACKETS.equals(p)) {
1588 if (isBracketHighlightingEnabled())
1589 startBracketHighlighting();
1591 stopBracketHighlighting();
1594 if (MATCHING_BRACKETS_COLOR.equals(p)) {
1595 if (fBracketPainter != null)
1597 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1600 if (CURRENT_LINE.equals(p)) {
1601 if (isLineHighlightingEnabled())
1602 startLineHighlighting();
1604 stopLineHighlighting();
1607 if (CURRENT_LINE_COLOR.equals(p)) {
1608 if (fLinePainter != null) {
1609 stopLineHighlighting();
1610 startLineHighlighting();
1614 if (PRINT_MARGIN.equals(p)) {
1615 if (isPrintMarginVisible())
1621 if (PRINT_MARGIN_COLOR.equals(p)) {
1622 if (fPrintMarginPainter != null)
1624 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1627 if (PRINT_MARGIN_COLUMN.equals(p)) {
1628 if (fPrintMarginPainter != null)
1629 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore()
1630 .getInt(PRINT_MARGIN_COLUMN));
1633 // if (OVERVIEW_RULER.equals(p)) {
1634 // if (isOverviewRulerVisible())
1635 // showOverviewRuler();
1637 // hideOverviewRuler();
1640 // AnnotationType type = getAnnotationType(p);
1641 // if (type != null) {
1643 // AnnotationInfo info = (AnnotationInfo)
1644 // ANNOTATION_MAP.get(type);
1645 // if (info.fColorPreference.equals(p)) {
1646 // Color color = getColor(type);
1647 // if (fProblemPainter != null) {
1648 // fProblemPainter.setColor(type, color);
1649 // fProblemPainter.paint(IPainter.CONFIGURATION);
1651 // setColorInOverviewRuler(type, color);
1655 // if (info.fEditorPreference.equals(p)) {
1656 // if (isAnnotationIndicationEnabled(type))
1657 // startAnnotationIndication(type);
1659 // stopAnnotationIndication(type);
1663 // if (info.fOverviewRulerPreference.equals(p)) {
1664 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1665 // showAnnotationIndicationInOverviewRuler(type, true);
1667 // showAnnotationIndicationInOverviewRuler(type, false);
1671 IContentAssistant c = asv.getContentAssistant();
1672 if (c instanceof ContentAssistant)
1673 ContentAssistPreference.changeConfiguration((ContentAssistant) c,
1674 getPreferenceStore(), event);
1677 super.handlePreferenceStoreChanged(event);
1682 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
1684 protected void handlePreferencePropertyChanged(
1685 org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1686 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1688 String p = event.getProperty();
1689 if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1690 asv.updateIndentationPrefixes();
1691 if (fTabConverter != null)
1692 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1695 super.handlePreferencePropertyChanged(event);
1699 * Handles a property change event describing a change of the php core's
1700 * preferences and updates the preference related editor properties.
1703 * the property change event
1706 // handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
1708 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1709 // if (asv != null) {
1710 // String p = event.getProperty();
1711 // if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1712 // asv.updateIndentationPrefixes();
1713 // if (fTabConverter != null)
1714 // fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1719 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#createJavaSourceViewer(org.eclipse.swt.widgets.Composite,
1720 * org.eclipse.jface.text.source.IVerticalRuler,
1721 * org.eclipse.jface.text.source.IOverviewRuler, boolean, int)
1723 protected ISourceViewer createJavaSourceViewer(Composite parent,
1724 IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
1725 boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
1726 return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler,
1727 isOverviewRulerVisible, styles, store);
1730 // protected ISourceViewer createJavaSourceViewer(Composite parent,
1731 // IVerticalRuler ruler, int styles) {
1732 // return new AdaptedSourceViewer(parent, ruler, styles);
1734 private boolean isValidSelection(int offset, int length) {
1735 IDocumentProvider provider = getDocumentProvider();
1736 if (provider != null) {
1737 IDocument document = provider.getDocument(getEditorInput());
1738 if (document != null) {
1739 int end = offset + length;
1740 int documentLength = document.getLength();
1741 return 0 <= offset && offset <= documentLength && 0 <= end
1742 && end <= documentLength;
1749 * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput)
1751 protected boolean canHandleMove(IEditorInput originalElement,
1752 IEditorInput movedElement) {
1753 String oldExtension = ""; //$NON-NLS-1$
1754 if (originalElement instanceof IFileEditorInput) {
1755 IFile file = ((IFileEditorInput) originalElement).getFile();
1757 String ext = file.getFileExtension();
1762 String newExtension = ""; //$NON-NLS-1$
1763 if (movedElement instanceof IFileEditorInput) {
1764 IFile file = ((IFileEditorInput) movedElement).getFile();
1766 newExtension = file.getFileExtension();
1768 return oldExtension.equals(newExtension);
1771 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#getInputElement()
1773 protected IJavaElement getInputJavaElement() {
1774 return PHPeclipsePlugin.getDefault().getWorkingCopyManager().getWorkingCopy(getEditorInput());
1777 * @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager)
1779 public void editorContextMenuAboutToShow(IMenuManager menu) {
1780 super.editorContextMenuAboutToShow(menu);
1781 ActionContext context = new ActionContext(getSelectionProvider()
1783 fContextMenuGroup.setContext(context);
1784 fContextMenuGroup.fillContextMenu(menu);
1785 fContextMenuGroup.setContext(null);
1789 * @see JavaEditor#setOutlinePageInput(JavaOutlinePage, IEditorInput)
1791 protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input) {
1793 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1794 .getWorkingCopyManager();
1795 page.setInput(manager.getWorkingCopy(input));
1800 * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation,
1803 // protected void performSaveOperation(WorkspaceModifyOperation operation,
1804 // IProgressMonitor progressMonitor) {
1805 // IDocumentProvider p = getDocumentProvider();
1806 // if (p instanceof PHPDocumentProvider) {
1807 // PHPDocumentProvider cp = (PHPDocumentProvider) p;
1808 // cp.setSavePolicy(fSavePolicy);
1812 // super.performSaveOperation(operation, progressMonitor);
1814 // if (p instanceof PHPDocumentProvider) {
1815 // PHPDocumentProvider cp = (PHPDocumentProvider) p;
1816 // cp.setSavePolicy(null);
1821 * @see AbstractTextEditor#doSave(IProgressMonitor)
1823 public void doSave(IProgressMonitor progressMonitor) {
1825 IDocumentProvider p = getDocumentProvider();
1827 // editor has been closed
1831 if (p.isDeleted(getEditorInput())) {
1833 if (isSaveAsAllowed()) {
1836 * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the
1837 * editors. Changed Behavior to make sure that if called inside a
1838 * regular save (because of deletion of input element) there is a way to
1839 * report back to the caller.
1841 performSaveAs(progressMonitor);
1846 * 1GF5YOX: ITPJUI:ALL - Save of delete file claims it's still there
1847 * Missing resources.
1849 Shell shell = getSite().getShell();
1854 .getString("PHPUnitEditor.error.saving.title1"), PHPEditorMessages.getString("PHPUnitEditor.error.saving.message1")); //$NON-NLS-1$ //$NON-NLS-2$
1859 setStatusLineErrorMessage(null);
1861 updateState(getEditorInput());
1862 validateState(getEditorInput());
1864 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1865 .getWorkingCopyManager();
1866 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1869 synchronized (unit) {
1870 performSave(false, progressMonitor);
1873 performSave(false, progressMonitor);
1875 ShowExternalPreviewAction a = ShowExternalPreviewAction.getInstance();
1881 public boolean isSaveAsAllowed() {
1886 * The compilation unit editor implementation of this
1887 * <code>AbstractTextEditor</code> method asks the user for the workspace
1888 * path of a file resource and saves the document there. See
1889 * http://dev.eclipse.org/bugs/show_bug.cgi?id=6295
1891 * @param progressMonitor
1892 * the progress monitor
1894 protected void performSaveAs(IProgressMonitor progressMonitor) {
1896 Shell shell = getSite().getShell();
1897 IEditorInput input = getEditorInput();
1899 SaveAsDialog dialog = new SaveAsDialog(shell);
1901 IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input)
1904 if (original != null)
1905 dialog.setOriginalFile(original);
1909 IDocumentProvider provider = getDocumentProvider();
1910 if (provider == null) {
1911 // editor has been programmatically closed while the dialog was open
1915 if (provider.isDeleted(input) && original != null) {
1916 String message = PHPEditorMessages
1917 .getFormattedString(
1918 "CompilationUnitEditor.warning.save.delete", new Object[] { original.getName() }); //$NON-NLS-1$
1919 dialog.setErrorMessage(null);
1920 dialog.setMessage(message, IMessageProvider.WARNING);
1923 if (dialog.open() == Window.CANCEL) {
1924 if (progressMonitor != null)
1925 progressMonitor.setCanceled(true);
1929 IPath filePath = dialog.getResult();
1930 if (filePath == null) {
1931 if (progressMonitor != null)
1932 progressMonitor.setCanceled(true);
1936 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1937 IFile file = workspaceRoot.getFile(filePath);
1938 final IEditorInput newInput = new FileEditorInput(file);
1940 boolean success = false;
1943 provider.aboutToChange(newInput);
1944 getDocumentProvider().saveDocument(progressMonitor, newInput,
1945 getDocumentProvider().getDocument(getEditorInput()), true);
1948 } catch (CoreException x) {
1949 IStatus status = x.getStatus();
1950 if (status == null || status.getSeverity() != IStatus.CANCEL)
1955 .getString("CompilationUnitEditor.error.saving.title2"), PHPEditorMessages.getString("CompilationUnitEditor.error.saving.message2"), x.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
1957 provider.changed(newInput);
1962 if (progressMonitor != null)
1963 progressMonitor.setCanceled(!success);
1967 * @see AbstractTextEditor#doSetInput(IEditorInput)
1969 protected void doSetInput(IEditorInput input) throws CoreException {
1970 super.doSetInput(input);
1971 configureTabConverter();
1972 configureToggleCommentAction();
1977 // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#installOverrideIndicator(boolean)
1980 // protected void installOverrideIndicator(boolean waitForReconcilation) {
1981 // IAnnotationModel model=
1982 // getDocumentProvider().getAnnotationModel(getEditorInput());
1983 // if (!waitForReconcilation)
1984 // super.installOverrideIndicator(false);
1986 // uninstallOverrideIndicator();
1987 // IJavaElement inputElement= getInputJavaElement();
1988 // if (model == null || inputElement == null)
1991 // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
1992 // inputElement, null);
1993 // addReconcileListener(fOverrideIndicatorManager);
1999 // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#uninstallOverrideIndicator()
2002 // protected void uninstallOverrideIndicator() {
2003 // if (fOverrideIndicatorManager != null)
2004 // removeReconcileListener(fOverrideIndicatorManager);
2005 // super.uninstallOverrideIndicator();
2009 * Configures the toggle comment action
2013 private void configureToggleCommentAction() {
2014 IAction action = getAction("ToggleComment"); //$NON-NLS-1$
2015 if (action instanceof ToggleCommentAction) {
2016 ISourceViewer sourceViewer = getSourceViewer();
2017 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
2018 ((ToggleCommentAction) action).configure(sourceViewer, configuration);
2022 private void configureTabConverter() {
2023 if (fTabConverter != null) {
2024 IDocumentProvider provider = getDocumentProvider();
2025 if (provider instanceof PHPDocumentProvider) {
2026 PHPDocumentProvider cup = (PHPDocumentProvider) provider;
2027 fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
2032 private void startTabConversion() {
2033 if (fTabConverter == null) {
2034 fTabConverter = new TabConverter();
2035 configureTabConverter();
2036 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
2037 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
2038 asv.addTextConverter(fTabConverter);
2039 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
2040 asv.updateIndentationPrefixes();
2044 private void stopTabConversion() {
2045 if (fTabConverter != null) {
2046 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
2047 asv.removeTextConverter(fTabConverter);
2048 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
2049 asv.updateIndentationPrefixes();
2050 fTabConverter = null;
2055 * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean,
2056 * org.eclipse.core.runtime.IProgressMonitor)
2058 protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) {
2059 IDocumentProvider p = getDocumentProvider();
2060 if (p instanceof PHPDocumentProvider) {
2061 PHPDocumentProvider cp = (PHPDocumentProvider) p;
2062 cp.setSavePolicy(fSavePolicy);
2065 super.performSave(overwrite, progressMonitor);
2067 if (p instanceof PHPDocumentProvider) {
2068 PHPDocumentProvider cp = (PHPDocumentProvider) p;
2069 cp.setSavePolicy(null);
2075 * @see AbstractTextEditor#doSaveAs
2077 public void doSaveAs() {
2078 if (askIfNonWorkbenchEncodingIsOk()) {
2084 * Asks the user if it is ok to store in non-workbench encoding.
2086 * @return <true>if the user wants to continue
2088 private boolean askIfNonWorkbenchEncodingIsOk() {
2089 IDocumentProvider provider = getDocumentProvider();
2090 if (provider instanceof IStorageDocumentProvider) {
2091 IEditorInput input = getEditorInput();
2092 IStorageDocumentProvider storageProvider = (IStorageDocumentProvider) provider;
2093 String encoding = storageProvider.getEncoding(input);
2094 String defaultEncoding = storageProvider.getDefaultEncoding();
2095 if (encoding != null && !encoding.equals(defaultEncoding)) {
2096 Shell shell = getSite().getShell();
2097 String title = PHPEditorMessages
2098 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$
2104 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"),
2105 new String[] { input.getName(), encoding }); //$NON-NLS-1$
2110 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message2"),
2111 new String[] { encoding }); //$NON-NLS-1$
2112 return MessageDialog.openQuestion(shell, title, msg);
2119 * @see IReconcilingParticipant#reconciled()
2121 public void reconciled() {
2122 if (synchronizeOutlineOnCursorMove()) {
2123 Shell shell = getSite().getShell();
2124 if (shell != null && !shell.isDisposed()) {
2125 shell.getDisplay().asyncExec(new Runnable() {
2127 synchronizeOutlinePageSelection();
2134 protected void updateStateDependentActions() {
2135 super.updateStateDependentActions();
2136 fGenerateActionGroup.editorStateChanged();
2139 private boolean synchronizeOutlineOnCursorMove() {
2140 return PreferenceConstants.getPreferenceStore().getBoolean(
2141 PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE);
2145 * Returns the updated java element for the old java element.
2147 private IJavaElement findElement(IJavaElement element) {
2148 if (element == null)
2150 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
2151 .getWorkingCopyManager();
2152 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
2155 synchronized (unit) {
2158 IJavaElement[] findings = unit.findElements(element);
2159 if (findings != null && findings.length > 0)
2161 } catch (JavaModelException x) {
2162 PHPeclipsePlugin.log(x.getStatus());
2163 // nothing found, be tolerant and go on
2170 * Returns the offset of the given Java element.
2172 private int getOffset(IJavaElement element) {
2173 if (element instanceof ISourceReference) {
2174 ISourceReference sr = (ISourceReference) element;
2176 ISourceRange srcRange = sr.getSourceRange();
2177 if (srcRange != null)
2178 return srcRange.getOffset();
2179 } catch (JavaModelException e) {
2186 * @see AbstractTextEditor#rememberSelection()
2188 protected void rememberSelection() {
2189 ISelectionProvider sp = getSelectionProvider();
2190 fRememberedSelection = (sp == null ? null : (ITextSelection) sp
2192 if (fRememberedSelection != null) {
2193 fRememberedElement = getElementAt(fRememberedSelection.getOffset(), true);
2194 fRememberedElementOffset = getOffset(fRememberedElement);
2199 * @see AbstractTextEditor#restoreSelection()
2201 protected void restoreSelection() {
2203 if (getSourceViewer() == null || fRememberedSelection == null)
2205 IJavaElement newElement = findElement(fRememberedElement);
2206 int newOffset = getOffset(newElement);
2207 int delta = (newOffset > -1 && fRememberedElementOffset > -1) ? newOffset
2208 - fRememberedElementOffset : 0;
2209 if (isValidSelection(delta + fRememberedSelection.getOffset(),
2210 fRememberedSelection.getLength()))
2211 selectAndReveal(delta + fRememberedSelection.getOffset(),
2212 fRememberedSelection.getLength());
2214 fRememberedSelection = null;
2215 fRememberedElement = null;
2216 fRememberedElementOffset = -1;
2222 // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
2225 // public void aboutToBeReconciled() {
2227 // // Notify AST provider
2228 // PHPeclipsePlugin.getDefault().getASTProvider().aboutToBeReconciled(getInputJavaElement());
2230 // // Notify listeners
2231 // Object[] listeners = fReconcilingListeners.getListeners();
2232 // for (int i = 0, length= listeners.length; i < length; ++i)
2233 // ((IJavaReconcilingListener)listeners[i]).aboutToBeReconciled();
2238 // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit,
2239 // boolean, IProgressMonitor)
2242 // public void reconciled(net.sourceforge.phpdt.core.dom.CompilationUnit
2243 // ast, boolean forced, IProgressMonitor progressMonitor) {
2245 // // Always notify AST provider
2246 // PHPeclipsePlugin.getDefault().getASTProvider().reconciled(ast,
2247 // getInputJavaElement());
2249 // // Notify listeners
2250 // Object[] listeners = fReconcilingListeners.getListeners();
2251 // for (int i = 0, length= listeners.length; i < length; ++i)
2252 // ((IJavaReconcilingListener)listeners[i]).reconciled(ast, forced,
2253 // progressMonitor);
2255 // // Update Java Outline page selection
2256 // if (!forced && !progressMonitor.isCanceled()) {
2257 // Shell shell= getSite().getShell();
2258 // if (shell != null && !shell.isDisposed()) {
2259 // shell.getDisplay().asyncExec(new Runnable() {
2260 // public void run() {
2261 // selectionChanged();