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.AddBlockCommentAction;
16 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
17 import net.sourceforge.phpdt.internal.ui.actions.RemoveBlockCommentAction;
18 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
19 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
20 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
21 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
22 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
23 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags;
24 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
25 import net.sourceforge.phpdt.ui.PreferenceConstants;
26 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
27 import net.sourceforge.phpdt.ui.text.JavaTextTools;
28 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
30 import org.eclipse.core.resources.IFile;
31 import org.eclipse.core.resources.IWorkspaceRoot;
32 import org.eclipse.core.resources.ResourcesPlugin;
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IPath;
35 import org.eclipse.core.runtime.IProgressMonitor;
36 import org.eclipse.core.runtime.IStatus;
37 import org.eclipse.core.runtime.Preferences;
38 import org.eclipse.jface.action.Action;
39 import org.eclipse.jface.action.IAction;
40 import org.eclipse.jface.action.IMenuManager;
41 import org.eclipse.jface.dialogs.ErrorDialog;
42 import org.eclipse.jface.dialogs.IMessageProvider;
43 import org.eclipse.jface.dialogs.MessageDialog;
44 import org.eclipse.jface.preference.IPreferenceStore;
45 import org.eclipse.jface.preference.PreferenceConverter;
46 import org.eclipse.jface.text.BadLocationException;
47 import org.eclipse.jface.text.DocumentCommand;
48 import org.eclipse.jface.text.IDocument;
49 import org.eclipse.jface.text.ILineTracker;
50 import org.eclipse.jface.text.IRegion;
51 import org.eclipse.jface.text.ITextOperationTarget;
52 import org.eclipse.jface.text.ITextSelection;
53 import org.eclipse.jface.text.ITextViewerExtension;
54 import org.eclipse.jface.text.ITypedRegion;
55 import org.eclipse.jface.text.IWidgetTokenKeeper;
56 import org.eclipse.jface.text.contentassist.ContentAssistant;
57 import org.eclipse.jface.text.contentassist.IContentAssistant;
58 import org.eclipse.jface.text.source.IOverviewRuler;
59 import org.eclipse.jface.text.source.ISourceViewer;
60 import org.eclipse.jface.text.source.IVerticalRuler;
61 import org.eclipse.jface.text.source.SourceViewerConfiguration;
62 import org.eclipse.jface.util.PropertyChangeEvent;
63 import org.eclipse.jface.viewers.ISelectionProvider;
64 import org.eclipse.jface.window.Window;
65 import org.eclipse.swt.SWT;
66 import org.eclipse.swt.custom.VerifyKeyListener;
67 import org.eclipse.swt.events.VerifyEvent;
68 import org.eclipse.swt.graphics.Color;
69 import org.eclipse.swt.graphics.Point;
70 import org.eclipse.swt.graphics.RGB;
71 import org.eclipse.swt.widgets.Composite;
72 import org.eclipse.swt.widgets.Display;
73 import org.eclipse.swt.widgets.Shell;
74 import org.eclipse.ui.IEditorInput;
75 import org.eclipse.ui.IFileEditorInput;
76 import org.eclipse.ui.actions.ActionContext;
77 import org.eclipse.ui.actions.ActionGroup;
78 import org.eclipse.ui.dialogs.SaveAsDialog;
79 import org.eclipse.ui.editors.text.IStorageDocumentProvider;
80 import org.eclipse.ui.help.WorkbenchHelp;
81 import org.eclipse.ui.part.FileEditorInput;
82 import org.eclipse.ui.texteditor.ContentAssistAction;
83 import org.eclipse.ui.texteditor.IDocumentProvider;
84 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
85 import org.eclipse.ui.texteditor.TextOperationAction;
86 /*******************************************************************************
87 * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
88 * program and the accompanying materials are made available under the terms of
89 * the Common Public License v1.0 which accompanies this distribution, and is
90 * available at http://www.eclipse.org/legal/cpl-v10.html
92 * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
93 * www.eclipseproject.de
94 ******************************************************************************/
96 * PHP specific text editor.
98 public class PHPUnitEditor extends PHPEditor { //implements
99 // IJavaReconcilingListener {
100 interface ITextConverter {
101 void customizeDocumentCommand(IDocument document,
102 DocumentCommand command);
104 // class AdaptedRulerLayout extends Layout {
106 // protected int fGap;
107 // protected AdaptedSourceViewer fAdaptedSourceViewer;
109 // protected AdaptedRulerLayout(int gap, AdaptedSourceViewer asv) {
111 // fAdaptedSourceViewer = asv;
114 // protected Point computeSize(Composite composite, int wHint, int hHint,
115 // boolean flushCache) {
116 // Control[] children = composite.getChildren();
117 // Point s = children[children.length - 1].computeSize(SWT.DEFAULT,
118 // SWT.DEFAULT, flushCache);
119 // if (fAdaptedSourceViewer.isVerticalRulerVisible())
120 // s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap;
124 // protected void layout(Composite composite, boolean flushCache) {
125 // Rectangle clArea = composite.getClientArea();
126 // if (fAdaptedSourceViewer.isVerticalRulerVisible()) {
128 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
129 // Rectangle trim = textWidget.computeTrim(0, 0, 0, 0);
130 // int scrollbarHeight = trim.height;
132 // IVerticalRuler vr = fAdaptedSourceViewer.getVerticalRuler();
133 // int vrWidth = vr.getWidth();
136 // if (fAdaptedSourceViewer.isOverviewRulerVisible()) {
137 // OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler();
138 // orWidth = or.getWidth();
139 // or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight,
140 // orWidth, clArea.height - 3 * scrollbarHeight);
143 // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth
145 // 2 * fGap, clArea.height);
146 // vr.getControl().setBounds(0, 0, vrWidth, clArea.height -
150 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
151 // textWidget.setBounds(0, 0, clArea.width, clArea.height);
156 // class AdaptedSourceViewer extends SourceViewer { // extends
157 // JavaCorrectionSourceViewer {
159 // private List fTextConverters;
161 // private OverviewRuler fOverviewRuler;
162 // private boolean fIsOverviewRulerVisible;
163 // /** The viewer's overview ruler hovering controller */
164 // private AbstractHoverInformationControlManager
165 // fOverviewRulerHoveringController;
167 // private boolean fIgnoreTextConverters = false;
169 // private IVerticalRuler fCachedVerticalRuler;
170 // private boolean fCachedIsVerticalRulerVisible;
172 // public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int
174 // super(parent, ruler, styles); //, CompilationUnitEditor.this);
176 // fCachedVerticalRuler = ruler;
177 // fCachedIsVerticalRulerVisible = (ruler != null);
178 // fOverviewRuler = new OverviewRuler(VERTICAL_RULER_WIDTH);
180 // delayedCreateControl(parent, styles);
184 // * @see ISourceViewer#showAnnotations(boolean)
186 // public void showAnnotations(boolean show) {
187 // fCachedIsVerticalRulerVisible = (show && fCachedVerticalRuler != null);
188 // // super.showAnnotations(show);
191 // public IContentAssistant getContentAssistant() {
192 // return fContentAssistant;
196 // * @see ITextOperationTarget#doOperation(int)
198 // public void doOperation(int operation) {
200 // if (getTextWidget() == null)
203 // switch (operation) {
204 // case CONTENTASSIST_PROPOSALS :
205 // String msg = fContentAssistant.showPossibleCompletions();
206 // setStatusLineErrorMessage(msg);
209 // fIgnoreTextConverters = true;
212 // fIgnoreTextConverters = true;
216 // super.doOperation(operation);
219 // public void insertTextConverter(ITextConverter textConverter, int index)
221 // throw new UnsupportedOperationException();
224 // public void addTextConverter(ITextConverter textConverter) {
225 // if (fTextConverters == null) {
226 // fTextConverters = new ArrayList(1);
227 // fTextConverters.add(textConverter);
228 // } else if (!fTextConverters.contains(textConverter))
229 // fTextConverters.add(textConverter);
232 // public void removeTextConverter(ITextConverter textConverter) {
233 // if (fTextConverters != null) {
234 // fTextConverters.remove(textConverter);
235 // if (fTextConverters.size() == 0)
236 // fTextConverters = null;
241 // * @see TextViewer#customizeDocumentCommand(DocumentCommand)
243 // protected void customizeDocumentCommand(DocumentCommand command) {
244 // super.customizeDocumentCommand(command);
245 // if (!fIgnoreTextConverters && fTextConverters != null) {
246 // for (Iterator e = fTextConverters.iterator(); e.hasNext();)
247 // ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(),
250 // fIgnoreTextConverters = false;
253 // public IVerticalRuler getVerticalRuler() {
254 // return fCachedVerticalRuler;
257 // public boolean isVerticalRulerVisible() {
258 // return fCachedIsVerticalRulerVisible;
261 // public OverviewRuler getOverviewRuler() {
262 // return fOverviewRuler;
266 // * @see TextViewer#createControl(Composite, int)
268 // protected void createControl(Composite parent, int styles) {
269 // // do nothing here
272 // protected void delayedCreateControl(Composite parent, int styles) {
273 // //create the viewer
274 // super.createControl(parent, styles);
276 // Control control = getControl();
277 // if (control instanceof Composite) {
278 // Composite composite = (Composite) control;
279 // composite.setLayout(new AdaptedRulerLayout(GAP_SIZE, this));
280 // fOverviewRuler.createControl(composite, this);
283 // protected void ensureOverviewHoverManagerInstalled() {
284 // if (fOverviewRulerHoveringController == null && fAnnotationHover != null
285 // && fHoverControlCreator != null) {
286 // fOverviewRulerHoveringController =
287 // new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover,
288 // fHoverControlCreator);
289 // fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
293 // public void hideOverviewRuler() {
294 // fIsOverviewRulerVisible = false;
295 // Control control = getControl();
296 // if (control instanceof Composite) {
297 // Composite composite = (Composite) control;
298 // composite.layout();
300 // if (fOverviewRulerHoveringController != null) {
301 // fOverviewRulerHoveringController.dispose();
302 // fOverviewRulerHoveringController = null;
306 // public void showOverviewRuler() {
307 // fIsOverviewRulerVisible = true;
308 // Control control = getControl();
309 // if (control instanceof Composite) {
310 // Composite composite = (Composite) control;
311 // composite.layout();
313 // ensureOverviewHoverManagerInstalled();
316 // public boolean isOverviewRulerVisible() {
317 // return fIsOverviewRulerVisible;
321 // * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
323 // public void setDocument(
324 // IDocument document,
325 // IAnnotationModel annotationModel,
326 // int visibleRegionOffset,
327 // int visibleRegionLength) {
328 // super.setDocument(document, annotationModel, visibleRegionOffset,
329 // visibleRegionLength);
330 // fOverviewRuler.setModel(annotationModel);
333 // // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
334 // public void updateIndentationPrefixes() {
335 // SourceViewerConfiguration configuration = getSourceViewerConfiguration();
336 // String[] types = configuration.getConfiguredContentTypes(this);
337 // for (int i = 0; i < types.length; i++) {
338 // String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
339 // if (prefixes != null && prefixes.length > 0)
340 // setIndentPrefixes(prefixes, types[i]);
345 // * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
347 // public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
348 // if (WorkbenchHelp.isContextHelpDisplayed())
350 // return super.requestWidgetToken(requester);
355 // org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
357 // public void configure(SourceViewerConfiguration configuration) {
358 // super.configure(configuration);
359 // // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
360 // IDocument.DEFAULT_CONTENT_TYPE);
363 // protected void handleDispose() {
364 // fOverviewRuler = null;
366 // if (fOverviewRulerHoveringController != null) {
367 // fOverviewRulerHoveringController.dispose();
368 // fOverviewRulerHoveringController = null;
371 // super.handleDispose();
375 class AdaptedSourceViewer extends JavaSourceViewer {
376 private List fTextConverters;
377 private boolean fIgnoreTextConverters = false;
378 // private JavaCorrectionAssistant fCorrectionAssistant;
379 public AdaptedSourceViewer(Composite parent,
380 IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
381 boolean showAnnotationsOverview, int styles,
382 IPreferenceStore store) {
383 super(parent, verticalRuler, overviewRuler,
384 showAnnotationsOverview, styles, store);
386 // public AdaptedSourceViewer(Composite parent,
387 // IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
388 // boolean showAnnotationsOverview, int styles) {
389 // super(parent, verticalRuler, overviewRuler,
390 // showAnnotationsOverview, styles);
392 public IContentAssistant getContentAssistant() {
393 return fContentAssistant;
396 * @see ITextOperationTarget#doOperation(int)
398 public void doOperation(int operation) {
399 if (getTextWidget() == null)
402 case CONTENTASSIST_PROPOSALS :
403 String msg = fContentAssistant.showPossibleCompletions();
404 setStatusLineErrorMessage(msg);
406 // case CORRECTIONASSIST_PROPOSALS:
407 // fCorrectionAssistant.showPossibleCompletions();
410 fIgnoreTextConverters = true;
413 fIgnoreTextConverters = true;
416 super.doOperation(operation);
419 * @see ITextOperationTarget#canDoOperation(int)
421 public boolean canDoOperation(int operation) {
422 // if (operation == CORRECTIONASSIST_PROPOSALS)
423 // return isEditable();
424 return super.canDoOperation(operation);
427 * @see TextViewer#handleDispose()
429 protected void handleDispose() {
430 // if (fCorrectionAssistant != null) {
431 // fCorrectionAssistant.uninstall();
432 // fCorrectionAssistant= null;
434 super.handleDispose();
436 public void insertTextConverter(ITextConverter textConverter, int index) {
437 throw new UnsupportedOperationException();
439 public void addTextConverter(ITextConverter textConverter) {
440 if (fTextConverters == null) {
441 fTextConverters = new ArrayList(1);
442 fTextConverters.add(textConverter);
443 } else if (!fTextConverters.contains(textConverter))
444 fTextConverters.add(textConverter);
446 public void removeTextConverter(ITextConverter textConverter) {
447 if (fTextConverters != null) {
448 fTextConverters.remove(textConverter);
449 if (fTextConverters.size() == 0)
450 fTextConverters = null;
454 * @see TextViewer#customizeDocumentCommand(DocumentCommand)
456 protected void customizeDocumentCommand(DocumentCommand command) {
457 super.customizeDocumentCommand(command);
458 if (!fIgnoreTextConverters && fTextConverters != null) {
459 for (Iterator e = fTextConverters.iterator(); e.hasNext();)
460 ((ITextConverter) e.next()).customizeDocumentCommand(
461 getDocument(), command);
463 fIgnoreTextConverters = false;
465 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
466 public void updateIndentationPrefixes() {
467 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
468 String[] types = configuration.getConfiguredContentTypes(this);
469 for (int i = 0; i < types.length; i++) {
470 String[] prefixes = configuration.getIndentPrefixes(this,
472 if (prefixes != null && prefixes.length > 0)
473 setIndentPrefixes(prefixes, types[i]);
477 * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
479 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
480 if (WorkbenchHelp.isContextHelpDisplayed())
482 return super.requestWidgetToken(requester);
485 * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
487 public void configure(SourceViewerConfiguration configuration) {
488 super.configure(configuration);
489 // fCorrectionAssistant= new
490 // JavaCorrectionAssistant(CompilationUnitEditor.this);
491 // fCorrectionAssistant.install(this);
492 //TODO install SmartBracesAutoEditStrategy
493 // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
494 // IDocument.DEFAULT_CONTENT_TYPE);
497 static class TabConverter implements ITextConverter {
498 private int fTabRatio;
499 private ILineTracker fLineTracker;
500 public TabConverter() {
502 public void setNumberOfSpacesPerTab(int ratio) {
505 public void setLineTracker(ILineTracker lineTracker) {
506 fLineTracker = lineTracker;
508 private int insertTabString(StringBuffer buffer, int offsetInLine) {
511 int remainder = offsetInLine % fTabRatio;
512 remainder = fTabRatio - remainder;
513 for (int i = 0; i < remainder; i++)
517 public void customizeDocumentCommand(IDocument document,
518 DocumentCommand command) {
519 String text = command.text;
522 int index = text.indexOf('\t');
524 StringBuffer buffer = new StringBuffer();
525 fLineTracker.set(command.text);
526 int lines = fLineTracker.getNumberOfLines();
528 for (int i = 0; i < lines; i++) {
529 int offset = fLineTracker.getLineOffset(i);
530 int endOffset = offset + fLineTracker.getLineLength(i);
531 String line = text.substring(offset, endOffset);
534 IRegion firstLine = document
535 .getLineInformationOfOffset(command.offset);
536 position = command.offset - firstLine.getOffset();
538 int length = line.length();
539 for (int j = 0; j < length; j++) {
540 char c = line.charAt(j);
542 position += insertTabString(buffer, position);
549 command.text = buffer.toString();
550 } catch (BadLocationException x) {
555 private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
556 final char fExitCharacter;
557 public ExitPolicy(char exitCharacter) {
558 fExitCharacter = exitCharacter;
561 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager,
562 * org.eclipse.swt.events.VerifyEvent, int, int)
564 public ExitFlags doExit(LinkedPositionManager manager,
565 VerifyEvent event, int offset, int length) {
566 if (event.character == fExitCharacter) {
567 if (manager.anyPositionIncludes(offset, length))
568 return new ExitFlags(LinkedPositionUI.COMMIT
569 | LinkedPositionUI.UPDATE_CARET, false);
571 return new ExitFlags(LinkedPositionUI.COMMIT, true);
573 switch (event.character) {
575 if (manager.getFirstPosition().length == 0)
576 return new ExitFlags(0, false);
581 return new ExitFlags(LinkedPositionUI.COMMIT, true);
587 private static class BracketLevel {
590 LinkedPositionManager fManager;
591 LinkedPositionUI fEditor;
593 private class BracketInserter
596 LinkedPositionUI.ExitListener {
597 private boolean fCloseBracketsPHP = true;
598 private boolean fCloseStringsPHP = true;
599 private boolean fCloseBracketsHTML = true;
600 private boolean fCloseStringsHTML = true;
603 public void setCloseBracketsPHPEnabled(boolean enabled) {
604 fCloseBracketsPHP = enabled;
606 public void setCloseStringsPHPEnabled(boolean enabled) {
607 fCloseStringsPHP = enabled;
609 public void setCloseBracketsHTMLEnabled(boolean enabled) {
610 fCloseBracketsHTML = enabled;
612 public void setCloseStringsHTMLEnabled(boolean enabled) {
613 fCloseStringsHTML = enabled;
615 private boolean hasIdentifierToTheRight(IDocument document, int offset) {
618 IRegion endLine = document.getLineInformationOfOffset(end);
619 int maxEnd = endLine.getOffset() + endLine.getLength();
621 && Character.isWhitespace(document.getChar(end)))
624 && Scanner.isPHPIdentifierPart(document.getChar(end));
625 } catch (BadLocationException e) {
630 private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
633 IRegion startLine = document.getLineInformationOfOffset(start);
634 int minStart = startLine.getOffset();
635 while (start != minStart
636 && Character.isWhitespace(document.getChar(start - 1)))
638 return start != minStart
639 && Scanner.isPHPIdentifierPart(document
640 .getChar(start - 1));
641 } catch (BadLocationException e) {
645 private boolean hasCharacterToTheRight(IDocument document, int offset,
649 IRegion endLine = document.getLineInformationOfOffset(end);
650 int maxEnd = endLine.getOffset() + endLine.getLength();
652 && Character.isWhitespace(document.getChar(end)))
654 return end != maxEnd && document.getChar(end) == character;
655 } catch (BadLocationException e) {
661 * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
663 public void verifyKey(VerifyEvent event) {
666 final ISourceViewer sourceViewer = getSourceViewer();
667 IDocument document = sourceViewer.getDocument();
668 final Point selection = sourceViewer.getSelectedRange();
669 final int offset = selection.x;
670 final int length = selection.y;
672 ITypedRegion partition = document.getPartition(offset);
673 String type = partition.getType();
674 if (type.equals(IPHPPartitions.PHP_PARTITIONING)) {
675 switch (event.character) {
677 if (hasCharacterToTheRight(document, offset
682 if (!fCloseBracketsPHP)
684 if (hasIdentifierToTheRight(document, offset
689 if (event.character == '"') {
690 if (!fCloseStringsPHP)
692 // changed for statements like echo "" print ""
693 // if (hasIdentifierToTheLeft(document, offset)
695 // hasIdentifierToTheRight(document, offset +
697 if (hasIdentifierToTheRight(document, offset
701 // ITypedRegion partition=
702 // document.getPartition(offset);
704 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
706 // (partition.getOffset() != offset))
708 final char character = event.character;
709 final char closingCharacter = getPeerCharacter(character);
710 final StringBuffer buffer = new StringBuffer();
711 buffer.append(character);
712 buffer.append(closingCharacter);
713 document.replace(offset, length, buffer.toString());
714 LinkedPositionManager manager = new LinkedPositionManager(
716 manager.addPosition(offset + 1, 0);
719 LinkedPositionUI editor = new LinkedPositionUI(
720 sourceViewer, manager);
721 editor.setCancelListener(this);
722 editor.setExitPolicy(new ExitPolicy(
724 editor.setFinalCaretOffset(offset + 2);
726 IRegion newSelection = editor.getSelectedRegion();
727 sourceViewer.setSelectedRange(newSelection
728 .getOffset(), newSelection.getLength());
731 } else if (type.equals(IPHPPartitions.HTML)
732 || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
733 switch (event.character) {
735 if (hasCharacterToTheRight(document, offset
740 if (!fCloseBracketsHTML)
742 if (hasIdentifierToTheRight(document, offset
747 if (event.character == '"') {
748 if (!fCloseStringsHTML)
750 if (hasIdentifierToTheLeft(document, offset)
751 || hasIdentifierToTheRight(document,
755 // ITypedRegion partition=
756 // document.getPartition(offset);
758 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
760 // (partition.getOffset() != offset))
762 final char character = event.character;
763 final char closingCharacter = getPeerCharacter(character);
764 final StringBuffer buffer = new StringBuffer();
765 buffer.append(character);
766 buffer.append(closingCharacter);
767 document.replace(offset, length, buffer.toString());
768 LinkedPositionManager manager = new LinkedPositionManager(
770 manager.addPosition(offset + 1, 0);
773 LinkedPositionUI editor = new LinkedPositionUI(
774 sourceViewer, manager);
775 editor.setCancelListener(this);
776 editor.setExitPolicy(new ExitPolicy(
778 editor.setFinalCaretOffset(offset + 2);
780 IRegion newSelection = editor.getSelectedRegion();
781 sourceViewer.setSelectedRange(newSelection
782 .getOffset(), newSelection.getLength());
786 } catch (BadLocationException e) {
790 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean)
792 public void exit(boolean accept) {
797 final ISourceViewer sourceViewer = getSourceViewer();
798 IDocument document = sourceViewer.getDocument();
799 document.replace(fOffset, fLength, null);
800 } catch (BadLocationException e) {
804 /** The editor's save policy */
805 protected ISavePolicy fSavePolicy;
807 * Listener to annotation model changes that updates the error tick in the
810 private JavaEditorErrorTickUpdater fJavaEditorErrorTickUpdater;
811 /** The editor's paint manager */
812 // private PaintManager fPaintManager;
813 /** The editor's bracket painter */
814 private BracketPainter fBracketPainter;
815 /** The editor's bracket matcher */
816 private PHPPairMatcher fBracketMatcher;
817 /** The editor's line painter */
818 private LinePainter fLinePainter;
819 /** The editor's print margin ruler painter */
820 private PrintMarginPainter fPrintMarginPainter;
821 /** The editor's problem painter */
822 // private ProblemPainter fProblemPainter;
823 /** The editor's tab converter */
824 private TabConverter fTabConverter;
825 /** History for structure select action */
826 //private SelectionHistory fSelectionHistory;
827 /** The preference property change listener for php core. */
828 // private IPropertyChangeListener fPropertyChangeListener = new
829 // PropertyChangeListener();
830 /** The remembered java element */
831 private IJavaElement fRememberedElement;
832 /** The remembered selection */
833 private ITextSelection fRememberedSelection;
834 /** The remembered php element offset */
835 private int fRememberedElementOffset;
836 /** The bracket inserter. */
837 private BracketInserter fBracketInserter = new BracketInserter();
839 /** The standard action groups added to the menu */
840 private GenerateActionGroup fGenerateActionGroup;
841 private CompositeActionGroup fContextMenuGroup;
842 // private class PropertyChangeListener implements IPropertyChangeListener {
844 // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
847 // propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
849 // handlePreferencePropertyChanged(event);
852 /* Preference key for code formatter tab size */
853 private final static String CODE_FORMATTER_TAB_SIZE = JavaCore.FORMATTER_TAB_SIZE;
854 /** Preference key for matching brackets */
855 private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
856 /** Preference key for matching brackets color */
857 private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
858 /** Preference key for highlighting current line */
859 private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
860 /** Preference key for highlight color of current line */
861 private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
862 /** Preference key for showing print marging ruler */
863 private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
864 /** Preference key for print margin ruler color */
865 private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
866 /** Preference key for print margin ruler column */
867 private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
868 /** Preference key for inserting spaces rather than tabs */
869 private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
870 /** Preference key for error indication */
871 // private final static String ERROR_INDICATION =
872 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
873 /** Preference key for error color */
874 // private final static String ERROR_INDICATION_COLOR =
875 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
876 /** Preference key for warning indication */
877 // private final static String WARNING_INDICATION =
878 // PreferenceConstants.EDITOR_WARNING_INDICATION;
879 /** Preference key for warning color */
880 // private final static String WARNING_INDICATION_COLOR =
881 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
882 /** Preference key for task indication */
883 private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
884 /** Preference key for task color */
885 private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
886 /** Preference key for bookmark indication */
887 private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
888 /** Preference key for bookmark color */
889 private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
890 /** Preference key for search result indication */
891 private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
892 /** Preference key for search result color */
893 private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
894 /** Preference key for unknown annotation indication */
895 private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
896 /** Preference key for unknown annotation color */
897 private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
898 /** Preference key for linked position color */
899 private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
900 /** Preference key for shwoing the overview ruler */
901 private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
902 /** Preference key for error indication in overview ruler */
903 private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
904 /** Preference key for warning indication in overview ruler */
905 private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
906 /** Preference key for task indication in overview ruler */
907 private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
908 /** Preference key for bookmark indication in overview ruler */
909 private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
910 /** Preference key for search result indication in overview ruler */
911 private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
912 /** Preference key for unknown annotation indication in overview ruler */
913 private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
914 /** Preference key for automatically closing strings */
915 private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP;
916 /** Preference key for automatically wrapping Java strings */
917 private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS;
918 /** Preference key for automatically closing brackets and parenthesis */
919 private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
920 /** Preference key for automatically closing phpdocs and comments */
921 private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
922 /** Preference key for automatically adding phpdoc tags */
923 private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
924 /** Preference key for automatically formatting phpdocs */
925 private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
926 /** Preference key for automatically closing strings */
927 private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
928 /** Preference key for automatically closing brackets and parenthesis */
929 private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
930 /** Preference key for smart paste */
931 private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
932 // private final static class AnnotationInfo {
933 // public String fColorPreference;
934 // public String fOverviewRulerPreference;
935 // public String fEditorPreference;
937 // private final static Map ANNOTATION_MAP;
940 // AnnotationInfo info;
941 // ANNOTATION_MAP = new HashMap();
943 // info = new AnnotationInfo();
944 // info.fColorPreference = TASK_INDICATION_COLOR;
945 // info.fOverviewRulerPreference = TASK_INDICATION_IN_OVERVIEW_RULER;
946 // info.fEditorPreference = TASK_INDICATION;
947 // ANNOTATION_MAP.put(AnnotationType.TASK, info);
949 // info = new AnnotationInfo();
950 // info.fColorPreference = ERROR_INDICATION_COLOR;
951 // info.fOverviewRulerPreference = ERROR_INDICATION_IN_OVERVIEW_RULER;
952 // info.fEditorPreference = ERROR_INDICATION;
953 // ANNOTATION_MAP.put(AnnotationType.ERROR, info);
955 // info = new AnnotationInfo();
956 // info.fColorPreference = WARNING_INDICATION_COLOR;
957 // info.fOverviewRulerPreference = WARNING_INDICATION_IN_OVERVIEW_RULER;
958 // info.fEditorPreference = WARNING_INDICATION;
959 // ANNOTATION_MAP.put(AnnotationType.WARNING, info);
961 // info = new AnnotationInfo();
962 // info.fColorPreference = BOOKMARK_INDICATION_COLOR;
963 // info.fOverviewRulerPreference = BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
964 // info.fEditorPreference = BOOKMARK_INDICATION;
965 // ANNOTATION_MAP.put(AnnotationType.BOOKMARK, info);
967 // info = new AnnotationInfo();
968 // info.fColorPreference = SEARCH_RESULT_INDICATION_COLOR;
969 // info.fOverviewRulerPreference =
970 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
971 // info.fEditorPreference = SEARCH_RESULT_INDICATION;
972 // ANNOTATION_MAP.put(AnnotationType.SEARCH, info);
974 // info = new AnnotationInfo();
975 // info.fColorPreference = UNKNOWN_INDICATION_COLOR;
976 // info.fOverviewRulerPreference = UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
977 // info.fEditorPreference = UNKNOWN_INDICATION;
978 // ANNOTATION_MAP.put(AnnotationType.UNKNOWN, info);
981 // private final static AnnotationType[] ANNOTATION_LAYERS =
982 // new AnnotationType[] {
983 // AnnotationType.UNKNOWN,
984 // AnnotationType.BOOKMARK,
985 // AnnotationType.TASK,
986 // AnnotationType.SEARCH,
987 // AnnotationType.WARNING,
988 // AnnotationType.ERROR };
990 * Creates a new php unit editor.
992 public PHPUnitEditor() {
994 setDocumentProvider(PHPeclipsePlugin.getDefault()
995 .getCompilationUnitDocumentProvider());
996 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
997 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
998 setOutlinerContextMenuId("#PHPOutlinerContext"); //$NON-NLS-1$
999 // don't set help contextId, we install our own help context
1001 fJavaEditorErrorTickUpdater = new JavaEditorErrorTickUpdater(this);
1004 * @see AbstractTextEditor#createActions()
1006 protected void createActions() {
1007 super.createActions();
1009 // Action action= new
1010 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1011 // "CorrectionAssistProposal.", this, CORRECTIONASSIST_PROPOSALS);
1013 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
1014 // setAction("CorrectionAssistProposal", action); //$NON-NLS-1$
1015 // markAsStateDependentAction("CorrectionAssistProposal", true);
1017 //// WorkbenchHelp.setHelp(action,
1018 // IJavaHelpContextIds.QUICK_FIX_ACTION);
1019 action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(),
1020 "ContentAssistProposal.", this); //$NON-NLS-1$
1022 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
1023 setAction("ContentAssistProposal", action); //$NON-NLS-1$
1024 markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
1025 // WorkbenchHelp.setHelp(action,
1026 // IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
1027 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1028 "ContentAssistContextInformation.", this,
1029 ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$
1031 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
1032 setAction("ContentAssistContextInformation", action); //$NON-NLS-1$
1033 markAsStateDependentAction("ContentAssistContextInformation", true); //$NON-NLS-1$
1034 // WorkbenchHelp.setHelp(action,
1035 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1037 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1038 // "ContentAssistCompletePrefix.", this, CONTENTASSIST_COMPLETE_PREFIX);
1040 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_COMPLETE_PREFIX);
1041 // setAction("ContentAssistCompletePrefix", action); //$NON-NLS-1$
1042 // markAsStateDependentAction("ContentAssistCompletePrefix", true);
1044 //// WorkbenchHelp.setHelp(action,
1045 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1046 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1047 "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
1048 action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
1049 setAction("Comment", action); //$NON-NLS-1$
1050 markAsStateDependentAction("Comment", true); //$NON-NLS-1$
1051 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
1052 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1053 "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
1054 action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
1055 setAction("Uncomment", action); //$NON-NLS-1$
1056 markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
1057 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
1059 action = new ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1060 "ToggleComment.", this); //$NON-NLS-1$
1062 .setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1063 setAction("ToggleComment", action); //$NON-NLS-1$
1064 markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1065 //WorkbenchHelp.setHelp(action,
1066 // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1067 configureToggleCommentAction();
1070 // ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1071 // "ToggleComment.", this, getSourceViewerConfiguration()
1072 // .getDefaultPrefixes(getSourceViewer(), "")); //$NON-NLS-1$
1074 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1075 // setAction("ToggleComment", action); //$NON-NLS-1$
1076 // markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1077 // // WorkbenchHelp.setHelp(action,
1078 // // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1080 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1081 "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
1082 action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
1083 setAction("Format", action); //$NON-NLS-1$
1084 markAsStateDependentAction("Format", true); //$NON-NLS-1$
1085 markAsSelectionDependentAction("Format", true); //$NON-NLS-1$
1086 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
1088 action = new AddBlockCommentAction(PHPEditorMessages
1089 .getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$
1091 .setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
1092 setAction("AddBlockComment", action); //$NON-NLS-1$
1093 markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
1094 markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
1095 // WorkbenchHelp.setHelp(action,
1096 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1097 action = new RemoveBlockCommentAction(PHPEditorMessages
1098 .getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
1100 .setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
1101 setAction("RemoveBlockComment", action); //$NON-NLS-1$
1102 markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1103 markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1104 // WorkbenchHelp.setHelp(action,
1105 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1106 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1107 // "Indent.", this, false); //$NON-NLS-1$
1108 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT);
1109 // setAction("Indent", action); //$NON-NLS-1$
1110 // markAsStateDependentAction("Indent", true); //$NON-NLS-1$
1111 // markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
1112 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION);
1114 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1115 // "Indent.", this, true); //$NON-NLS-1$
1116 // setAction("IndentOnTab", action); //$NON-NLS-1$
1117 // markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
1118 // markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$
1120 if (getPreferenceStore().getBoolean(
1121 PreferenceConstants.EDITOR_SMART_TAB)) {
1122 // don't replace Shift Right - have to make sure their enablement is
1123 // mutually exclusive
1124 // removeActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT);
1125 setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$
1127 fGenerateActionGroup = new GenerateActionGroup(this,
1128 ITextEditorActionConstants.GROUP_EDIT);
1129 fActionGroups = new CompositeActionGroup(
1130 new ActionGroup[]{fGenerateActionGroup});
1131 // We have to keep the context menu group separate to have better
1134 fContextMenuGroup = new CompositeActionGroup(
1135 new ActionGroup[]{fGenerateActionGroup});
1137 // new LocalHistoryActionGroup(this,
1138 // ITextEditorActionConstants.GROUP_EDIT)});
1142 * @see JavaEditor#getElementAt(int)
1144 protected IJavaElement getElementAt(int offset) {
1145 return getElementAt(offset, true);
1148 * Returns the most narrow element including the given offset. If
1149 * <code>reconcile</code> is <code>true</code> the editor's input
1150 * element is reconciled in advance. If it is <code>false</code> this
1151 * method only returns a result if the editor's input element does not need
1155 * the offset included by the retrieved element
1157 * <code>true</code> if working copy should be reconciled
1159 protected IJavaElement getElementAt(int offset, boolean reconcile) {
1160 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1161 .getWorkingCopyManager();
1162 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1166 synchronized (unit) {
1169 return unit.getElementAt(offset);
1170 } else if (unit.isConsistent())
1171 return unit.getElementAt(offset);
1172 } catch (JavaModelException x) {
1173 PHPeclipsePlugin.log(x.getStatus());
1174 // nothing found, be tolerant and go on
1180 * @see JavaEditor#getCorrespondingElement(IJavaElement)
1182 protected IJavaElement getCorrespondingElement(IJavaElement element) {
1184 return EditorUtility.getWorkingCopy(element, true);
1185 } catch (JavaModelException x) {
1186 PHPeclipsePlugin.log(x.getStatus());
1187 // nothing found, be tolerant and go on
1191 public void createPartControl(Composite parent) {
1192 super.createPartControl(parent);
1193 // fPaintManager = new PaintManager(getSourceViewer());
1194 LinePainter linePainter;
1195 linePainter = new LinePainter(getSourceViewer());
1196 linePainter.setHighlightColor(new Color(Display.getCurrent(), 225, 235,
1198 // fPaintManager.addPainter(linePainter);
1199 if (isBracketHighlightingEnabled())
1200 startBracketHighlighting();
1201 if (isLineHighlightingEnabled())
1202 startLineHighlighting();
1203 if (isPrintMarginVisible())
1205 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1206 // while (e.hasNext()) {
1207 // AnnotationType type = (AnnotationType) e.next();
1208 // if (isAnnotationIndicationEnabled(type))
1209 // startAnnotationIndication(type);
1211 if (isTabConversionEnabled())
1212 startTabConversion();
1213 // if (isOverviewRulerVisible())
1214 // showOverviewRuler();
1216 // Preferences preferences =
1217 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1218 // preferences.addPropertyChangeListener(fPropertyChangeListener);
1219 IPreferenceStore preferenceStore = getPreferenceStore();
1220 boolean closeBracketsPHP = preferenceStore
1221 .getBoolean(CLOSE_BRACKETS_PHP);
1222 boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP);
1223 boolean closeBracketsHTML = preferenceStore
1224 .getBoolean(CLOSE_BRACKETS_HTML);
1225 boolean closeStringsHTML = preferenceStore
1226 .getBoolean(CLOSE_STRINGS_HTML);
1227 fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
1228 fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP);
1229 fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
1230 fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
1231 ISourceViewer sourceViewer = getSourceViewer();
1232 if (sourceViewer instanceof ITextViewerExtension)
1233 ((ITextViewerExtension) sourceViewer)
1234 .prependVerifyKeyListener(fBracketInserter);
1236 private static char getPeerCharacter(char character) {
1237 switch (character) {
1249 throw new IllegalArgumentException();
1253 private void startBracketHighlighting() {
1254 if (fBracketPainter == null) {
1255 ISourceViewer sourceViewer = getSourceViewer();
1256 fBracketPainter = new BracketPainter(sourceViewer);
1258 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1259 // fPaintManager.addPainter(fBracketPainter);
1262 private void stopBracketHighlighting() {
1263 if (fBracketPainter != null) {
1264 // fPaintManager.removePainter(fBracketPainter);
1265 fBracketPainter.deactivate(true);
1266 fBracketPainter.dispose();
1267 fBracketPainter = null;
1270 private boolean isBracketHighlightingEnabled() {
1271 IPreferenceStore store = getPreferenceStore();
1272 return store.getBoolean(MATCHING_BRACKETS);
1274 private void startLineHighlighting() {
1275 if (fLinePainter == null) {
1276 ISourceViewer sourceViewer = getSourceViewer();
1277 fLinePainter = new LinePainter(sourceViewer);
1278 fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR));
1279 // fPaintManager.addPainter(fLinePainter);
1282 private void stopLineHighlighting() {
1283 if (fLinePainter != null) {
1284 // fPaintManager.removePainter(fLinePainter);
1285 fLinePainter.deactivate(true);
1286 fLinePainter.dispose();
1287 fLinePainter = null;
1290 private boolean isLineHighlightingEnabled() {
1291 IPreferenceStore store = getPreferenceStore();
1292 return store.getBoolean(CURRENT_LINE);
1294 private void showPrintMargin() {
1295 if (fPrintMarginPainter == null) {
1296 fPrintMarginPainter = new PrintMarginPainter(getSourceViewer());
1298 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1299 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore()
1300 .getInt(PRINT_MARGIN_COLUMN));
1301 // fPaintManager.addPainter(fPrintMarginPainter);
1304 private void hidePrintMargin() {
1305 if (fPrintMarginPainter != null) {
1306 // fPaintManager.removePainter(fPrintMarginPainter);
1307 fPrintMarginPainter.deactivate(true);
1308 fPrintMarginPainter.dispose();
1309 fPrintMarginPainter = null;
1312 private boolean isPrintMarginVisible() {
1313 IPreferenceStore store = getPreferenceStore();
1314 return store.getBoolean(PRINT_MARGIN);
1316 // private void startAnnotationIndication(AnnotationType annotationType) {
1317 // if (fProblemPainter == null) {
1318 // fProblemPainter = new ProblemPainter(this, getSourceViewer());
1319 //// fPaintManager.addPainter(fProblemPainter);
1321 // fProblemPainter.setColor(annotationType, getColor(annotationType));
1322 // fProblemPainter.paintAnnotations(annotationType, true);
1323 // fProblemPainter.paint(IPainter.CONFIGURATION);
1326 // private void shutdownAnnotationIndication() {
1327 // if (fProblemPainter != null) {
1329 // if (!fProblemPainter.isPaintingAnnotations()) {
1330 //// fPaintManager.removePainter(fProblemPainter);
1331 // fProblemPainter.deactivate(true);
1332 // fProblemPainter.dispose();
1333 // fProblemPainter = null;
1335 // fProblemPainter.paint(IPainter.CONFIGURATION);
1340 // private void stopAnnotationIndication(AnnotationType annotationType) {
1341 // if (fProblemPainter != null) {
1342 // fProblemPainter.paintAnnotations(annotationType, false);
1343 // shutdownAnnotationIndication();
1347 // private boolean isAnnotationIndicationEnabled(AnnotationType
1348 // annotationType) {
1349 // IPreferenceStore store = getPreferenceStore();
1350 // AnnotationInfo info = (AnnotationInfo)
1351 // ANNOTATION_MAP.get(annotationType);
1352 // if (info != null)
1353 // return store.getBoolean(info.fEditorPreference);
1358 // isAnnotationIndicationInOverviewRulerEnabled(AnnotationType
1359 // annotationType) {
1360 // IPreferenceStore store = getPreferenceStore();
1361 // AnnotationInfo info = (AnnotationInfo)
1362 // ANNOTATION_MAP.get(annotationType);
1363 // if (info != null)
1364 // return store.getBoolean(info.fOverviewRulerPreference);
1368 // private void showAnnotationIndicationInOverviewRuler(AnnotationType
1369 // annotationType, boolean show) {
1370 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1371 // OverviewRuler ruler = asv.getOverviewRuler();
1372 // if (ruler != null) {
1373 // ruler.setColor(annotationType, getColor(annotationType));
1374 // ruler.showAnnotation(annotationType, show);
1379 // private void setColorInOverviewRuler(AnnotationType annotationType, Color
1381 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1382 // OverviewRuler ruler = asv.getOverviewRuler();
1383 // if (ruler != null) {
1384 // ruler.setColor(annotationType, color);
1389 private int getTabSize() {
1390 Preferences preferences = PHPeclipsePlugin.getDefault()
1391 .getPluginPreferences();
1392 return preferences.getInt(CODE_FORMATTER_TAB_SIZE);
1395 private boolean isTabConversionEnabled() {
1396 IPreferenceStore store = getPreferenceStore();
1397 return store.getBoolean(SPACES_FOR_TABS);
1399 // private void showOverviewRuler() {
1400 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1401 // asv.showOverviewRuler();
1403 // OverviewRuler overviewRuler = asv.getOverviewRuler();
1404 // if (overviewRuler != null) {
1405 // for (int i = 0; i < ANNOTATION_LAYERS.length; i++) {
1406 // AnnotationType type = ANNOTATION_LAYERS[i];
1407 // overviewRuler.setLayer(type, i);
1408 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1409 // showAnnotationIndicationInOverviewRuler(type, true);
1414 // private void hideOverviewRuler() {
1415 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1416 // asv.hideOverviewRuler();
1419 // private boolean isOverviewRulerVisible() {
1420 // IPreferenceStore store = getPreferenceStore();
1421 // return store.getBoolean(OVERVIEW_RULER);
1423 private Color getColor(String key) {
1424 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
1425 return getColor(rgb);
1427 private Color getColor(RGB rgb) {
1428 JavaTextTools textTools = PHPeclipsePlugin.getDefault()
1429 .getJavaTextTools();
1430 return textTools.getColorManager().getColor(rgb);
1432 // private Color getColor(AnnotationType annotationType) {
1433 // AnnotationInfo info = (AnnotationInfo)
1434 // ANNOTATION_MAP.get(annotationType);
1435 // if (info != null)
1436 // return getColor(info.fColorPreference);
1439 public void dispose() {
1440 ISourceViewer sourceViewer = getSourceViewer();
1441 if (sourceViewer instanceof ITextViewerExtension)
1442 ((ITextViewerExtension) sourceViewer)
1443 .removeVerifyKeyListener(fBracketInserter);
1444 // if (fPropertyChangeListener != null) {
1445 // Preferences preferences =
1446 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1447 // preferences.removePropertyChangeListener(fPropertyChangeListener);
1448 // fPropertyChangeListener = null;
1450 if (fJavaEditorErrorTickUpdater != null) {
1451 fJavaEditorErrorTickUpdater.dispose();
1452 fJavaEditorErrorTickUpdater = null;
1454 // if (fSelectionHistory != null)
1455 // fSelectionHistory.dispose();
1456 // if (fPaintManager != null) {
1457 // fPaintManager.dispose();
1458 // fPaintManager = null;
1460 if (fActionGroups != null) {
1461 fActionGroups.dispose();
1462 fActionGroups = null;
1466 // protected AnnotationType getAnnotationType(String preferenceKey) {
1467 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1468 // while (e.hasNext()) {
1469 // AnnotationType type = (AnnotationType) e.next();
1470 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1471 // if (info != null) {
1472 // if (preferenceKey.equals(info.fColorPreference)
1473 // || preferenceKey.equals(info.fEditorPreference)
1474 // || preferenceKey.equals(info.fOverviewRulerPreference))
1481 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1483 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1485 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1487 String p = event.getProperty();
1488 if (CLOSE_BRACKETS_PHP.equals(p)) {
1490 .setCloseBracketsPHPEnabled(getPreferenceStore()
1494 if (CLOSE_STRINGS_PHP.equals(p)) {
1496 .setCloseStringsPHPEnabled(getPreferenceStore()
1500 if (CLOSE_BRACKETS_HTML.equals(p)) {
1502 .setCloseBracketsHTMLEnabled(getPreferenceStore()
1506 if (CLOSE_STRINGS_HTML.equals(p)) {
1508 .setCloseStringsHTMLEnabled(getPreferenceStore()
1512 if (SPACES_FOR_TABS.equals(p)) {
1513 if (isTabConversionEnabled())
1514 startTabConversion();
1516 stopTabConversion();
1519 if (MATCHING_BRACKETS.equals(p)) {
1520 if (isBracketHighlightingEnabled())
1521 startBracketHighlighting();
1523 stopBracketHighlighting();
1526 if (MATCHING_BRACKETS_COLOR.equals(p)) {
1527 if (fBracketPainter != null)
1529 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1532 if (CURRENT_LINE.equals(p)) {
1533 if (isLineHighlightingEnabled())
1534 startLineHighlighting();
1536 stopLineHighlighting();
1539 if (CURRENT_LINE_COLOR.equals(p)) {
1540 if (fLinePainter != null) {
1541 stopLineHighlighting();
1542 startLineHighlighting();
1546 if (PRINT_MARGIN.equals(p)) {
1547 if (isPrintMarginVisible())
1553 if (PRINT_MARGIN_COLOR.equals(p)) {
1554 if (fPrintMarginPainter != null)
1556 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1559 if (PRINT_MARGIN_COLUMN.equals(p)) {
1560 if (fPrintMarginPainter != null)
1562 .setMarginRulerColumn(getPreferenceStore()
1563 .getInt(PRINT_MARGIN_COLUMN));
1566 // if (OVERVIEW_RULER.equals(p)) {
1567 // if (isOverviewRulerVisible())
1568 // showOverviewRuler();
1570 // hideOverviewRuler();
1573 // AnnotationType type = getAnnotationType(p);
1574 // if (type != null) {
1576 // AnnotationInfo info = (AnnotationInfo)
1577 // ANNOTATION_MAP.get(type);
1578 // if (info.fColorPreference.equals(p)) {
1579 // Color color = getColor(type);
1580 // if (fProblemPainter != null) {
1581 // fProblemPainter.setColor(type, color);
1582 // fProblemPainter.paint(IPainter.CONFIGURATION);
1584 // setColorInOverviewRuler(type, color);
1588 // if (info.fEditorPreference.equals(p)) {
1589 // if (isAnnotationIndicationEnabled(type))
1590 // startAnnotationIndication(type);
1592 // stopAnnotationIndication(type);
1596 // if (info.fOverviewRulerPreference.equals(p)) {
1597 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1598 // showAnnotationIndicationInOverviewRuler(type, true);
1600 // showAnnotationIndicationInOverviewRuler(type, false);
1604 IContentAssistant c = asv.getContentAssistant();
1605 if (c instanceof ContentAssistant)
1606 ContentAssistPreference.changeConfiguration(
1607 (ContentAssistant) c, getPreferenceStore(), event);
1610 super.handlePreferenceStoreChanged(event);
1614 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
1616 protected void handlePreferencePropertyChanged(
1617 org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1618 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1620 String p = event.getProperty();
1621 if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1622 asv.updateIndentationPrefixes();
1623 if (fTabConverter != null)
1624 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1627 super.handlePreferencePropertyChanged(event);
1630 * Handles a property change event describing a change of the php core's
1631 * preferences and updates the preference related editor properties.
1634 * the property change event
1637 // handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
1639 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1640 // if (asv != null) {
1641 // String p = event.getProperty();
1642 // if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1643 // asv.updateIndentationPrefixes();
1644 // if (fTabConverter != null)
1645 // fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1650 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#createJavaSourceViewer(org.eclipse.swt.widgets.Composite,
1651 * org.eclipse.jface.text.source.IVerticalRuler,
1652 * org.eclipse.jface.text.source.IOverviewRuler, boolean, int)
1654 protected ISourceViewer createJavaSourceViewer(Composite parent,
1655 IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
1656 boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
1657 return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler,
1658 isOverviewRulerVisible, styles, store);
1660 // protected ISourceViewer createJavaSourceViewer(Composite parent,
1661 // IVerticalRuler ruler, int styles) {
1662 // return new AdaptedSourceViewer(parent, ruler, styles);
1664 private boolean isValidSelection(int offset, int length) {
1665 IDocumentProvider provider = getDocumentProvider();
1666 if (provider != null) {
1667 IDocument document = provider.getDocument(getEditorInput());
1668 if (document != null) {
1669 int end = offset + length;
1670 int documentLength = document.getLength();
1671 return 0 <= offset && offset <= documentLength && 0 <= end
1672 && end <= documentLength;
1678 * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput)
1680 protected boolean canHandleMove(IEditorInput originalElement,
1681 IEditorInput movedElement) {
1682 String oldExtension = ""; //$NON-NLS-1$
1683 if (originalElement instanceof IFileEditorInput) {
1684 IFile file = ((IFileEditorInput) originalElement).getFile();
1686 String ext = file.getFileExtension();
1691 String newExtension = ""; //$NON-NLS-1$
1692 if (movedElement instanceof IFileEditorInput) {
1693 IFile file = ((IFileEditorInput) movedElement).getFile();
1695 newExtension = file.getFileExtension();
1697 return oldExtension.equals(newExtension);
1700 * @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager)
1702 public void editorContextMenuAboutToShow(IMenuManager menu) {
1703 super.editorContextMenuAboutToShow(menu);
1704 ActionContext context = new ActionContext(getSelectionProvider()
1706 fContextMenuGroup.setContext(context);
1707 fContextMenuGroup.fillContextMenu(menu);
1708 fContextMenuGroup.setContext(null);
1711 * @see JavaEditor#setOutlinePageInput(JavaOutlinePage, IEditorInput)
1713 protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input) {
1715 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1716 .getWorkingCopyManager();
1717 page.setInput(manager.getWorkingCopy(input));
1721 * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation,
1724 // protected void performSaveOperation(WorkspaceModifyOperation operation,
1725 // IProgressMonitor progressMonitor) {
1726 // IDocumentProvider p = getDocumentProvider();
1727 // if (p instanceof PHPDocumentProvider) {
1728 // PHPDocumentProvider cp = (PHPDocumentProvider) p;
1729 // cp.setSavePolicy(fSavePolicy);
1733 // super.performSaveOperation(operation, progressMonitor);
1735 // if (p instanceof PHPDocumentProvider) {
1736 // PHPDocumentProvider cp = (PHPDocumentProvider) p;
1737 // cp.setSavePolicy(null);
1742 * @see AbstractTextEditor#doSave(IProgressMonitor)
1744 public void doSave(IProgressMonitor progressMonitor) {
1746 IDocumentProvider p = getDocumentProvider();
1748 // editor has been closed
1752 if (p.isDeleted(getEditorInput())) {
1754 if (isSaveAsAllowed()) {
1757 * 1GEUSSR: ITPUI:ALL - User should never loose changes made in
1758 * the editors. Changed Behavior to make sure that if called
1759 * inside a regular save (because of deletion of input element)
1760 * there is a way to report back to the caller.
1762 performSaveAs(progressMonitor);
1767 * 1GF5YOX: ITPJUI:ALL - Save of delete file claims it's still
1768 * there Missing resources.
1770 Shell shell = getSite().getShell();
1775 .getString("PHPUnitEditor.error.saving.title1"), PHPEditorMessages.getString("PHPUnitEditor.error.saving.message1")); //$NON-NLS-1$ //$NON-NLS-2$
1780 setStatusLineErrorMessage(null);
1782 updateState(getEditorInput());
1783 validateState(getEditorInput());
1785 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault().getWorkingCopyManager();
1786 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1789 synchronized (unit) {
1790 performSave(false, progressMonitor);
1793 performSave(false, progressMonitor);
1795 ShowExternalPreviewAction a = ShowExternalPreviewAction.getInstance();
1801 public boolean isSaveAsAllowed() {
1806 * The compilation unit editor implementation of this
1807 * <code>AbstractTextEditor</code> method asks the user for the workspace
1808 * path of a file resource and saves the document there. See
1809 * http://dev.eclipse.org/bugs/show_bug.cgi?id=6295
1811 * @param progressMonitor
1812 * the progress monitor
1814 protected void performSaveAs(IProgressMonitor progressMonitor) {
1816 Shell shell = getSite().getShell();
1817 IEditorInput input = getEditorInput();
1819 SaveAsDialog dialog = new SaveAsDialog(shell);
1821 IFile original = (input instanceof IFileEditorInput)
1822 ? ((IFileEditorInput) input).getFile()
1824 if (original != null)
1825 dialog.setOriginalFile(original);
1829 IDocumentProvider provider = getDocumentProvider();
1830 if (provider == null) {
1831 // editor has been programmatically closed while the dialog was open
1835 if (provider.isDeleted(input) && original != null) {
1836 String message = PHPEditorMessages
1837 .getFormattedString(
1838 "CompilationUnitEditor.warning.save.delete", new Object[]{original.getName()}); //$NON-NLS-1$
1839 dialog.setErrorMessage(null);
1840 dialog.setMessage(message, IMessageProvider.WARNING);
1843 if (dialog.open() == Window.CANCEL) {
1844 if (progressMonitor != null)
1845 progressMonitor.setCanceled(true);
1849 IPath filePath = dialog.getResult();
1850 if (filePath == null) {
1851 if (progressMonitor != null)
1852 progressMonitor.setCanceled(true);
1856 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1857 IFile file = workspaceRoot.getFile(filePath);
1858 final IEditorInput newInput = new FileEditorInput(file);
1860 boolean success = false;
1863 provider.aboutToChange(newInput);
1864 getDocumentProvider().saveDocument(progressMonitor, newInput,
1865 getDocumentProvider().getDocument(getEditorInput()), true);
1868 } catch (CoreException x) {
1869 IStatus status = x.getStatus();
1870 if (status == null || status.getSeverity() != IStatus.CANCEL)
1875 .getString("CompilationUnitEditor.error.saving.title2"), PHPEditorMessages.getString("CompilationUnitEditor.error.saving.message2"), x.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
1877 provider.changed(newInput);
1882 if (progressMonitor != null)
1883 progressMonitor.setCanceled(!success);
1887 * @see AbstractTextEditor#doSetInput(IEditorInput)
1889 protected void doSetInput(IEditorInput input) throws CoreException {
1890 super.doSetInput(input);
1891 configureTabConverter();
1892 configureToggleCommentAction();
1897 // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#installOverrideIndicator(boolean)
1900 // protected void installOverrideIndicator(boolean waitForReconcilation) {
1901 // IAnnotationModel model=
1902 // getDocumentProvider().getAnnotationModel(getEditorInput());
1903 // if (!waitForReconcilation)
1904 // super.installOverrideIndicator(false);
1906 // uninstallOverrideIndicator();
1907 // IJavaElement inputElement= getInputJavaElement();
1908 // if (model == null || inputElement == null)
1911 // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
1912 // inputElement, null);
1913 // addReconcileListener(fOverrideIndicatorManager);
1919 // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#uninstallOverrideIndicator()
1922 // protected void uninstallOverrideIndicator() {
1923 // if (fOverrideIndicatorManager != null)
1924 // removeReconcileListener(fOverrideIndicatorManager);
1925 // super.uninstallOverrideIndicator();
1929 * Configures the toggle comment action
1933 private void configureToggleCommentAction() {
1934 IAction action = getAction("ToggleComment"); //$NON-NLS-1$
1935 if (action instanceof ToggleCommentAction) {
1936 ISourceViewer sourceViewer = getSourceViewer();
1937 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
1938 ((ToggleCommentAction) action).configure(sourceViewer,
1943 private void configureTabConverter() {
1944 if (fTabConverter != null) {
1945 IDocumentProvider provider = getDocumentProvider();
1946 if (provider instanceof PHPDocumentProvider) {
1947 PHPDocumentProvider cup = (PHPDocumentProvider) provider;
1948 fTabConverter.setLineTracker(cup
1949 .createLineTracker(getEditorInput()));
1954 private void startTabConversion() {
1955 if (fTabConverter == null) {
1956 fTabConverter = new TabConverter();
1957 configureTabConverter();
1958 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1959 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1960 asv.addTextConverter(fTabConverter);
1961 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1962 asv.updateIndentationPrefixes();
1966 private void stopTabConversion() {
1967 if (fTabConverter != null) {
1968 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1969 asv.removeTextConverter(fTabConverter);
1970 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1971 asv.updateIndentationPrefixes();
1972 fTabConverter = null;
1977 * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean,
1978 * org.eclipse.core.runtime.IProgressMonitor)
1980 protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) {
1981 IDocumentProvider p = getDocumentProvider();
1982 if (p instanceof PHPDocumentProvider) {
1983 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1984 cp.setSavePolicy(fSavePolicy);
1987 super.performSave(overwrite, progressMonitor);
1989 if (p instanceof PHPDocumentProvider) {
1990 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1991 cp.setSavePolicy(null);
1996 * @see AbstractTextEditor#doSaveAs
1998 public void doSaveAs() {
1999 if (askIfNonWorkbenchEncodingIsOk()) {
2005 * Asks the user if it is ok to store in non-workbench encoding.
2007 * @return <true>if the user wants to continue
2009 private boolean askIfNonWorkbenchEncodingIsOk() {
2010 IDocumentProvider provider = getDocumentProvider();
2011 if (provider instanceof IStorageDocumentProvider) {
2012 IEditorInput input = getEditorInput();
2013 IStorageDocumentProvider storageProvider = (IStorageDocumentProvider) provider;
2014 String encoding = storageProvider.getEncoding(input);
2015 String defaultEncoding = storageProvider.getDefaultEncoding();
2016 if (encoding != null && !encoding.equals(defaultEncoding)) {
2017 Shell shell = getSite().getShell();
2018 String title = PHPEditorMessages
2019 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$
2025 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"),
2026 new String[]{input.getName(), encoding}); //$NON-NLS-1$
2031 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message2"),
2032 new String[]{encoding}); //$NON-NLS-1$
2033 return MessageDialog.openQuestion(shell, title, msg);
2039 * @see IReconcilingParticipant#reconciled()
2041 public void reconciled() {
2042 if (synchronizeOutlineOnCursorMove()) {
2043 Shell shell = getSite().getShell();
2044 if (shell != null && !shell.isDisposed()) {
2045 shell.getDisplay().asyncExec(new Runnable() {
2047 synchronizeOutlinePageSelection();
2054 protected void updateStateDependentActions() {
2055 super.updateStateDependentActions();
2056 fGenerateActionGroup.editorStateChanged();
2059 private boolean synchronizeOutlineOnCursorMove() {
2060 return PreferenceConstants.getPreferenceStore().getBoolean(
2061 PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE);
2065 * Returns the updated java element for the old java element.
2067 private IJavaElement findElement(IJavaElement element) {
2068 if (element == null)
2070 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
2071 .getWorkingCopyManager();
2072 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
2075 synchronized (unit) {
2078 IJavaElement[] findings = unit.findElements(element);
2079 if (findings != null && findings.length > 0)
2081 } catch (JavaModelException x) {
2082 PHPeclipsePlugin.log(x.getStatus());
2083 // nothing found, be tolerant and go on
2089 * Returns the offset of the given Java element.
2091 private int getOffset(IJavaElement element) {
2092 if (element instanceof ISourceReference) {
2093 ISourceReference sr = (ISourceReference) element;
2095 ISourceRange srcRange = sr.getSourceRange();
2096 if (srcRange != null)
2097 return srcRange.getOffset();
2098 } catch (JavaModelException e) {
2104 * @see AbstractTextEditor#rememberSelection()
2106 protected void rememberSelection() {
2107 ISelectionProvider sp = getSelectionProvider();
2108 fRememberedSelection = (sp == null ? null : (ITextSelection) sp
2110 if (fRememberedSelection != null) {
2111 fRememberedElement = getElementAt(fRememberedSelection.getOffset(),
2113 fRememberedElementOffset = getOffset(fRememberedElement);
2117 * @see AbstractTextEditor#restoreSelection()
2119 protected void restoreSelection() {
2121 if (getSourceViewer() == null || fRememberedSelection == null)
2123 IJavaElement newElement = findElement(fRememberedElement);
2124 int newOffset = getOffset(newElement);
2125 int delta = (newOffset > -1 && fRememberedElementOffset > -1)
2126 ? newOffset - fRememberedElementOffset
2128 if (isValidSelection(delta + fRememberedSelection.getOffset(),
2129 fRememberedSelection.getLength()))
2130 selectAndReveal(delta + fRememberedSelection.getOffset(),
2131 fRememberedSelection.getLength());
2133 fRememberedSelection = null;
2134 fRememberedElement = null;
2135 fRememberedElementOffset = -1;
2141 // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
2144 // public void aboutToBeReconciled() {
2146 // // Notify AST provider
2147 // PHPeclipsePlugin.getDefault().getASTProvider().aboutToBeReconciled(getInputJavaElement());
2149 // // Notify listeners
2150 // Object[] listeners = fReconcilingListeners.getListeners();
2151 // for (int i = 0, length= listeners.length; i < length; ++i)
2152 // ((IJavaReconcilingListener)listeners[i]).aboutToBeReconciled();
2157 // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit,
2158 // boolean, IProgressMonitor)
2161 // public void reconciled(net.sourceforge.phpdt.core.dom.CompilationUnit
2162 // ast, boolean forced, IProgressMonitor progressMonitor) {
2164 // // Always notify AST provider
2165 // PHPeclipsePlugin.getDefault().getASTProvider().reconciled(ast,
2166 // getInputJavaElement());
2168 // // Notify listeners
2169 // Object[] listeners = fReconcilingListeners.getListeners();
2170 // for (int i = 0, length= listeners.length; i < length; ++i)
2171 // ((IJavaReconcilingListener)listeners[i]).reconciled(ast, forced,
2172 // progressMonitor);
2174 // // Update Java Outline page selection
2175 // if (!forced && !progressMonitor.isCanceled()) {
2176 // Shell shell= getSite().getShell();
2177 // if (shell != null && !shell.isDisposed()) {
2178 // shell.getDisplay().asyncExec(new Runnable() {
2179 // public void run() {
2180 // selectionChanged();