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
108 // IJavaReconcilingListener {
109 interface ITextConverter {
110 void customizeDocumentCommand(IDocument document,
111 DocumentCommand command);
113 // class AdaptedRulerLayout extends Layout {
115 // protected int fGap;
116 // protected AdaptedSourceViewer fAdaptedSourceViewer;
118 // protected AdaptedRulerLayout(int gap, AdaptedSourceViewer asv) {
120 // fAdaptedSourceViewer = asv;
123 // protected Point computeSize(Composite composite, int wHint, int hHint,
124 // boolean flushCache) {
125 // Control[] children = composite.getChildren();
126 // Point s = children[children.length - 1].computeSize(SWT.DEFAULT,
127 // SWT.DEFAULT, flushCache);
128 // if (fAdaptedSourceViewer.isVerticalRulerVisible())
129 // s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap;
133 // protected void layout(Composite composite, boolean flushCache) {
134 // Rectangle clArea = composite.getClientArea();
135 // if (fAdaptedSourceViewer.isVerticalRulerVisible()) {
137 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
138 // Rectangle trim = textWidget.computeTrim(0, 0, 0, 0);
139 // int scrollbarHeight = trim.height;
141 // IVerticalRuler vr = fAdaptedSourceViewer.getVerticalRuler();
142 // int vrWidth = vr.getWidth();
145 // if (fAdaptedSourceViewer.isOverviewRulerVisible()) {
146 // OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler();
147 // orWidth = or.getWidth();
148 // or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight,
149 // orWidth, clArea.height - 3 * scrollbarHeight);
152 // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth
154 // 2 * fGap, clArea.height);
155 // vr.getControl().setBounds(0, 0, vrWidth, clArea.height -
159 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
160 // textWidget.setBounds(0, 0, clArea.width, clArea.height);
165 // class AdaptedSourceViewer extends SourceViewer { // extends
166 // JavaCorrectionSourceViewer {
168 // private List fTextConverters;
170 // private OverviewRuler fOverviewRuler;
171 // private boolean fIsOverviewRulerVisible;
172 // /** The viewer's overview ruler hovering controller */
173 // private AbstractHoverInformationControlManager
174 // fOverviewRulerHoveringController;
176 // private boolean fIgnoreTextConverters = false;
178 // private IVerticalRuler fCachedVerticalRuler;
179 // private boolean fCachedIsVerticalRulerVisible;
181 // public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int
183 // super(parent, ruler, styles); //, CompilationUnitEditor.this);
185 // fCachedVerticalRuler = ruler;
186 // fCachedIsVerticalRulerVisible = (ruler != null);
187 // fOverviewRuler = new OverviewRuler(VERTICAL_RULER_WIDTH);
189 // delayedCreateControl(parent, styles);
193 // * @see ISourceViewer#showAnnotations(boolean)
195 // public void showAnnotations(boolean show) {
196 // fCachedIsVerticalRulerVisible = (show && fCachedVerticalRuler != null);
197 // // super.showAnnotations(show);
200 // public IContentAssistant getContentAssistant() {
201 // return fContentAssistant;
205 // * @see ITextOperationTarget#doOperation(int)
207 // public void doOperation(int operation) {
209 // if (getTextWidget() == null)
212 // switch (operation) {
213 // case CONTENTASSIST_PROPOSALS :
214 // String msg = fContentAssistant.showPossibleCompletions();
215 // setStatusLineErrorMessage(msg);
218 // fIgnoreTextConverters = true;
221 // fIgnoreTextConverters = true;
225 // super.doOperation(operation);
228 // public void insertTextConverter(ITextConverter textConverter, int index)
230 // throw new UnsupportedOperationException();
233 // public void addTextConverter(ITextConverter textConverter) {
234 // if (fTextConverters == null) {
235 // fTextConverters = new ArrayList(1);
236 // fTextConverters.add(textConverter);
237 // } else if (!fTextConverters.contains(textConverter))
238 // fTextConverters.add(textConverter);
241 // public void removeTextConverter(ITextConverter textConverter) {
242 // if (fTextConverters != null) {
243 // fTextConverters.remove(textConverter);
244 // if (fTextConverters.size() == 0)
245 // fTextConverters = null;
250 // * @see TextViewer#customizeDocumentCommand(DocumentCommand)
252 // protected void customizeDocumentCommand(DocumentCommand command) {
253 // super.customizeDocumentCommand(command);
254 // if (!fIgnoreTextConverters && fTextConverters != null) {
255 // for (Iterator e = fTextConverters.iterator(); e.hasNext();)
256 // ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(),
259 // fIgnoreTextConverters = false;
262 // public IVerticalRuler getVerticalRuler() {
263 // return fCachedVerticalRuler;
266 // public boolean isVerticalRulerVisible() {
267 // return fCachedIsVerticalRulerVisible;
270 // public OverviewRuler getOverviewRuler() {
271 // return fOverviewRuler;
275 // * @see TextViewer#createControl(Composite, int)
277 // protected void createControl(Composite parent, int styles) {
278 // // do nothing here
281 // protected void delayedCreateControl(Composite parent, int styles) {
282 // //create the viewer
283 // super.createControl(parent, styles);
285 // Control control = getControl();
286 // if (control instanceof Composite) {
287 // Composite composite = (Composite) control;
288 // composite.setLayout(new AdaptedRulerLayout(GAP_SIZE, this));
289 // fOverviewRuler.createControl(composite, this);
292 // protected void ensureOverviewHoverManagerInstalled() {
293 // if (fOverviewRulerHoveringController == null && fAnnotationHover != null
294 // && fHoverControlCreator != null) {
295 // fOverviewRulerHoveringController =
296 // new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover,
297 // fHoverControlCreator);
298 // fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
302 // public void hideOverviewRuler() {
303 // fIsOverviewRulerVisible = false;
304 // Control control = getControl();
305 // if (control instanceof Composite) {
306 // Composite composite = (Composite) control;
307 // composite.layout();
309 // if (fOverviewRulerHoveringController != null) {
310 // fOverviewRulerHoveringController.dispose();
311 // fOverviewRulerHoveringController = null;
315 // public void showOverviewRuler() {
316 // fIsOverviewRulerVisible = true;
317 // Control control = getControl();
318 // if (control instanceof Composite) {
319 // Composite composite = (Composite) control;
320 // composite.layout();
322 // ensureOverviewHoverManagerInstalled();
325 // public boolean isOverviewRulerVisible() {
326 // return fIsOverviewRulerVisible;
330 // * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
332 // public void setDocument(
333 // IDocument document,
334 // IAnnotationModel annotationModel,
335 // int visibleRegionOffset,
336 // int visibleRegionLength) {
337 // super.setDocument(document, annotationModel, visibleRegionOffset,
338 // visibleRegionLength);
339 // fOverviewRuler.setModel(annotationModel);
342 // // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
343 // public void updateIndentationPrefixes() {
344 // SourceViewerConfiguration configuration = getSourceViewerConfiguration();
345 // String[] types = configuration.getConfiguredContentTypes(this);
346 // for (int i = 0; i < types.length; i++) {
347 // String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
348 // if (prefixes != null && prefixes.length > 0)
349 // setIndentPrefixes(prefixes, types[i]);
354 // * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
356 // public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
357 // if (WorkbenchHelp.isContextHelpDisplayed())
359 // return super.requestWidgetToken(requester);
364 // org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
366 // public void configure(SourceViewerConfiguration configuration) {
367 // super.configure(configuration);
368 // // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
369 // IDocument.DEFAULT_CONTENT_TYPE);
372 // protected void handleDispose() {
373 // fOverviewRuler = null;
375 // if (fOverviewRulerHoveringController != null) {
376 // fOverviewRulerHoveringController.dispose();
377 // fOverviewRulerHoveringController = null;
380 // super.handleDispose();
384 class AdaptedSourceViewer extends JavaSourceViewer {
385 private List fTextConverters;
386 private boolean fIgnoreTextConverters = false;
387 // private JavaCorrectionAssistant fCorrectionAssistant;
388 public AdaptedSourceViewer(Composite parent,
389 IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
390 boolean showAnnotationsOverview, int styles,
391 IPreferenceStore store) {
392 super(parent, verticalRuler, overviewRuler,
393 showAnnotationsOverview, styles, store);
395 // public AdaptedSourceViewer(Composite parent,
396 // IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
397 // boolean showAnnotationsOverview, int styles) {
398 // super(parent, verticalRuler, overviewRuler,
399 // showAnnotationsOverview, styles);
401 public IContentAssistant getContentAssistant() {
402 return fContentAssistant;
405 * @see ITextOperationTarget#doOperation(int)
407 public void doOperation(int operation) {
408 if (getTextWidget() == null)
411 case CONTENTASSIST_PROPOSALS :
412 String msg = fContentAssistant.showPossibleCompletions();
413 setStatusLineErrorMessage(msg);
415 // case CORRECTIONASSIST_PROPOSALS:
416 // fCorrectionAssistant.showPossibleCompletions();
419 fIgnoreTextConverters = true;
422 fIgnoreTextConverters = true;
425 super.doOperation(operation);
428 * @see ITextOperationTarget#canDoOperation(int)
430 public boolean canDoOperation(int operation) {
431 // if (operation == CORRECTIONASSIST_PROPOSALS)
432 // return isEditable();
433 return super.canDoOperation(operation);
436 * @see TextViewer#handleDispose()
438 protected void handleDispose() {
439 // if (fCorrectionAssistant != null) {
440 // fCorrectionAssistant.uninstall();
441 // fCorrectionAssistant= null;
443 super.handleDispose();
445 public void insertTextConverter(ITextConverter textConverter, int index) {
446 throw new UnsupportedOperationException();
448 public void addTextConverter(ITextConverter textConverter) {
449 if (fTextConverters == null) {
450 fTextConverters = new ArrayList(1);
451 fTextConverters.add(textConverter);
452 } else if (!fTextConverters.contains(textConverter))
453 fTextConverters.add(textConverter);
455 public void removeTextConverter(ITextConverter textConverter) {
456 if (fTextConverters != null) {
457 fTextConverters.remove(textConverter);
458 if (fTextConverters.size() == 0)
459 fTextConverters = null;
463 * @see TextViewer#customizeDocumentCommand(DocumentCommand)
465 protected void customizeDocumentCommand(DocumentCommand command) {
466 super.customizeDocumentCommand(command);
467 if (!fIgnoreTextConverters && fTextConverters != null) {
468 for (Iterator e = fTextConverters.iterator(); e.hasNext();)
469 ((ITextConverter) e.next()).customizeDocumentCommand(
470 getDocument(), command);
472 fIgnoreTextConverters = false;
474 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
475 public void updateIndentationPrefixes() {
476 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
477 String[] types = configuration.getConfiguredContentTypes(this);
478 for (int i = 0; i < types.length; i++) {
479 String[] prefixes = configuration.getIndentPrefixes(this,
481 if (prefixes != null && prefixes.length > 0)
482 setIndentPrefixes(prefixes, types[i]);
486 * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
488 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
489 if (WorkbenchHelp.isContextHelpDisplayed())
491 return super.requestWidgetToken(requester);
494 * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
496 public void configure(SourceViewerConfiguration configuration) {
497 super.configure(configuration);
498 // fCorrectionAssistant= new
499 // JavaCorrectionAssistant(CompilationUnitEditor.this);
500 // fCorrectionAssistant.install(this);
501 //TODO install SmartBracesAutoEditStrategy
502 // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
503 // IDocument.DEFAULT_CONTENT_TYPE);
506 static class TabConverter implements ITextConverter {
507 private int fTabRatio;
508 private ILineTracker fLineTracker;
509 public TabConverter() {
511 public void setNumberOfSpacesPerTab(int ratio) {
514 public void setLineTracker(ILineTracker lineTracker) {
515 fLineTracker = lineTracker;
517 private int insertTabString(StringBuffer buffer, int offsetInLine) {
520 int remainder = offsetInLine % fTabRatio;
521 remainder = fTabRatio - remainder;
522 for (int i = 0; i < remainder; i++)
526 public void customizeDocumentCommand(IDocument document,
527 DocumentCommand command) {
528 String text = command.text;
531 int index = text.indexOf('\t');
533 StringBuffer buffer = new StringBuffer();
534 fLineTracker.set(command.text);
535 int lines = fLineTracker.getNumberOfLines();
537 for (int i = 0; i < lines; i++) {
538 int offset = fLineTracker.getLineOffset(i);
539 int endOffset = offset + fLineTracker.getLineLength(i);
540 String line = text.substring(offset, endOffset);
543 IRegion firstLine = document
544 .getLineInformationOfOffset(command.offset);
545 position = command.offset - firstLine.getOffset();
547 int length = line.length();
548 for (int j = 0; j < length; j++) {
549 char c = line.charAt(j);
551 position += insertTabString(buffer, position);
558 command.text = buffer.toString();
559 } catch (BadLocationException x) {
564 private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
565 final char fExitCharacter;
566 public ExitPolicy(char exitCharacter) {
567 fExitCharacter = exitCharacter;
570 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager,
571 * org.eclipse.swt.events.VerifyEvent, int, int)
573 public ExitFlags doExit(LinkedPositionManager manager,
574 VerifyEvent event, int offset, int length) {
575 if (event.character == fExitCharacter) {
576 if (manager.anyPositionIncludes(offset, length))
577 return new ExitFlags(LinkedPositionUI.COMMIT
578 | LinkedPositionUI.UPDATE_CARET, false);
580 return new ExitFlags(LinkedPositionUI.COMMIT, true);
582 switch (event.character) {
584 if (manager.getFirstPosition().length == 0)
585 return new ExitFlags(0, false);
590 return new ExitFlags(LinkedPositionUI.COMMIT, true);
596 private static class BracketLevel {
599 LinkedPositionManager fManager;
600 LinkedPositionUI fEditor;
602 private class BracketInserter
605 LinkedPositionUI.ExitListener {
606 private boolean fCloseBracketsPHP = true;
607 private boolean fCloseStringsPHP = true;
608 private boolean fCloseBracketsHTML = true;
609 private boolean fCloseStringsHTML = true;
612 public void setCloseBracketsPHPEnabled(boolean enabled) {
613 fCloseBracketsPHP = enabled;
615 public void setCloseStringsPHPEnabled(boolean enabled) {
616 fCloseStringsPHP = enabled;
618 public void setCloseBracketsHTMLEnabled(boolean enabled) {
619 fCloseBracketsHTML = enabled;
621 public void setCloseStringsHTMLEnabled(boolean enabled) {
622 fCloseStringsHTML = enabled;
624 private boolean hasIdentifierToTheRight(IDocument document, int offset) {
627 IRegion endLine = document.getLineInformationOfOffset(end);
628 int maxEnd = endLine.getOffset() + endLine.getLength();
630 && Character.isWhitespace(document.getChar(end)))
633 && Scanner.isPHPIdentifierPart(document.getChar(end));
634 } catch (BadLocationException e) {
639 private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
642 IRegion startLine = document.getLineInformationOfOffset(start);
643 int minStart = startLine.getOffset();
644 while (start != minStart
645 && Character.isWhitespace(document.getChar(start - 1)))
647 return start != minStart
648 && Scanner.isPHPIdentifierPart(document
649 .getChar(start - 1));
650 } catch (BadLocationException e) {
654 private boolean hasCharacterToTheRight(IDocument document, int offset,
658 IRegion endLine = document.getLineInformationOfOffset(end);
659 int maxEnd = endLine.getOffset() + endLine.getLength();
661 && Character.isWhitespace(document.getChar(end)))
663 return end != maxEnd && document.getChar(end) == character;
664 } catch (BadLocationException e) {
670 * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
672 public void verifyKey(VerifyEvent event) {
675 final ISourceViewer sourceViewer = getSourceViewer();
676 IDocument document = sourceViewer.getDocument();
677 final Point selection = sourceViewer.getSelectedRange();
678 final int offset = selection.x;
679 final int length = selection.y;
681 ITypedRegion partition = document.getPartition(offset);
682 String type = partition.getType();
683 if (type.equals(IPHPPartitions.PHP_PARTITIONING)) {
684 switch (event.character) {
686 if (hasCharacterToTheRight(document, offset
691 if (!fCloseBracketsPHP)
693 if (hasIdentifierToTheRight(document, offset
698 if (event.character == '"') {
699 if (!fCloseStringsPHP)
701 // changed for statements like echo "" print ""
702 // if (hasIdentifierToTheLeft(document, offset)
704 // hasIdentifierToTheRight(document, offset +
706 if (hasIdentifierToTheRight(document, offset
710 // ITypedRegion partition=
711 // document.getPartition(offset);
713 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
715 // (partition.getOffset() != offset))
717 final char character = event.character;
718 final char closingCharacter = getPeerCharacter(character);
719 final StringBuffer buffer = new StringBuffer();
720 buffer.append(character);
721 buffer.append(closingCharacter);
722 document.replace(offset, length, buffer.toString());
723 LinkedPositionManager manager = new LinkedPositionManager(
725 manager.addPosition(offset + 1, 0);
728 LinkedPositionUI editor = new LinkedPositionUI(
729 sourceViewer, manager);
730 editor.setCancelListener(this);
731 editor.setExitPolicy(new ExitPolicy(
733 editor.setFinalCaretOffset(offset + 2);
735 IRegion newSelection = editor.getSelectedRegion();
736 sourceViewer.setSelectedRange(newSelection
737 .getOffset(), newSelection.getLength());
740 } else if (type.equals(IPHPPartitions.HTML)
741 || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
742 switch (event.character) {
744 if (hasCharacterToTheRight(document, offset
749 if (!fCloseBracketsHTML)
751 if (hasIdentifierToTheRight(document, offset
756 if (event.character == '"') {
757 if (!fCloseStringsHTML)
759 if (hasIdentifierToTheLeft(document, offset)
760 || hasIdentifierToTheRight(document,
764 // ITypedRegion partition=
765 // document.getPartition(offset);
767 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
769 // (partition.getOffset() != offset))
771 final char character = event.character;
772 final char closingCharacter = getPeerCharacter(character);
773 final StringBuffer buffer = new StringBuffer();
774 buffer.append(character);
775 buffer.append(closingCharacter);
776 document.replace(offset, length, buffer.toString());
777 LinkedPositionManager manager = new LinkedPositionManager(
779 manager.addPosition(offset + 1, 0);
782 LinkedPositionUI editor = new LinkedPositionUI(
783 sourceViewer, manager);
784 editor.setCancelListener(this);
785 editor.setExitPolicy(new ExitPolicy(
787 editor.setFinalCaretOffset(offset + 2);
789 IRegion newSelection = editor.getSelectedRegion();
790 sourceViewer.setSelectedRange(newSelection
791 .getOffset(), newSelection.getLength());
795 } catch (BadLocationException e) {
799 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean)
801 public void exit(boolean accept) {
806 final ISourceViewer sourceViewer = getSourceViewer();
807 IDocument document = sourceViewer.getDocument();
808 document.replace(fOffset, fLength, null);
809 } catch (BadLocationException e) {
813 /** The editor's save policy */
814 protected ISavePolicy fSavePolicy;
816 * Listener to annotation model changes that updates the error tick in the
819 private JavaEditorErrorTickUpdater fJavaEditorErrorTickUpdater;
820 /** The editor's paint manager */
821 // private PaintManager fPaintManager;
822 /** The editor's bracket painter */
823 private BracketPainter fBracketPainter;
824 /** The editor's bracket matcher */
825 private PHPPairMatcher fBracketMatcher;
826 /** The editor's line painter */
827 private LinePainter fLinePainter;
828 /** The editor's print margin ruler painter */
829 private PrintMarginPainter fPrintMarginPainter;
830 /** The editor's problem painter */
831 // private ProblemPainter fProblemPainter;
832 /** The editor's tab converter */
833 private TabConverter fTabConverter;
834 /** History for structure select action */
835 //private SelectionHistory fSelectionHistory;
836 /** The preference property change listener for php core. */
837 // private IPropertyChangeListener fPropertyChangeListener = new
838 // PropertyChangeListener();
839 /** The remembered java element */
840 private IJavaElement fRememberedElement;
841 /** The remembered selection */
842 private ITextSelection fRememberedSelection;
843 /** The remembered php element offset */
844 private int fRememberedElementOffset;
845 /** The bracket inserter. */
846 private BracketInserter fBracketInserter = new BracketInserter();
848 /** The standard action groups added to the menu */
849 private GenerateActionGroup fGenerateActionGroup;
850 private CompositeActionGroup fContextMenuGroup;
851 // private class PropertyChangeListener implements IPropertyChangeListener {
853 // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
856 // propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
858 // handlePreferencePropertyChanged(event);
861 /* Preference key for code formatter tab size */
862 private final static String CODE_FORMATTER_TAB_SIZE = JavaCore.FORMATTER_TAB_SIZE;
863 /** Preference key for matching brackets */
864 private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
865 /** Preference key for matching brackets color */
866 private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
867 /** Preference key for highlighting current line */
868 private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
869 /** Preference key for highlight color of current line */
870 private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
871 /** Preference key for showing print marging ruler */
872 private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
873 /** Preference key for print margin ruler color */
874 private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
875 /** Preference key for print margin ruler column */
876 private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
877 /** Preference key for inserting spaces rather than tabs */
878 private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
879 /** Preference key for error indication */
880 // private final static String ERROR_INDICATION =
881 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
882 /** Preference key for error color */
883 // private final static String ERROR_INDICATION_COLOR =
884 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
885 /** Preference key for warning indication */
886 // private final static String WARNING_INDICATION =
887 // PreferenceConstants.EDITOR_WARNING_INDICATION;
888 /** Preference key for warning color */
889 // private final static String WARNING_INDICATION_COLOR =
890 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
891 /** Preference key for task indication */
892 private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
893 /** Preference key for task color */
894 private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
895 /** Preference key for bookmark indication */
896 private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
897 /** Preference key for bookmark color */
898 private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
899 /** Preference key for search result indication */
900 private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
901 /** Preference key for search result color */
902 private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
903 /** Preference key for unknown annotation indication */
904 private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
905 /** Preference key for unknown annotation color */
906 private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
907 /** Preference key for linked position color */
908 private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
909 /** Preference key for shwoing the overview ruler */
910 private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
911 /** Preference key for error indication in overview ruler */
912 private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
913 /** Preference key for warning indication in overview ruler */
914 private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
915 /** Preference key for task indication in overview ruler */
916 private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
917 /** Preference key for bookmark indication in overview ruler */
918 private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
919 /** Preference key for search result indication in overview ruler */
920 private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
921 /** Preference key for unknown annotation indication in overview ruler */
922 private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
923 /** Preference key for automatically closing strings */
924 private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP;
925 /** Preference key for automatically wrapping Java strings */
926 private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS;
927 /** Preference key for automatically closing brackets and parenthesis */
928 private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
929 /** Preference key for automatically closing phpdocs and comments */
930 private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
931 /** Preference key for automatically adding phpdoc tags */
932 private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
933 /** Preference key for automatically formatting phpdocs */
934 private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
935 /** Preference key for automatically closing strings */
936 private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
937 /** Preference key for automatically closing brackets and parenthesis */
938 private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
939 /** Preference key for smart paste */
940 private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
941 // private final static class AnnotationInfo {
942 // public String fColorPreference;
943 // public String fOverviewRulerPreference;
944 // public String fEditorPreference;
946 // private final static Map ANNOTATION_MAP;
949 // AnnotationInfo info;
950 // ANNOTATION_MAP = new HashMap();
952 // info = new AnnotationInfo();
953 // info.fColorPreference = TASK_INDICATION_COLOR;
954 // info.fOverviewRulerPreference = TASK_INDICATION_IN_OVERVIEW_RULER;
955 // info.fEditorPreference = TASK_INDICATION;
956 // ANNOTATION_MAP.put(AnnotationType.TASK, info);
958 // info = new AnnotationInfo();
959 // info.fColorPreference = ERROR_INDICATION_COLOR;
960 // info.fOverviewRulerPreference = ERROR_INDICATION_IN_OVERVIEW_RULER;
961 // info.fEditorPreference = ERROR_INDICATION;
962 // ANNOTATION_MAP.put(AnnotationType.ERROR, info);
964 // info = new AnnotationInfo();
965 // info.fColorPreference = WARNING_INDICATION_COLOR;
966 // info.fOverviewRulerPreference = WARNING_INDICATION_IN_OVERVIEW_RULER;
967 // info.fEditorPreference = WARNING_INDICATION;
968 // ANNOTATION_MAP.put(AnnotationType.WARNING, info);
970 // info = new AnnotationInfo();
971 // info.fColorPreference = BOOKMARK_INDICATION_COLOR;
972 // info.fOverviewRulerPreference = BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
973 // info.fEditorPreference = BOOKMARK_INDICATION;
974 // ANNOTATION_MAP.put(AnnotationType.BOOKMARK, info);
976 // info = new AnnotationInfo();
977 // info.fColorPreference = SEARCH_RESULT_INDICATION_COLOR;
978 // info.fOverviewRulerPreference =
979 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
980 // info.fEditorPreference = SEARCH_RESULT_INDICATION;
981 // ANNOTATION_MAP.put(AnnotationType.SEARCH, info);
983 // info = new AnnotationInfo();
984 // info.fColorPreference = UNKNOWN_INDICATION_COLOR;
985 // info.fOverviewRulerPreference = UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
986 // info.fEditorPreference = UNKNOWN_INDICATION;
987 // ANNOTATION_MAP.put(AnnotationType.UNKNOWN, info);
990 // private final static AnnotationType[] ANNOTATION_LAYERS =
991 // new AnnotationType[] {
992 // AnnotationType.UNKNOWN,
993 // AnnotationType.BOOKMARK,
994 // AnnotationType.TASK,
995 // AnnotationType.SEARCH,
996 // AnnotationType.WARNING,
997 // AnnotationType.ERROR };
999 * Creates a new php unit editor.
1001 public PHPUnitEditor() {
1003 setDocumentProvider(PHPeclipsePlugin.getDefault()
1004 .getCompilationUnitDocumentProvider());
1005 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
1006 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
1007 setOutlinerContextMenuId("#PHPOutlinerContext"); //$NON-NLS-1$
1008 // don't set help contextId, we install our own help context
1010 fJavaEditorErrorTickUpdater = new JavaEditorErrorTickUpdater(this);
1013 * @see AbstractTextEditor#createActions()
1015 protected void createActions() {
1016 super.createActions();
1018 // Action action= new
1019 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1020 // "CorrectionAssistProposal.", this, CORRECTIONASSIST_PROPOSALS);
1022 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
1023 // setAction("CorrectionAssistProposal", action); //$NON-NLS-1$
1024 // markAsStateDependentAction("CorrectionAssistProposal", true);
1026 //// WorkbenchHelp.setHelp(action,
1027 // IJavaHelpContextIds.QUICK_FIX_ACTION);
1028 action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(),
1029 "ContentAssistProposal.", this); //$NON-NLS-1$
1031 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
1032 setAction("ContentAssistProposal", action); //$NON-NLS-1$
1033 markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
1034 // WorkbenchHelp.setHelp(action,
1035 // IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
1036 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1037 "ContentAssistContextInformation.", this,
1038 ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$
1040 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
1041 setAction("ContentAssistContextInformation", action); //$NON-NLS-1$
1042 markAsStateDependentAction("ContentAssistContextInformation", true); //$NON-NLS-1$
1043 // WorkbenchHelp.setHelp(action,
1044 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1046 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
1047 // "ContentAssistCompletePrefix.", this, CONTENTASSIST_COMPLETE_PREFIX);
1049 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_COMPLETE_PREFIX);
1050 // setAction("ContentAssistCompletePrefix", action); //$NON-NLS-1$
1051 // markAsStateDependentAction("ContentAssistCompletePrefix", true);
1053 //// WorkbenchHelp.setHelp(action,
1054 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1055 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1056 "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
1057 action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
1058 setAction("Comment", action); //$NON-NLS-1$
1059 markAsStateDependentAction("Comment", true); //$NON-NLS-1$
1060 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
1061 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1062 "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
1063 action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
1064 setAction("Uncomment", action); //$NON-NLS-1$
1065 markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
1066 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
1068 action = new ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1069 "ToggleComment.", this); //$NON-NLS-1$
1071 .setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1072 setAction("ToggleComment", action); //$NON-NLS-1$
1073 markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1074 //WorkbenchHelp.setHelp(action,
1075 // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1076 configureToggleCommentAction();
1079 // ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1080 // "ToggleComment.", this, getSourceViewerConfiguration()
1081 // .getDefaultPrefixes(getSourceViewer(), "")); //$NON-NLS-1$
1083 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1084 // setAction("ToggleComment", action); //$NON-NLS-1$
1085 // markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1086 // // WorkbenchHelp.setHelp(action,
1087 // // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1089 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1090 "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
1091 action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
1092 setAction("Format", action); //$NON-NLS-1$
1093 markAsStateDependentAction("Format", true); //$NON-NLS-1$
1094 markAsSelectionDependentAction("Format", true); //$NON-NLS-1$
1095 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
1097 action = new AddBlockCommentAction(PHPEditorMessages
1098 .getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$
1100 .setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
1101 setAction("AddBlockComment", action); //$NON-NLS-1$
1102 markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
1103 markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
1104 // WorkbenchHelp.setHelp(action,
1105 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1106 action = new RemoveBlockCommentAction(PHPEditorMessages
1107 .getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
1109 .setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
1110 setAction("RemoveBlockComment", action); //$NON-NLS-1$
1111 markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1112 markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1113 // WorkbenchHelp.setHelp(action,
1114 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1115 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1116 // "Indent.", this, false); //$NON-NLS-1$
1117 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT);
1118 // setAction("Indent", action); //$NON-NLS-1$
1119 // markAsStateDependentAction("Indent", true); //$NON-NLS-1$
1120 // markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
1121 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION);
1123 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1124 // "Indent.", this, true); //$NON-NLS-1$
1125 // setAction("IndentOnTab", action); //$NON-NLS-1$
1126 // markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
1127 // markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$
1129 if (getPreferenceStore().getBoolean(
1130 PreferenceConstants.EDITOR_SMART_TAB)) {
1131 // don't replace Shift Right - have to make sure their enablement is
1132 // mutually exclusive
1133 // removeActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT);
1134 setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$
1136 fGenerateActionGroup = new GenerateActionGroup(this,
1137 ITextEditorActionConstants.GROUP_EDIT);
1138 fActionGroups = new CompositeActionGroup(
1139 new ActionGroup[]{fGenerateActionGroup});
1140 // We have to keep the context menu group separate to have better
1143 fContextMenuGroup = new CompositeActionGroup(
1144 new ActionGroup[]{fGenerateActionGroup});
1146 // new LocalHistoryActionGroup(this,
1147 // ITextEditorActionConstants.GROUP_EDIT)});
1151 * @see JavaEditor#getElementAt(int)
1153 protected IJavaElement getElementAt(int offset) {
1154 return getElementAt(offset, true);
1157 * Returns the most narrow element including the given offset. If
1158 * <code>reconcile</code> is <code>true</code> the editor's input
1159 * element is reconciled in advance. If it is <code>false</code> this
1160 * method only returns a result if the editor's input element does not need
1164 * the offset included by the retrieved element
1166 * <code>true</code> if working copy should be reconciled
1168 protected IJavaElement getElementAt(int offset, boolean reconcile) {
1169 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1170 .getWorkingCopyManager();
1171 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1175 synchronized (unit) {
1178 return unit.getElementAt(offset);
1179 } else if (unit.isConsistent())
1180 return unit.getElementAt(offset);
1181 } catch (JavaModelException x) {
1182 PHPeclipsePlugin.log(x.getStatus());
1183 // nothing found, be tolerant and go on
1189 * @see JavaEditor#getCorrespondingElement(IJavaElement)
1191 protected IJavaElement getCorrespondingElement(IJavaElement element) {
1193 return EditorUtility.getWorkingCopy(element, true);
1194 } catch (JavaModelException x) {
1195 PHPeclipsePlugin.log(x.getStatus());
1196 // nothing found, be tolerant and go on
1200 public void createPartControl(Composite parent) {
1201 super.createPartControl(parent);
1202 // fPaintManager = new PaintManager(getSourceViewer());
1203 LinePainter linePainter;
1204 linePainter = new LinePainter(getSourceViewer());
1205 linePainter.setHighlightColor(new Color(Display.getCurrent(), 225, 235,
1207 // fPaintManager.addPainter(linePainter);
1208 if (isBracketHighlightingEnabled())
1209 startBracketHighlighting();
1210 if (isLineHighlightingEnabled())
1211 startLineHighlighting();
1212 if (isPrintMarginVisible())
1214 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1215 // while (e.hasNext()) {
1216 // AnnotationType type = (AnnotationType) e.next();
1217 // if (isAnnotationIndicationEnabled(type))
1218 // startAnnotationIndication(type);
1220 if (isTabConversionEnabled())
1221 startTabConversion();
1222 // if (isOverviewRulerVisible())
1223 // showOverviewRuler();
1225 // Preferences preferences =
1226 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1227 // preferences.addPropertyChangeListener(fPropertyChangeListener);
1228 IPreferenceStore preferenceStore = getPreferenceStore();
1229 boolean closeBracketsPHP = preferenceStore
1230 .getBoolean(CLOSE_BRACKETS_PHP);
1231 boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP);
1232 boolean closeBracketsHTML = preferenceStore
1233 .getBoolean(CLOSE_BRACKETS_HTML);
1234 boolean closeStringsHTML = preferenceStore
1235 .getBoolean(CLOSE_STRINGS_HTML);
1236 fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
1237 fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP);
1238 fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
1239 fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
1240 ISourceViewer sourceViewer = getSourceViewer();
1241 if (sourceViewer instanceof ITextViewerExtension)
1242 ((ITextViewerExtension) sourceViewer)
1243 .prependVerifyKeyListener(fBracketInserter);
1245 private static char getPeerCharacter(char character) {
1246 switch (character) {
1258 throw new IllegalArgumentException();
1262 private void startBracketHighlighting() {
1263 if (fBracketPainter == null) {
1264 ISourceViewer sourceViewer = getSourceViewer();
1265 fBracketPainter = new BracketPainter(sourceViewer);
1267 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1268 // fPaintManager.addPainter(fBracketPainter);
1271 private void stopBracketHighlighting() {
1272 if (fBracketPainter != null) {
1273 // fPaintManager.removePainter(fBracketPainter);
1274 fBracketPainter.deactivate(true);
1275 fBracketPainter.dispose();
1276 fBracketPainter = null;
1279 private boolean isBracketHighlightingEnabled() {
1280 IPreferenceStore store = getPreferenceStore();
1281 return store.getBoolean(MATCHING_BRACKETS);
1283 private void startLineHighlighting() {
1284 if (fLinePainter == null) {
1285 ISourceViewer sourceViewer = getSourceViewer();
1286 fLinePainter = new LinePainter(sourceViewer);
1287 fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR));
1288 // fPaintManager.addPainter(fLinePainter);
1291 private void stopLineHighlighting() {
1292 if (fLinePainter != null) {
1293 // fPaintManager.removePainter(fLinePainter);
1294 fLinePainter.deactivate(true);
1295 fLinePainter.dispose();
1296 fLinePainter = null;
1299 private boolean isLineHighlightingEnabled() {
1300 IPreferenceStore store = getPreferenceStore();
1301 return store.getBoolean(CURRENT_LINE);
1303 private void showPrintMargin() {
1304 if (fPrintMarginPainter == null) {
1305 fPrintMarginPainter = new PrintMarginPainter(getSourceViewer());
1307 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1308 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore()
1309 .getInt(PRINT_MARGIN_COLUMN));
1310 // fPaintManager.addPainter(fPrintMarginPainter);
1313 private void hidePrintMargin() {
1314 if (fPrintMarginPainter != null) {
1315 // fPaintManager.removePainter(fPrintMarginPainter);
1316 fPrintMarginPainter.deactivate(true);
1317 fPrintMarginPainter.dispose();
1318 fPrintMarginPainter = null;
1321 private boolean isPrintMarginVisible() {
1322 IPreferenceStore store = getPreferenceStore();
1323 return store.getBoolean(PRINT_MARGIN);
1325 // private void startAnnotationIndication(AnnotationType annotationType) {
1326 // if (fProblemPainter == null) {
1327 // fProblemPainter = new ProblemPainter(this, getSourceViewer());
1328 //// fPaintManager.addPainter(fProblemPainter);
1330 // fProblemPainter.setColor(annotationType, getColor(annotationType));
1331 // fProblemPainter.paintAnnotations(annotationType, true);
1332 // fProblemPainter.paint(IPainter.CONFIGURATION);
1335 // private void shutdownAnnotationIndication() {
1336 // if (fProblemPainter != null) {
1338 // if (!fProblemPainter.isPaintingAnnotations()) {
1339 //// fPaintManager.removePainter(fProblemPainter);
1340 // fProblemPainter.deactivate(true);
1341 // fProblemPainter.dispose();
1342 // fProblemPainter = null;
1344 // fProblemPainter.paint(IPainter.CONFIGURATION);
1349 // private void stopAnnotationIndication(AnnotationType annotationType) {
1350 // if (fProblemPainter != null) {
1351 // fProblemPainter.paintAnnotations(annotationType, false);
1352 // shutdownAnnotationIndication();
1356 // private boolean isAnnotationIndicationEnabled(AnnotationType
1357 // annotationType) {
1358 // IPreferenceStore store = getPreferenceStore();
1359 // AnnotationInfo info = (AnnotationInfo)
1360 // ANNOTATION_MAP.get(annotationType);
1361 // if (info != null)
1362 // return store.getBoolean(info.fEditorPreference);
1367 // isAnnotationIndicationInOverviewRulerEnabled(AnnotationType
1368 // annotationType) {
1369 // IPreferenceStore store = getPreferenceStore();
1370 // AnnotationInfo info = (AnnotationInfo)
1371 // ANNOTATION_MAP.get(annotationType);
1372 // if (info != null)
1373 // return store.getBoolean(info.fOverviewRulerPreference);
1377 // private void showAnnotationIndicationInOverviewRuler(AnnotationType
1378 // annotationType, boolean show) {
1379 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1380 // OverviewRuler ruler = asv.getOverviewRuler();
1381 // if (ruler != null) {
1382 // ruler.setColor(annotationType, getColor(annotationType));
1383 // ruler.showAnnotation(annotationType, show);
1388 // private void setColorInOverviewRuler(AnnotationType annotationType, Color
1390 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1391 // OverviewRuler ruler = asv.getOverviewRuler();
1392 // if (ruler != null) {
1393 // ruler.setColor(annotationType, color);
1398 private int getTabSize() {
1399 Preferences preferences = PHPeclipsePlugin.getDefault()
1400 .getPluginPreferences();
1401 return preferences.getInt(CODE_FORMATTER_TAB_SIZE);
1404 private boolean isTabConversionEnabled() {
1405 IPreferenceStore store = getPreferenceStore();
1406 return store.getBoolean(SPACES_FOR_TABS);
1408 // private void showOverviewRuler() {
1409 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1410 // asv.showOverviewRuler();
1412 // OverviewRuler overviewRuler = asv.getOverviewRuler();
1413 // if (overviewRuler != null) {
1414 // for (int i = 0; i < ANNOTATION_LAYERS.length; i++) {
1415 // AnnotationType type = ANNOTATION_LAYERS[i];
1416 // overviewRuler.setLayer(type, i);
1417 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1418 // showAnnotationIndicationInOverviewRuler(type, true);
1423 // private void hideOverviewRuler() {
1424 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1425 // asv.hideOverviewRuler();
1428 // private boolean isOverviewRulerVisible() {
1429 // IPreferenceStore store = getPreferenceStore();
1430 // return store.getBoolean(OVERVIEW_RULER);
1432 private Color getColor(String key) {
1433 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
1434 return getColor(rgb);
1436 private Color getColor(RGB rgb) {
1437 JavaTextTools textTools = PHPeclipsePlugin.getDefault()
1438 .getJavaTextTools();
1439 return textTools.getColorManager().getColor(rgb);
1441 // private Color getColor(AnnotationType annotationType) {
1442 // AnnotationInfo info = (AnnotationInfo)
1443 // ANNOTATION_MAP.get(annotationType);
1444 // if (info != null)
1445 // return getColor(info.fColorPreference);
1448 public void dispose() {
1449 ISourceViewer sourceViewer = getSourceViewer();
1450 if (sourceViewer instanceof ITextViewerExtension)
1451 ((ITextViewerExtension) sourceViewer)
1452 .removeVerifyKeyListener(fBracketInserter);
1453 // if (fPropertyChangeListener != null) {
1454 // Preferences preferences =
1455 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1456 // preferences.removePropertyChangeListener(fPropertyChangeListener);
1457 // fPropertyChangeListener = null;
1459 if (fJavaEditorErrorTickUpdater != null) {
1460 fJavaEditorErrorTickUpdater.dispose();
1461 fJavaEditorErrorTickUpdater = null;
1463 // if (fSelectionHistory != null)
1464 // fSelectionHistory.dispose();
1465 // if (fPaintManager != null) {
1466 // fPaintManager.dispose();
1467 // fPaintManager = null;
1469 if (fActionGroups != null) {
1470 fActionGroups.dispose();
1471 fActionGroups = null;
1475 // protected AnnotationType getAnnotationType(String preferenceKey) {
1476 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1477 // while (e.hasNext()) {
1478 // AnnotationType type = (AnnotationType) e.next();
1479 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1480 // if (info != null) {
1481 // if (preferenceKey.equals(info.fColorPreference)
1482 // || preferenceKey.equals(info.fEditorPreference)
1483 // || preferenceKey.equals(info.fOverviewRulerPreference))
1490 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1492 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1494 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1496 String p = event.getProperty();
1497 if (CLOSE_BRACKETS_PHP.equals(p)) {
1499 .setCloseBracketsPHPEnabled(getPreferenceStore()
1503 if (CLOSE_STRINGS_PHP.equals(p)) {
1505 .setCloseStringsPHPEnabled(getPreferenceStore()
1509 if (CLOSE_BRACKETS_HTML.equals(p)) {
1511 .setCloseBracketsHTMLEnabled(getPreferenceStore()
1515 if (CLOSE_STRINGS_HTML.equals(p)) {
1517 .setCloseStringsHTMLEnabled(getPreferenceStore()
1521 if (SPACES_FOR_TABS.equals(p)) {
1522 if (isTabConversionEnabled())
1523 startTabConversion();
1525 stopTabConversion();
1528 if (MATCHING_BRACKETS.equals(p)) {
1529 if (isBracketHighlightingEnabled())
1530 startBracketHighlighting();
1532 stopBracketHighlighting();
1535 if (MATCHING_BRACKETS_COLOR.equals(p)) {
1536 if (fBracketPainter != null)
1538 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1541 if (CURRENT_LINE.equals(p)) {
1542 if (isLineHighlightingEnabled())
1543 startLineHighlighting();
1545 stopLineHighlighting();
1548 if (CURRENT_LINE_COLOR.equals(p)) {
1549 if (fLinePainter != null) {
1550 stopLineHighlighting();
1551 startLineHighlighting();
1555 if (PRINT_MARGIN.equals(p)) {
1556 if (isPrintMarginVisible())
1562 if (PRINT_MARGIN_COLOR.equals(p)) {
1563 if (fPrintMarginPainter != null)
1565 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1568 if (PRINT_MARGIN_COLUMN.equals(p)) {
1569 if (fPrintMarginPainter != null)
1571 .setMarginRulerColumn(getPreferenceStore()
1572 .getInt(PRINT_MARGIN_COLUMN));
1575 // if (OVERVIEW_RULER.equals(p)) {
1576 // if (isOverviewRulerVisible())
1577 // showOverviewRuler();
1579 // hideOverviewRuler();
1582 // AnnotationType type = getAnnotationType(p);
1583 // if (type != null) {
1585 // AnnotationInfo info = (AnnotationInfo)
1586 // ANNOTATION_MAP.get(type);
1587 // if (info.fColorPreference.equals(p)) {
1588 // Color color = getColor(type);
1589 // if (fProblemPainter != null) {
1590 // fProblemPainter.setColor(type, color);
1591 // fProblemPainter.paint(IPainter.CONFIGURATION);
1593 // setColorInOverviewRuler(type, color);
1597 // if (info.fEditorPreference.equals(p)) {
1598 // if (isAnnotationIndicationEnabled(type))
1599 // startAnnotationIndication(type);
1601 // stopAnnotationIndication(type);
1605 // if (info.fOverviewRulerPreference.equals(p)) {
1606 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1607 // showAnnotationIndicationInOverviewRuler(type, true);
1609 // showAnnotationIndicationInOverviewRuler(type, false);
1613 IContentAssistant c = asv.getContentAssistant();
1614 if (c instanceof ContentAssistant)
1615 ContentAssistPreference.changeConfiguration(
1616 (ContentAssistant) c, getPreferenceStore(), event);
1619 super.handlePreferenceStoreChanged(event);
1623 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
1625 protected void handlePreferencePropertyChanged(
1626 org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1627 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1629 String p = event.getProperty();
1630 if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1631 asv.updateIndentationPrefixes();
1632 if (fTabConverter != null)
1633 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1636 super.handlePreferencePropertyChanged(event);
1639 * Handles a property change event describing a change of the php core's
1640 * preferences and updates the preference related editor properties.
1643 * the property change event
1646 // handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
1648 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1649 // if (asv != null) {
1650 // String p = event.getProperty();
1651 // if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1652 // asv.updateIndentationPrefixes();
1653 // if (fTabConverter != null)
1654 // fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1659 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#createJavaSourceViewer(org.eclipse.swt.widgets.Composite,
1660 * org.eclipse.jface.text.source.IVerticalRuler,
1661 * org.eclipse.jface.text.source.IOverviewRuler, boolean, int)
1663 protected ISourceViewer createJavaSourceViewer(Composite parent,
1664 IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
1665 boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
1666 return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler,
1667 isOverviewRulerVisible, styles, store);
1669 // protected ISourceViewer createJavaSourceViewer(Composite parent,
1670 // IVerticalRuler ruler, int styles) {
1671 // return new AdaptedSourceViewer(parent, ruler, styles);
1673 private boolean isValidSelection(int offset, int length) {
1674 IDocumentProvider provider = getDocumentProvider();
1675 if (provider != null) {
1676 IDocument document = provider.getDocument(getEditorInput());
1677 if (document != null) {
1678 int end = offset + length;
1679 int documentLength = document.getLength();
1680 return 0 <= offset && offset <= documentLength && 0 <= end
1681 && end <= documentLength;
1687 * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput)
1689 protected boolean canHandleMove(IEditorInput originalElement,
1690 IEditorInput movedElement) {
1691 String oldExtension = ""; //$NON-NLS-1$
1692 if (originalElement instanceof IFileEditorInput) {
1693 IFile file = ((IFileEditorInput) originalElement).getFile();
1695 String ext = file.getFileExtension();
1700 String newExtension = ""; //$NON-NLS-1$
1701 if (movedElement instanceof IFileEditorInput) {
1702 IFile file = ((IFileEditorInput) movedElement).getFile();
1704 newExtension = file.getFileExtension();
1706 return oldExtension.equals(newExtension);
1709 * @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager)
1711 public void editorContextMenuAboutToShow(IMenuManager menu) {
1712 super.editorContextMenuAboutToShow(menu);
1713 ActionContext context = new ActionContext(getSelectionProvider()
1715 fContextMenuGroup.setContext(context);
1716 fContextMenuGroup.fillContextMenu(menu);
1717 fContextMenuGroup.setContext(null);
1720 * @see JavaEditor#setOutlinePageInput(JavaOutlinePage, IEditorInput)
1722 protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input) {
1724 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1725 .getWorkingCopyManager();
1726 page.setInput(manager.getWorkingCopy(input));
1730 * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation,
1733 // protected void performSaveOperation(WorkspaceModifyOperation operation,
1734 // IProgressMonitor progressMonitor) {
1735 // IDocumentProvider p = getDocumentProvider();
1736 // if (p instanceof PHPDocumentProvider) {
1737 // PHPDocumentProvider cp = (PHPDocumentProvider) p;
1738 // cp.setSavePolicy(fSavePolicy);
1742 // super.performSaveOperation(operation, progressMonitor);
1744 // if (p instanceof PHPDocumentProvider) {
1745 // PHPDocumentProvider cp = (PHPDocumentProvider) p;
1746 // cp.setSavePolicy(null);
1751 * @see AbstractTextEditor#doSave(IProgressMonitor)
1753 public void doSave(IProgressMonitor progressMonitor) {
1755 IDocumentProvider p = getDocumentProvider();
1757 // editor has been closed
1761 if (p.isDeleted(getEditorInput())) {
1763 if (isSaveAsAllowed()) {
1766 * 1GEUSSR: ITPUI:ALL - User should never loose changes made in
1767 * the editors. Changed Behavior to make sure that if called
1768 * inside a regular save (because of deletion of input element)
1769 * there is a way to report back to the caller.
1771 performSaveAs(progressMonitor);
1776 * 1GF5YOX: ITPJUI:ALL - Save of delete file claims it's still
1777 * there Missing resources.
1779 Shell shell = getSite().getShell();
1784 .getString("PHPUnitEditor.error.saving.title1"), PHPEditorMessages.getString("PHPUnitEditor.error.saving.message1")); //$NON-NLS-1$ //$NON-NLS-2$
1789 setStatusLineErrorMessage(null);
1791 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1792 .getWorkingCopyManager();
1793 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1796 synchronized (unit) {
1797 performSave(false, progressMonitor);
1800 performSave(false, progressMonitor);
1802 // IAction a = ShowExternalPreviewAction.getInstance();
1808 public boolean isSaveAsAllowed() {
1813 * The compilation unit editor implementation of this
1814 * <code>AbstractTextEditor</code> method asks the user for the workspace
1815 * path of a file resource and saves the document there. See
1816 * http://dev.eclipse.org/bugs/show_bug.cgi?id=6295
1818 * @param progressMonitor
1819 * the progress monitor
1821 protected void performSaveAs(IProgressMonitor progressMonitor) {
1823 Shell shell = getSite().getShell();
1824 IEditorInput input = getEditorInput();
1826 SaveAsDialog dialog = new SaveAsDialog(shell);
1828 IFile original = (input instanceof IFileEditorInput)
1829 ? ((IFileEditorInput) input).getFile()
1831 if (original != null)
1832 dialog.setOriginalFile(original);
1836 IDocumentProvider provider = getDocumentProvider();
1837 if (provider == null) {
1838 // editor has been programmatically closed while the dialog was open
1842 if (provider.isDeleted(input) && original != null) {
1843 String message = PHPEditorMessages
1844 .getFormattedString(
1845 "CompilationUnitEditor.warning.save.delete", new Object[]{original.getName()}); //$NON-NLS-1$
1846 dialog.setErrorMessage(null);
1847 dialog.setMessage(message, IMessageProvider.WARNING);
1850 if (dialog.open() == Window.CANCEL) {
1851 if (progressMonitor != null)
1852 progressMonitor.setCanceled(true);
1856 IPath filePath = dialog.getResult();
1857 if (filePath == null) {
1858 if (progressMonitor != null)
1859 progressMonitor.setCanceled(true);
1863 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1864 IFile file = workspaceRoot.getFile(filePath);
1865 final IEditorInput newInput = new FileEditorInput(file);
1867 boolean success = false;
1870 provider.aboutToChange(newInput);
1871 getDocumentProvider().saveDocument(progressMonitor, newInput,
1872 getDocumentProvider().getDocument(getEditorInput()), true);
1875 } catch (CoreException x) {
1876 IStatus status = x.getStatus();
1877 if (status == null || status.getSeverity() != IStatus.CANCEL)
1882 .getString("CompilationUnitEditor.error.saving.title2"), PHPEditorMessages.getString("CompilationUnitEditor.error.saving.message2"), x.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
1884 provider.changed(newInput);
1889 if (progressMonitor != null)
1890 progressMonitor.setCanceled(!success);
1894 * @see AbstractTextEditor#doSetInput(IEditorInput)
1896 protected void doSetInput(IEditorInput input) throws CoreException {
1897 super.doSetInput(input);
1898 configureTabConverter();
1899 configureToggleCommentAction();
1904 // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#installOverrideIndicator(boolean)
1907 // protected void installOverrideIndicator(boolean waitForReconcilation) {
1908 // IAnnotationModel model=
1909 // getDocumentProvider().getAnnotationModel(getEditorInput());
1910 // if (!waitForReconcilation)
1911 // super.installOverrideIndicator(false);
1913 // uninstallOverrideIndicator();
1914 // IJavaElement inputElement= getInputJavaElement();
1915 // if (model == null || inputElement == null)
1918 // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
1919 // inputElement, null);
1920 // addReconcileListener(fOverrideIndicatorManager);
1926 // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#uninstallOverrideIndicator()
1929 // protected void uninstallOverrideIndicator() {
1930 // if (fOverrideIndicatorManager != null)
1931 // removeReconcileListener(fOverrideIndicatorManager);
1932 // super.uninstallOverrideIndicator();
1936 * Configures the toggle comment action
1940 private void configureToggleCommentAction() {
1941 IAction action = getAction("ToggleComment"); //$NON-NLS-1$
1942 if (action instanceof ToggleCommentAction) {
1943 ISourceViewer sourceViewer = getSourceViewer();
1944 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
1945 ((ToggleCommentAction) action).configure(sourceViewer,
1950 private void configureTabConverter() {
1951 if (fTabConverter != null) {
1952 IDocumentProvider provider = getDocumentProvider();
1953 if (provider instanceof PHPDocumentProvider) {
1954 PHPDocumentProvider cup = (PHPDocumentProvider) provider;
1955 fTabConverter.setLineTracker(cup
1956 .createLineTracker(getEditorInput()));
1961 private void startTabConversion() {
1962 if (fTabConverter == null) {
1963 fTabConverter = new TabConverter();
1964 configureTabConverter();
1965 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1966 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1967 asv.addTextConverter(fTabConverter);
1968 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1969 asv.updateIndentationPrefixes();
1973 private void stopTabConversion() {
1974 if (fTabConverter != null) {
1975 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1976 asv.removeTextConverter(fTabConverter);
1977 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1978 asv.updateIndentationPrefixes();
1979 fTabConverter = null;
1984 * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean,
1985 * org.eclipse.core.runtime.IProgressMonitor)
1987 protected void performSave(boolean overwrite,
1988 IProgressMonitor progressMonitor) {
1989 IDocumentProvider p = getDocumentProvider();
1990 if (p instanceof PHPDocumentProvider) {
1991 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1992 cp.setSavePolicy(fSavePolicy);
1995 super.performSave(overwrite, progressMonitor);
1997 if (p instanceof PHPDocumentProvider) {
1998 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1999 cp.setSavePolicy(null);
2004 * @see AbstractTextEditor#doSaveAs
2006 public void doSaveAs() {
2007 if (askIfNonWorkbenchEncodingIsOk()) {
2013 * Asks the user if it is ok to store in non-workbench encoding.
2015 * @return <true>if the user wants to continue
2017 private boolean askIfNonWorkbenchEncodingIsOk() {
2018 IDocumentProvider provider = getDocumentProvider();
2019 if (provider instanceof IStorageDocumentProvider) {
2020 IEditorInput input = getEditorInput();
2021 IStorageDocumentProvider storageProvider = (IStorageDocumentProvider) provider;
2022 String encoding = storageProvider.getEncoding(input);
2023 String defaultEncoding = storageProvider.getDefaultEncoding();
2024 if (encoding != null && !encoding.equals(defaultEncoding)) {
2025 Shell shell = getSite().getShell();
2026 String title = PHPEditorMessages
2027 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$
2033 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"),
2034 new String[]{input.getName(), encoding}); //$NON-NLS-1$
2039 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message2"),
2040 new String[]{encoding}); //$NON-NLS-1$
2041 return MessageDialog.openQuestion(shell, title, msg);
2047 * @see IReconcilingParticipant#reconciled()
2049 public void reconciled() {
2050 if (synchronizeOutlineOnCursorMove()) {
2051 Shell shell = getSite().getShell();
2052 if (shell != null && !shell.isDisposed()) {
2053 shell.getDisplay().asyncExec(new Runnable() {
2055 synchronizeOutlinePageSelection();
2062 protected void updateStateDependentActions() {
2063 super.updateStateDependentActions();
2064 fGenerateActionGroup.editorStateChanged();
2067 private boolean synchronizeOutlineOnCursorMove() {
2068 return PreferenceConstants.getPreferenceStore().getBoolean(
2069 PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE);
2073 * Returns the updated java element for the old java element.
2075 private IJavaElement findElement(IJavaElement element) {
2076 if (element == null)
2078 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
2079 .getWorkingCopyManager();
2080 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
2083 synchronized (unit) {
2086 IJavaElement[] findings = unit.findElements(element);
2087 if (findings != null && findings.length > 0)
2089 } catch (JavaModelException x) {
2090 PHPeclipsePlugin.log(x.getStatus());
2091 // nothing found, be tolerant and go on
2097 * Returns the offset of the given Java element.
2099 private int getOffset(IJavaElement element) {
2100 if (element instanceof ISourceReference) {
2101 ISourceReference sr = (ISourceReference) element;
2103 ISourceRange srcRange = sr.getSourceRange();
2104 if (srcRange != null)
2105 return srcRange.getOffset();
2106 } catch (JavaModelException e) {
2112 * @see AbstractTextEditor#rememberSelection()
2114 protected void rememberSelection() {
2115 ISelectionProvider sp = getSelectionProvider();
2116 fRememberedSelection = (sp == null ? null : (ITextSelection) sp
2118 if (fRememberedSelection != null) {
2119 fRememberedElement = getElementAt(fRememberedSelection.getOffset(),
2121 fRememberedElementOffset = getOffset(fRememberedElement);
2125 * @see AbstractTextEditor#restoreSelection()
2127 protected void restoreSelection() {
2129 if (getSourceViewer() == null || fRememberedSelection == null)
2131 IJavaElement newElement = findElement(fRememberedElement);
2132 int newOffset = getOffset(newElement);
2133 int delta = (newOffset > -1 && fRememberedElementOffset > -1)
2134 ? newOffset - fRememberedElementOffset
2136 if (isValidSelection(delta + fRememberedSelection.getOffset(),
2137 fRememberedSelection.getLength()))
2138 selectAndReveal(delta + fRememberedSelection.getOffset(),
2139 fRememberedSelection.getLength());
2141 fRememberedSelection = null;
2142 fRememberedElement = null;
2143 fRememberedElementOffset = -1;
2149 // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
2152 // public void aboutToBeReconciled() {
2154 // // Notify AST provider
2155 // PHPeclipsePlugin.getDefault().getASTProvider().aboutToBeReconciled(getInputJavaElement());
2157 // // Notify listeners
2158 // Object[] listeners = fReconcilingListeners.getListeners();
2159 // for (int i = 0, length= listeners.length; i < length; ++i)
2160 // ((IJavaReconcilingListener)listeners[i]).aboutToBeReconciled();
2165 // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit,
2166 // boolean, IProgressMonitor)
2169 // public void reconciled(net.sourceforge.phpdt.core.dom.CompilationUnit
2170 // ast, boolean forced, IProgressMonitor progressMonitor) {
2172 // // Always notify AST provider
2173 // PHPeclipsePlugin.getDefault().getASTProvider().reconciled(ast,
2174 // getInputJavaElement());
2176 // // Notify listeners
2177 // Object[] listeners = fReconcilingListeners.getListeners();
2178 // for (int i = 0, length= listeners.length; i < length; ++i)
2179 // ((IJavaReconcilingListener)listeners[i]).reconciled(ast, forced,
2180 // progressMonitor);
2182 // // Update Java Outline page selection
2183 // if (!forced && !progressMonitor.isCanceled()) {
2184 // Shell shell= getSite().getShell();
2185 // if (shell != null && !shell.isDisposed()) {
2186 // shell.getDisplay().asyncExec(new Runnable() {
2187 // public void run() {
2188 // selectionChanged();