1 package net.sourceforge.phpeclipse.phpeditor;
3 import java.lang.reflect.InvocationTargetException;
4 import java.text.MessageFormat;
5 import java.util.ArrayList;
6 import java.util.Iterator;
9 import net.sourceforge.phpdt.core.ICompilationUnit;
10 import net.sourceforge.phpdt.core.IJavaElement;
11 import net.sourceforge.phpdt.core.ISourceRange;
12 import net.sourceforge.phpdt.core.ISourceReference;
13 import net.sourceforge.phpdt.core.JavaCore;
14 import net.sourceforge.phpdt.core.JavaModelException;
15 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
16 import net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction;
17 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
18 import net.sourceforge.phpdt.internal.ui.actions.RemoveBlockCommentAction;
19 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
20 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
21 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
22 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
23 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
24 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags;
25 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
26 import net.sourceforge.phpdt.ui.PreferenceConstants;
27 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
28 import net.sourceforge.phpdt.ui.text.JavaTextTools;
29 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
31 import org.eclipse.core.resources.IFile;
32 import org.eclipse.core.resources.IWorkspace;
33 import org.eclipse.core.resources.IWorkspaceRoot;
34 import org.eclipse.core.resources.ResourcesPlugin;
35 import org.eclipse.core.runtime.CoreException;
36 import org.eclipse.core.runtime.IPath;
37 import org.eclipse.core.runtime.IProgressMonitor;
38 import org.eclipse.core.runtime.IStatus;
39 import org.eclipse.core.runtime.Preferences;
41 import net.sourceforge.phpdt.internal.ui.text.java.IJavaReconcilingListener;
43 import org.eclipse.jface.action.Action;
44 import org.eclipse.jface.action.IAction;
45 import org.eclipse.jface.action.IMenuManager;
46 import org.eclipse.jface.dialogs.Dialog;
47 import org.eclipse.jface.dialogs.ErrorDialog;
48 import org.eclipse.jface.dialogs.IMessageProvider;
49 import org.eclipse.jface.dialogs.MessageDialog;
50 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
51 import org.eclipse.jface.preference.IPreferenceStore;
52 import org.eclipse.jface.preference.PreferenceConverter;
53 import org.eclipse.jface.text.BadLocationException;
54 import org.eclipse.jface.text.DocumentCommand;
55 import org.eclipse.jface.text.IDocument;
56 import org.eclipse.jface.text.ILineTracker;
57 import org.eclipse.jface.text.IRegion;
58 import org.eclipse.jface.text.ITextOperationTarget;
59 import org.eclipse.jface.text.ITextSelection;
60 import org.eclipse.jface.text.ITextViewerExtension;
61 import org.eclipse.jface.text.ITypedRegion;
62 import org.eclipse.jface.text.IWidgetTokenKeeper;
63 import org.eclipse.jface.text.contentassist.ContentAssistant;
64 import org.eclipse.jface.text.contentassist.IContentAssistant;
65 import org.eclipse.jface.text.source.IAnnotationModel;
66 import org.eclipse.jface.text.source.IOverviewRuler;
67 import org.eclipse.jface.text.source.ISourceViewer;
68 import org.eclipse.jface.text.source.IVerticalRuler;
69 import org.eclipse.jface.text.source.SourceViewerConfiguration;
70 import org.eclipse.jface.util.PropertyChangeEvent;
71 import org.eclipse.jface.viewers.ISelectionProvider;
72 import org.eclipse.jface.window.Window;
73 import org.eclipse.swt.SWT;
74 import org.eclipse.swt.custom.VerifyKeyListener;
75 import org.eclipse.swt.events.VerifyEvent;
76 import org.eclipse.swt.graphics.Color;
77 import org.eclipse.swt.graphics.Point;
78 import org.eclipse.swt.graphics.RGB;
79 import org.eclipse.swt.widgets.Composite;
80 import org.eclipse.swt.widgets.Display;
81 import org.eclipse.swt.widgets.Shell;
82 import org.eclipse.ui.IEditorInput;
83 import org.eclipse.ui.IFileEditorInput;
84 import org.eclipse.ui.actions.ActionContext;
85 import org.eclipse.ui.actions.ActionGroup;
86 import org.eclipse.ui.actions.WorkspaceModifyOperation;
87 import org.eclipse.ui.dialogs.SaveAsDialog;
88 import org.eclipse.ui.editors.text.IStorageDocumentProvider;
89 import org.eclipse.ui.help.WorkbenchHelp;
90 import org.eclipse.ui.part.FileEditorInput;
91 import org.eclipse.ui.texteditor.ContentAssistAction;
92 import org.eclipse.ui.texteditor.IDocumentProvider;
93 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
94 import org.eclipse.ui.texteditor.TextOperationAction;
95 /*******************************************************************************
96 * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
97 * program and the accompanying materials are made available under the terms of
98 * the Common Public License v1.0 which accompanies this distribution, and is
99 * available at http://www.eclipse.org/legal/cpl-v10.html
101 * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
102 * www.eclipseproject.de
103 ******************************************************************************/
105 * PHP specific text editor.
107 public class PHPUnitEditor extends PHPEditor{ //implements IJavaReconcilingListener {
108 interface ITextConverter {
109 void customizeDocumentCommand(IDocument document,
110 DocumentCommand command);
112 // class AdaptedRulerLayout extends Layout {
114 // protected int fGap;
115 // protected AdaptedSourceViewer fAdaptedSourceViewer;
117 // protected AdaptedRulerLayout(int gap, AdaptedSourceViewer asv) {
119 // fAdaptedSourceViewer = asv;
122 // protected Point computeSize(Composite composite, int wHint, int hHint,
123 // boolean flushCache) {
124 // Control[] children = composite.getChildren();
125 // Point s = children[children.length - 1].computeSize(SWT.DEFAULT,
126 // SWT.DEFAULT, flushCache);
127 // if (fAdaptedSourceViewer.isVerticalRulerVisible())
128 // s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap;
132 // protected void layout(Composite composite, boolean flushCache) {
133 // Rectangle clArea = composite.getClientArea();
134 // if (fAdaptedSourceViewer.isVerticalRulerVisible()) {
136 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
137 // Rectangle trim = textWidget.computeTrim(0, 0, 0, 0);
138 // int scrollbarHeight = trim.height;
140 // IVerticalRuler vr = fAdaptedSourceViewer.getVerticalRuler();
141 // int vrWidth = vr.getWidth();
144 // if (fAdaptedSourceViewer.isOverviewRulerVisible()) {
145 // OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler();
146 // orWidth = or.getWidth();
147 // or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight,
148 // orWidth, clArea.height - 3 * scrollbarHeight);
151 // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth
153 // 2 * fGap, clArea.height);
154 // vr.getControl().setBounds(0, 0, vrWidth, clArea.height -
158 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
159 // textWidget.setBounds(0, 0, clArea.width, clArea.height);
164 // class AdaptedSourceViewer extends SourceViewer { // extends
165 // JavaCorrectionSourceViewer {
167 // private List fTextConverters;
169 // private OverviewRuler fOverviewRuler;
170 // private boolean fIsOverviewRulerVisible;
171 // /** The viewer's overview ruler hovering controller */
172 // private AbstractHoverInformationControlManager
173 // fOverviewRulerHoveringController;
175 // private boolean fIgnoreTextConverters = false;
177 // private IVerticalRuler fCachedVerticalRuler;
178 // private boolean fCachedIsVerticalRulerVisible;
180 // public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int
182 // super(parent, ruler, styles); //, CompilationUnitEditor.this);
184 // fCachedVerticalRuler = ruler;
185 // fCachedIsVerticalRulerVisible = (ruler != null);
186 // fOverviewRuler = new OverviewRuler(VERTICAL_RULER_WIDTH);
188 // delayedCreateControl(parent, styles);
192 // * @see ISourceViewer#showAnnotations(boolean)
194 // public void showAnnotations(boolean show) {
195 // fCachedIsVerticalRulerVisible = (show && fCachedVerticalRuler != null);
196 // // super.showAnnotations(show);
199 // public IContentAssistant getContentAssistant() {
200 // return fContentAssistant;
204 // * @see ITextOperationTarget#doOperation(int)
206 // public void doOperation(int operation) {
208 // if (getTextWidget() == null)
211 // switch (operation) {
212 // case CONTENTASSIST_PROPOSALS :
213 // String msg = fContentAssistant.showPossibleCompletions();
214 // setStatusLineErrorMessage(msg);
217 // fIgnoreTextConverters = true;
220 // fIgnoreTextConverters = true;
224 // super.doOperation(operation);
227 // public void insertTextConverter(ITextConverter textConverter, int index)
229 // throw new UnsupportedOperationException();
232 // public void addTextConverter(ITextConverter textConverter) {
233 // if (fTextConverters == null) {
234 // fTextConverters = new ArrayList(1);
235 // fTextConverters.add(textConverter);
236 // } else if (!fTextConverters.contains(textConverter))
237 // fTextConverters.add(textConverter);
240 // public void removeTextConverter(ITextConverter textConverter) {
241 // if (fTextConverters != null) {
242 // fTextConverters.remove(textConverter);
243 // if (fTextConverters.size() == 0)
244 // fTextConverters = null;
249 // * @see TextViewer#customizeDocumentCommand(DocumentCommand)
251 // protected void customizeDocumentCommand(DocumentCommand command) {
252 // super.customizeDocumentCommand(command);
253 // if (!fIgnoreTextConverters && fTextConverters != null) {
254 // for (Iterator e = fTextConverters.iterator(); e.hasNext();)
255 // ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(),
258 // fIgnoreTextConverters = false;
261 // public IVerticalRuler getVerticalRuler() {
262 // return fCachedVerticalRuler;
265 // public boolean isVerticalRulerVisible() {
266 // return fCachedIsVerticalRulerVisible;
269 // public OverviewRuler getOverviewRuler() {
270 // return fOverviewRuler;
274 // * @see TextViewer#createControl(Composite, int)
276 // protected void createControl(Composite parent, int styles) {
277 // // do nothing here
280 // protected void delayedCreateControl(Composite parent, int styles) {
281 // //create the viewer
282 // super.createControl(parent, styles);
284 // Control control = getControl();
285 // if (control instanceof Composite) {
286 // Composite composite = (Composite) control;
287 // composite.setLayout(new AdaptedRulerLayout(GAP_SIZE, this));
288 // fOverviewRuler.createControl(composite, this);
291 // protected void ensureOverviewHoverManagerInstalled() {
292 // if (fOverviewRulerHoveringController == null && fAnnotationHover != null
293 // && fHoverControlCreator != null) {
294 // fOverviewRulerHoveringController =
295 // new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover,
296 // fHoverControlCreator);
297 // fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
301 // public void hideOverviewRuler() {
302 // fIsOverviewRulerVisible = false;
303 // Control control = getControl();
304 // if (control instanceof Composite) {
305 // Composite composite = (Composite) control;
306 // composite.layout();
308 // if (fOverviewRulerHoveringController != null) {
309 // fOverviewRulerHoveringController.dispose();
310 // fOverviewRulerHoveringController = null;
314 // public void showOverviewRuler() {
315 // fIsOverviewRulerVisible = true;
316 // Control control = getControl();
317 // if (control instanceof Composite) {
318 // Composite composite = (Composite) control;
319 // composite.layout();
321 // ensureOverviewHoverManagerInstalled();
324 // public boolean isOverviewRulerVisible() {
325 // return fIsOverviewRulerVisible;
329 // * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
331 // public void setDocument(
332 // IDocument document,
333 // IAnnotationModel annotationModel,
334 // int visibleRegionOffset,
335 // int visibleRegionLength) {
336 // super.setDocument(document, annotationModel, visibleRegionOffset,
337 // visibleRegionLength);
338 // fOverviewRuler.setModel(annotationModel);
341 // // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
342 // public void updateIndentationPrefixes() {
343 // SourceViewerConfiguration configuration = getSourceViewerConfiguration();
344 // String[] types = configuration.getConfiguredContentTypes(this);
345 // for (int i = 0; i < types.length; i++) {
346 // String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
347 // if (prefixes != null && prefixes.length > 0)
348 // setIndentPrefixes(prefixes, types[i]);
353 // * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
355 // public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
356 // if (WorkbenchHelp.isContextHelpDisplayed())
358 // return super.requestWidgetToken(requester);
363 // org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
365 // public void configure(SourceViewerConfiguration configuration) {
366 // super.configure(configuration);
367 // // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
368 // IDocument.DEFAULT_CONTENT_TYPE);
371 // protected void handleDispose() {
372 // fOverviewRuler = null;
374 // if (fOverviewRulerHoveringController != null) {
375 // fOverviewRulerHoveringController.dispose();
376 // fOverviewRulerHoveringController = null;
379 // super.handleDispose();
383 class AdaptedSourceViewer extends JavaSourceViewer {
384 private List fTextConverters;
385 private boolean fIgnoreTextConverters = false;
386 // private JavaCorrectionAssistant fCorrectionAssistant;
387 public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles, IPreferenceStore store) {
388 super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles, store);
390 // public AdaptedSourceViewer(Composite parent,
391 // IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
392 // boolean showAnnotationsOverview, int styles) {
393 // super(parent, verticalRuler, overviewRuler,
394 // showAnnotationsOverview, styles);
396 public IContentAssistant getContentAssistant() {
397 return fContentAssistant;
400 * @see ITextOperationTarget#doOperation(int)
402 public void doOperation(int operation) {
403 if (getTextWidget() == null)
406 case CONTENTASSIST_PROPOSALS :
407 String msg = fContentAssistant.showPossibleCompletions();
408 setStatusLineErrorMessage(msg);
410 // case CORRECTIONASSIST_PROPOSALS:
411 // fCorrectionAssistant.showPossibleCompletions();
414 fIgnoreTextConverters = true;
417 fIgnoreTextConverters = true;
420 super.doOperation(operation);
423 * @see ITextOperationTarget#canDoOperation(int)
425 public boolean canDoOperation(int operation) {
426 // if (operation == CORRECTIONASSIST_PROPOSALS)
427 // return isEditable();
428 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();
440 public void insertTextConverter(ITextConverter textConverter, int index) {
441 throw new UnsupportedOperationException();
443 public void addTextConverter(ITextConverter textConverter) {
444 if (fTextConverters == null) {
445 fTextConverters = new ArrayList(1);
446 fTextConverters.add(textConverter);
447 } else if (!fTextConverters.contains(textConverter))
448 fTextConverters.add(textConverter);
450 public void removeTextConverter(ITextConverter textConverter) {
451 if (fTextConverters != null) {
452 fTextConverters.remove(textConverter);
453 if (fTextConverters.size() == 0)
454 fTextConverters = null;
458 * @see TextViewer#customizeDocumentCommand(DocumentCommand)
460 protected void customizeDocumentCommand(DocumentCommand command) {
461 super.customizeDocumentCommand(command);
462 if (!fIgnoreTextConverters && fTextConverters != null) {
463 for (Iterator e = fTextConverters.iterator(); e.hasNext();)
464 ((ITextConverter) e.next()).customizeDocumentCommand(
465 getDocument(), command);
467 fIgnoreTextConverters = false;
469 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
470 public void updateIndentationPrefixes() {
471 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
472 String[] types = configuration.getConfiguredContentTypes(this);
473 for (int i = 0; i < types.length; i++) {
474 String[] prefixes = configuration.getIndentPrefixes(this,
476 if (prefixes != null && prefixes.length > 0)
477 setIndentPrefixes(prefixes, types[i]);
481 * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
483 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
484 if (WorkbenchHelp.isContextHelpDisplayed())
486 return super.requestWidgetToken(requester);
489 * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
491 public void configure(SourceViewerConfiguration configuration) {
492 super.configure(configuration);
493 // fCorrectionAssistant= new
494 // JavaCorrectionAssistant(CompilationUnitEditor.this);
495 // fCorrectionAssistant.install(this);
496 //TODO install SmartBracesAutoEditStrategy
497 // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
498 // IDocument.DEFAULT_CONTENT_TYPE);
501 static class TabConverter implements ITextConverter {
502 private int fTabRatio;
503 private ILineTracker fLineTracker;
504 public TabConverter() {
506 public void setNumberOfSpacesPerTab(int ratio) {
509 public void setLineTracker(ILineTracker lineTracker) {
510 fLineTracker = lineTracker;
512 private int insertTabString(StringBuffer buffer, int offsetInLine) {
515 int remainder = offsetInLine % fTabRatio;
516 remainder = fTabRatio - remainder;
517 for (int i = 0; i < remainder; i++)
521 public void customizeDocumentCommand(IDocument document,
522 DocumentCommand command) {
523 String text = command.text;
526 int index = text.indexOf('\t');
528 StringBuffer buffer = new StringBuffer();
529 fLineTracker.set(command.text);
530 int lines = fLineTracker.getNumberOfLines();
532 for (int i = 0; i < lines; i++) {
533 int offset = fLineTracker.getLineOffset(i);
534 int endOffset = offset + fLineTracker.getLineLength(i);
535 String line = text.substring(offset, endOffset);
538 IRegion firstLine = document
539 .getLineInformationOfOffset(command.offset);
540 position = command.offset - firstLine.getOffset();
542 int length = line.length();
543 for (int j = 0; j < length; j++) {
544 char c = line.charAt(j);
546 position += insertTabString(buffer, position);
553 command.text = buffer.toString();
554 } catch (BadLocationException x) {
559 private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
560 final char fExitCharacter;
561 public ExitPolicy(char exitCharacter) {
562 fExitCharacter = exitCharacter;
565 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager,
566 * org.eclipse.swt.events.VerifyEvent, int, int)
568 public ExitFlags doExit(LinkedPositionManager manager,
569 VerifyEvent event, int offset, int length) {
570 if (event.character == fExitCharacter) {
571 if (manager.anyPositionIncludes(offset, length))
572 return new ExitFlags(LinkedPositionUI.COMMIT
573 | LinkedPositionUI.UPDATE_CARET, false);
575 return new ExitFlags(LinkedPositionUI.COMMIT, true);
577 switch (event.character) {
579 if (manager.getFirstPosition().length == 0)
580 return new ExitFlags(0, false);
585 return new ExitFlags(LinkedPositionUI.COMMIT, true);
591 private static class BracketLevel {
594 LinkedPositionManager fManager;
595 LinkedPositionUI fEditor;
597 private class BracketInserter
600 LinkedPositionUI.ExitListener {
601 private boolean fCloseBracketsPHP = true;
602 private boolean fCloseStringsPHP = true;
603 private boolean fCloseBracketsHTML = true;
604 private boolean fCloseStringsHTML = true;
607 public void setCloseBracketsPHPEnabled(boolean enabled) {
608 fCloseBracketsPHP = enabled;
610 public void setCloseStringsPHPEnabled(boolean enabled) {
611 fCloseStringsPHP = enabled;
613 public void setCloseBracketsHTMLEnabled(boolean enabled) {
614 fCloseBracketsHTML = enabled;
616 public void setCloseStringsHTMLEnabled(boolean enabled) {
617 fCloseStringsHTML = enabled;
619 private boolean hasIdentifierToTheRight(IDocument document, int offset) {
622 IRegion endLine = document.getLineInformationOfOffset(end);
623 int maxEnd = endLine.getOffset() + endLine.getLength();
625 && Character.isWhitespace(document.getChar(end)))
628 && Scanner.isPHPIdentifierPart(document.getChar(end));
629 } catch (BadLocationException e) {
634 private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
637 IRegion startLine = document.getLineInformationOfOffset(start);
638 int minStart = startLine.getOffset();
639 while (start != minStart
640 && Character.isWhitespace(document.getChar(start - 1)))
642 return start != minStart
643 && Scanner.isPHPIdentifierPart(document
644 .getChar(start - 1));
645 } catch (BadLocationException e) {
649 private boolean hasCharacterToTheRight(IDocument document, int offset,
653 IRegion endLine = document.getLineInformationOfOffset(end);
654 int maxEnd = endLine.getOffset() + endLine.getLength();
656 && Character.isWhitespace(document.getChar(end)))
658 return end != maxEnd && document.getChar(end) == character;
659 } catch (BadLocationException e) {
665 * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
667 public void verifyKey(VerifyEvent event) {
670 final ISourceViewer sourceViewer = getSourceViewer();
671 IDocument document = sourceViewer.getDocument();
672 final Point selection = sourceViewer.getSelectedRange();
673 final int offset = selection.x;
674 final int length = selection.y;
676 ITypedRegion partition = document.getPartition(offset);
677 String type = partition.getType();
678 if (type.equals(IPHPPartitions.PHP_PARTITIONING)) {
679 switch (event.character) {
681 if (hasCharacterToTheRight(document, offset
686 if (!fCloseBracketsPHP)
688 if (hasIdentifierToTheRight(document, offset
693 if (event.character == '"') {
694 if (!fCloseStringsPHP)
696 // changed for statements like echo "" print ""
697 // if (hasIdentifierToTheLeft(document, offset)
699 // hasIdentifierToTheRight(document, offset +
701 if (hasIdentifierToTheRight(document, offset
705 // ITypedRegion partition=
706 // document.getPartition(offset);
708 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
710 // (partition.getOffset() != offset))
712 final char character = event.character;
713 final char closingCharacter = getPeerCharacter(character);
714 final StringBuffer buffer = new StringBuffer();
715 buffer.append(character);
716 buffer.append(closingCharacter);
717 document.replace(offset, length, buffer.toString());
718 LinkedPositionManager manager = new LinkedPositionManager(
720 manager.addPosition(offset + 1, 0);
723 LinkedPositionUI editor = new LinkedPositionUI(
724 sourceViewer, manager);
725 editor.setCancelListener(this);
726 editor.setExitPolicy(new ExitPolicy(
728 editor.setFinalCaretOffset(offset + 2);
730 IRegion newSelection = editor.getSelectedRegion();
731 sourceViewer.setSelectedRange(newSelection
732 .getOffset(), newSelection.getLength());
735 } else if (type.equals(IPHPPartitions.HTML)
736 || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
737 switch (event.character) {
739 if (hasCharacterToTheRight(document, offset
744 if (!fCloseBracketsHTML)
746 if (hasIdentifierToTheRight(document, offset
751 if (event.character == '"') {
752 if (!fCloseStringsHTML)
754 if (hasIdentifierToTheLeft(document, offset)
755 || hasIdentifierToTheRight(document,
759 // ITypedRegion partition=
760 // document.getPartition(offset);
762 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
764 // (partition.getOffset() != offset))
766 final char character = event.character;
767 final char closingCharacter = getPeerCharacter(character);
768 final StringBuffer buffer = new StringBuffer();
769 buffer.append(character);
770 buffer.append(closingCharacter);
771 document.replace(offset, length, buffer.toString());
772 LinkedPositionManager manager = new LinkedPositionManager(
774 manager.addPosition(offset + 1, 0);
777 LinkedPositionUI editor = new LinkedPositionUI(
778 sourceViewer, manager);
779 editor.setCancelListener(this);
780 editor.setExitPolicy(new ExitPolicy(
782 editor.setFinalCaretOffset(offset + 2);
784 IRegion newSelection = editor.getSelectedRegion();
785 sourceViewer.setSelectedRange(newSelection
786 .getOffset(), newSelection.getLength());
790 } catch (BadLocationException e) {
794 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean)
796 public void exit(boolean accept) {
801 final ISourceViewer sourceViewer = getSourceViewer();
802 IDocument document = sourceViewer.getDocument();
803 document.replace(fOffset, fLength, null);
804 } catch (BadLocationException e) {
808 /** The editor's save policy */
809 protected ISavePolicy fSavePolicy;
811 * Listener to annotation model changes that updates the error tick in the
814 private JavaEditorErrorTickUpdater fJavaEditorErrorTickUpdater;
815 /** The editor's paint manager */
816 // private PaintManager fPaintManager;
817 /** The editor's bracket painter */
818 private BracketPainter fBracketPainter;
819 /** The editor's bracket matcher */
820 private PHPPairMatcher fBracketMatcher;
821 /** The editor's line painter */
822 private LinePainter fLinePainter;
823 /** The editor's print margin ruler painter */
824 private PrintMarginPainter fPrintMarginPainter;
825 /** The editor's problem painter */
826 // private ProblemPainter fProblemPainter;
827 /** The editor's tab converter */
828 private TabConverter fTabConverter;
829 /** History for structure select action */
830 //private SelectionHistory fSelectionHistory;
831 /** The preference property change listener for php core. */
832 // private IPropertyChangeListener fPropertyChangeListener = new
833 // PropertyChangeListener();
834 /** The remembered java element */
835 private IJavaElement fRememberedElement;
836 /** The remembered selection */
837 private ITextSelection fRememberedSelection;
838 /** The remembered php element offset */
839 private int fRememberedElementOffset;
840 /** The bracket inserter. */
841 private BracketInserter fBracketInserter = new BracketInserter();
843 /** The standard action groups added to the menu */
844 private GenerateActionGroup fGenerateActionGroup;
845 private CompositeActionGroup fContextMenuGroup;
846 // private class PropertyChangeListener implements IPropertyChangeListener {
848 // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
851 // propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
853 // handlePreferencePropertyChanged(event);
856 /* Preference key for code formatter tab size */
857 private final static String CODE_FORMATTER_TAB_SIZE = JavaCore.FORMATTER_TAB_SIZE;
858 /** Preference key for matching brackets */
859 private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
860 /** Preference key for matching brackets color */
861 private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
862 /** Preference key for highlighting current line */
863 private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
864 /** Preference key for highlight color of current line */
865 private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
866 /** Preference key for showing print marging ruler */
867 private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
868 /** Preference key for print margin ruler color */
869 private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
870 /** Preference key for print margin ruler column */
871 private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
872 /** Preference key for inserting spaces rather than tabs */
873 private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
874 /** Preference key for error indication */
875 // private final static String ERROR_INDICATION =
876 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
877 /** Preference key for error color */
878 // private final static String ERROR_INDICATION_COLOR =
879 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
880 /** Preference key for warning indication */
881 // private final static String WARNING_INDICATION =
882 // PreferenceConstants.EDITOR_WARNING_INDICATION;
883 /** Preference key for warning color */
884 // private final static String WARNING_INDICATION_COLOR =
885 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
886 /** Preference key for task indication */
887 private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
888 /** Preference key for task color */
889 private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
890 /** Preference key for bookmark indication */
891 private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
892 /** Preference key for bookmark color */
893 private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
894 /** Preference key for search result indication */
895 private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
896 /** Preference key for search result color */
897 private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
898 /** Preference key for unknown annotation indication */
899 private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
900 /** Preference key for unknown annotation color */
901 private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
902 /** Preference key for linked position color */
903 private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
904 /** Preference key for shwoing the overview ruler */
905 private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
906 /** Preference key for error indication in overview ruler */
907 private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
908 /** Preference key for warning indication in overview ruler */
909 private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
910 /** Preference key for task indication in overview ruler */
911 private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
912 /** Preference key for bookmark indication in overview ruler */
913 private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
914 /** Preference key for search result indication in overview ruler */
915 private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
916 /** Preference key for unknown annotation indication in overview ruler */
917 private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
918 /** Preference key for automatically closing strings */
919 private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP;
920 /** Preference key for automatically wrapping Java strings */
921 private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS;
922 /** Preference key for automatically closing brackets and parenthesis */
923 private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
924 /** Preference key for automatically closing phpdocs and comments */
925 private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
926 /** Preference key for automatically adding phpdoc tags */
927 private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
928 /** Preference key for automatically formatting phpdocs */
929 private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
930 /** Preference key for automatically closing strings */
931 private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
932 /** Preference key for automatically closing brackets and parenthesis */
933 private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
934 /** Preference key for smart paste */
935 private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
936 // private final static class AnnotationInfo {
937 // public String fColorPreference;
938 // public String fOverviewRulerPreference;
939 // public String fEditorPreference;
941 // private final static Map ANNOTATION_MAP;
944 // AnnotationInfo info;
945 // ANNOTATION_MAP = new HashMap();
947 // info = new AnnotationInfo();
948 // info.fColorPreference = TASK_INDICATION_COLOR;
949 // info.fOverviewRulerPreference = TASK_INDICATION_IN_OVERVIEW_RULER;
950 // info.fEditorPreference = TASK_INDICATION;
951 // ANNOTATION_MAP.put(AnnotationType.TASK, info);
953 // info = new AnnotationInfo();
954 // info.fColorPreference = ERROR_INDICATION_COLOR;
955 // info.fOverviewRulerPreference = ERROR_INDICATION_IN_OVERVIEW_RULER;
956 // info.fEditorPreference = ERROR_INDICATION;
957 // ANNOTATION_MAP.put(AnnotationType.ERROR, info);
959 // info = new AnnotationInfo();
960 // info.fColorPreference = WARNING_INDICATION_COLOR;
961 // info.fOverviewRulerPreference = WARNING_INDICATION_IN_OVERVIEW_RULER;
962 // info.fEditorPreference = WARNING_INDICATION;
963 // ANNOTATION_MAP.put(AnnotationType.WARNING, info);
965 // info = new AnnotationInfo();
966 // info.fColorPreference = BOOKMARK_INDICATION_COLOR;
967 // info.fOverviewRulerPreference = BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
968 // info.fEditorPreference = BOOKMARK_INDICATION;
969 // ANNOTATION_MAP.put(AnnotationType.BOOKMARK, info);
971 // info = new AnnotationInfo();
972 // info.fColorPreference = SEARCH_RESULT_INDICATION_COLOR;
973 // info.fOverviewRulerPreference =
974 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
975 // info.fEditorPreference = SEARCH_RESULT_INDICATION;
976 // ANNOTATION_MAP.put(AnnotationType.SEARCH, info);
978 // info = new AnnotationInfo();
979 // info.fColorPreference = UNKNOWN_INDICATION_COLOR;
980 // info.fOverviewRulerPreference = UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
981 // info.fEditorPreference = UNKNOWN_INDICATION;
982 // ANNOTATION_MAP.put(AnnotationType.UNKNOWN, info);
985 // private final static AnnotationType[] ANNOTATION_LAYERS =
986 // new AnnotationType[] {
987 // AnnotationType.UNKNOWN,
988 // AnnotationType.BOOKMARK,
989 // AnnotationType.TASK,
990 // AnnotationType.SEARCH,
991 // AnnotationType.WARNING,
992 // AnnotationType.ERROR };
994 * Creates a new php unit editor.
996 public PHPUnitEditor() {
998 setDocumentProvider(PHPeclipsePlugin.getDefault()
999 .getCompilationUnitDocumentProvider());
1000 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
1001 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
1002 setOutlinerContextMenuId("#PHPOutlinerContext"); //$NON-NLS-1$
1003 // don't set help contextId, we install our own help context
1005 fJavaEditorErrorTickUpdater = new JavaEditorErrorTickUpdater(this);
1008 * @see AbstractTextEditor#createActions()
1010 protected void createActions() {
1011 super.createActions();
1013 // Action action= new
1014 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1015 // "CorrectionAssistProposal.", this, CORRECTIONASSIST_PROPOSALS);
1017 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
1018 // setAction("CorrectionAssistProposal", action); //$NON-NLS-1$
1019 // markAsStateDependentAction("CorrectionAssistProposal", true);
1021 //// WorkbenchHelp.setHelp(action,
1022 // IJavaHelpContextIds.QUICK_FIX_ACTION);
1023 action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(),
1024 "ContentAssistProposal.", this); //$NON-NLS-1$
1026 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
1027 setAction("ContentAssistProposal", action); //$NON-NLS-1$
1028 markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
1029 // WorkbenchHelp.setHelp(action,
1030 // IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
1031 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1032 "ContentAssistContextInformation.", this,
1033 ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$
1035 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
1036 setAction("ContentAssistContextInformation", action); //$NON-NLS-1$
1037 markAsStateDependentAction("ContentAssistContextInformation", true); //$NON-NLS-1$
1038 // WorkbenchHelp.setHelp(action,
1039 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1041 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1042 // "ContentAssistCompletePrefix.", this, CONTENTASSIST_COMPLETE_PREFIX);
1044 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_COMPLETE_PREFIX);
1045 // setAction("ContentAssistCompletePrefix", action); //$NON-NLS-1$
1046 // markAsStateDependentAction("ContentAssistCompletePrefix", true);
1048 //// WorkbenchHelp.setHelp(action,
1049 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1050 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1051 "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
1052 action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
1053 setAction("Comment", action); //$NON-NLS-1$
1054 markAsStateDependentAction("Comment", true); //$NON-NLS-1$
1055 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
1056 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1057 "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
1058 action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
1059 setAction("Uncomment", action); //$NON-NLS-1$
1060 markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
1061 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
1063 action = new ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1064 "ToggleComment.", this); //$NON-NLS-1$
1066 .setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1067 setAction("ToggleComment", action); //$NON-NLS-1$
1068 markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1069 //WorkbenchHelp.setHelp(action,
1070 // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1071 configureToggleCommentAction();
1074 // ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1075 // "ToggleComment.", this, getSourceViewerConfiguration()
1076 // .getDefaultPrefixes(getSourceViewer(), "")); //$NON-NLS-1$
1078 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1079 // setAction("ToggleComment", action); //$NON-NLS-1$
1080 // markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1081 // // WorkbenchHelp.setHelp(action,
1082 // // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1084 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1085 "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
1086 action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
1087 setAction("Format", action); //$NON-NLS-1$
1088 markAsStateDependentAction("Format", true); //$NON-NLS-1$
1089 markAsSelectionDependentAction("Format", true); //$NON-NLS-1$
1090 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
1092 action = new AddBlockCommentAction(PHPEditorMessages
1093 .getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$
1095 .setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
1096 setAction("AddBlockComment", action); //$NON-NLS-1$
1097 markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
1098 markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
1099 // WorkbenchHelp.setHelp(action,
1100 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1101 action = new RemoveBlockCommentAction(PHPEditorMessages
1102 .getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
1104 .setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
1105 setAction("RemoveBlockComment", action); //$NON-NLS-1$
1106 markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1107 markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1108 // WorkbenchHelp.setHelp(action,
1109 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1110 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1111 // "Indent.", this, false); //$NON-NLS-1$
1112 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT);
1113 // setAction("Indent", action); //$NON-NLS-1$
1114 // markAsStateDependentAction("Indent", true); //$NON-NLS-1$
1115 // markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
1116 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION);
1118 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1119 // "Indent.", this, true); //$NON-NLS-1$
1120 // setAction("IndentOnTab", action); //$NON-NLS-1$
1121 // markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
1122 // markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$
1124 if (getPreferenceStore().getBoolean(
1125 PreferenceConstants.EDITOR_SMART_TAB)) {
1126 // don't replace Shift Right - have to make sure their enablement is
1127 // mutually exclusive
1128 // removeActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT);
1129 setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$
1131 fGenerateActionGroup = new GenerateActionGroup(this,
1132 ITextEditorActionConstants.GROUP_EDIT);
1133 fActionGroups = new CompositeActionGroup(
1134 new ActionGroup[]{fGenerateActionGroup});
1135 // We have to keep the context menu group separate to have better
1138 fContextMenuGroup = new CompositeActionGroup(
1139 new ActionGroup[]{fGenerateActionGroup});
1141 // new LocalHistoryActionGroup(this,
1142 // ITextEditorActionConstants.GROUP_EDIT)});
1146 * @see JavaEditor#getElementAt(int)
1148 protected IJavaElement getElementAt(int offset) {
1149 return getElementAt(offset, true);
1152 * Returns the most narrow element including the given offset. If
1153 * <code>reconcile</code> is <code>true</code> the editor's input
1154 * element is reconciled in advance. If it is <code>false</code> this
1155 * method only returns a result if the editor's input element does not need
1159 * the offset included by the retrieved element
1161 * <code>true</code> if working copy should be reconciled
1163 protected IJavaElement getElementAt(int offset, boolean reconcile) {
1164 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1165 .getWorkingCopyManager();
1166 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1170 synchronized (unit) {
1173 return unit.getElementAt(offset);
1174 } else if (unit.isConsistent())
1175 return unit.getElementAt(offset);
1176 } catch (JavaModelException x) {
1177 PHPeclipsePlugin.log(x.getStatus());
1178 // nothing found, be tolerant and go on
1184 * @see JavaEditor#getCorrespondingElement(IJavaElement)
1186 protected IJavaElement getCorrespondingElement(IJavaElement element) {
1188 return EditorUtility.getWorkingCopy(element, true);
1189 } catch (JavaModelException x) {
1190 PHPeclipsePlugin.log(x.getStatus());
1191 // nothing found, be tolerant and go on
1195 public void createPartControl(Composite parent) {
1196 super.createPartControl(parent);
1197 // fPaintManager = new PaintManager(getSourceViewer());
1198 LinePainter linePainter;
1199 linePainter = new LinePainter(getSourceViewer());
1200 linePainter.setHighlightColor(new Color(Display.getCurrent(), 225, 235,
1202 // fPaintManager.addPainter(linePainter);
1203 if (isBracketHighlightingEnabled())
1204 startBracketHighlighting();
1205 if (isLineHighlightingEnabled())
1206 startLineHighlighting();
1207 if (isPrintMarginVisible())
1209 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1210 // while (e.hasNext()) {
1211 // AnnotationType type = (AnnotationType) e.next();
1212 // if (isAnnotationIndicationEnabled(type))
1213 // startAnnotationIndication(type);
1215 if (isTabConversionEnabled())
1216 startTabConversion();
1217 // if (isOverviewRulerVisible())
1218 // showOverviewRuler();
1220 // Preferences preferences =
1221 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1222 // preferences.addPropertyChangeListener(fPropertyChangeListener);
1223 IPreferenceStore preferenceStore = getPreferenceStore();
1224 boolean closeBracketsPHP = preferenceStore
1225 .getBoolean(CLOSE_BRACKETS_PHP);
1226 boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP);
1227 boolean closeBracketsHTML = preferenceStore
1228 .getBoolean(CLOSE_BRACKETS_HTML);
1229 boolean closeStringsHTML = preferenceStore
1230 .getBoolean(CLOSE_STRINGS_HTML);
1231 fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
1232 fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP);
1233 fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
1234 fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
1235 ISourceViewer sourceViewer = getSourceViewer();
1236 if (sourceViewer instanceof ITextViewerExtension)
1237 ((ITextViewerExtension) sourceViewer)
1238 .prependVerifyKeyListener(fBracketInserter);
1240 private static char getPeerCharacter(char character) {
1241 switch (character) {
1253 throw new IllegalArgumentException();
1257 private void startBracketHighlighting() {
1258 if (fBracketPainter == null) {
1259 ISourceViewer sourceViewer = getSourceViewer();
1260 fBracketPainter = new BracketPainter(sourceViewer);
1262 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1263 // fPaintManager.addPainter(fBracketPainter);
1266 private void stopBracketHighlighting() {
1267 if (fBracketPainter != null) {
1268 // fPaintManager.removePainter(fBracketPainter);
1269 fBracketPainter.deactivate(true);
1270 fBracketPainter.dispose();
1271 fBracketPainter = null;
1274 private boolean isBracketHighlightingEnabled() {
1275 IPreferenceStore store = getPreferenceStore();
1276 return store.getBoolean(MATCHING_BRACKETS);
1278 private void startLineHighlighting() {
1279 if (fLinePainter == null) {
1280 ISourceViewer sourceViewer = getSourceViewer();
1281 fLinePainter = new LinePainter(sourceViewer);
1282 fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR));
1283 // fPaintManager.addPainter(fLinePainter);
1286 private void stopLineHighlighting() {
1287 if (fLinePainter != null) {
1288 // fPaintManager.removePainter(fLinePainter);
1289 fLinePainter.deactivate(true);
1290 fLinePainter.dispose();
1291 fLinePainter = null;
1294 private boolean isLineHighlightingEnabled() {
1295 IPreferenceStore store = getPreferenceStore();
1296 return store.getBoolean(CURRENT_LINE);
1298 private void showPrintMargin() {
1299 if (fPrintMarginPainter == null) {
1300 fPrintMarginPainter = new PrintMarginPainter(getSourceViewer());
1302 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1303 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore()
1304 .getInt(PRINT_MARGIN_COLUMN));
1305 // fPaintManager.addPainter(fPrintMarginPainter);
1308 private void hidePrintMargin() {
1309 if (fPrintMarginPainter != null) {
1310 // fPaintManager.removePainter(fPrintMarginPainter);
1311 fPrintMarginPainter.deactivate(true);
1312 fPrintMarginPainter.dispose();
1313 fPrintMarginPainter = null;
1316 private boolean isPrintMarginVisible() {
1317 IPreferenceStore store = getPreferenceStore();
1318 return store.getBoolean(PRINT_MARGIN);
1320 // private void startAnnotationIndication(AnnotationType annotationType) {
1321 // if (fProblemPainter == null) {
1322 // fProblemPainter = new ProblemPainter(this, getSourceViewer());
1323 //// fPaintManager.addPainter(fProblemPainter);
1325 // fProblemPainter.setColor(annotationType, getColor(annotationType));
1326 // fProblemPainter.paintAnnotations(annotationType, true);
1327 // fProblemPainter.paint(IPainter.CONFIGURATION);
1330 // private void shutdownAnnotationIndication() {
1331 // if (fProblemPainter != null) {
1333 // if (!fProblemPainter.isPaintingAnnotations()) {
1334 //// fPaintManager.removePainter(fProblemPainter);
1335 // fProblemPainter.deactivate(true);
1336 // fProblemPainter.dispose();
1337 // fProblemPainter = null;
1339 // fProblemPainter.paint(IPainter.CONFIGURATION);
1344 // private void stopAnnotationIndication(AnnotationType annotationType) {
1345 // if (fProblemPainter != null) {
1346 // fProblemPainter.paintAnnotations(annotationType, false);
1347 // shutdownAnnotationIndication();
1351 // private boolean isAnnotationIndicationEnabled(AnnotationType
1352 // annotationType) {
1353 // IPreferenceStore store = getPreferenceStore();
1354 // AnnotationInfo info = (AnnotationInfo)
1355 // ANNOTATION_MAP.get(annotationType);
1356 // if (info != null)
1357 // return store.getBoolean(info.fEditorPreference);
1362 // isAnnotationIndicationInOverviewRulerEnabled(AnnotationType
1363 // annotationType) {
1364 // IPreferenceStore store = getPreferenceStore();
1365 // AnnotationInfo info = (AnnotationInfo)
1366 // ANNOTATION_MAP.get(annotationType);
1367 // if (info != null)
1368 // return store.getBoolean(info.fOverviewRulerPreference);
1372 // private void showAnnotationIndicationInOverviewRuler(AnnotationType
1373 // annotationType, boolean show) {
1374 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1375 // OverviewRuler ruler = asv.getOverviewRuler();
1376 // if (ruler != null) {
1377 // ruler.setColor(annotationType, getColor(annotationType));
1378 // ruler.showAnnotation(annotationType, show);
1383 // private void setColorInOverviewRuler(AnnotationType annotationType, Color
1385 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1386 // OverviewRuler ruler = asv.getOverviewRuler();
1387 // if (ruler != null) {
1388 // ruler.setColor(annotationType, color);
1393 private int getTabSize() {
1394 Preferences preferences = PHPeclipsePlugin.getDefault()
1395 .getPluginPreferences();
1396 return preferences.getInt(CODE_FORMATTER_TAB_SIZE);
1399 private boolean isTabConversionEnabled() {
1400 IPreferenceStore store = getPreferenceStore();
1401 return store.getBoolean(SPACES_FOR_TABS);
1403 // private void showOverviewRuler() {
1404 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1405 // asv.showOverviewRuler();
1407 // OverviewRuler overviewRuler = asv.getOverviewRuler();
1408 // if (overviewRuler != null) {
1409 // for (int i = 0; i < ANNOTATION_LAYERS.length; i++) {
1410 // AnnotationType type = ANNOTATION_LAYERS[i];
1411 // overviewRuler.setLayer(type, i);
1412 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1413 // showAnnotationIndicationInOverviewRuler(type, true);
1418 // private void hideOverviewRuler() {
1419 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1420 // asv.hideOverviewRuler();
1423 // private boolean isOverviewRulerVisible() {
1424 // IPreferenceStore store = getPreferenceStore();
1425 // return store.getBoolean(OVERVIEW_RULER);
1427 private Color getColor(String key) {
1428 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
1429 return getColor(rgb);
1431 private Color getColor(RGB rgb) {
1432 JavaTextTools textTools = PHPeclipsePlugin.getDefault()
1433 .getJavaTextTools();
1434 return textTools.getColorManager().getColor(rgb);
1436 // private Color getColor(AnnotationType annotationType) {
1437 // AnnotationInfo info = (AnnotationInfo)
1438 // ANNOTATION_MAP.get(annotationType);
1439 // if (info != null)
1440 // return getColor(info.fColorPreference);
1443 public void dispose() {
1444 ISourceViewer sourceViewer = getSourceViewer();
1445 if (sourceViewer instanceof ITextViewerExtension)
1446 ((ITextViewerExtension) sourceViewer)
1447 .removeVerifyKeyListener(fBracketInserter);
1448 // if (fPropertyChangeListener != null) {
1449 // Preferences preferences =
1450 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1451 // preferences.removePropertyChangeListener(fPropertyChangeListener);
1452 // fPropertyChangeListener = null;
1454 if (fJavaEditorErrorTickUpdater != null) {
1455 fJavaEditorErrorTickUpdater.dispose();
1456 fJavaEditorErrorTickUpdater = null;
1458 // if (fSelectionHistory != null)
1459 // fSelectionHistory.dispose();
1460 // if (fPaintManager != null) {
1461 // fPaintManager.dispose();
1462 // fPaintManager = null;
1464 if (fActionGroups != null) {
1465 fActionGroups.dispose();
1466 fActionGroups = null;
1470 // protected AnnotationType getAnnotationType(String preferenceKey) {
1471 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1472 // while (e.hasNext()) {
1473 // AnnotationType type = (AnnotationType) e.next();
1474 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1475 // if (info != null) {
1476 // if (preferenceKey.equals(info.fColorPreference)
1477 // || preferenceKey.equals(info.fEditorPreference)
1478 // || preferenceKey.equals(info.fOverviewRulerPreference))
1485 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1487 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1489 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1491 String p = event.getProperty();
1492 if (CLOSE_BRACKETS_PHP.equals(p)) {
1494 .setCloseBracketsPHPEnabled(getPreferenceStore()
1498 if (CLOSE_STRINGS_PHP.equals(p)) {
1500 .setCloseStringsPHPEnabled(getPreferenceStore()
1504 if (CLOSE_BRACKETS_HTML.equals(p)) {
1506 .setCloseBracketsHTMLEnabled(getPreferenceStore()
1510 if (CLOSE_STRINGS_HTML.equals(p)) {
1512 .setCloseStringsHTMLEnabled(getPreferenceStore()
1516 if (SPACES_FOR_TABS.equals(p)) {
1517 if (isTabConversionEnabled())
1518 startTabConversion();
1520 stopTabConversion();
1523 if (MATCHING_BRACKETS.equals(p)) {
1524 if (isBracketHighlightingEnabled())
1525 startBracketHighlighting();
1527 stopBracketHighlighting();
1530 if (MATCHING_BRACKETS_COLOR.equals(p)) {
1531 if (fBracketPainter != null)
1533 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1536 if (CURRENT_LINE.equals(p)) {
1537 if (isLineHighlightingEnabled())
1538 startLineHighlighting();
1540 stopLineHighlighting();
1543 if (CURRENT_LINE_COLOR.equals(p)) {
1544 if (fLinePainter != null) {
1545 stopLineHighlighting();
1546 startLineHighlighting();
1550 if (PRINT_MARGIN.equals(p)) {
1551 if (isPrintMarginVisible())
1557 if (PRINT_MARGIN_COLOR.equals(p)) {
1558 if (fPrintMarginPainter != null)
1560 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1563 if (PRINT_MARGIN_COLUMN.equals(p)) {
1564 if (fPrintMarginPainter != null)
1566 .setMarginRulerColumn(getPreferenceStore()
1567 .getInt(PRINT_MARGIN_COLUMN));
1570 // if (OVERVIEW_RULER.equals(p)) {
1571 // if (isOverviewRulerVisible())
1572 // showOverviewRuler();
1574 // hideOverviewRuler();
1577 // AnnotationType type = getAnnotationType(p);
1578 // if (type != null) {
1580 // AnnotationInfo info = (AnnotationInfo)
1581 // ANNOTATION_MAP.get(type);
1582 // if (info.fColorPreference.equals(p)) {
1583 // Color color = getColor(type);
1584 // if (fProblemPainter != null) {
1585 // fProblemPainter.setColor(type, color);
1586 // fProblemPainter.paint(IPainter.CONFIGURATION);
1588 // setColorInOverviewRuler(type, color);
1592 // if (info.fEditorPreference.equals(p)) {
1593 // if (isAnnotationIndicationEnabled(type))
1594 // startAnnotationIndication(type);
1596 // stopAnnotationIndication(type);
1600 // if (info.fOverviewRulerPreference.equals(p)) {
1601 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1602 // showAnnotationIndicationInOverviewRuler(type, true);
1604 // showAnnotationIndicationInOverviewRuler(type, false);
1608 IContentAssistant c = asv.getContentAssistant();
1609 if (c instanceof ContentAssistant)
1610 ContentAssistPreference.changeConfiguration(
1611 (ContentAssistant) c, getPreferenceStore(), event);
1614 super.handlePreferenceStoreChanged(event);
1618 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
1620 protected void handlePreferencePropertyChanged(
1621 org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1622 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1624 String p = event.getProperty();
1625 if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1626 asv.updateIndentationPrefixes();
1627 if (fTabConverter != null)
1628 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1631 super.handlePreferencePropertyChanged(event);
1634 * Handles a property change event describing a change of the php core's
1635 * preferences and updates the preference related editor properties.
1638 * the property change event
1641 // handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
1643 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1644 // if (asv != null) {
1645 // String p = event.getProperty();
1646 // if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1647 // asv.updateIndentationPrefixes();
1648 // if (fTabConverter != null)
1649 // fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1655 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#createJavaSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, org.eclipse.jface.text.source.IOverviewRuler, boolean, int)
1657 protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
1658 return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler, 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 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1783 .getWorkingCopyManager();
1784 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1787 synchronized (unit) {
1788 performSave(false, progressMonitor);
1791 performSave(false, progressMonitor);
1795 public boolean isSaveAsAllowed() {
1800 * The compilation unit editor implementation of this
1801 * <code>AbstractTextEditor</code> method asks the user for the workspace
1802 * path of a file resource and saves the document there. See
1803 * http://dev.eclipse.org/bugs/show_bug.cgi?id=6295
1805 * @param progressMonitor
1806 * the progress monitor
1808 protected void performSaveAs(IProgressMonitor progressMonitor) {
1810 Shell shell = getSite().getShell();
1811 IEditorInput input = getEditorInput();
1813 SaveAsDialog dialog = new SaveAsDialog(shell);
1815 IFile original = (input instanceof IFileEditorInput)
1816 ? ((IFileEditorInput) input).getFile()
1818 if (original != null)
1819 dialog.setOriginalFile(original);
1823 IDocumentProvider provider = getDocumentProvider();
1824 if (provider == null) {
1825 // editor has been programmatically closed while the dialog was open
1829 if (provider.isDeleted(input) && original != null) {
1830 String message = PHPEditorMessages
1831 .getFormattedString(
1832 "CompilationUnitEditor.warning.save.delete", new Object[]{original.getName()}); //$NON-NLS-1$
1833 dialog.setErrorMessage(null);
1834 dialog.setMessage(message, IMessageProvider.WARNING);
1837 if (dialog.open() == Window.CANCEL) {
1838 if (progressMonitor != null)
1839 progressMonitor.setCanceled(true);
1843 IPath filePath = dialog.getResult();
1844 if (filePath == null) {
1845 if (progressMonitor != null)
1846 progressMonitor.setCanceled(true);
1850 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1851 IFile file = workspaceRoot.getFile(filePath);
1852 final IEditorInput newInput = new FileEditorInput(file);
1854 boolean success = false;
1857 provider.aboutToChange(newInput);
1858 getDocumentProvider().saveDocument(progressMonitor, newInput,
1859 getDocumentProvider().getDocument(getEditorInput()), true);
1862 } catch (CoreException x) {
1863 IStatus status = x.getStatus();
1864 if (status == null || status.getSeverity() != IStatus.CANCEL)
1869 .getString("CompilationUnitEditor.error.saving.title2"), PHPEditorMessages.getString("CompilationUnitEditor.error.saving.message2"), x.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
1871 provider.changed(newInput);
1876 if (progressMonitor != null)
1877 progressMonitor.setCanceled(!success);
1881 * @see AbstractTextEditor#doSetInput(IEditorInput)
1883 protected void doSetInput(IEditorInput input) throws CoreException {
1884 super.doSetInput(input);
1885 configureTabConverter();
1886 configureToggleCommentAction();
1891 // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#installOverrideIndicator(boolean)
1894 // protected void installOverrideIndicator(boolean waitForReconcilation) {
1895 // IAnnotationModel model=
1896 // getDocumentProvider().getAnnotationModel(getEditorInput());
1897 // if (!waitForReconcilation)
1898 // super.installOverrideIndicator(false);
1900 // uninstallOverrideIndicator();
1901 // IJavaElement inputElement= getInputJavaElement();
1902 // if (model == null || inputElement == null)
1905 // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
1906 // inputElement, null);
1907 // addReconcileListener(fOverrideIndicatorManager);
1913 // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#uninstallOverrideIndicator()
1916 // protected void uninstallOverrideIndicator() {
1917 // if (fOverrideIndicatorManager != null)
1918 // removeReconcileListener(fOverrideIndicatorManager);
1919 // super.uninstallOverrideIndicator();
1923 * Configures the toggle comment action
1927 private void configureToggleCommentAction() {
1928 IAction action = getAction("ToggleComment"); //$NON-NLS-1$
1929 if (action instanceof ToggleCommentAction) {
1930 ISourceViewer sourceViewer = getSourceViewer();
1931 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
1932 ((ToggleCommentAction) action).configure(sourceViewer,
1937 private void configureTabConverter() {
1938 if (fTabConverter != null) {
1939 IDocumentProvider provider = getDocumentProvider();
1940 if (provider instanceof PHPDocumentProvider) {
1941 PHPDocumentProvider cup = (PHPDocumentProvider) provider;
1942 fTabConverter.setLineTracker(cup
1943 .createLineTracker(getEditorInput()));
1948 private void startTabConversion() {
1949 if (fTabConverter == null) {
1950 fTabConverter = new TabConverter();
1951 configureTabConverter();
1952 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1953 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1954 asv.addTextConverter(fTabConverter);
1955 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1956 asv.updateIndentationPrefixes();
1960 private void stopTabConversion() {
1961 if (fTabConverter != null) {
1962 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1963 asv.removeTextConverter(fTabConverter);
1964 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1965 asv.updateIndentationPrefixes();
1966 fTabConverter = null;
1971 * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean,
1972 * org.eclipse.core.runtime.IProgressMonitor)
1974 protected void performSave(boolean overwrite,
1975 IProgressMonitor progressMonitor) {
1976 IDocumentProvider p = getDocumentProvider();
1977 if (p instanceof PHPDocumentProvider) {
1978 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1979 cp.setSavePolicy(fSavePolicy);
1982 super.performSave(overwrite, progressMonitor);
1984 if (p instanceof PHPDocumentProvider) {
1985 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1986 cp.setSavePolicy(null);
1991 * @see AbstractTextEditor#doSaveAs
1993 public void doSaveAs() {
1994 if (askIfNonWorkbenchEncodingIsOk()) {
2000 * Asks the user if it is ok to store in non-workbench encoding.
2002 * @return <true>if the user wants to continue
2004 private boolean askIfNonWorkbenchEncodingIsOk() {
2005 IDocumentProvider provider = getDocumentProvider();
2006 if (provider instanceof IStorageDocumentProvider) {
2007 IEditorInput input = getEditorInput();
2008 IStorageDocumentProvider storageProvider = (IStorageDocumentProvider) provider;
2009 String encoding = storageProvider.getEncoding(input);
2010 String defaultEncoding = storageProvider.getDefaultEncoding();
2011 if (encoding != null && !encoding.equals(defaultEncoding)) {
2012 Shell shell = getSite().getShell();
2013 String title = PHPEditorMessages
2014 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$
2020 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"),
2021 new String[]{input.getName(), encoding}); //$NON-NLS-1$
2026 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message2"),
2027 new String[]{encoding}); //$NON-NLS-1$
2028 return MessageDialog.openQuestion(shell, title, msg);
2034 * @see IReconcilingParticipant#reconciled()
2036 public void reconciled() {
2037 if (synchronizeOutlineOnCursorMove()) {
2038 Shell shell = getSite().getShell();
2039 if (shell != null && !shell.isDisposed()) {
2040 shell.getDisplay().asyncExec(new Runnable() {
2042 synchronizeOutlinePageSelection();
2049 protected void updateStateDependentActions() {
2050 super.updateStateDependentActions();
2051 fGenerateActionGroup.editorStateChanged();
2054 private boolean synchronizeOutlineOnCursorMove() {
2055 return PreferenceConstants.getPreferenceStore().getBoolean(
2056 PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE);
2060 * Returns the updated java element for the old java element.
2062 private IJavaElement findElement(IJavaElement element) {
2063 if (element == null)
2065 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
2066 .getWorkingCopyManager();
2067 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
2070 synchronized (unit) {
2073 IJavaElement[] findings = unit.findElements(element);
2074 if (findings != null && findings.length > 0)
2076 } catch (JavaModelException x) {
2077 PHPeclipsePlugin.log(x.getStatus());
2078 // nothing found, be tolerant and go on
2084 * Returns the offset of the given Java element.
2086 private int getOffset(IJavaElement element) {
2087 if (element instanceof ISourceReference) {
2088 ISourceReference sr = (ISourceReference) element;
2090 ISourceRange srcRange = sr.getSourceRange();
2091 if (srcRange != null)
2092 return srcRange.getOffset();
2093 } catch (JavaModelException e) {
2099 * @see AbstractTextEditor#rememberSelection()
2101 protected void rememberSelection() {
2102 ISelectionProvider sp = getSelectionProvider();
2103 fRememberedSelection = (sp == null ? null : (ITextSelection) sp
2105 if (fRememberedSelection != null) {
2106 fRememberedElement = getElementAt(fRememberedSelection.getOffset(),
2108 fRememberedElementOffset = getOffset(fRememberedElement);
2112 * @see AbstractTextEditor#restoreSelection()
2114 protected void restoreSelection() {
2116 if (getSourceViewer() == null || fRememberedSelection == null)
2118 IJavaElement newElement = findElement(fRememberedElement);
2119 int newOffset = getOffset(newElement);
2120 int delta = (newOffset > -1 && fRememberedElementOffset > -1)
2121 ? newOffset - fRememberedElementOffset
2123 if (isValidSelection(delta + fRememberedSelection.getOffset(),
2124 fRememberedSelection.getLength()))
2125 selectAndReveal(delta + fRememberedSelection.getOffset(),
2126 fRememberedSelection.getLength());
2128 fRememberedSelection = null;
2129 fRememberedElement = null;
2130 fRememberedElementOffset = -1;
2135 // * @see org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
2138 // public void aboutToBeReconciled() {
2140 // // Notify AST provider
2141 // PHPeclipsePlugin.getDefault().getASTProvider().aboutToBeReconciled(getInputJavaElement());
2143 // // Notify listeners
2144 // Object[] listeners = fReconcilingListeners.getListeners();
2145 // for (int i = 0, length= listeners.length; i < length; ++i)
2146 // ((IJavaReconcilingListener)listeners[i]).aboutToBeReconciled();
2150 // * @see org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit, boolean, IProgressMonitor)
2153 // public void reconciled(net.sourceforge.phpdt.core.dom.CompilationUnit ast, boolean forced, IProgressMonitor progressMonitor) {
2155 // // Always notify AST provider
2156 // PHPeclipsePlugin.getDefault().getASTProvider().reconciled(ast, getInputJavaElement());
2158 // // Notify listeners
2159 // Object[] listeners = fReconcilingListeners.getListeners();
2160 // for (int i = 0, length= listeners.length; i < length; ++i)
2161 // ((IJavaReconcilingListener)listeners[i]).reconciled(ast, forced, progressMonitor);
2163 // // Update Java Outline page selection
2164 // if (!forced && !progressMonitor.isCanceled()) {
2165 // Shell shell= getSite().getShell();
2166 // if (shell != null && !shell.isDisposed()) {
2167 // shell.getDisplay().asyncExec(new Runnable() {
2168 // public void run() {
2169 // selectionChanged();