1 package net.sourceforge.phpeclipse.phpeditor;
2 import java.lang.reflect.InvocationTargetException;
3 import java.text.MessageFormat;
4 import java.util.ArrayList;
5 import java.util.Iterator;
8 import net.sourceforge.phpdt.core.ICompilationUnit;
9 import net.sourceforge.phpdt.core.IJavaElement;
10 import net.sourceforge.phpdt.core.ISourceRange;
11 import net.sourceforge.phpdt.core.ISourceReference;
12 import net.sourceforge.phpdt.core.JavaCore;
13 import net.sourceforge.phpdt.core.JavaModelException;
14 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
15 import net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction;
16 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
17 import net.sourceforge.phpdt.internal.ui.actions.RemoveBlockCommentAction;
18 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
19 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
20 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
21 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
22 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
23 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags;
24 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
25 import net.sourceforge.phpdt.ui.PreferenceConstants;
26 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
27 import net.sourceforge.phpdt.ui.text.JavaTextTools;
28 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
30 import org.eclipse.core.resources.IFile;
31 import org.eclipse.core.resources.IWorkspace;
32 import org.eclipse.core.resources.ResourcesPlugin;
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IPath;
35 import org.eclipse.core.runtime.IProgressMonitor;
36 import org.eclipse.core.runtime.Preferences;
37 import org.eclipse.jface.action.Action;
38 import org.eclipse.jface.action.IMenuManager;
39 import org.eclipse.jface.dialogs.Dialog;
40 import org.eclipse.jface.dialogs.ErrorDialog;
41 import org.eclipse.jface.dialogs.IMessageProvider;
42 import org.eclipse.jface.dialogs.MessageDialog;
43 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
44 import org.eclipse.jface.preference.IPreferenceStore;
45 import org.eclipse.jface.preference.PreferenceConverter;
46 import org.eclipse.jface.text.BadLocationException;
47 import org.eclipse.jface.text.DocumentCommand;
48 import org.eclipse.jface.text.IDocument;
49 import org.eclipse.jface.text.ILineTracker;
50 import org.eclipse.jface.text.IRegion;
51 import org.eclipse.jface.text.ITextOperationTarget;
52 import org.eclipse.jface.text.ITextSelection;
53 import org.eclipse.jface.text.ITextViewerExtension;
54 import org.eclipse.jface.text.ITypedRegion;
55 import org.eclipse.jface.text.IWidgetTokenKeeper;
56 import org.eclipse.jface.text.contentassist.ContentAssistant;
57 import org.eclipse.jface.text.contentassist.IContentAssistant;
58 import org.eclipse.jface.text.source.IOverviewRuler;
59 import org.eclipse.jface.text.source.ISourceViewer;
60 import org.eclipse.jface.text.source.IVerticalRuler;
61 import org.eclipse.jface.text.source.SourceViewerConfiguration;
62 import org.eclipse.jface.util.PropertyChangeEvent;
63 import org.eclipse.jface.viewers.ISelectionProvider;
64 import org.eclipse.swt.SWT;
65 import org.eclipse.swt.custom.VerifyKeyListener;
66 import org.eclipse.swt.events.VerifyEvent;
67 import org.eclipse.swt.graphics.Color;
68 import org.eclipse.swt.graphics.Point;
69 import org.eclipse.swt.graphics.RGB;
70 import org.eclipse.swt.widgets.Composite;
71 import org.eclipse.swt.widgets.Display;
72 import org.eclipse.swt.widgets.Shell;
73 import org.eclipse.ui.IEditorInput;
74 import org.eclipse.ui.IFileEditorInput;
75 import org.eclipse.ui.actions.ActionContext;
76 import org.eclipse.ui.actions.ActionGroup;
77 import org.eclipse.ui.actions.WorkspaceModifyOperation;
78 import org.eclipse.ui.dialogs.SaveAsDialog;
79 import org.eclipse.ui.editors.text.IStorageDocumentProvider;
80 import org.eclipse.ui.help.WorkbenchHelp;
81 import org.eclipse.ui.part.FileEditorInput;
82 import org.eclipse.ui.texteditor.ContentAssistAction;
83 import org.eclipse.ui.texteditor.IDocumentProvider;
84 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
85 import org.eclipse.ui.texteditor.TextOperationAction;
86 /*******************************************************************************
87 * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
88 * program and the accompanying materials are made available under the terms of
89 * the Common Public License v1.0 which accompanies this distribution, and is
90 * available at http://www.eclipse.org/legal/cpl-v10.html
92 * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
93 * www.eclipseproject.de
94 ******************************************************************************/
96 * PHP specific text editor.
98 public class PHPUnitEditor extends PHPEditor {
99 interface ITextConverter {
100 void customizeDocumentCommand(IDocument document, DocumentCommand command);
102 // class AdaptedRulerLayout extends Layout {
104 // protected int fGap;
105 // protected AdaptedSourceViewer fAdaptedSourceViewer;
107 // protected AdaptedRulerLayout(int gap, AdaptedSourceViewer asv) {
109 // fAdaptedSourceViewer = asv;
112 // protected Point computeSize(Composite composite, int wHint, int hHint,
113 // boolean flushCache) {
114 // Control[] children = composite.getChildren();
115 // Point s = children[children.length - 1].computeSize(SWT.DEFAULT,
116 // SWT.DEFAULT, flushCache);
117 // if (fAdaptedSourceViewer.isVerticalRulerVisible())
118 // s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap;
122 // protected void layout(Composite composite, boolean flushCache) {
123 // Rectangle clArea = composite.getClientArea();
124 // if (fAdaptedSourceViewer.isVerticalRulerVisible()) {
126 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
127 // Rectangle trim = textWidget.computeTrim(0, 0, 0, 0);
128 // int scrollbarHeight = trim.height;
130 // IVerticalRuler vr = fAdaptedSourceViewer.getVerticalRuler();
131 // int vrWidth = vr.getWidth();
134 // if (fAdaptedSourceViewer.isOverviewRulerVisible()) {
135 // OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler();
136 // orWidth = or.getWidth();
137 // or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight,
138 // orWidth, clArea.height - 3 * scrollbarHeight);
141 // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth -
142 // 2 * fGap, clArea.height);
143 // vr.getControl().setBounds(0, 0, vrWidth, clArea.height - scrollbarHeight);
146 // StyledText textWidget = fAdaptedSourceViewer.getTextWidget();
147 // textWidget.setBounds(0, 0, clArea.width, clArea.height);
152 // class AdaptedSourceViewer extends SourceViewer { // extends
153 // JavaCorrectionSourceViewer {
155 // private List fTextConverters;
157 // private OverviewRuler fOverviewRuler;
158 // private boolean fIsOverviewRulerVisible;
159 // /** The viewer's overview ruler hovering controller */
160 // private AbstractHoverInformationControlManager
161 // fOverviewRulerHoveringController;
163 // private boolean fIgnoreTextConverters = false;
165 // private IVerticalRuler fCachedVerticalRuler;
166 // private boolean fCachedIsVerticalRulerVisible;
168 // public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int
170 // super(parent, ruler, styles); //, CompilationUnitEditor.this);
172 // fCachedVerticalRuler = ruler;
173 // fCachedIsVerticalRulerVisible = (ruler != null);
174 // fOverviewRuler = new OverviewRuler(VERTICAL_RULER_WIDTH);
176 // delayedCreateControl(parent, styles);
180 // * @see ISourceViewer#showAnnotations(boolean)
182 // public void showAnnotations(boolean show) {
183 // fCachedIsVerticalRulerVisible = (show && fCachedVerticalRuler != null);
184 // // super.showAnnotations(show);
187 // public IContentAssistant getContentAssistant() {
188 // return fContentAssistant;
192 // * @see ITextOperationTarget#doOperation(int)
194 // public void doOperation(int operation) {
196 // if (getTextWidget() == null)
199 // switch (operation) {
200 // case CONTENTASSIST_PROPOSALS :
201 // String msg = fContentAssistant.showPossibleCompletions();
202 // setStatusLineErrorMessage(msg);
205 // fIgnoreTextConverters = true;
208 // fIgnoreTextConverters = true;
212 // super.doOperation(operation);
215 // public void insertTextConverter(ITextConverter textConverter, int index) {
216 // throw new UnsupportedOperationException();
219 // public void addTextConverter(ITextConverter textConverter) {
220 // if (fTextConverters == null) {
221 // fTextConverters = new ArrayList(1);
222 // fTextConverters.add(textConverter);
223 // } else if (!fTextConverters.contains(textConverter))
224 // fTextConverters.add(textConverter);
227 // public void removeTextConverter(ITextConverter textConverter) {
228 // if (fTextConverters != null) {
229 // fTextConverters.remove(textConverter);
230 // if (fTextConverters.size() == 0)
231 // fTextConverters = null;
236 // * @see TextViewer#customizeDocumentCommand(DocumentCommand)
238 // protected void customizeDocumentCommand(DocumentCommand command) {
239 // super.customizeDocumentCommand(command);
240 // if (!fIgnoreTextConverters && fTextConverters != null) {
241 // for (Iterator e = fTextConverters.iterator(); e.hasNext();)
242 // ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(),
245 // fIgnoreTextConverters = false;
248 // public IVerticalRuler getVerticalRuler() {
249 // return fCachedVerticalRuler;
252 // public boolean isVerticalRulerVisible() {
253 // return fCachedIsVerticalRulerVisible;
256 // public OverviewRuler getOverviewRuler() {
257 // return fOverviewRuler;
261 // * @see TextViewer#createControl(Composite, int)
263 // protected void createControl(Composite parent, int styles) {
264 // // do nothing here
267 // protected void delayedCreateControl(Composite parent, int styles) {
268 // //create the viewer
269 // super.createControl(parent, styles);
271 // Control control = getControl();
272 // if (control instanceof Composite) {
273 // Composite composite = (Composite) control;
274 // composite.setLayout(new AdaptedRulerLayout(GAP_SIZE, this));
275 // fOverviewRuler.createControl(composite, this);
278 // protected void ensureOverviewHoverManagerInstalled() {
279 // if (fOverviewRulerHoveringController == null && fAnnotationHover != null
280 // && fHoverControlCreator != null) {
281 // fOverviewRulerHoveringController =
282 // new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover,
283 // fHoverControlCreator);
284 // fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
288 // public void hideOverviewRuler() {
289 // fIsOverviewRulerVisible = false;
290 // Control control = getControl();
291 // if (control instanceof Composite) {
292 // Composite composite = (Composite) control;
293 // composite.layout();
295 // if (fOverviewRulerHoveringController != null) {
296 // fOverviewRulerHoveringController.dispose();
297 // fOverviewRulerHoveringController = null;
301 // public void showOverviewRuler() {
302 // fIsOverviewRulerVisible = true;
303 // Control control = getControl();
304 // if (control instanceof Composite) {
305 // Composite composite = (Composite) control;
306 // composite.layout();
308 // ensureOverviewHoverManagerInstalled();
311 // public boolean isOverviewRulerVisible() {
312 // return fIsOverviewRulerVisible;
316 // * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
318 // public void setDocument(
319 // IDocument document,
320 // IAnnotationModel annotationModel,
321 // int visibleRegionOffset,
322 // int visibleRegionLength) {
323 // super.setDocument(document, annotationModel, visibleRegionOffset,
324 // visibleRegionLength);
325 // fOverviewRuler.setModel(annotationModel);
328 // // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
329 // public void updateIndentationPrefixes() {
330 // SourceViewerConfiguration configuration = getSourceViewerConfiguration();
331 // String[] types = configuration.getConfiguredContentTypes(this);
332 // for (int i = 0; i < types.length; i++) {
333 // String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
334 // if (prefixes != null && prefixes.length > 0)
335 // setIndentPrefixes(prefixes, types[i]);
340 // * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
342 // public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
343 // if (WorkbenchHelp.isContextHelpDisplayed())
345 // return super.requestWidgetToken(requester);
350 // org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
352 // public void configure(SourceViewerConfiguration configuration) {
353 // super.configure(configuration);
354 // // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
355 // IDocument.DEFAULT_CONTENT_TYPE);
358 // protected void handleDispose() {
359 // fOverviewRuler = null;
361 // if (fOverviewRulerHoveringController != null) {
362 // fOverviewRulerHoveringController.dispose();
363 // fOverviewRulerHoveringController = null;
366 // super.handleDispose();
370 class AdaptedSourceViewer extends JavaSourceViewer {
371 private List fTextConverters;
372 private boolean fIgnoreTextConverters = false;
373 // private JavaCorrectionAssistant fCorrectionAssistant;
374 public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler,
375 IOverviewRuler overviewRuler, boolean showAnnotationsOverview,
377 super(parent, verticalRuler, overviewRuler, showAnnotationsOverview,
380 public IContentAssistant getContentAssistant() {
381 return fContentAssistant;
384 * @see ITextOperationTarget#doOperation(int)
386 public void doOperation(int operation) {
387 if (getTextWidget() == null)
390 case CONTENTASSIST_PROPOSALS :
391 String msg = fContentAssistant.showPossibleCompletions();
392 setStatusLineErrorMessage(msg);
394 // case CORRECTIONASSIST_PROPOSALS:
395 // fCorrectionAssistant.showPossibleCompletions();
398 fIgnoreTextConverters = true;
401 fIgnoreTextConverters = true;
404 super.doOperation(operation);
407 * @see ITextOperationTarget#canDoOperation(int)
409 public boolean canDoOperation(int operation) {
410 // if (operation == CORRECTIONASSIST_PROPOSALS)
411 // return isEditable();
412 return super.canDoOperation(operation);
415 * @see TextViewer#handleDispose()
417 protected void handleDispose() {
418 // if (fCorrectionAssistant != null) {
419 // fCorrectionAssistant.uninstall();
420 // fCorrectionAssistant= null;
422 super.handleDispose();
424 public void insertTextConverter(ITextConverter textConverter, int index) {
425 throw new UnsupportedOperationException();
427 public void addTextConverter(ITextConverter textConverter) {
428 if (fTextConverters == null) {
429 fTextConverters = new ArrayList(1);
430 fTextConverters.add(textConverter);
431 } else if (!fTextConverters.contains(textConverter))
432 fTextConverters.add(textConverter);
434 public void removeTextConverter(ITextConverter textConverter) {
435 if (fTextConverters != null) {
436 fTextConverters.remove(textConverter);
437 if (fTextConverters.size() == 0)
438 fTextConverters = null;
442 * @see TextViewer#customizeDocumentCommand(DocumentCommand)
444 protected void customizeDocumentCommand(DocumentCommand command) {
445 super.customizeDocumentCommand(command);
446 if (!fIgnoreTextConverters && fTextConverters != null) {
447 for (Iterator e = fTextConverters.iterator(); e.hasNext();)
448 ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(),
451 fIgnoreTextConverters = false;
453 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
454 public void updateIndentationPrefixes() {
455 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
456 String[] types = configuration.getConfiguredContentTypes(this);
457 for (int i = 0; i < types.length; i++) {
458 String[] prefixes = configuration.getIndentPrefixes(this, types[i]);
459 if (prefixes != null && prefixes.length > 0)
460 setIndentPrefixes(prefixes, types[i]);
464 * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
466 public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
467 if (WorkbenchHelp.isContextHelpDisplayed())
469 return super.requestWidgetToken(requester);
472 * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
474 public void configure(SourceViewerConfiguration configuration) {
475 super.configure(configuration);
476 // fCorrectionAssistant= new
477 // JavaCorrectionAssistant(CompilationUnitEditor.this);
478 // fCorrectionAssistant.install(this);
479 //TODO install SmartBracesAutoEditStrategy
480 // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this),
481 // IDocument.DEFAULT_CONTENT_TYPE);
484 static class TabConverter implements ITextConverter {
485 private int fTabRatio;
486 private ILineTracker fLineTracker;
487 public TabConverter() {
489 public void setNumberOfSpacesPerTab(int ratio) {
492 public void setLineTracker(ILineTracker lineTracker) {
493 fLineTracker = lineTracker;
495 private int insertTabString(StringBuffer buffer, int offsetInLine) {
498 int remainder = offsetInLine % fTabRatio;
499 remainder = fTabRatio - remainder;
500 for (int i = 0; i < remainder; i++)
504 public void customizeDocumentCommand(IDocument document,
505 DocumentCommand command) {
506 String text = command.text;
509 int index = text.indexOf('\t');
511 StringBuffer buffer = new StringBuffer();
512 fLineTracker.set(command.text);
513 int lines = fLineTracker.getNumberOfLines();
515 for (int i = 0; i < lines; i++) {
516 int offset = fLineTracker.getLineOffset(i);
517 int endOffset = offset + fLineTracker.getLineLength(i);
518 String line = text.substring(offset, endOffset);
521 IRegion firstLine = document
522 .getLineInformationOfOffset(command.offset);
523 position = command.offset - firstLine.getOffset();
525 int length = line.length();
526 for (int j = 0; j < length; j++) {
527 char c = line.charAt(j);
529 position += insertTabString(buffer, position);
536 command.text = buffer.toString();
537 } catch (BadLocationException x) {
542 private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
543 final char fExitCharacter;
544 public ExitPolicy(char exitCharacter) {
545 fExitCharacter = exitCharacter;
548 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager,
549 * org.eclipse.swt.events.VerifyEvent, int, int)
551 public ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event,
552 int offset, int length) {
553 if (event.character == fExitCharacter) {
554 if (manager.anyPositionIncludes(offset, length))
555 return new ExitFlags(LinkedPositionUI.COMMIT
556 | LinkedPositionUI.UPDATE_CARET, false);
558 return new ExitFlags(LinkedPositionUI.COMMIT, true);
560 switch (event.character) {
562 if (manager.getFirstPosition().length == 0)
563 return new ExitFlags(0, false);
568 return new ExitFlags(LinkedPositionUI.COMMIT, true);
574 private static class BracketLevel {
577 LinkedPositionManager fManager;
578 LinkedPositionUI fEditor;
580 private class BracketInserter
583 LinkedPositionUI.ExitListener {
584 private boolean fCloseBracketsPHP = true;
585 private boolean fCloseStringsPHP = true;
586 private boolean fCloseBracketsHTML = true;
587 private boolean fCloseStringsHTML = true;
590 public void setCloseBracketsPHPEnabled(boolean enabled) {
591 fCloseBracketsPHP = enabled;
593 public void setCloseStringsPHPEnabled(boolean enabled) {
594 fCloseStringsPHP = enabled;
596 public void setCloseBracketsHTMLEnabled(boolean enabled) {
597 fCloseBracketsHTML = enabled;
599 public void setCloseStringsHTMLEnabled(boolean enabled) {
600 fCloseStringsHTML = enabled;
602 private boolean hasIdentifierToTheRight(IDocument document, int offset) {
605 IRegion endLine = document.getLineInformationOfOffset(end);
606 int maxEnd = endLine.getOffset() + endLine.getLength();
607 while (end != maxEnd && Character.isWhitespace(document.getChar(end)))
610 && Scanner.isPHPIdentifierPart(document.getChar(end));
611 } catch (BadLocationException e) {
616 private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
619 IRegion startLine = document.getLineInformationOfOffset(start);
620 int minStart = startLine.getOffset();
621 while (start != minStart
622 && Character.isWhitespace(document.getChar(start - 1)))
624 return start != minStart
625 && Scanner.isPHPIdentifierPart(document.getChar(start - 1));
626 } catch (BadLocationException e) {
630 private boolean hasCharacterToTheRight(IDocument document, int offset,
634 IRegion endLine = document.getLineInformationOfOffset(end);
635 int maxEnd = endLine.getOffset() + endLine.getLength();
636 while (end != maxEnd && Character.isWhitespace(document.getChar(end)))
638 return end != maxEnd && document.getChar(end) == character;
639 } catch (BadLocationException e) {
645 * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
647 public void verifyKey(VerifyEvent event) {
650 final ISourceViewer sourceViewer = getSourceViewer();
651 IDocument document = sourceViewer.getDocument();
652 final Point selection = sourceViewer.getSelectedRange();
653 final int offset = selection.x;
654 final int length = selection.y;
656 ITypedRegion partition = document.getPartition(offset);
657 String type = partition.getType();
658 if (type.equals(IPHPPartitions.PHP_PARTITIONING)) {
659 switch (event.character) {
661 if (hasCharacterToTheRight(document, offset + length, '('))
665 if (!fCloseBracketsPHP)
667 if (hasIdentifierToTheRight(document, offset + length))
671 if (event.character == '"') {
672 if (!fCloseStringsPHP)
674 // changed for statements like echo "" print ""
675 // if (hasIdentifierToTheLeft(document, offset) ||
676 // hasIdentifierToTheRight(document, offset + length))
677 if (hasIdentifierToTheRight(document, offset + length))
680 // ITypedRegion partition= document.getPartition(offset);
682 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) &&
683 // (partition.getOffset() != offset))
685 final char character = event.character;
686 final char closingCharacter = getPeerCharacter(character);
687 final StringBuffer buffer = new StringBuffer();
688 buffer.append(character);
689 buffer.append(closingCharacter);
690 document.replace(offset, length, buffer.toString());
691 LinkedPositionManager manager = new LinkedPositionManager(
693 manager.addPosition(offset + 1, 0);
696 LinkedPositionUI editor = new LinkedPositionUI(sourceViewer,
698 editor.setCancelListener(this);
699 editor.setExitPolicy(new ExitPolicy(closingCharacter));
700 editor.setFinalCaretOffset(offset + 2);
702 IRegion newSelection = editor.getSelectedRegion();
703 sourceViewer.setSelectedRange(newSelection.getOffset(),
704 newSelection.getLength());
707 } else if (type.equals(IPHPPartitions.HTML)
708 || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
709 switch (event.character) {
711 if (hasCharacterToTheRight(document, offset + length, '('))
715 if (!fCloseBracketsHTML)
717 if (hasIdentifierToTheRight(document, offset + length))
721 if (event.character == '"') {
722 if (!fCloseStringsHTML)
724 if (hasIdentifierToTheLeft(document, offset)
725 || hasIdentifierToTheRight(document, offset + length))
728 // ITypedRegion partition= document.getPartition(offset);
730 // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) &&
731 // (partition.getOffset() != offset))
733 final char character = event.character;
734 final char closingCharacter = getPeerCharacter(character);
735 final StringBuffer buffer = new StringBuffer();
736 buffer.append(character);
737 buffer.append(closingCharacter);
738 document.replace(offset, length, buffer.toString());
739 LinkedPositionManager manager = new LinkedPositionManager(
741 manager.addPosition(offset + 1, 0);
744 LinkedPositionUI editor = new LinkedPositionUI(sourceViewer,
746 editor.setCancelListener(this);
747 editor.setExitPolicy(new ExitPolicy(closingCharacter));
748 editor.setFinalCaretOffset(offset + 2);
750 IRegion newSelection = editor.getSelectedRegion();
751 sourceViewer.setSelectedRange(newSelection.getOffset(),
752 newSelection.getLength());
756 } catch (BadLocationException e) {
760 * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean)
762 public void exit(boolean accept) {
767 final ISourceViewer sourceViewer = getSourceViewer();
768 IDocument document = sourceViewer.getDocument();
769 document.replace(fOffset, fLength, null);
770 } catch (BadLocationException e) {
774 /** The editor's save policy */
775 protected ISavePolicy fSavePolicy;
777 * Listener to annotation model changes that updates the error tick in the
780 private JavaEditorErrorTickUpdater fJavaEditorErrorTickUpdater;
781 /** The editor's paint manager */
782 // private PaintManager fPaintManager;
783 /** The editor's bracket painter */
784 private BracketPainter fBracketPainter;
785 /** The editor's bracket matcher */
786 private PHPPairMatcher fBracketMatcher;
787 /** The editor's line painter */
788 private LinePainter fLinePainter;
789 /** The editor's print margin ruler painter */
790 private PrintMarginPainter fPrintMarginPainter;
791 /** The editor's problem painter */
792 // private ProblemPainter fProblemPainter;
793 /** The editor's tab converter */
794 private TabConverter fTabConverter;
795 /** History for structure select action */
796 //private SelectionHistory fSelectionHistory;
797 /** The preference property change listener for php core. */
798 // private IPropertyChangeListener fPropertyChangeListener = new
799 // PropertyChangeListener();
800 /** The remembered java element */
801 private IJavaElement fRememberedElement;
802 /** The remembered selection */
803 private ITextSelection fRememberedSelection;
804 /** The remembered php element offset */
805 private int fRememberedElementOffset;
806 /** The bracket inserter. */
807 private BracketInserter fBracketInserter = new BracketInserter();
809 /** The standard action groups added to the menu */
810 private GenerateActionGroup fGenerateActionGroup;
811 private CompositeActionGroup fContextMenuGroup;
812 // private class PropertyChangeListener implements IPropertyChangeListener {
814 // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
817 // propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
819 // handlePreferencePropertyChanged(event);
822 /* Preference key for code formatter tab size */
823 private final static String CODE_FORMATTER_TAB_SIZE = JavaCore.FORMATTER_TAB_SIZE;
824 /** Preference key for matching brackets */
825 private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
826 /** Preference key for matching brackets color */
827 private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
828 /** Preference key for highlighting current line */
829 private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE;
830 /** Preference key for highlight color of current line */
831 private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
832 /** Preference key for showing print marging ruler */
833 private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN;
834 /** Preference key for print margin ruler color */
835 private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
836 /** Preference key for print margin ruler column */
837 private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
838 /** Preference key for inserting spaces rather than tabs */
839 private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
840 /** Preference key for error indication */
841 // private final static String ERROR_INDICATION =
842 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
843 /** Preference key for error color */
844 // private final static String ERROR_INDICATION_COLOR =
845 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
846 /** Preference key for warning indication */
847 // private final static String WARNING_INDICATION =
848 // PreferenceConstants.EDITOR_WARNING_INDICATION;
849 /** Preference key for warning color */
850 // private final static String WARNING_INDICATION_COLOR =
851 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
852 /** Preference key for task indication */
853 private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
854 /** Preference key for task color */
855 private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
856 /** Preference key for bookmark indication */
857 private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
858 /** Preference key for bookmark color */
859 private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
860 /** Preference key for search result indication */
861 private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
862 /** Preference key for search result color */
863 private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
864 /** Preference key for unknown annotation indication */
865 private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
866 /** Preference key for unknown annotation color */
867 private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
868 /** Preference key for linked position color */
869 private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
870 /** Preference key for shwoing the overview ruler */
871 private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
872 /** Preference key for error indication in overview ruler */
873 private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
874 /** Preference key for warning indication in overview ruler */
875 private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
876 /** Preference key for task indication in overview ruler */
877 private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
878 /** Preference key for bookmark indication in overview ruler */
879 private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
880 /** Preference key for search result indication in overview ruler */
881 private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
882 /** Preference key for unknown annotation indication in overview ruler */
883 private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
884 /** Preference key for automatically closing strings */
885 private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP;
886 /** Preference key for automatically wrapping Java strings */
887 private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS;
888 /** Preference key for automatically closing brackets and parenthesis */
889 private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
890 /** Preference key for automatically closing phpdocs and comments */
891 private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
892 /** Preference key for automatically adding phpdoc tags */
893 private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
894 /** Preference key for automatically formatting phpdocs */
895 private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
896 /** Preference key for automatically closing strings */
897 private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
898 /** Preference key for automatically closing brackets and parenthesis */
899 private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
900 /** Preference key for smart paste */
901 private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
902 // private final static class AnnotationInfo {
903 // public String fColorPreference;
904 // public String fOverviewRulerPreference;
905 // public String fEditorPreference;
907 // private final static Map ANNOTATION_MAP;
910 // AnnotationInfo info;
911 // ANNOTATION_MAP = new HashMap();
913 // info = new AnnotationInfo();
914 // info.fColorPreference = TASK_INDICATION_COLOR;
915 // info.fOverviewRulerPreference = TASK_INDICATION_IN_OVERVIEW_RULER;
916 // info.fEditorPreference = TASK_INDICATION;
917 // ANNOTATION_MAP.put(AnnotationType.TASK, info);
919 // info = new AnnotationInfo();
920 // info.fColorPreference = ERROR_INDICATION_COLOR;
921 // info.fOverviewRulerPreference = ERROR_INDICATION_IN_OVERVIEW_RULER;
922 // info.fEditorPreference = ERROR_INDICATION;
923 // ANNOTATION_MAP.put(AnnotationType.ERROR, info);
925 // info = new AnnotationInfo();
926 // info.fColorPreference = WARNING_INDICATION_COLOR;
927 // info.fOverviewRulerPreference = WARNING_INDICATION_IN_OVERVIEW_RULER;
928 // info.fEditorPreference = WARNING_INDICATION;
929 // ANNOTATION_MAP.put(AnnotationType.WARNING, info);
931 // info = new AnnotationInfo();
932 // info.fColorPreference = BOOKMARK_INDICATION_COLOR;
933 // info.fOverviewRulerPreference = BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
934 // info.fEditorPreference = BOOKMARK_INDICATION;
935 // ANNOTATION_MAP.put(AnnotationType.BOOKMARK, info);
937 // info = new AnnotationInfo();
938 // info.fColorPreference = SEARCH_RESULT_INDICATION_COLOR;
939 // info.fOverviewRulerPreference =
940 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
941 // info.fEditorPreference = SEARCH_RESULT_INDICATION;
942 // ANNOTATION_MAP.put(AnnotationType.SEARCH, info);
944 // info = new AnnotationInfo();
945 // info.fColorPreference = UNKNOWN_INDICATION_COLOR;
946 // info.fOverviewRulerPreference = UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
947 // info.fEditorPreference = UNKNOWN_INDICATION;
948 // ANNOTATION_MAP.put(AnnotationType.UNKNOWN, info);
951 // private final static AnnotationType[] ANNOTATION_LAYERS =
952 // new AnnotationType[] {
953 // AnnotationType.UNKNOWN,
954 // AnnotationType.BOOKMARK,
955 // AnnotationType.TASK,
956 // AnnotationType.SEARCH,
957 // AnnotationType.WARNING,
958 // AnnotationType.ERROR };
960 * Creates a new php unit editor.
962 public PHPUnitEditor() {
964 setDocumentProvider(PHPeclipsePlugin.getDefault()
965 .getCompilationUnitDocumentProvider());
966 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
967 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
968 setOutlinerContextMenuId("#PHPOutlinerContext"); //$NON-NLS-1$
969 // don't set help contextId, we install our own help context
971 fJavaEditorErrorTickUpdater = new JavaEditorErrorTickUpdater(this);
974 * @see AbstractTextEditor#createActions()
976 protected void createActions() {
977 super.createActions();
979 // Action action= new
980 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
981 // "CorrectionAssistProposal.", this, CORRECTIONASSIST_PROPOSALS);
983 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
984 // setAction("CorrectionAssistProposal", action); //$NON-NLS-1$
985 // markAsStateDependentAction("CorrectionAssistProposal", true);
987 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.QUICK_FIX_ACTION);
988 action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(),
989 "ContentAssistProposal.", this); //$NON-NLS-1$
991 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
992 setAction("ContentAssistProposal", action); //$NON-NLS-1$
993 markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
994 // WorkbenchHelp.setHelp(action,
995 // IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
996 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
997 "ContentAssistContextInformation.", this,
998 ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$
1000 .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
1001 setAction("ContentAssistContextInformation", action); //$NON-NLS-1$
1002 markAsStateDependentAction("ContentAssistContextInformation", true); //$NON-NLS-1$
1003 // WorkbenchHelp.setHelp(action,
1004 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1005 // action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1006 // "ContentAssistCompletePrefix.", this, CONTENTASSIST_COMPLETE_PREFIX);
1008 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_COMPLETE_PREFIX);
1009 // setAction("ContentAssistCompletePrefix", action); //$NON-NLS-1$
1010 // markAsStateDependentAction("ContentAssistCompletePrefix", true);
1012 //// WorkbenchHelp.setHelp(action,
1013 // IJavaHelpContextIds.PARAMETER_HINTS_ACTION);
1014 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1015 "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
1016 action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
1017 setAction("Comment", action); //$NON-NLS-1$
1018 markAsStateDependentAction("Comment", true); //$NON-NLS-1$
1019 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
1020 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1021 "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
1022 action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
1023 setAction("Uncomment", action); //$NON-NLS-1$
1024 markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
1025 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
1026 action = new ToggleCommentAction(PHPEditorMessages.getResourceBundle(),
1027 "ToggleComment.", this, getSourceViewerConfiguration()
1028 .getDefaultPrefixes(getSourceViewer(), "")); //$NON-NLS-1$ //$NON-NLS-2$
1029 action.setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT);
1030 setAction("ToggleComment", action); //$NON-NLS-1$
1031 markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
1032 // WorkbenchHelp.setHelp(action,
1033 // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
1034 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(),
1035 "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
1036 action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
1037 setAction("Format", action); //$NON-NLS-1$
1038 markAsStateDependentAction("Format", true); //$NON-NLS-1$
1039 markAsSelectionDependentAction("Format", true); //$NON-NLS-1$
1040 // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
1041 action = new AddBlockCommentAction(PHPEditorMessages.getResourceBundle(),
1042 "AddBlockComment.", this); //$NON-NLS-1$
1044 .setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
1045 setAction("AddBlockComment", action); //$NON-NLS-1$
1046 markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
1047 markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
1048 // WorkbenchHelp.setHelp(action,
1049 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1050 action = new RemoveBlockCommentAction(
1051 PHPEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
1053 .setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
1054 setAction("RemoveBlockComment", action); //$NON-NLS-1$
1055 markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1056 markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
1057 // WorkbenchHelp.setHelp(action,
1058 // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
1059 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1060 // "Indent.", this, false); //$NON-NLS-1$
1061 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT);
1062 // setAction("Indent", action); //$NON-NLS-1$
1063 // markAsStateDependentAction("Indent", true); //$NON-NLS-1$
1064 // markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
1065 //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION);
1067 // action= new IndentAction(PHPEditorMessages.getResourceBundle(),
1068 // "Indent.", this, true); //$NON-NLS-1$
1069 // setAction("IndentOnTab", action); //$NON-NLS-1$
1070 // markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
1071 // markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$
1073 if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_TAB)) {
1074 // don't replace Shift Right - have to make sure their enablement is
1075 // mutually exclusive
1076 // removeActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT);
1077 setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$
1079 fGenerateActionGroup = new GenerateActionGroup(this,
1080 ITextEditorActionConstants.GROUP_EDIT);
1081 fActionGroups = new CompositeActionGroup(
1082 new ActionGroup[]{fGenerateActionGroup});
1083 // We have to keep the context menu group separate to have better control
1085 fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
1087 // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)});
1091 * @see JavaEditor#getElementAt(int)
1093 protected IJavaElement getElementAt(int offset) {
1094 return getElementAt(offset, true);
1097 * Returns the most narrow element including the given offset. If <code>reconcile</code>
1098 * is <code>true</code> the editor's input element is reconciled in
1099 * advance. If it is <code>false</code> this method only returns a result
1100 * if the editor's input element does not need to be reconciled.
1103 * the offset included by the retrieved element
1105 * <code>true</code> if working copy should be reconciled
1107 protected IJavaElement getElementAt(int offset, boolean reconcile) {
1108 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1109 .getWorkingCopyManager();
1110 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1114 synchronized (unit) {
1117 return unit.getElementAt(offset);
1118 } else if (unit.isConsistent())
1119 return unit.getElementAt(offset);
1120 } catch (JavaModelException x) {
1121 PHPeclipsePlugin.log(x.getStatus());
1122 // nothing found, be tolerant and go on
1128 * @see JavaEditor#getCorrespondingElement(IJavaElement)
1130 protected IJavaElement getCorrespondingElement(IJavaElement element) {
1132 return EditorUtility.getWorkingCopy(element, true);
1133 } catch (JavaModelException x) {
1134 PHPeclipsePlugin.log(x.getStatus());
1135 // nothing found, be tolerant and go on
1139 public void createPartControl(Composite parent) {
1140 super.createPartControl(parent);
1141 // fPaintManager = new PaintManager(getSourceViewer());
1142 LinePainter linePainter;
1143 linePainter = new LinePainter(getSourceViewer());
1145 .setHighlightColor(new Color(Display.getCurrent(), 225, 235, 224));
1146 // fPaintManager.addPainter(linePainter);
1147 if (isBracketHighlightingEnabled())
1148 startBracketHighlighting();
1149 if (isLineHighlightingEnabled())
1150 startLineHighlighting();
1151 if (isPrintMarginVisible())
1153 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1154 // while (e.hasNext()) {
1155 // AnnotationType type = (AnnotationType) e.next();
1156 // if (isAnnotationIndicationEnabled(type))
1157 // startAnnotationIndication(type);
1159 if (isTabConversionEnabled())
1160 startTabConversion();
1161 // if (isOverviewRulerVisible())
1162 // showOverviewRuler();
1164 // Preferences preferences =
1165 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1166 // preferences.addPropertyChangeListener(fPropertyChangeListener);
1167 IPreferenceStore preferenceStore = getPreferenceStore();
1168 boolean closeBracketsPHP = preferenceStore.getBoolean(CLOSE_BRACKETS_PHP);
1169 boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP);
1170 boolean closeBracketsHTML = preferenceStore.getBoolean(CLOSE_BRACKETS_HTML);
1171 boolean closeStringsHTML = preferenceStore.getBoolean(CLOSE_STRINGS_HTML);
1172 fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
1173 fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP);
1174 fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
1175 fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
1176 ISourceViewer sourceViewer = getSourceViewer();
1177 if (sourceViewer instanceof ITextViewerExtension)
1178 ((ITextViewerExtension) sourceViewer)
1179 .prependVerifyKeyListener(fBracketInserter);
1181 private static char getPeerCharacter(char character) {
1182 switch (character) {
1194 throw new IllegalArgumentException();
1198 * The compilation unit editor implementation of this <code>AbstractTextEditor</code>
1199 * method asks the user for the workspace path of a file resource and saves
1200 * the document there. See http://dev.eclipse.org/bugs/show_bug.cgi?id=6295
1202 protected void performSaveAs(IProgressMonitor progressMonitor) {
1203 Shell shell = getSite().getShell();
1204 IEditorInput input = getEditorInput();
1205 SaveAsDialog dialog = new SaveAsDialog(shell);
1206 IFile original = (input instanceof IFileEditorInput)
1207 ? ((IFileEditorInput) input).getFile()
1209 if (original != null)
1210 dialog.setOriginalFile(original);
1212 IDocumentProvider provider = getDocumentProvider();
1213 if (provider == null) {
1214 // editor has been programmatically closed while the dialog was open
1217 if (provider.isDeleted(input) && original != null) {
1218 String message = PHPEditorMessages.getFormattedString(
1219 "CompilationUnitEditor.warning.save.delete", new Object[]{original
1220 .getName()}); //$NON-NLS-1$
1221 dialog.setErrorMessage(null);
1222 dialog.setMessage(message, IMessageProvider.WARNING);
1224 if (dialog.open() == Dialog.CANCEL) {
1225 if (progressMonitor != null)
1226 progressMonitor.setCanceled(true);
1229 IPath filePath = dialog.getResult();
1230 if (filePath == null) {
1231 if (progressMonitor != null)
1232 progressMonitor.setCanceled(true);
1235 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1236 IFile file = workspace.getRoot().getFile(filePath);
1237 final IEditorInput newInput = new FileEditorInput(file);
1238 WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
1239 public void execute(final IProgressMonitor monitor) throws CoreException {
1240 getDocumentProvider().saveDocument(monitor, newInput,
1241 getDocumentProvider().getDocument(getEditorInput()), true);
1244 boolean success = false;
1246 provider.aboutToChange(newInput);
1247 new ProgressMonitorDialog(shell).run(false, true, op);
1249 } catch (InterruptedException x) {
1250 } catch (InvocationTargetException x) {
1251 Throwable t = x.getTargetException();
1252 if (t instanceof CoreException) {
1253 CoreException cx = (CoreException) t;
1254 ErrorDialog.openError(shell, PHPEditorMessages
1255 .getString("CompilationUnitEditor.error.saving.title2"),
1257 .getString("CompilationUnitEditor.error.saving.message2"), cx
1258 .getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
1260 MessageDialog.openError(shell, PHPEditorMessages
1261 .getString("CompilationUnitEditor.error.saving.title3"),
1263 .getString("CompilationUnitEditor.error.saving.message3")
1264 + t.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
1267 provider.changed(newInput);
1271 if (progressMonitor != null)
1272 progressMonitor.setCanceled(!success);
1275 * @see AbstractTextEditor#doSetInput(IEditorInput)
1277 protected void doSetInput(IEditorInput input) throws CoreException {
1278 super.doSetInput(input);
1279 configureTabConverter();
1281 private void startBracketHighlighting() {
1282 if (fBracketPainter == null) {
1283 ISourceViewer sourceViewer = getSourceViewer();
1284 fBracketPainter = new BracketPainter(sourceViewer);
1285 fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1286 // fPaintManager.addPainter(fBracketPainter);
1289 private void stopBracketHighlighting() {
1290 if (fBracketPainter != null) {
1291 // fPaintManager.removePainter(fBracketPainter);
1292 fBracketPainter.deactivate(true);
1293 fBracketPainter.dispose();
1294 fBracketPainter = null;
1297 private boolean isBracketHighlightingEnabled() {
1298 IPreferenceStore store = getPreferenceStore();
1299 return store.getBoolean(MATCHING_BRACKETS);
1301 private void startLineHighlighting() {
1302 if (fLinePainter == null) {
1303 ISourceViewer sourceViewer = getSourceViewer();
1304 fLinePainter = new LinePainter(sourceViewer);
1305 fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR));
1306 // fPaintManager.addPainter(fLinePainter);
1309 private void stopLineHighlighting() {
1310 if (fLinePainter != null) {
1311 // fPaintManager.removePainter(fLinePainter);
1312 fLinePainter.deactivate(true);
1313 fLinePainter.dispose();
1314 fLinePainter = null;
1317 private boolean isLineHighlightingEnabled() {
1318 IPreferenceStore store = getPreferenceStore();
1319 return store.getBoolean(CURRENT_LINE);
1321 private void showPrintMargin() {
1322 if (fPrintMarginPainter == null) {
1323 fPrintMarginPainter = new PrintMarginPainter(getSourceViewer());
1324 fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1325 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(
1326 PRINT_MARGIN_COLUMN));
1327 // fPaintManager.addPainter(fPrintMarginPainter);
1330 private void hidePrintMargin() {
1331 if (fPrintMarginPainter != null) {
1332 // fPaintManager.removePainter(fPrintMarginPainter);
1333 fPrintMarginPainter.deactivate(true);
1334 fPrintMarginPainter.dispose();
1335 fPrintMarginPainter = null;
1338 private boolean isPrintMarginVisible() {
1339 IPreferenceStore store = getPreferenceStore();
1340 return store.getBoolean(PRINT_MARGIN);
1342 // private void startAnnotationIndication(AnnotationType annotationType) {
1343 // if (fProblemPainter == null) {
1344 // fProblemPainter = new ProblemPainter(this, getSourceViewer());
1345 //// fPaintManager.addPainter(fProblemPainter);
1347 // fProblemPainter.setColor(annotationType, getColor(annotationType));
1348 // fProblemPainter.paintAnnotations(annotationType, true);
1349 // fProblemPainter.paint(IPainter.CONFIGURATION);
1352 // private void shutdownAnnotationIndication() {
1353 // if (fProblemPainter != null) {
1355 // if (!fProblemPainter.isPaintingAnnotations()) {
1356 //// fPaintManager.removePainter(fProblemPainter);
1357 // fProblemPainter.deactivate(true);
1358 // fProblemPainter.dispose();
1359 // fProblemPainter = null;
1361 // fProblemPainter.paint(IPainter.CONFIGURATION);
1366 // private void stopAnnotationIndication(AnnotationType annotationType) {
1367 // if (fProblemPainter != null) {
1368 // fProblemPainter.paintAnnotations(annotationType, false);
1369 // shutdownAnnotationIndication();
1373 // private boolean isAnnotationIndicationEnabled(AnnotationType
1374 // annotationType) {
1375 // IPreferenceStore store = getPreferenceStore();
1376 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType);
1377 // if (info != null)
1378 // return store.getBoolean(info.fEditorPreference);
1383 // isAnnotationIndicationInOverviewRulerEnabled(AnnotationType
1384 // annotationType) {
1385 // IPreferenceStore store = getPreferenceStore();
1386 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType);
1387 // if (info != null)
1388 // return store.getBoolean(info.fOverviewRulerPreference);
1392 // private void showAnnotationIndicationInOverviewRuler(AnnotationType
1393 // annotationType, boolean show) {
1394 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1395 // OverviewRuler ruler = asv.getOverviewRuler();
1396 // if (ruler != null) {
1397 // ruler.setColor(annotationType, getColor(annotationType));
1398 // ruler.showAnnotation(annotationType, show);
1403 // private void setColorInOverviewRuler(AnnotationType annotationType, Color
1405 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1406 // OverviewRuler ruler = asv.getOverviewRuler();
1407 // if (ruler != null) {
1408 // ruler.setColor(annotationType, color);
1412 private void configureTabConverter() {
1413 if (fTabConverter != null) {
1414 IDocumentProvider provider = getDocumentProvider();
1415 if (provider instanceof PHPDocumentProvider) {
1416 PHPDocumentProvider cup = (PHPDocumentProvider) provider;
1417 fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
1421 private int getTabSize() {
1422 Preferences preferences = PHPeclipsePlugin.getDefault()
1423 .getPluginPreferences();
1424 return preferences.getInt(CODE_FORMATTER_TAB_SIZE);
1426 private void startTabConversion() {
1427 if (fTabConverter == null) {
1428 fTabConverter = new TabConverter();
1429 configureTabConverter();
1430 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1431 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1432 asv.addTextConverter(fTabConverter);
1433 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1434 asv.updateIndentationPrefixes();
1437 private void stopTabConversion() {
1438 if (fTabConverter != null) {
1439 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1440 asv.removeTextConverter(fTabConverter);
1441 // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
1442 asv.updateIndentationPrefixes();
1443 fTabConverter = null;
1446 private boolean isTabConversionEnabled() {
1447 IPreferenceStore store = getPreferenceStore();
1448 return store.getBoolean(SPACES_FOR_TABS);
1450 // private void showOverviewRuler() {
1451 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1452 // asv.showOverviewRuler();
1454 // OverviewRuler overviewRuler = asv.getOverviewRuler();
1455 // if (overviewRuler != null) {
1456 // for (int i = 0; i < ANNOTATION_LAYERS.length; i++) {
1457 // AnnotationType type = ANNOTATION_LAYERS[i];
1458 // overviewRuler.setLayer(type, i);
1459 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1460 // showAnnotationIndicationInOverviewRuler(type, true);
1465 // private void hideOverviewRuler() {
1466 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1467 // asv.hideOverviewRuler();
1470 // private boolean isOverviewRulerVisible() {
1471 // IPreferenceStore store = getPreferenceStore();
1472 // return store.getBoolean(OVERVIEW_RULER);
1474 private Color getColor(String key) {
1475 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
1476 return getColor(rgb);
1478 private Color getColor(RGB rgb) {
1479 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1480 return textTools.getColorManager().getColor(rgb);
1482 // private Color getColor(AnnotationType annotationType) {
1483 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType);
1484 // if (info != null)
1485 // return getColor(info.fColorPreference);
1488 public void dispose() {
1489 ISourceViewer sourceViewer = getSourceViewer();
1490 if (sourceViewer instanceof ITextViewerExtension)
1491 ((ITextViewerExtension) sourceViewer)
1492 .removeVerifyKeyListener(fBracketInserter);
1493 // if (fPropertyChangeListener != null) {
1494 // Preferences preferences =
1495 // PHPeclipsePlugin.getDefault().getPluginPreferences();
1496 // preferences.removePropertyChangeListener(fPropertyChangeListener);
1497 // fPropertyChangeListener = null;
1499 if (fJavaEditorErrorTickUpdater != null) {
1500 fJavaEditorErrorTickUpdater.dispose();
1501 fJavaEditorErrorTickUpdater = null;
1503 // if (fSelectionHistory != null)
1504 // fSelectionHistory.dispose();
1505 // if (fPaintManager != null) {
1506 // fPaintManager.dispose();
1507 // fPaintManager = null;
1509 if (fActionGroups != null) {
1510 fActionGroups.dispose();
1511 fActionGroups = null;
1515 // protected AnnotationType getAnnotationType(String preferenceKey) {
1516 // Iterator e = ANNOTATION_MAP.keySet().iterator();
1517 // while (e.hasNext()) {
1518 // AnnotationType type = (AnnotationType) e.next();
1519 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1520 // if (info != null) {
1521 // if (preferenceKey.equals(info.fColorPreference)
1522 // || preferenceKey.equals(info.fEditorPreference)
1523 // || preferenceKey.equals(info.fOverviewRulerPreference))
1530 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
1532 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
1534 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1536 String p = event.getProperty();
1537 if (CLOSE_BRACKETS_PHP.equals(p)) {
1538 fBracketInserter.setCloseBracketsPHPEnabled(getPreferenceStore()
1542 if (CLOSE_STRINGS_PHP.equals(p)) {
1543 fBracketInserter.setCloseStringsPHPEnabled(getPreferenceStore()
1547 if (CLOSE_BRACKETS_HTML.equals(p)) {
1548 fBracketInserter.setCloseBracketsHTMLEnabled(getPreferenceStore()
1552 if (CLOSE_STRINGS_HTML.equals(p)) {
1553 fBracketInserter.setCloseStringsHTMLEnabled(getPreferenceStore()
1557 if (SPACES_FOR_TABS.equals(p)) {
1558 if (isTabConversionEnabled())
1559 startTabConversion();
1561 stopTabConversion();
1564 if (MATCHING_BRACKETS.equals(p)) {
1565 if (isBracketHighlightingEnabled())
1566 startBracketHighlighting();
1568 stopBracketHighlighting();
1571 if (MATCHING_BRACKETS_COLOR.equals(p)) {
1572 if (fBracketPainter != null)
1574 .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR));
1577 if (CURRENT_LINE.equals(p)) {
1578 if (isLineHighlightingEnabled())
1579 startLineHighlighting();
1581 stopLineHighlighting();
1584 if (CURRENT_LINE_COLOR.equals(p)) {
1585 if (fLinePainter != null) {
1586 stopLineHighlighting();
1587 startLineHighlighting();
1591 if (PRINT_MARGIN.equals(p)) {
1592 if (isPrintMarginVisible())
1598 if (PRINT_MARGIN_COLOR.equals(p)) {
1599 if (fPrintMarginPainter != null)
1601 .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR));
1604 if (PRINT_MARGIN_COLUMN.equals(p)) {
1605 if (fPrintMarginPainter != null)
1606 fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore()
1607 .getInt(PRINT_MARGIN_COLUMN));
1610 // if (OVERVIEW_RULER.equals(p)) {
1611 // if (isOverviewRulerVisible())
1612 // showOverviewRuler();
1614 // hideOverviewRuler();
1617 // AnnotationType type = getAnnotationType(p);
1618 // if (type != null) {
1620 // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type);
1621 // if (info.fColorPreference.equals(p)) {
1622 // Color color = getColor(type);
1623 // if (fProblemPainter != null) {
1624 // fProblemPainter.setColor(type, color);
1625 // fProblemPainter.paint(IPainter.CONFIGURATION);
1627 // setColorInOverviewRuler(type, color);
1631 // if (info.fEditorPreference.equals(p)) {
1632 // if (isAnnotationIndicationEnabled(type))
1633 // startAnnotationIndication(type);
1635 // stopAnnotationIndication(type);
1639 // if (info.fOverviewRulerPreference.equals(p)) {
1640 // if (isAnnotationIndicationInOverviewRulerEnabled(type))
1641 // showAnnotationIndicationInOverviewRuler(type, true);
1643 // showAnnotationIndicationInOverviewRuler(type, false);
1647 IContentAssistant c = asv.getContentAssistant();
1648 if (c instanceof ContentAssistant)
1649 ContentAssistPreference.changeConfiguration((ContentAssistant) c,
1650 getPreferenceStore(), event);
1653 super.handlePreferenceStoreChanged(event);
1657 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
1659 protected void handlePreferencePropertyChanged(
1660 org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
1661 AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1663 String p = event.getProperty();
1664 if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1665 asv.updateIndentationPrefixes();
1666 if (fTabConverter != null)
1667 fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1670 super.handlePreferencePropertyChanged(event);
1673 * Handles a property change event describing a change of the php core's
1674 * preferences and updates the preference related editor properties.
1677 * the property change event
1680 // handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent
1682 // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
1683 // if (asv != null) {
1684 // String p = event.getProperty();
1685 // if (CODE_FORMATTER_TAB_SIZE.equals(p)) {
1686 // asv.updateIndentationPrefixes();
1687 // if (fTabConverter != null)
1688 // fTabConverter.setNumberOfSpacesPerTab(getTabSize());
1693 * @see PHPEditor#createJavaSourceViewer(Composite, IVerticalRuler, int)
1695 protected ISourceViewer createJavaSourceViewer(Composite parent,
1696 IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
1697 boolean isOverviewRulerVisible, int styles) {
1698 return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler,
1699 isOverviewRulerVisible, styles);
1701 // protected ISourceViewer createJavaSourceViewer(Composite parent,
1702 // IVerticalRuler ruler, int styles) {
1703 // return new AdaptedSourceViewer(parent, ruler, styles);
1705 private boolean isValidSelection(int offset, int length) {
1706 IDocumentProvider provider = getDocumentProvider();
1707 if (provider != null) {
1708 IDocument document = provider.getDocument(getEditorInput());
1709 if (document != null) {
1710 int end = offset + length;
1711 int documentLength = document.getLength();
1712 return 0 <= offset && offset <= documentLength && 0 <= end
1713 && end <= documentLength;
1719 * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput)
1721 protected boolean canHandleMove(IEditorInput originalElement,
1722 IEditorInput movedElement) {
1723 String oldExtension = ""; //$NON-NLS-1$
1724 if (originalElement instanceof IFileEditorInput) {
1725 IFile file = ((IFileEditorInput) originalElement).getFile();
1727 String ext = file.getFileExtension();
1732 String newExtension = ""; //$NON-NLS-1$
1733 if (movedElement instanceof IFileEditorInput) {
1734 IFile file = ((IFileEditorInput) movedElement).getFile();
1736 newExtension = file.getFileExtension();
1738 return oldExtension.equals(newExtension);
1741 * @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager)
1743 public void editorContextMenuAboutToShow(IMenuManager menu) {
1744 super.editorContextMenuAboutToShow(menu);
1745 ActionContext context = new ActionContext(getSelectionProvider()
1747 fContextMenuGroup.setContext(context);
1748 fContextMenuGroup.fillContextMenu(menu);
1749 fContextMenuGroup.setContext(null);
1752 * @see JavaEditor#setOutlinePageInput(JavaOutlinePage, IEditorInput)
1754 protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input) {
1756 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1757 .getWorkingCopyManager();
1758 page.setInput(manager.getWorkingCopy(input));
1762 * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation,
1765 // protected void performSaveOperation(WorkspaceModifyOperation operation,
1766 // IProgressMonitor progressMonitor) {
1767 // IDocumentProvider p = getDocumentProvider();
1768 // if (p instanceof PHPDocumentProvider) {
1769 // PHPDocumentProvider cp = (PHPDocumentProvider) p;
1770 // cp.setSavePolicy(fSavePolicy);
1774 // super.performSaveOperation(operation, progressMonitor);
1776 // if (p instanceof PHPDocumentProvider) {
1777 // PHPDocumentProvider cp = (PHPDocumentProvider) p;
1778 // cp.setSavePolicy(null);
1783 * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean,
1784 * org.eclipse.core.runtime.IProgressMonitor)
1786 protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) {
1787 IDocumentProvider p = getDocumentProvider();
1788 if (p instanceof PHPDocumentProvider) {
1789 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1790 cp.setSavePolicy(fSavePolicy);
1793 super.performSave(overwrite, progressMonitor);
1795 if (p instanceof PHPDocumentProvider) {
1796 PHPDocumentProvider cp = (PHPDocumentProvider) p;
1797 cp.setSavePolicy(null);
1802 * @see AbstractTextEditor#doSaveAs
1804 public void doSaveAs() {
1805 if (askIfNonWorkbenchEncodingIsOk()) {
1810 * @see AbstractTextEditor#doSave(IProgressMonitor)
1812 public void doSave(IProgressMonitor progressMonitor) {
1813 IDocumentProvider p = getDocumentProvider();
1815 // editor has been closed
1818 if (!askIfNonWorkbenchEncodingIsOk()) {
1819 progressMonitor.setCanceled(true);
1822 if (p.isDeleted(getEditorInput())) {
1823 if (isSaveAsAllowed()) {
1825 * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the
1826 * editors. Changed Behavior to make sure that if called inside a
1827 * regular save (because of deletion of input element) there is a way
1828 * to report back to the caller.
1830 // performSaveAs(progressMonitor);
1831 super.doSave(progressMonitor);
1834 * 1GF5YOX: ITPJUI:ALL - Save of delete file claims it's still there
1835 * Missing resources.
1837 Shell shell = getSite().getShell();
1838 MessageDialog.openError(shell, PHPEditorMessages
1839 .getString("PHPUnitEditor.error.saving.title1"), PHPEditorMessages
1840 .getString("PHPUnitEditor.error.saving.message1")); //$NON-NLS-1$ //$NON-NLS-2$
1843 setStatusLineErrorMessage(null);
1844 super.doSave(progressMonitor);
1845 // IWorkingCopyManager manager=
1846 // JavaPlugin.getDefault().getWorkingCopyManager();
1847 // ICompilationUnit unit= manager.getWorkingCopy(getEditorInput());
1849 // if (unit != null) {
1850 // synchronized (unit) {
1851 // performSaveOperation(createSaveOperation(false), progressMonitor);
1854 // performSaveOperation(createSaveOperation(false), progressMonitor);
1858 * Asks the user if it is ok to store in non-workbench encoding.
1860 * @return <true>if the user wants to continue
1862 private boolean askIfNonWorkbenchEncodingIsOk() {
1863 IDocumentProvider provider = getDocumentProvider();
1864 if (provider instanceof IStorageDocumentProvider) {
1865 IEditorInput input = getEditorInput();
1866 IStorageDocumentProvider storageProvider = (IStorageDocumentProvider) provider;
1867 String encoding = storageProvider.getEncoding(input);
1868 String defaultEncoding = storageProvider.getDefaultEncoding();
1869 if (encoding != null && !encoding.equals(defaultEncoding)) {
1870 Shell shell = getSite().getShell();
1871 String title = PHPEditorMessages
1872 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$
1878 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"),
1879 new String[]{input.getName(), encoding}); //$NON-NLS-1$
1884 .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message2"),
1885 new String[]{encoding}); //$NON-NLS-1$
1886 return MessageDialog.openQuestion(shell, title, msg);
1892 * @see IReconcilingParticipant#reconciled()
1894 public void reconciled() {
1895 if (synchronizeOutlineOnCursorMove()) {
1896 Shell shell = getSite().getShell();
1897 if (shell != null && !shell.isDisposed()) {
1898 shell.getDisplay().asyncExec(new Runnable() {
1900 synchronizeOutlinePageSelection();
1907 protected void updateStateDependentActions() {
1908 super.updateStateDependentActions();
1909 fGenerateActionGroup.editorStateChanged();
1912 private boolean synchronizeOutlineOnCursorMove() {
1913 return PreferenceConstants.getPreferenceStore().getBoolean(
1914 PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE);
1918 * Returns the updated java element for the old java element.
1920 private IJavaElement findElement(IJavaElement element) {
1921 if (element == null)
1923 IWorkingCopyManager manager = PHPeclipsePlugin.getDefault()
1924 .getWorkingCopyManager();
1925 ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
1928 synchronized (unit) {
1931 IJavaElement[] findings = unit.findElements(element);
1932 if (findings != null && findings.length > 0)
1934 } catch (JavaModelException x) {
1935 PHPeclipsePlugin.log(x.getStatus());
1936 // nothing found, be tolerant and go on
1942 * Returns the offset of the given Java element.
1944 private int getOffset(IJavaElement element) {
1945 if (element instanceof ISourceReference) {
1946 ISourceReference sr = (ISourceReference) element;
1948 ISourceRange srcRange = sr.getSourceRange();
1949 if (srcRange != null)
1950 return srcRange.getOffset();
1951 } catch (JavaModelException e) {
1957 * @see AbstractTextEditor#rememberSelection()
1959 protected void rememberSelection() {
1960 ISelectionProvider sp = getSelectionProvider();
1961 fRememberedSelection = (sp == null ? null : (ITextSelection) sp
1963 if (fRememberedSelection != null) {
1964 fRememberedElement = getElementAt(fRememberedSelection.getOffset(), true);
1965 fRememberedElementOffset = getOffset(fRememberedElement);
1969 * @see AbstractTextEditor#restoreSelection()
1971 protected void restoreSelection() {
1973 if (getSourceViewer() == null || fRememberedSelection == null)
1975 IJavaElement newElement = findElement(fRememberedElement);
1976 int newOffset = getOffset(newElement);
1977 int delta = (newOffset > -1 && fRememberedElementOffset > -1) ? newOffset
1978 - fRememberedElementOffset : 0;
1979 if (isValidSelection(delta + fRememberedSelection.getOffset(),
1980 fRememberedSelection.getLength()))
1981 selectAndReveal(delta + fRememberedSelection.getOffset(),
1982 fRememberedSelection.getLength());
1984 fRememberedSelection = null;
1985 fRememberedElement = null;
1986 fRememberedElementOffset = -1;