X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java index df0ea7e..34ceb6f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java @@ -1,5 +1,5 @@ package net.sourceforge.phpeclipse.phpeditor; -import java.lang.reflect.InvocationTargetException; + import java.text.MessageFormat; import java.util.ArrayList; import java.util.Iterator; @@ -12,9 +12,7 @@ import net.sourceforge.phpdt.core.ISourceReference; import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.internal.compiler.parser.Scanner; -import net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction; import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup; -import net.sourceforge.phpdt.internal.ui.actions.RemoveBlockCommentAction; import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference; import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher; @@ -28,19 +26,19 @@ import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.text.BadLocationException; @@ -61,6 +59,7 @@ import org.eclipse.jface.text.source.IVerticalRuler; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.VerifyEvent; @@ -74,7 +73,6 @@ import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.dialogs.SaveAsDialog; import org.eclipse.ui.editors.text.IStorageDocumentProvider; import org.eclipse.ui.help.WorkbenchHelp; @@ -83,6 +81,7 @@ import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.TextOperationAction; + /******************************************************************************* * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This * program and the accompanying materials are made available under the terms of @@ -95,10 +94,12 @@ import org.eclipse.ui.texteditor.TextOperationAction; /** * PHP specific text editor. */ -public class PHPUnitEditor extends PHPEditor { +public class PHPUnitEditor extends PHPEditor { //implements + // IJavaReconcilingListener { interface ITextConverter { void customizeDocumentCommand(IDocument document, DocumentCommand command); }; + // class AdaptedRulerLayout extends Layout { // // protected int fGap; @@ -138,9 +139,11 @@ public class PHPUnitEditor extends PHPEditor { // orWidth, clArea.height - 3 * scrollbarHeight); // } // - // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth - + // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth + // - // 2 * fGap, clArea.height); - // vr.getControl().setBounds(0, 0, vrWidth, clArea.height - scrollbarHeight); + // vr.getControl().setBounds(0, 0, vrWidth, clArea.height - + // scrollbarHeight); // // } else { // StyledText textWidget = fAdaptedSourceViewer.getTextWidget(); @@ -212,7 +215,8 @@ public class PHPUnitEditor extends PHPEditor { // super.doOperation(operation); // } // - // public void insertTextConverter(ITextConverter textConverter, int index) { + // public void insertTextConverter(ITextConverter textConverter, int index) + // { // throw new UnsupportedOperationException(); // } // @@ -369,17 +373,27 @@ public class PHPUnitEditor extends PHPEditor { // }; class AdaptedSourceViewer extends JavaSourceViewer { private List fTextConverters; + private boolean fIgnoreTextConverters = false; + // private JavaCorrectionAssistant fCorrectionAssistant; public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, - int styles) { + int styles, IPreferenceStore store) { super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, - styles); + styles, store); } + + // public AdaptedSourceViewer(Composite parent, + // IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, + // boolean showAnnotationsOverview, int styles) { + // super(parent, verticalRuler, overviewRuler, + // showAnnotationsOverview, styles); + // } public IContentAssistant getContentAssistant() { return fContentAssistant; } + /* * @see ITextOperationTarget#doOperation(int) */ @@ -387,22 +401,23 @@ public class PHPUnitEditor extends PHPEditor { if (getTextWidget() == null) return; switch (operation) { - case CONTENTASSIST_PROPOSALS : - String msg = fContentAssistant.showPossibleCompletions(); - setStatusLineErrorMessage(msg); - return; - // case CORRECTIONASSIST_PROPOSALS: - // fCorrectionAssistant.showPossibleCompletions(); - // return; - case UNDO : - fIgnoreTextConverters = true; - break; - case REDO : - fIgnoreTextConverters = true; - break; + case CONTENTASSIST_PROPOSALS: + String msg = fContentAssistant.showPossibleCompletions(); + setStatusLineErrorMessage(msg); + return; + // case CORRECTIONASSIST_PROPOSALS: + // fCorrectionAssistant.showPossibleCompletions(); + // return; + case UNDO: + fIgnoreTextConverters = true; + break; + case REDO: + fIgnoreTextConverters = true; + break; } super.doOperation(operation); } + /* * @see ITextOperationTarget#canDoOperation(int) */ @@ -411,6 +426,7 @@ public class PHPUnitEditor extends PHPEditor { // return isEditable(); return super.canDoOperation(operation); } + /* * @see TextViewer#handleDispose() */ @@ -421,9 +437,11 @@ public class PHPUnitEditor extends PHPEditor { // } super.handleDispose(); } + public void insertTextConverter(ITextConverter textConverter, int index) { throw new UnsupportedOperationException(); } + public void addTextConverter(ITextConverter textConverter) { if (fTextConverters == null) { fTextConverters = new ArrayList(1); @@ -431,6 +449,7 @@ public class PHPUnitEditor extends PHPEditor { } else if (!fTextConverters.contains(textConverter)) fTextConverters.add(textConverter); } + public void removeTextConverter(ITextConverter textConverter) { if (fTextConverters != null) { fTextConverters.remove(textConverter); @@ -438,6 +457,7 @@ public class PHPUnitEditor extends PHPEditor { fTextConverters = null; } } + /* * @see TextViewer#customizeDocumentCommand(DocumentCommand) */ @@ -450,6 +470,7 @@ public class PHPUnitEditor extends PHPEditor { } fIgnoreTextConverters = false; } + // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 public void updateIndentationPrefixes() { SourceViewerConfiguration configuration = getSourceViewerConfiguration(); @@ -460,6 +481,7 @@ public class PHPUnitEditor extends PHPEditor { setIndentPrefixes(prefixes, types[i]); } } + /* * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper) */ @@ -468,6 +490,7 @@ public class PHPUnitEditor extends PHPEditor { return false; return super.requestWidgetToken(requester); } + /* * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration) */ @@ -481,17 +504,23 @@ public class PHPUnitEditor extends PHPEditor { // IDocument.DEFAULT_CONTENT_TYPE); } }; + static class TabConverter implements ITextConverter { private int fTabRatio; + private ILineTracker fLineTracker; + public TabConverter() { } + public void setNumberOfSpacesPerTab(int ratio) { fTabRatio = ratio; } + public void setLineTracker(ILineTracker lineTracker) { fLineTracker = lineTracker; } + private int insertTabString(StringBuffer buffer, int offsetInLine) { if (fTabRatio == 0) return 0; @@ -501,6 +530,7 @@ public class PHPUnitEditor extends PHPEditor { buffer.append(' '); return remainder; } + public void customizeDocumentCommand(IDocument document, DocumentCommand command) { String text = command.text; @@ -539,11 +569,14 @@ public class PHPUnitEditor extends PHPEditor { } } }; + private static class ExitPolicy implements LinkedPositionUI.ExitPolicy { final char fExitCharacter; + public ExitPolicy(char exitCharacter) { fExitCharacter = exitCharacter; } + /* * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionManager, * org.eclipse.swt.events.VerifyEvent, int, int) @@ -558,47 +591,60 @@ public class PHPUnitEditor extends PHPEditor { return new ExitFlags(LinkedPositionUI.COMMIT, true); } switch (event.character) { - case '\b' : - if (manager.getFirstPosition().length == 0) - return new ExitFlags(0, false); - else - return null; - case '\n' : - case '\r' : - return new ExitFlags(LinkedPositionUI.COMMIT, true); - default : + case '\b': + if (manager.getFirstPosition().length == 0) + return new ExitFlags(0, false); + else return null; + case '\n': + case '\r': + return new ExitFlags(LinkedPositionUI.COMMIT, true); + default: + return null; } } } + private static class BracketLevel { int fOffset; + int fLength; + LinkedPositionManager fManager; + LinkedPositionUI fEditor; }; - private class BracketInserter - implements - VerifyKeyListener, - LinkedPositionUI.ExitListener { + + private class BracketInserter implements VerifyKeyListener, + LinkedPositionUI.ExitListener { private boolean fCloseBracketsPHP = true; + private boolean fCloseStringsPHP = true; + private boolean fCloseBracketsHTML = true; + private boolean fCloseStringsHTML = true; + private int fOffset; + private int fLength; + public void setCloseBracketsPHPEnabled(boolean enabled) { fCloseBracketsPHP = enabled; } + public void setCloseStringsPHPEnabled(boolean enabled) { fCloseStringsPHP = enabled; } + public void setCloseBracketsHTMLEnabled(boolean enabled) { fCloseBracketsHTML = enabled; } + public void setCloseStringsHTMLEnabled(boolean enabled) { fCloseStringsHTML = enabled; } + private boolean hasIdentifierToTheRight(IDocument document, int offset) { try { int end = offset; @@ -613,6 +659,7 @@ public class PHPUnitEditor extends PHPEditor { return true; } } + private boolean hasIdentifierToTheLeft(IDocument document, int offset) { try { int start = offset; @@ -627,6 +674,7 @@ public class PHPUnitEditor extends PHPEditor { return true; } } + private boolean hasCharacterToTheRight(IDocument document, int offset, char character) { try { @@ -641,6 +689,7 @@ public class PHPUnitEditor extends PHPEditor { return true; } } + /* * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent) */ @@ -657,105 +706,110 @@ public class PHPUnitEditor extends PHPEditor { String type = partition.getType(); if (type.equals(IPHPPartitions.PHP_PARTITIONING)) { switch (event.character) { - case '(' : - if (hasCharacterToTheRight(document, offset + length, '(')) - return; - // fall through - case '[' : - if (!fCloseBracketsPHP) + case '(': + if (hasCharacterToTheRight(document, offset + length, '(')) + return; + // fall through + case '[': + if (!fCloseBracketsPHP) + return; + if (hasIdentifierToTheRight(document, offset + length)) + return; + // fall through + case '"': + if (event.character == '"') { + if (!fCloseStringsPHP) return; + // changed for statements like echo "" print "" + // if (hasIdentifierToTheLeft(document, offset) + // || + // hasIdentifierToTheRight(document, offset + + // length)) if (hasIdentifierToTheRight(document, offset + length)) return; - // fall through - case '"' : - if (event.character == '"') { - if (!fCloseStringsPHP) - return; - // changed for statements like echo "" print "" - // if (hasIdentifierToTheLeft(document, offset) || - // hasIdentifierToTheRight(document, offset + length)) - if (hasIdentifierToTheRight(document, offset + length)) - return; - } - // ITypedRegion partition= document.getPartition(offset); - // if (! - // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) && - // (partition.getOffset() != offset)) - // return; - final char character = event.character; - final char closingCharacter = getPeerCharacter(character); - final StringBuffer buffer = new StringBuffer(); - buffer.append(character); - buffer.append(closingCharacter); - document.replace(offset, length, buffer.toString()); - LinkedPositionManager manager = new LinkedPositionManager( - document); - manager.addPosition(offset + 1, 0); - fOffset = offset; - fLength = 2; - LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, - manager); - editor.setCancelListener(this); - editor.setExitPolicy(new ExitPolicy(closingCharacter)); - editor.setFinalCaretOffset(offset + 2); - editor.enter(); - IRegion newSelection = editor.getSelectedRegion(); - sourceViewer.setSelectedRange(newSelection.getOffset(), - newSelection.getLength()); - event.doit = false; + } + // ITypedRegion partition= + // document.getPartition(offset); + // if (! + // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) + // && + // (partition.getOffset() != offset)) + // return; + final char character = event.character; + final char closingCharacter = getPeerCharacter(character); + final StringBuffer buffer = new StringBuffer(); + buffer.append(character); + buffer.append(closingCharacter); + document.replace(offset, length, buffer.toString()); + LinkedPositionManager manager = new LinkedPositionManager(document); + manager.addPosition(offset + 1, 0); + fOffset = offset; + fLength = 2; + LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, + manager); + editor.setCancelListener(this); + editor.setExitPolicy(new ExitPolicy(closingCharacter)); + editor.setFinalCaretOffset(offset + 2); + editor.enter(); + IRegion newSelection = editor.getSelectedRegion(); + sourceViewer.setSelectedRange(newSelection.getOffset(), + newSelection.getLength()); + event.doit = false; } } else if (type.equals(IPHPPartitions.HTML) || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) { switch (event.character) { - case '(' : - if (hasCharacterToTheRight(document, offset + length, '(')) + case '(': + if (hasCharacterToTheRight(document, offset + length, '(')) + return; + // fall through + case '[': + if (!fCloseBracketsHTML) + return; + if (hasIdentifierToTheRight(document, offset + length)) + return; + // fall through + case '"': + if (event.character == '"') { + if (!fCloseStringsHTML) return; - // fall through - case '[' : - if (!fCloseBracketsHTML) + if (hasIdentifierToTheLeft(document, offset) + || hasIdentifierToTheRight(document, offset + length)) return; - if (hasIdentifierToTheRight(document, offset + length)) - return; - // fall through - case '"' : - if (event.character == '"') { - if (!fCloseStringsHTML) - return; - if (hasIdentifierToTheLeft(document, offset) - || hasIdentifierToTheRight(document, offset + length)) - return; - } - // ITypedRegion partition= document.getPartition(offset); - // if (! - // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) && - // (partition.getOffset() != offset)) - // return; - final char character = event.character; - final char closingCharacter = getPeerCharacter(character); - final StringBuffer buffer = new StringBuffer(); - buffer.append(character); - buffer.append(closingCharacter); - document.replace(offset, length, buffer.toString()); - LinkedPositionManager manager = new LinkedPositionManager( - document); - manager.addPosition(offset + 1, 0); - fOffset = offset; - fLength = 2; - LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, - manager); - editor.setCancelListener(this); - editor.setExitPolicy(new ExitPolicy(closingCharacter)); - editor.setFinalCaretOffset(offset + 2); - editor.enter(); - IRegion newSelection = editor.getSelectedRegion(); - sourceViewer.setSelectedRange(newSelection.getOffset(), - newSelection.getLength()); - event.doit = false; + } + // ITypedRegion partition= + // document.getPartition(offset); + // if (! + // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) + // && + // (partition.getOffset() != offset)) + // return; + final char character = event.character; + final char closingCharacter = getPeerCharacter(character); + final StringBuffer buffer = new StringBuffer(); + buffer.append(character); + buffer.append(closingCharacter); + document.replace(offset, length, buffer.toString()); + LinkedPositionManager manager = new LinkedPositionManager(document); + manager.addPosition(offset + 1, 0); + fOffset = offset; + fLength = 2; + LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, + manager); + editor.setCancelListener(this); + editor.setExitPolicy(new ExitPolicy(closingCharacter)); + editor.setFinalCaretOffset(offset + 2); + editor.enter(); + IRegion newSelection = editor.getSelectedRegion(); + sourceViewer.setSelectedRange(newSelection.getOffset(), + newSelection.getLength()); + event.doit = false; } } } catch (BadLocationException e) { } } + /* * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean) */ @@ -771,27 +825,35 @@ public class PHPUnitEditor extends PHPEditor { } } } + /** The editor's save policy */ protected ISavePolicy fSavePolicy; + /** - * Listener to annotation model changes that updates the error tick in the - * tab image + * Listener to annotation model changes that updates the error tick in the tab + * image */ private JavaEditorErrorTickUpdater fJavaEditorErrorTickUpdater; + /** The editor's paint manager */ // private PaintManager fPaintManager; /** The editor's bracket painter */ private BracketPainter fBracketPainter; + /** The editor's bracket matcher */ private PHPPairMatcher fBracketMatcher; + /** The editor's line painter */ private LinePainter fLinePainter; + /** The editor's print margin ruler painter */ private PrintMarginPainter fPrintMarginPainter; + /** The editor's problem painter */ // private ProblemPainter fProblemPainter; /** The editor's tab converter */ private TabConverter fTabConverter; + /** History for structure select action */ //private SelectionHistory fSelectionHistory; /** The preference property change listener for php core. */ @@ -799,16 +861,21 @@ public class PHPUnitEditor extends PHPEditor { // PropertyChangeListener(); /** The remembered java element */ private IJavaElement fRememberedElement; + /** The remembered selection */ private ITextSelection fRememberedSelection; + /** The remembered php element offset */ private int fRememberedElementOffset; + /** The bracket inserter. */ private BracketInserter fBracketInserter = new BracketInserter(); - + /** The standard action groups added to the menu */ private GenerateActionGroup fGenerateActionGroup; + private CompositeActionGroup fContextMenuGroup; + // private class PropertyChangeListener implements IPropertyChangeListener { // /* // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) @@ -821,22 +888,31 @@ public class PHPUnitEditor extends PHPEditor { // } /* Preference key for code formatter tab size */ private final static String CODE_FORMATTER_TAB_SIZE = JavaCore.FORMATTER_TAB_SIZE; + /** Preference key for matching brackets */ private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS; + /** Preference key for matching brackets color */ private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR; + /** Preference key for highlighting current line */ private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE; + /** Preference key for highlight color of current line */ private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR; + /** Preference key for showing print marging ruler */ private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN; + /** Preference key for print margin ruler color */ private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR; + /** Preference key for print margin ruler column */ private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN; + /** Preference key for inserting spaces rather than tabs */ private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS; + /** Preference key for error indication */ // private final static String ERROR_INDICATION = // PreferenceConstants.EDITOR_PROBLEM_INDICATION; @@ -851,54 +927,79 @@ public class PHPUnitEditor extends PHPEditor { // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR; /** Preference key for task indication */ private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION; + /** Preference key for task color */ private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR; + /** Preference key for bookmark indication */ private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION; + /** Preference key for bookmark color */ private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR; + /** Preference key for search result indication */ private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION; + /** Preference key for search result color */ private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR; + /** Preference key for unknown annotation indication */ private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION; + /** Preference key for unknown annotation color */ private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR; + /** Preference key for linked position color */ private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR; + /** Preference key for shwoing the overview ruler */ private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER; + /** Preference key for error indication in overview ruler */ private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for warning indication in overview ruler */ private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for task indication in overview ruler */ private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for bookmark indication in overview ruler */ private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for search result indication in overview ruler */ private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for unknown annotation indication in overview ruler */ private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER; + /** Preference key for automatically closing strings */ private final static String CLOSE_STRINGS_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_PHP; + /** Preference key for automatically wrapping Java strings */ private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS; + /** Preference key for automatically closing brackets and parenthesis */ private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP; + /** Preference key for automatically closing phpdocs and comments */ private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS; + /** Preference key for automatically adding phpdoc tags */ private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS; + /** Preference key for automatically formatting phpdocs */ private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS; + /** Preference key for automatically closing strings */ private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML; + /** Preference key for automatically closing brackets and parenthesis */ private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML; + /** Preference key for smart paste */ private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE; + // private final static class AnnotationInfo { // public String fColorPreference; // public String fOverviewRulerPreference; @@ -970,6 +1071,7 @@ public class PHPUnitEditor extends PHPEditor { fSavePolicy = null; fJavaEditorErrorTickUpdater = new JavaEditorErrorTickUpdater(this); } + /* * @see AbstractTextEditor#createActions() */ @@ -984,8 +1086,9 @@ public class PHPUnitEditor extends PHPEditor { // setAction("CorrectionAssistProposal", action); //$NON-NLS-1$ // markAsStateDependentAction("CorrectionAssistProposal", true); // //$NON-NLS-1$ - //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.QUICK_FIX_ACTION); - action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), + //// WorkbenchHelp.setHelp(action, + // IJavaHelpContextIds.QUICK_FIX_ACTION); + action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$ action .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); @@ -993,16 +1096,18 @@ public class PHPUnitEditor extends PHPEditor { markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ // WorkbenchHelp.setHelp(action, // IJavaHelpContextIds.CONTENT_ASSIST_ACTION); - action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), - "ContentAssistContextInformation.", this, - ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$ - action - .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); - setAction("ContentAssistContextInformation", action); //$NON-NLS-1$ - markAsStateDependentAction("ContentAssistContextInformation", true); //$NON-NLS-1$ + // action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), + // "ContentAssistContextInformation.", this, + // ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$ + // action + // .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); + // setAction("ContentAssistContextInformation", action); //$NON-NLS-1$ + // markAsStateDependentAction("ContentAssistContextInformation", true); + // //$NON-NLS-1$ // WorkbenchHelp.setHelp(action, // IJavaHelpContextIds.PARAMETER_HINTS_ACTION); - // action= new TextOperationAction(PHPEditorMessages.getResourceBundle(), + // action= new + // TextOperationAction(PHPEditorMessages.getResourceBundle(), // "ContentAssistCompletePrefix.", this, CONTENTASSIST_COMPLETE_PREFIX); // //$NON-NLS-1$ // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_COMPLETE_PREFIX); @@ -1023,14 +1128,16 @@ public class PHPUnitEditor extends PHPEditor { setAction("Uncomment", action); //$NON-NLS-1$ markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$ // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION); + action = new ToggleCommentAction(PHPEditorMessages.getResourceBundle(), - "ToggleComment.", this, getSourceViewerConfiguration() - .getDefaultPrefixes(getSourceViewer(), "")); //$NON-NLS-1$ //$NON-NLS-2$ + "ToggleComment.", this); //$NON-NLS-1$ action.setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT); setAction("ToggleComment", action); //$NON-NLS-1$ markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$ - // WorkbenchHelp.setHelp(action, + //WorkbenchHelp.setHelp(action, // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION); + configureToggleCommentAction(); + action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT); @@ -1038,22 +1145,23 @@ public class PHPUnitEditor extends PHPEditor { markAsStateDependentAction("Format", true); //$NON-NLS-1$ markAsSelectionDependentAction("Format", true); //$NON-NLS-1$ // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION); - action = new AddBlockCommentAction(PHPEditorMessages.getResourceBundle(), - "AddBlockComment.", this); //$NON-NLS-1$ - action - .setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT); - setAction("AddBlockComment", action); //$NON-NLS-1$ - markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$ - markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$ - // WorkbenchHelp.setHelp(action, - // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION); - action = new RemoveBlockCommentAction( - PHPEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$ - action - .setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT); - setAction("RemoveBlockComment", action); //$NON-NLS-1$ - markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ - markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ + +// action = new AddBlockCommentAction(PHPEditorMessages.getResourceBundle(), +// "AddBlockComment.", this); //$NON-NLS-1$ +// action +// .setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT); +// setAction("AddBlockComment", action); //$NON-NLS-1$ +// markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$ +// markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$ +// // WorkbenchHelp.setHelp(action, +// // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION); +// action = new RemoveBlockCommentAction( +// PHPEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$ +// action +// .setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT); +// setAction("RemoveBlockComment", action); //$NON-NLS-1$ +// markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ +// markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ // WorkbenchHelp.setHelp(action, // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION); // action= new IndentAction(PHPEditorMessages.getResourceBundle(), @@ -1079,30 +1187,36 @@ public class PHPUnitEditor extends PHPEditor { fGenerateActionGroup = new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); fActionGroups = new CompositeActionGroup( - new ActionGroup[]{fGenerateActionGroup}); - // We have to keep the context menu group separate to have better control + new ActionGroup[] { fGenerateActionGroup }); + // We have to keep the context menu group separate to have better + // control // over positioning - fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup }); - // rg, - // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)}); - + fContextMenuGroup = new CompositeActionGroup( + new ActionGroup[] { fGenerateActionGroup }); + // rg, + // new LocalHistoryActionGroup(this, + // ITextEditorActionConstants.GROUP_EDIT)}); + } + /* * @see JavaEditor#getElementAt(int) */ protected IJavaElement getElementAt(int offset) { return getElementAt(offset, true); } + /** - * Returns the most narrow element including the given offset. If reconcile - * is true the editor's input element is reconciled in - * advance. If it is false this method only returns a result - * if the editor's input element does not need to be reconciled. + * Returns the most narrow element including the given offset. If + * reconcile is true the editor's input element + * is reconciled in advance. If it is false this method only + * returns a result if the editor's input element does not need to be + * reconciled. * * @param offset - * the offset included by the retrieved element + * the offset included by the retrieved element * @param reconcile - * true if working copy should be reconciled + * true if working copy should be reconciled */ protected IJavaElement getElementAt(int offset, boolean reconcile) { IWorkingCopyManager manager = PHPeclipsePlugin.getDefault() @@ -1124,6 +1238,7 @@ public class PHPUnitEditor extends PHPEditor { } return null; } + /* * @see JavaEditor#getCorrespondingElement(IJavaElement) */ @@ -1136,6 +1251,7 @@ public class PHPUnitEditor extends PHPEditor { } return null; } + public void createPartControl(Composite parent) { super.createPartControl(parent); // fPaintManager = new PaintManager(getSourceViewer()); @@ -1178,106 +1294,24 @@ public class PHPUnitEditor extends PHPEditor { ((ITextViewerExtension) sourceViewer) .prependVerifyKeyListener(fBracketInserter); } + private static char getPeerCharacter(char character) { switch (character) { - case '(' : - return ')'; - case ')' : - return '('; - case '[' : - return ']'; - case ']' : - return '['; - case '"' : - return character; - default : - throw new IllegalArgumentException(); + case '(': + return ')'; + case ')': + return '('; + case '[': + return ']'; + case ']': + return '['; + case '"': + return character; + default: + throw new IllegalArgumentException(); } } - /** - * The compilation unit editor implementation of this AbstractTextEditor - * method asks the user for the workspace path of a file resource and saves - * the document there. See http://dev.eclipse.org/bugs/show_bug.cgi?id=6295 - */ - protected void performSaveAs(IProgressMonitor progressMonitor) { - Shell shell = getSite().getShell(); - IEditorInput input = getEditorInput(); - SaveAsDialog dialog = new SaveAsDialog(shell); - IFile original = (input instanceof IFileEditorInput) - ? ((IFileEditorInput) input).getFile() - : null; - if (original != null) - dialog.setOriginalFile(original); - dialog.create(); - IDocumentProvider provider = getDocumentProvider(); - if (provider == null) { - // editor has been programmatically closed while the dialog was open - return; - } - if (provider.isDeleted(input) && original != null) { - String message = PHPEditorMessages.getFormattedString( - "CompilationUnitEditor.warning.save.delete", new Object[]{original - .getName()}); //$NON-NLS-1$ - dialog.setErrorMessage(null); - dialog.setMessage(message, IMessageProvider.WARNING); - } - if (dialog.open() == Dialog.CANCEL) { - if (progressMonitor != null) - progressMonitor.setCanceled(true); - return; - } - IPath filePath = dialog.getResult(); - if (filePath == null) { - if (progressMonitor != null) - progressMonitor.setCanceled(true); - return; - } - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IFile file = workspace.getRoot().getFile(filePath); - final IEditorInput newInput = new FileEditorInput(file); - WorkspaceModifyOperation op = new WorkspaceModifyOperation() { - public void execute(final IProgressMonitor monitor) throws CoreException { - getDocumentProvider().saveDocument(monitor, newInput, - getDocumentProvider().getDocument(getEditorInput()), true); - } - }; - boolean success = false; - try { - provider.aboutToChange(newInput); - new ProgressMonitorDialog(shell).run(false, true, op); - success = true; - } catch (InterruptedException x) { - } catch (InvocationTargetException x) { - Throwable t = x.getTargetException(); - if (t instanceof CoreException) { - CoreException cx = (CoreException) t; - ErrorDialog.openError(shell, PHPEditorMessages - .getString("CompilationUnitEditor.error.saving.title2"), - PHPEditorMessages - .getString("CompilationUnitEditor.error.saving.message2"), cx - .getStatus()); //$NON-NLS-1$ //$NON-NLS-2$ - } else { - MessageDialog.openError(shell, PHPEditorMessages - .getString("CompilationUnitEditor.error.saving.title3"), - PHPEditorMessages - .getString("CompilationUnitEditor.error.saving.message3") - + t.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ - } - } finally { - provider.changed(newInput); - if (success) - setInput(newInput); - } - if (progressMonitor != null) - progressMonitor.setCanceled(!success); - } - /* - * @see AbstractTextEditor#doSetInput(IEditorInput) - */ - protected void doSetInput(IEditorInput input) throws CoreException { - super.doSetInput(input); - configureTabConverter(); - } + private void startBracketHighlighting() { if (fBracketPainter == null) { ISourceViewer sourceViewer = getSourceViewer(); @@ -1286,6 +1320,7 @@ public class PHPUnitEditor extends PHPEditor { // fPaintManager.addPainter(fBracketPainter); } } + private void stopBracketHighlighting() { if (fBracketPainter != null) { // fPaintManager.removePainter(fBracketPainter); @@ -1294,10 +1329,12 @@ public class PHPUnitEditor extends PHPEditor { fBracketPainter = null; } } + private boolean isBracketHighlightingEnabled() { IPreferenceStore store = getPreferenceStore(); return store.getBoolean(MATCHING_BRACKETS); } + private void startLineHighlighting() { if (fLinePainter == null) { ISourceViewer sourceViewer = getSourceViewer(); @@ -1306,6 +1343,7 @@ public class PHPUnitEditor extends PHPEditor { // fPaintManager.addPainter(fLinePainter); } } + private void stopLineHighlighting() { if (fLinePainter != null) { // fPaintManager.removePainter(fLinePainter); @@ -1314,10 +1352,12 @@ public class PHPUnitEditor extends PHPEditor { fLinePainter = null; } } + private boolean isLineHighlightingEnabled() { IPreferenceStore store = getPreferenceStore(); return store.getBoolean(CURRENT_LINE); } + private void showPrintMargin() { if (fPrintMarginPainter == null) { fPrintMarginPainter = new PrintMarginPainter(getSourceViewer()); @@ -1327,6 +1367,7 @@ public class PHPUnitEditor extends PHPEditor { // fPaintManager.addPainter(fPrintMarginPainter); } } + private void hidePrintMargin() { if (fPrintMarginPainter != null) { // fPaintManager.removePainter(fPrintMarginPainter); @@ -1335,10 +1376,12 @@ public class PHPUnitEditor extends PHPEditor { fPrintMarginPainter = null; } } + private boolean isPrintMarginVisible() { IPreferenceStore store = getPreferenceStore(); return store.getBoolean(PRINT_MARGIN); } + // private void startAnnotationIndication(AnnotationType annotationType) { // if (fProblemPainter == null) { // fProblemPainter = new ProblemPainter(this, getSourceViewer()); @@ -1373,7 +1416,8 @@ public class PHPUnitEditor extends PHPEditor { // private boolean isAnnotationIndicationEnabled(AnnotationType // annotationType) { // IPreferenceStore store = getPreferenceStore(); - // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType); + // AnnotationInfo info = (AnnotationInfo) + // ANNOTATION_MAP.get(annotationType); // if (info != null) // return store.getBoolean(info.fEditorPreference); // return false; @@ -1383,7 +1427,8 @@ public class PHPUnitEditor extends PHPEditor { // isAnnotationIndicationInOverviewRulerEnabled(AnnotationType // annotationType) { // IPreferenceStore store = getPreferenceStore(); - // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType); + // AnnotationInfo info = (AnnotationInfo) + // ANNOTATION_MAP.get(annotationType); // if (info != null) // return store.getBoolean(info.fOverviewRulerPreference); // return false; @@ -1409,44 +1454,18 @@ public class PHPUnitEditor extends PHPEditor { // ruler.update(); // } // } - private void configureTabConverter() { - if (fTabConverter != null) { - IDocumentProvider provider = getDocumentProvider(); - if (provider instanceof PHPDocumentProvider) { - PHPDocumentProvider cup = (PHPDocumentProvider) provider; - fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); - } - } - } + private int getTabSize() { Preferences preferences = PHPeclipsePlugin.getDefault() .getPluginPreferences(); return preferences.getInt(CODE_FORMATTER_TAB_SIZE); } - private void startTabConversion() { - if (fTabConverter == null) { - fTabConverter = new TabConverter(); - configureTabConverter(); - fTabConverter.setNumberOfSpacesPerTab(getTabSize()); - AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); - asv.addTextConverter(fTabConverter); - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 - asv.updateIndentationPrefixes(); - } - } - private void stopTabConversion() { - if (fTabConverter != null) { - AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); - asv.removeTextConverter(fTabConverter); - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 - asv.updateIndentationPrefixes(); - fTabConverter = null; - } - } + private boolean isTabConversionEnabled() { IPreferenceStore store = getPreferenceStore(); return store.getBoolean(SPACES_FOR_TABS); } + // private void showOverviewRuler() { // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); // asv.showOverviewRuler(); @@ -1475,12 +1494,15 @@ public class PHPUnitEditor extends PHPEditor { RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key); return getColor(rgb); } + private Color getColor(RGB rgb) { JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); return textTools.getColorManager().getColor(rgb); } + // private Color getColor(AnnotationType annotationType) { - // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType); + // AnnotationInfo info = (AnnotationInfo) + // ANNOTATION_MAP.get(annotationType); // if (info != null) // return getColor(info.fColorPreference); // return null; @@ -1512,6 +1534,7 @@ public class PHPUnitEditor extends PHPEditor { } super.dispose(); } + // protected AnnotationType getAnnotationType(String preferenceKey) { // Iterator e = ANNOTATION_MAP.keySet().iterator(); // while (e.hasNext()) { @@ -1617,7 +1640,8 @@ public class PHPUnitEditor extends PHPEditor { // AnnotationType type = getAnnotationType(p); // if (type != null) { // - // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(type); + // AnnotationInfo info = (AnnotationInfo) + // ANNOTATION_MAP.get(type); // if (info.fColorPreference.equals(p)) { // Color color = getColor(type); // if (fProblemPainter != null) { @@ -1653,6 +1677,7 @@ public class PHPUnitEditor extends PHPEditor { super.handlePreferenceStoreChanged(event); } } + /* * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) */ @@ -1669,12 +1694,13 @@ public class PHPUnitEditor extends PHPEditor { } super.handlePreferencePropertyChanged(event); } + /** * Handles a property change event describing a change of the php core's * preferences and updates the preference related editor properties. * * @param event - * the property change event + * the property change event */ // protected void // handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent @@ -1690,14 +1716,17 @@ public class PHPUnitEditor extends PHPEditor { // } // } /* - * @see PHPEditor#createJavaSourceViewer(Composite, IVerticalRuler, int) + * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#createJavaSourceViewer(org.eclipse.swt.widgets.Composite, + * org.eclipse.jface.text.source.IVerticalRuler, + * org.eclipse.jface.text.source.IOverviewRuler, boolean, int) */ protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, - boolean isOverviewRulerVisible, int styles) { + boolean isOverviewRulerVisible, int styles, IPreferenceStore store) { return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler, - isOverviewRulerVisible, styles); + isOverviewRulerVisible, styles, store); } + // protected ISourceViewer createJavaSourceViewer(Composite parent, // IVerticalRuler ruler, int styles) { // return new AdaptedSourceViewer(parent, ruler, styles); @@ -1715,6 +1744,7 @@ public class PHPUnitEditor extends PHPEditor { } return false; } + /* * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput) */ @@ -1738,6 +1768,12 @@ public class PHPUnitEditor extends PHPEditor { return oldExtension.equals(newExtension); } /* + * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#getInputElement() + */ + protected IJavaElement getInputJavaElement() { + return PHPeclipsePlugin.getDefault().getWorkingCopyManager().getWorkingCopy(getEditorInput()); + } + /* * @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager) */ public void editorContextMenuAboutToShow(IMenuManager menu) { @@ -1748,6 +1784,7 @@ public class PHPUnitEditor extends PHPEditor { fContextMenuGroup.fillContextMenu(menu); fContextMenuGroup.setContext(null); } + /* * @see JavaEditor#setOutlinePageInput(JavaOutlinePage, IEditorInput) */ @@ -1758,6 +1795,7 @@ public class PHPUnitEditor extends PHPEditor { page.setInput(manager.getWorkingCopy(input)); } } + /* * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation, * IProgressMonitor) @@ -1780,6 +1818,240 @@ public class PHPUnitEditor extends PHPEditor { // } // } /* + * @see AbstractTextEditor#doSave(IProgressMonitor) + */ + public void doSave(IProgressMonitor progressMonitor) { + + IDocumentProvider p = getDocumentProvider(); + if (p == null) { + // editor has been closed + return; + } + + if (p.isDeleted(getEditorInput())) { + + if (isSaveAsAllowed()) { + + /* + * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the + * editors. Changed Behavior to make sure that if called inside a + * regular save (because of deletion of input element) there is a way to + * report back to the caller. + */ + performSaveAs(progressMonitor); + + } else { + + /* + * 1GF5YOX: ITPJUI:ALL - Save of delete file claims it's still there + * Missing resources. + */ + Shell shell = getSite().getShell(); + MessageDialog + .openError( + shell, + PHPEditorMessages + .getString("PHPUnitEditor.error.saving.title1"), PHPEditorMessages.getString("PHPUnitEditor.error.saving.message1")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + } else { + + setStatusLineErrorMessage(null); + + updateState(getEditorInput()); + validateState(getEditorInput()); + + IWorkingCopyManager manager = PHPeclipsePlugin.getDefault() + .getWorkingCopyManager(); + ICompilationUnit unit = manager.getWorkingCopy(getEditorInput()); + + if (unit != null) { + synchronized (unit) { + performSave(false, progressMonitor); + } + } else + performSave(false, progressMonitor); + } + ShowExternalPreviewAction a = ShowExternalPreviewAction.getInstance(); + if (a != null) { + a.refresh(); + } + } + + public boolean isSaveAsAllowed() { + return true; + } + + /** + * The compilation unit editor implementation of this + * AbstractTextEditor method asks the user for the workspace + * path of a file resource and saves the document there. See + * http://dev.eclipse.org/bugs/show_bug.cgi?id=6295 + * + * @param progressMonitor + * the progress monitor + */ + protected void performSaveAs(IProgressMonitor progressMonitor) { + + Shell shell = getSite().getShell(); + IEditorInput input = getEditorInput(); + + SaveAsDialog dialog = new SaveAsDialog(shell); + + IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input) + .getFile() + : null; + if (original != null) + dialog.setOriginalFile(original); + + dialog.create(); + + IDocumentProvider provider = getDocumentProvider(); + if (provider == null) { + // editor has been programmatically closed while the dialog was open + return; + } + + if (provider.isDeleted(input) && original != null) { + String message = PHPEditorMessages + .getFormattedString( + "CompilationUnitEditor.warning.save.delete", new Object[] { original.getName() }); //$NON-NLS-1$ + dialog.setErrorMessage(null); + dialog.setMessage(message, IMessageProvider.WARNING); + } + + if (dialog.open() == Window.CANCEL) { + if (progressMonitor != null) + progressMonitor.setCanceled(true); + return; + } + + IPath filePath = dialog.getResult(); + if (filePath == null) { + if (progressMonitor != null) + progressMonitor.setCanceled(true); + return; + } + + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IFile file = workspaceRoot.getFile(filePath); + final IEditorInput newInput = new FileEditorInput(file); + + boolean success = false; + try { + + provider.aboutToChange(newInput); + getDocumentProvider().saveDocument(progressMonitor, newInput, + getDocumentProvider().getDocument(getEditorInput()), true); + success = true; + + } catch (CoreException x) { + IStatus status = x.getStatus(); + if (status == null || status.getSeverity() != IStatus.CANCEL) + ErrorDialog + .openError( + shell, + PHPEditorMessages + .getString("CompilationUnitEditor.error.saving.title2"), PHPEditorMessages.getString("CompilationUnitEditor.error.saving.message2"), x.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$ + } finally { + provider.changed(newInput); + if (success) + setInput(newInput); + } + + if (progressMonitor != null) + progressMonitor.setCanceled(!success); + } + + /* + * @see AbstractTextEditor#doSetInput(IEditorInput) + */ + protected void doSetInput(IEditorInput input) throws CoreException { + super.doSetInput(input); + configureTabConverter(); + configureToggleCommentAction(); + } + + // /* + // * @see + // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#installOverrideIndicator(boolean) + // * @since 3.0 + // */ + // protected void installOverrideIndicator(boolean waitForReconcilation) { + // IAnnotationModel model= + // getDocumentProvider().getAnnotationModel(getEditorInput()); + // if (!waitForReconcilation) + // super.installOverrideIndicator(false); + // else { + // uninstallOverrideIndicator(); + // IJavaElement inputElement= getInputJavaElement(); + // if (model == null || inputElement == null) + // return; + // + // fOverrideIndicatorManager= new OverrideIndicatorManager(model, + // inputElement, null); + // addReconcileListener(fOverrideIndicatorManager); + // } + // } + // + // /* + // * @see + // org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#uninstallOverrideIndicator() + // * @since 3.0 + // */ + // protected void uninstallOverrideIndicator() { + // if (fOverrideIndicatorManager != null) + // removeReconcileListener(fOverrideIndicatorManager); + // super.uninstallOverrideIndicator(); + // } + + /** + * Configures the toggle comment action + * + * @since 3.0 + */ + private void configureToggleCommentAction() { + IAction action = getAction("ToggleComment"); //$NON-NLS-1$ + if (action instanceof ToggleCommentAction) { + ISourceViewer sourceViewer = getSourceViewer(); + SourceViewerConfiguration configuration = getSourceViewerConfiguration(); + ((ToggleCommentAction) action).configure(sourceViewer, configuration); + } + } + + private void configureTabConverter() { + if (fTabConverter != null) { + IDocumentProvider provider = getDocumentProvider(); + if (provider instanceof PHPDocumentProvider) { + PHPDocumentProvider cup = (PHPDocumentProvider) provider; + fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); + } + } + } + + private void startTabConversion() { + if (fTabConverter == null) { + fTabConverter = new TabConverter(); + configureTabConverter(); + fTabConverter.setNumberOfSpacesPerTab(getTabSize()); + AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); + asv.addTextConverter(fTabConverter); + // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 + asv.updateIndentationPrefixes(); + } + } + + private void stopTabConversion() { + if (fTabConverter != null) { + AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); + asv.removeTextConverter(fTabConverter); + // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 + asv.updateIndentationPrefixes(); + fTabConverter = null; + } + } + + /* * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean, * org.eclipse.core.runtime.IProgressMonitor) */ @@ -1798,6 +2070,7 @@ public class PHPUnitEditor extends PHPEditor { } } } + /* * @see AbstractTextEditor#doSaveAs */ @@ -1806,54 +2079,7 @@ public class PHPUnitEditor extends PHPEditor { super.doSaveAs(); } } - /* - * @see AbstractTextEditor#doSave(IProgressMonitor) - */ - public void doSave(IProgressMonitor progressMonitor) { - IDocumentProvider p = getDocumentProvider(); - if (p == null) { - // editor has been closed - return; - } - if (!askIfNonWorkbenchEncodingIsOk()) { - progressMonitor.setCanceled(true); - return; - } - if (p.isDeleted(getEditorInput())) { - if (isSaveAsAllowed()) { - /* - * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the - * editors. Changed Behavior to make sure that if called inside a - * regular save (because of deletion of input element) there is a way - * to report back to the caller. - */ - // performSaveAs(progressMonitor); - super.doSave(progressMonitor); - } else { - /* - * 1GF5YOX: ITPJUI:ALL - Save of delete file claims it's still there - * Missing resources. - */ - Shell shell = getSite().getShell(); - MessageDialog.openError(shell, PHPEditorMessages - .getString("PHPUnitEditor.error.saving.title1"), PHPEditorMessages - .getString("PHPUnitEditor.error.saving.message1")); //$NON-NLS-1$ //$NON-NLS-2$ - } - } else { - setStatusLineErrorMessage(null); - super.doSave(progressMonitor); - // IWorkingCopyManager manager= - // JavaPlugin.getDefault().getWorkingCopyManager(); - // ICompilationUnit unit= manager.getWorkingCopy(getEditorInput()); - // - // if (unit != null) { - // synchronized (unit) { - // performSaveOperation(createSaveOperation(false), progressMonitor); - // } - // } else - // performSaveOperation(createSaveOperation(false), progressMonitor); - } - } + /** * Asks the user if it is ok to store in non-workbench encoding. * @@ -1876,18 +2102,19 @@ public class PHPUnitEditor extends PHPEditor { .format( PHPEditorMessages .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"), - new String[]{input.getName(), encoding}); //$NON-NLS-1$ + new String[] { input.getName(), encoding }); //$NON-NLS-1$ else msg = MessageFormat .format( PHPEditorMessages .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message2"), - new String[]{encoding}); //$NON-NLS-1$ + new String[] { encoding }); //$NON-NLS-1$ return MessageDialog.openQuestion(shell, title, msg); } } return true; } + /* * @see IReconcilingParticipant#reconciled() */ @@ -1903,12 +2130,12 @@ public class PHPUnitEditor extends PHPEditor { } } } - + protected void updateStateDependentActions() { super.updateStateDependentActions(); fGenerateActionGroup.editorStateChanged(); } - + private boolean synchronizeOutlineOnCursorMove() { return PreferenceConstants.getPreferenceStore().getBoolean( PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE); @@ -1938,6 +2165,7 @@ public class PHPUnitEditor extends PHPEditor { } return null; } + /** * Returns the offset of the given Java element. */ @@ -1953,6 +2181,7 @@ public class PHPUnitEditor extends PHPEditor { } return -1; } + /* * @see AbstractTextEditor#rememberSelection() */ @@ -1965,6 +2194,7 @@ public class PHPUnitEditor extends PHPEditor { fRememberedElementOffset = getOffset(fRememberedElement); } } + /* * @see AbstractTextEditor#restoreSelection() */ @@ -1986,4 +2216,52 @@ public class PHPUnitEditor extends PHPEditor { fRememberedElementOffset = -1; } } -} + + // /* + // * @see + // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled() + // * @since 3.0 + // */ + // public void aboutToBeReconciled() { + // + // // Notify AST provider + // PHPeclipsePlugin.getDefault().getASTProvider().aboutToBeReconciled(getInputJavaElement()); + // + // // Notify listeners + // Object[] listeners = fReconcilingListeners.getListeners(); + // for (int i = 0, length= listeners.length; i < length; ++i) + // ((IJavaReconcilingListener)listeners[i]).aboutToBeReconciled(); + // } + // + // /* + // * @see + // org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit, + // boolean, IProgressMonitor) + // * @since 3.0 + // */ + // public void reconciled(net.sourceforge.phpdt.core.dom.CompilationUnit + // ast, boolean forced, IProgressMonitor progressMonitor) { + // + // // Always notify AST provider + // PHPeclipsePlugin.getDefault().getASTProvider().reconciled(ast, + // getInputJavaElement()); + // + // // Notify listeners + // Object[] listeners = fReconcilingListeners.getListeners(); + // for (int i = 0, length= listeners.length; i < length; ++i) + // ((IJavaReconcilingListener)listeners[i]).reconciled(ast, forced, + // progressMonitor); + // + // // Update Java Outline page selection + // if (!forced && !progressMonitor.isCanceled()) { + // Shell shell= getSite().getShell(); + // if (shell != null && !shell.isDisposed()) { + // shell.getDisplay().asyncExec(new Runnable() { + // public void run() { + // selectionChanged(); + // } + // }); + // } + // } + // } +} \ No newline at end of file