From bee14fb37ed5483afdff728728b551b34f010ac0 Mon Sep 17 00:00:00 2001 From: khartlage Date: Sat, 8 May 2004 11:16:25 +0000 Subject: [PATCH] misc changes --- net.sourceforge.phpeclipse/plugin.properties | 8 +- net.sourceforge.phpeclipse/plugin.xml | 176 ++++- .../internal/ui/actions/AddBlockCommentAction.java | 196 +++++ .../internal/ui/actions/BlockCommentAction.java | 328 ++++++++ .../ui/actions/RemoveBlockCommentAction.java | 88 ++ .../internal/ui/text/ContentAssistPreference.java | 7 +- .../phpdt/internal/ui/text/IPHPPartitions.java | 29 + .../sourceforge/phpdt/ui/PreferenceConstants.java | 275 +++++++- .../phpdt/ui/actions/PHPdtActionConstants.java | 7 +- .../sourceforge/phpdt/ui/text/JavaTextTools.java | 26 +- .../phpeclipse/PHPPerspectiveFactory.java | 66 +- .../sourceforge/phpeclipse/PHPeclipsePlugin.java | 3 +- .../BasicJavaEditorActionContributor.java | 231 ++++++ .../phpeclipse/phpeditor/PHPActionContributor.java | 270 +++---- .../phpeclipse/phpeditor/PHPEditor.java | 218 +++-- .../phpeditor/PHPEditorActionDefinitionIds.java | 31 +- .../phpeditor/PHPSourceViewerConfiguration.java | 94 ++-- .../phpeclipse/phpeditor/PHPUnitEditor.java | 857 ++++++++++---------- .../phpeclipse/phpeditor/ToggleCommentAction.java | 163 ++++ .../php/IPHPPartitionScannerConstants.java | 29 - .../phpeclipse/phpeditor/php/PHPPartition.java | 8 +- .../phpeditor/php/PHPPartitionScanner.java | 128 ++-- .../phpeclipse/phpeditor/php/Partition.java | 6 +- .../phpeclipse/phpeditor/php/PartitionStack.java | 6 +- 24 files changed, 2370 insertions(+), 880 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/AddBlockCommentAction.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/BlockCommentAction.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/RemoveBlockCommentAction.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/IPHPPartitions.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/BasicJavaEditorActionContributor.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ToggleCommentAction.java delete mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/IPHPPartitionScannerConstants.java diff --git a/net.sourceforge.phpeclipse/plugin.properties b/net.sourceforge.phpeclipse/plugin.properties index 904f2d7..16b1068 100644 --- a/net.sourceforge.phpeclipse/plugin.properties +++ b/net.sourceforge.phpeclipse/plugin.properties @@ -101,10 +101,10 @@ FindStringsToExternalizeAction.label= &Find Strings to Externalize... ExternalizeStringsAction.label= &Externalize Strings... -ConvertLineDelimitersActions.label= Co&nvert Line Delimiters -ConvertLineDelimitersToWindowsAction.label= To &Windows -ConvertLineDelimitersToUNIXAction.label= To &UNIX -ConvertLineDelimitersToMacAction.label= To &Mac +ConvertLineDelimitersActions.label= Co&nvert Line Delimiters To +ConvertLineDelimitersToWindowsAction.label= &Windows +ConvertLineDelimitersToUNIXAction.label= &UNIX +ConvertLineDelimitersToMacAction.label= &Mac ########################################################################## # Javadoc Support diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index 4342e98..ac91d55 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -477,6 +477,7 @@ @@ -486,7 +487,12 @@ label="%SourceMenu.label" path="edit" id="net.sourceforge.phpeclipse.ui.source.menu"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /* and */). + * + * @since 3.0 + */ +public class AddBlockCommentAction extends BlockCommentAction { + + /** + * Creates a new instance. + * + * @param bundle the resource bundle + * @param prefix a prefix to be prepended to the various resource keys + * (described in ResourceAction constructor), or + * null if none + * @param editor the text editor + */ + public AddBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) { + super(bundle, prefix, editor); + } + + /* + * @see org.eclipse.jdt.internal.ui.actions.BlockCommentAction#runInternal(org.eclipse.jface.text.ITextSelection, org.eclipse.jface.text.IDocumentExtension3, org.eclipse.jdt.internal.ui.actions.BlockCommentAction.Edit.EditFactory) + */ + protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException { + int selectionOffset= selection.getOffset(); + int selectionEndOffset= selectionOffset + selection.getLength(); + List edits= new LinkedList(); + ITypedRegion partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, selectionOffset); + + handleFirstPartition(partition, edits, factory, selectionOffset); + + while (partition.getOffset() + partition.getLength() < selectionEndOffset) { + partition= handleInteriorPartition(partition, edits, factory, docExtension); + } + + handleLastPartition(partition, edits, factory, selectionEndOffset); + + executeEdits(edits); + } + + /** + * Handle the first partition of the selected text. + * + * @param partition + * @param edits + * @param factory + * @param offset + */ + private void handleFirstPartition(ITypedRegion partition, List edits, Edit.EditFactory factory, int offset) throws BadLocationException { + + int partOffset= partition.getOffset(); + String partType= partition.getType(); + + Assert.isTrue(partOffset <= offset, "illegal partition"); //$NON-NLS-1$ + + // first partition: mark start of comment + if (partType == IDocument.DEFAULT_CONTENT_TYPE) { + // Java code: right where selection starts + edits.add(factory.createEdit(offset, 0, getCommentStart())); + } else if (isSpecialPartition(partType)) { + // special types: include the entire partition + edits.add(factory.createEdit(partOffset, 0, getCommentStart())); + } // javadoc: no mark, will only start after comment + + } + + /** + * Handles the end of the given partition and the start of the next partition, which is returned. + * + * @param partition + * @param edits + * @param factory + * @param docExtension + * @return + * @throws BadLocationException + * @throws BadPartitioningException + */ + private ITypedRegion handleInteriorPartition(ITypedRegion partition, List edits, Edit.EditFactory factory, IDocumentExtension3 docExtension) throws BadPartitioningException, BadLocationException { + + // end of previous partition + String partType= partition.getType(); + int partEndOffset= partition.getOffset() + partition.getLength(); + int tokenLength= getCommentStart().length(); + + boolean wasJavadoc= false; // true if the previous partition is javadoc + + if (partType == IPHPPartitions.PHP_MULTILINE_COMMENT) { + + wasJavadoc= true; + +// } else if (partType == IPHPPartitions.JAVA_MULTI_LINE_COMMENT) { +// +// // already in a comment - remove ending mark +// edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ +// + } + + // advance to next partition + partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, partEndOffset); + partType= partition.getType(); + + // start of next partition + if (wasJavadoc) { + + // if previous was javadoc, and the current one is not, then add block comment start + if (partType == IDocument.DEFAULT_CONTENT_TYPE + || isSpecialPartition(partType)) { + edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart())); + } + + } else { // !wasJavadoc + + if (partType == IPHPPartitions.PHP_MULTILINE_COMMENT) { + // if next is javadoc, end block comment before + edits.add(factory.createEdit(partition.getOffset(), 0, getCommentEnd())); +// } else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) { +// // already in a comment - remove startToken +// edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$ + } + } + + return partition; + } + + /** + * Handles the end of the last partition. + * + * @param partition + * @param edits + * @param factory + * @param endOffset + */ + private void handleLastPartition(ITypedRegion partition, List edits, Edit.EditFactory factory, int endOffset) throws BadLocationException { + + String partType= partition.getType(); + + if (partType == IDocument.DEFAULT_CONTENT_TYPE) { + // normal java: end comment where selection ends + edits.add(factory.createEdit(endOffset, 0, getCommentEnd())); + } else if (isSpecialPartition(partType)) { + // special types: consume entire partition + edits.add(factory.createEdit(partition.getOffset() + partition.getLength(), 0, getCommentEnd())); + } + + } + + /** + * Returns whether partType is special, i.e. a Java String, + * Character, or Line End Comment partition. + * + * @param partType the partition type to check + * @return true if partType is special, false otherwise + */ + private boolean isSpecialPartition(String partType) { + return// partType == IPHPPartitions.PHP_CHARACTER + //|| + partType == IPHPPartitions.PHP_STRING; + //|| partType == IPHPPartitions.PHP_SINGLE_LINE_COMMENT; + } + + /* + * @see org.eclipse.jdt.internal.ui.actions.BlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection) + */ + protected boolean isValidSelection(ITextSelection selection) { + return selection != null && !selection.isEmpty() && selection.getLength() > 0; + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/BlockCommentAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/BlockCommentAction.java new file mode 100644 index 0000000..285a373 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/BlockCommentAction.java @@ -0,0 +1,328 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.ui.actions; + +import java.util.Iterator; +import java.util.List; +import java.util.ResourceBundle; + +import net.sourceforge.phpdt.internal.corext.Assert; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.BadPartitioningException; +import org.eclipse.jface.text.BadPositionCategoryException; +import org.eclipse.jface.text.DefaultPositionUpdater; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentExtension3; +import org.eclipse.jface.text.IPositionUpdater; +import org.eclipse.jface.text.IRewriteTarget; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorExtension2; +import org.eclipse.ui.texteditor.TextEditorAction; + + +/** + * Common block comment code. + * + * @since 3.0 + */ +public abstract class BlockCommentAction extends TextEditorAction { + + /** + * Creates a new instance. + * @param bundle + * @param prefix + * @param editor + */ + public BlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) { + super(bundle, prefix, editor); + } + + /** + * An edit is a kind of DocumentEvent, in this case an edit instruction, that is + * affilitated with a Position on a document. The offset of the document event is + * not stored statically, but taken from the affiliated Position, which gets + * updated when other edits occurr. + */ + static class Edit extends DocumentEvent { + + /** + * Factory for edits which manages the creation, installation and destruction of + * position categories, position updaters etc. on a certain document. Once a factory has + * been obtained, Edit objects can be obtained from it which will be linked to + * the document by positions of one position category. + *

Clients are required to call release once the Edits are not + * used any more, so the positions can be discarded.

+ */ + public static class EditFactory { + + /** The position category basename for this edits. */ + private static final String CATEGORY= "__positionalEditPositionCategory"; //$NON-NLS-1$ + + /** The count of factories. */ + private static int fgCount= 0; + + /** This factory's category. */ + private final String fCategory; + private IDocument fDocument; + private IPositionUpdater fUpdater; + + /** + * Creates a new EditFactory with an unambiguous position category name. + * @param document the document that is being edited. + */ + public EditFactory(IDocument document) { + fCategory= CATEGORY + fgCount++; + fDocument= document; + } + + /** + * Creates a new edition on the document of this factory. + * + * @param offset the offset of the edition at the point when is created. + * @param length the length of the edition (not updated via the position update mechanism) + * @param text the text to be replaced on the document + * @return an Edit reflecting the edition on the document + */ + public Edit createEdit(int offset, int length, String text) throws BadLocationException { + + if (!fDocument.containsPositionCategory(fCategory)) { + fDocument.addPositionCategory(fCategory); + fUpdater= new DefaultPositionUpdater(fCategory); + fDocument.addPositionUpdater(fUpdater); + } + + Position position= new Position(offset); + try { + fDocument.addPosition(fCategory, position); + } catch (BadPositionCategoryException e) { + Assert.isTrue(false); + } + return new Edit(fDocument, length, text, position); + } + + /** + * Releases the position category on the document and uninstalls the position updater. + * Edits managed by this factory are not updated after this call. + */ + public void release() { + if (fDocument != null && fDocument.containsPositionCategory(fCategory)) { + fDocument.removePositionUpdater(fUpdater); + try { + fDocument.removePositionCategory(fCategory); + } catch (BadPositionCategoryException e) { + Assert.isTrue(false); + } + fDocument= null; + fUpdater= null; + } + } + } + + /** The position in the document where this edit be executed. */ + private Position fPosition; + + /** + * Creates a new edition on document, taking its offset from position. + * + * @param document the document being edited + * @param length the length of the edition + * @param text the replacement text of the edition + * @param position the position keeping the edition's offset + */ + protected Edit(IDocument document, int length, String text, Position position) { + super(document, 0, length, text); + fPosition= position; + } + + /* + * @see org.eclipse.jface.text.DocumentEvent#getOffset() + */ + public int getOffset() { + return fPosition.getOffset(); + } + + /** + * Executes the edition on document. The offset is taken from the position. + * + * @throws BadLocationException if the execution of the document fails. + */ + public void perform() throws BadLocationException { + getDocument().replace(getOffset(), getLength(), getText()); + } + + } + + public void run() { + if (!isEnabled()) + return; + + ITextEditor editor= getTextEditor(); + if (editor == null || !ensureEditable(editor)) + return; + + ITextSelection selection= getCurrentSelection(); + if (!isValidSelection(selection)) + return; + + if (!validateEditorInputState()) + return; + + IDocumentProvider docProvider= editor.getDocumentProvider(); + IEditorInput input= editor.getEditorInput(); + if (docProvider == null || input == null) + return; + + IDocument document= docProvider.getDocument(input); + if (document == null) + return; + + IDocumentExtension3 docExtension; + if (document instanceof IDocumentExtension3) + docExtension= (IDocumentExtension3) document; + else + return; + + IRewriteTarget target= (IRewriteTarget)editor.getAdapter(IRewriteTarget.class); + if (target != null) { + target.beginCompoundChange(); + } + + Edit.EditFactory factory= new Edit.EditFactory(document); + + try { + runInternal(selection, docExtension, factory); + + } catch (BadLocationException e) { + // can happen on concurrent modification, deletion etc. of the document + // -> don't complain, just bail out + } catch (BadPartitioningException e) { + // should not happen + Assert.isTrue(false, "bad partitioning"); //$NON-NLS-1$ + } finally { + factory.release(); + + if (target != null) { + target.endCompoundChange(); + } + } + } + + /** + * Calls perform on all Edits in edits. + * + * @param edits a list of Edits + * @throws BadLocationException if an Edit threw such an exception. + */ + protected void executeEdits(List edits) throws BadLocationException { + for (Iterator it= edits.iterator(); it.hasNext();) { + Edit edit= (Edit) it.next(); + edit.perform(); + } + } + + /** + * Ensures that the editor is modifyable. If the editor is an instance of + * ITextEditorExtension2, its validateEditorInputState method + * is called, otherwise, the result of isEditable is returned. + * + * @param editor the editor to be checked + * @return true if the editor is editable, false otherwise + */ + protected boolean ensureEditable(ITextEditor editor) { + Assert.isNotNull(editor); + + if (editor instanceof ITextEditorExtension2) { + ITextEditorExtension2 ext= (ITextEditorExtension2) editor; + return ext.validateEditorInputState(); + } + + return editor.isEditable(); + } + + /* + * @see org.eclipse.ui.texteditor.IUpdate#update() + */ + public void update() { + super.update(); + + if (isEnabled()) { + if (!canModifyEditor() || !isValidSelection(getCurrentSelection())) + setEnabled(false); + } + } + + /** + * Returns the editor's selection, or null if no selection can be obtained or the + * editor is null. + * + * @return the selection of the action's editor, or null + */ + protected ITextSelection getCurrentSelection() { + ITextEditor editor= getTextEditor(); + if (editor != null) { + ISelectionProvider provider= editor.getSelectionProvider(); + if (provider != null) { + ISelection selection= provider.getSelection(); + if (selection instanceof ITextSelection) + return (ITextSelection) selection; + } + } + return null; + } + + /** + * Runs the real command once all the editor, document, and selection checks have succeeded. + * + * @param selection the current selection we are being called for + * @param docExtension the document extension where we get the partitioning from + * @param factory the edit factory we can use to create Edits + * @throws BadLocationException if an edition fails + * @throws BadPartitioningException if a partitioning call fails + */ + protected abstract void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException; + + /** + * Checks whether selection is valid. + * + * @param selection the selection to check + * @return true if the selection is valid, false otherwise + */ + protected abstract boolean isValidSelection(ITextSelection selection); + + /** + * Returns the text to be inserted at the selection start. + * + * @return the text to be inserted at the selection start + */ + protected String getCommentStart() { + // for now: no space story + return "/*"; //$NON-NLS-1$ + } + + /** + * Returns the text to be inserted at the selection end. + * + * @return the text to be inserted at the selection end + */ + protected String getCommentEnd() { + // for now: no space story + return "*/"; //$NON-NLS-1$ + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/RemoveBlockCommentAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/RemoveBlockCommentAction.java new file mode 100644 index 0000000..562c26a --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/RemoveBlockCommentAction.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.ui.actions; + +import java.util.LinkedList; +import java.util.List; +import java.util.ResourceBundle; + +import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.BadPartitioningException; +import org.eclipse.jface.text.IDocumentExtension3; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.ui.texteditor.ITextEditor; + + +/** + * Action that removes the enclosing comment marks from a Java block comment. + * + * @since 3.0 + */ +public class RemoveBlockCommentAction extends BlockCommentAction { + + /** + * Creates a new instance. + * + * @param bundle the resource bundle + * @param prefix a prefix to be prepended to the various resource keys + * (described in ResourceAction constructor), or + * null if none + * @param editor the text editor + */ + public RemoveBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) { + super(bundle, prefix, editor); + } + + /* + * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#runInternal(org.eclipse.jface.text.ITextSelection, org.eclipse.jface.text.IDocumentExtension3, org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction.Edit.EditFactory) + */ + protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException { + List edits= new LinkedList(); + int tokenLength= getCommentStart().length(); + + int offset= selection.getOffset(); + int endOffset= offset + selection.getLength(); + + ITypedRegion partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, offset); + int partOffset= partition.getOffset(); + int partEndOffset= partOffset + partition.getLength(); + + while (partEndOffset < endOffset) { + + if (partition.getType() == IPHPPartitions.PHP_MULTILINE_COMMENT) { + edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$ + edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ + } + + partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, partEndOffset); + partOffset= partition.getOffset(); + partEndOffset= partOffset + partition.getLength(); + } + + if (partition.getType() == IPHPPartitions.PHP_MULTILINE_COMMENT) { + edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$ + edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$ + } + + executeEdits(edits); + } + + /* + * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection) + */ + protected boolean isValidSelection(ITextSelection selection) { + return selection != null && !selection.isEmpty(); + } + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/ContentAssistPreference.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/ContentAssistPreference.java index 61d4a1b..148058e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/ContentAssistPreference.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/ContentAssistPreference.java @@ -10,7 +10,6 @@ import net.sourceforge.phpdt.ui.text.IColorManager; import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor; -import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants; import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor; import org.eclipse.jface.preference.IPreferenceStore; @@ -75,21 +74,21 @@ public class ContentAssistPreference { } private static PHPCompletionProcessor getJavaProcessor(ContentAssistant assistant) { - IContentAssistProcessor p = assistant.getContentAssistProcessor(IPHPPartitionScannerConstants.PHP); + IContentAssistProcessor p = assistant.getContentAssistProcessor(IPHPPartitions.PHP_PARTITIONING); if (p instanceof PHPCompletionProcessor) return (PHPCompletionProcessor) p; return null; } private static PHPDocCompletionProcessor getJavaDocProcessor(ContentAssistant assistant) { - IContentAssistProcessor p = assistant.getContentAssistProcessor(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + IContentAssistProcessor p = assistant.getContentAssistProcessor(IPHPPartitions.PHP_MULTILINE_COMMENT); if (p instanceof PHPDocCompletionProcessor) return (PHPDocCompletionProcessor) p; return null; } private static HTMLCompletionProcessor getHTMLProcessor(ContentAssistant assistant) { - IContentAssistProcessor p = assistant.getContentAssistProcessor(IPHPPartitionScannerConstants.HTML); + IContentAssistProcessor p = assistant.getContentAssistProcessor(IPHPPartitions.HTML); if (p instanceof HTMLCompletionProcessor) return (HTMLCompletionProcessor) p; return null; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/IPHPPartitions.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/IPHPPartitions.java new file mode 100644 index 0000000..0e582b6 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/IPHPPartitions.java @@ -0,0 +1,29 @@ +/* + * Created on 05.03.2003 + * + */ +package net.sourceforge.phpdt.internal.ui.text; + +/** + * @author Stefan Langer (musk) + * + */ +public interface IPHPPartitions +{ + public final static String PHP_PARTITIONING = "__php"; //$NON-NLS-1$ + public final static String PHP_MULTILINE_COMMENT = "__php_multiline_comment"; //$NON-NLS-1$ + public final static String PHP_STRING = "__php_string"; //$NON-NLS-1$ + public final static String JAVASCRIPT = "__javascript"; //$NON-NLS-1$ + public final static String JS_MULTILINE_COMMENT = "__js_multiline_comment"; //$NON-NLS-1$ + public final static String CSS = "__css"; //$NON-NLS-1$ + public final static String CSS_MULTILINE_COMMENT = "__css_multiline_comment"; //$NON-NLS-1$ + public final static String HTML = "__html"; //$NON-NLS-1$ + public final static String HTML_MULTILINE_COMMENT = "__html_multiline_comment"; //$NON-NLS-1$ + public final static String SMARTY = "__smarty"; //$NON-NLS-1$ + public final static String SMARTY_MULTILINE_COMMENT = "__smarty_multiline_comment"; //$NON-NLS-1$ + + public final static int PHP_FILE = 1; + public final static int HTML_FILE = 2; + public final static int XML_FILE = 3; + public final static int SMARTY_FILE = 4; +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java index 1110caa..75c3a01 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java @@ -10,19 +10,18 @@ ******************************************************************************/ package net.sourceforge.phpdt.ui; +import net.sourceforge.phpdt.core.IClasspathEntry; import net.sourceforge.phpeclipse.IPreferenceConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.jface.action.Action; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.texteditor.AbstractTextEditor; -import org.eclipse.ui.texteditor.WorkbenchChainedTextFontFieldEditor; // //import org.phpeclipse.phpdt.internal.ui.JavaPlugin; //import org.phpeclipse.phpdt.internal.ui.preferences.NewJavaProjectPreferencePage; @@ -1416,6 +1415,278 @@ public class PreferenceConstants { * @since 2.1 */ public static final String EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER = "browserLikeLinksKeyModifier"; //$NON-NLS-1$ + /** + * A named preference that controls whether occurrences are marked in the editor. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public static final String EDITOR_MARK_OCCURRENCES= "markOccurrences"; //$NON-NLS-1$ + + /** + * A named preference that controls whether occurrences are sticky in the editor. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public static final String EDITOR_STICKY_OCCURRENCES= "stickyOccurrences"; //$NON-NLS-1$ + + /** + * A named preference that controls disabling of the overwrite mode. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public static final String EDITOR_DISABLE_OVERWRITE_MODE= "disable_overwrite_mode"; //$NON-NLS-1$ + + /** + * A named preference that controls the "smart semicolon" smart typing handler + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public static final String EDITOR_SMART_SEMICOLON= "smart_semicolon"; //$NON-NLS-1$ + + /** + * A named preference that controls the "smart opening brace" smart typing handler + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public static final String EDITOR_SMART_OPENING_BRACE= "smart_opening_brace"; //$NON-NLS-1$ + + /** + * A named preference that controls the smart tab behaviour. + *

+ * Value is of type Boolean. + * + * @since 3.0 + */ + public static final String EDITOR_SMART_TAB= "smart_tab"; //$NON-NLS-1$ + + /** + * A named preference that controls whether Java comments should be + * spell-checked. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_CHECK_SPELLING= ISpellCheckPreferenceKeys.SPELLING_CHECK_SPELLING; + + /** + * A named preference that controls whether words containing digits should + * be skipped during spell-checking. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_IGNORE_DIGITS= ISpellCheckPreferenceKeys.SPELLING_IGNORE_DIGITS; + + /** + * A named preference that controls whether mixed case words should be + * skipped during spell-checking. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_IGNORE_MIXED= ISpellCheckPreferenceKeys.SPELLING_IGNORE_MIXED; + + /** + * A named preference that controls whether sentence capitalization should + * be ignored during spell-checking. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_IGNORE_SENTENCE= ISpellCheckPreferenceKeys.SPELLING_IGNORE_SENTENCE; + + /** + * A named preference that controls whether upper case words should be + * skipped during spell-checking. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_IGNORE_UPPER= ISpellCheckPreferenceKeys.SPELLING_IGNORE_UPPER; + + /** + * A named preference that controls whether urls should be ignored during + * spell-checking. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_IGNORE_URLS= ISpellCheckPreferenceKeys.SPELLING_IGNORE_URLS; + + /** + * A named preference that controls the locale used for spell-checking. + *

+ * Value is of type String. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_LOCALE= ISpellCheckPreferenceKeys.SPELLING_LOCALE; + + /** + * A named preference that controls the number of proposals offered during + * spell-checking. + *

+ * Value is of type Integer. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_PROPOSAL_THRESHOLD= ISpellCheckPreferenceKeys.SPELLING_PROPOSAL_THRESHOLD; + + /** + * A named preference that specifies the workspace user dictionary. + *

+ * Value is of type Integer. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_USER_DICTIONARY= ISpellCheckPreferenceKeys.SPELLING_USER_DICTIONARY; + + /** + * A named preference that specifies whether spelling dictionaries are available to content assist. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ +// public final static String SPELLING_ENABLE_CONTENTASSIST= ISpellCheckPreferenceKeys.SPELLING_ENABLE_CONTENTASSIST; + + /** + * A named preference that controls whether code snippets are formatted + * in Javadoc comments. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_FORMATSOURCE= "comment_format_source_code"; //$NON-NLS-1$ + + /** + * A named preference that controls whether description of Javadoc + * parameters are indented. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_INDENTPARAMETERDESCRIPTION= "comment_indent_parameter_description"; //$NON-NLS-1$ + + /** + * A named preference that controls whether the header comment of + * a Java source file is formatted. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_FORMATHEADER= "comment_format_header"; //$NON-NLS-1$ + + /** + * A named preference that controls whether Javadoc root tags + * are indented. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_INDENTROOTTAGS= "comment_indent_root_tags"; //$NON-NLS-1$ + + /** + * A named preference that controls whether Javadoc comments + * are formatted by the content formatter. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_FORMAT= "comment_format_comments"; //$NON-NLS-1$ + + /** + * A named preference that controls whether a new line is inserted + * after Javadoc root tag parameters. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_NEWLINEFORPARAMETER= "comment_new_line_for_parameter"; //$NON-NLS-1$ + + /** + * A named preference that controls whether an empty line is inserted before + * the Javadoc root tag block. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_SEPARATEROOTTAGS= "comment_separate_root_tags"; //$NON-NLS-1$ + + /** + * A named preference that controls whether blank lines are cleared during formatting + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_CLEARBLANKLINES= "comment_clear_blank_lines"; //$NON-NLS-1$ + + /** + * A named preference that controls the line length of comments. + *

+ * Value is of type Integer. The value must be at least 4 for reasonable formatting. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_LINELENGTH= "comment_line_length"; //$NON-NLS-1$ + + /** + * A named preference that controls whether html tags are formatted. + *

+ * Value is of type Boolean. + *

+ * + * @since 3.0 + */ + public final static String FORMATTER_COMMENT_FORMATHTML= "comment_format_html"; //$NON-NLS-1$ /** * A named preference that controls if the Java code assist gets auto activated. diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPdtActionConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPdtActionConstants.java index 350dfef..0a848b3 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPdtActionConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPdtActionConstants.java @@ -23,7 +23,12 @@ package net.sourceforge.phpdt.ui.actions; public class PHPdtActionConstants { // Edit menu - + /** + * Edit menu: name of standard Show Javadoc global action + * (value "org.eclipse.jdt.ui.actions.ShowJavaDoc"). + */ + public static final String SHOW_JAVA_DOC= "net.sourceforge.phpeclipse.phpeditor.ShowJavaDoc"; //$NON-NLS-1$ + /** * Edit menu: name of standard Code Assist global action * (value "org.phpeclipse.phpdt.ui.actions.ContentAssist"). diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/JavaTextTools.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/JavaTextTools.java index ec11f3c..2937b46 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/JavaTextTools.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/JavaTextTools.java @@ -6,11 +6,11 @@ package net.sourceforge.phpdt.ui.text; */ import net.sourceforge.phpdt.internal.ui.text.FastJavaPartitionScanner; +import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; import net.sourceforge.phpdt.internal.ui.text.JavaColorManager; import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner; import net.sourceforge.phpeclipse.IPreferenceConstants; import net.sourceforge.phpeclipse.phpeditor.php.HTMLCodeScanner; -import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants; import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner; import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner; import net.sourceforge.phpeclipse.phpeditor.php.SmartyCodeScanner; @@ -53,14 +53,14 @@ public class JavaTextTools { // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT }; private final static String[] TYPES = new String[] { - IPHPPartitionScannerConstants.PHP, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.HTML, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.JAVASCRIPT, - IPHPPartitionScannerConstants.CSS, - IPHPPartitionScannerConstants.SMARTY, - IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT }; + IPHPPartitions.PHP_PARTITIONING, + IPHPPartitions.PHP_MULTILINE_COMMENT, + IPHPPartitions.HTML, + IPHPPartitions.HTML_MULTILINE_COMMENT, + IPHPPartitions.JAVASCRIPT, + IPHPPartitions.CSS, + IPHPPartitions.SMARTY, + IPHPPartitions.SMARTY_MULTILINE_COMMENT }; private static PHPPartitionScanner XML_PARTITION_SCANNER = null; /** @@ -469,7 +469,7 @@ public class JavaTextTools { */ private static PHPPartitionScanner getHTMLPartitionScanner() { if (HTML_PARTITION_SCANNER == null) - HTML_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.HTML_FILE); + HTML_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitions.HTML_FILE); return HTML_PARTITION_SCANNER; } /** @@ -477,7 +477,7 @@ public class JavaTextTools { */ private static PHPPartitionScanner getPHPPartitionScanner() { if (PHP_PARTITION_SCANNER == null) - PHP_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.PHP_FILE); + PHP_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitions.PHP_FILE); return PHP_PARTITION_SCANNER; } @@ -486,7 +486,7 @@ public class JavaTextTools { */ private static PHPPartitionScanner getSmartyPartitionScanner() { if (SMARTY_PARTITION_SCANNER == null) - SMARTY_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.SMARTY_FILE); + SMARTY_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitions.SMARTY_FILE); return SMARTY_PARTITION_SCANNER; } @@ -495,7 +495,7 @@ public class JavaTextTools { */ private static PHPPartitionScanner getXMLPartitionScanner() { if (XML_PARTITION_SCANNER == null) - XML_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.XML_FILE); + XML_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitions.XML_FILE); return XML_PARTITION_SCANNER; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java index dcc15e4..1b9238d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java @@ -1,66 +1,52 @@ package net.sourceforge.phpeclipse; - import net.sourceforge.phpeclipse.views.browser.BrowserView; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.search.ui.SearchUI; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; +import org.eclipse.ui.console.IConsoleConstants; //import org.eclipse.update.internal.ui.UpdatePerspective; - public class PHPPerspectiveFactory implements IPerspectiveFactory { - public PHPPerspectiveFactory() { super(); } - public void createInitialLayout(IPageLayout layout) { String editorArea = layout.getEditorArea(); - - // IFolderLayout phpResourcesArea = layout.createFolder("phpresourcesarea", IPageLayout.LEFT, (float)0.25, editorArea); + // IFolderLayout phpResourcesArea = layout.createFolder("phpresourcesarea", + // IPageLayout.LEFT, (float)0.25, editorArea); // phpResourcesArea.addView(PHPeclipsePlugin.PHP_RESOURCES_VIEW_ID); - IFolderLayout folder = layout.createFolder("left", IPageLayout.LEFT, (float) 0.25, editorArea); //$NON-NLS-1$ + IFolderLayout folder = layout.createFolder("left", IPageLayout.LEFT, + (float) 0.25, editorArea); //$NON-NLS-1$ folder.addView(IPageLayout.ID_RES_NAV); //folder.addPlaceholder(IPageLayout.ID_RES_NAV); - - IFolderLayout consoleArea = - layout.createFolder( - "consoleArea", - IPageLayout.BOTTOM, - (float) 0.75, + IFolderLayout outputfolder = layout.createFolder("bottom", + IPageLayout.BOTTOM, (float) 0.75, editorArea); //$NON-NLS-1$ + outputfolder.addView(IPageLayout.ID_PROBLEM_VIEW); + outputfolder.addPlaceholder(SearchUI.SEARCH_RESULT_VIEW_ID); + outputfolder.addView(IConsoleConstants.ID_CONSOLE_VIEW); + outputfolder.addView(IPageLayout.ID_BOOKMARKS); + + layout.addView(IPageLayout.ID_OUTLINE, IPageLayout.RIGHT, (float) 0.75, editorArea); - - consoleArea.addView(IPageLayout.ID_TASK_LIST); - consoleArea.addView(org.eclipse.ui.console.IConsoleConstants.ID_CONSOLE_VIEW); - consoleArea.addView(IPageLayout.ID_BOOKMARKS); - - layout.addView( - IPageLayout.ID_OUTLINE, - IPageLayout.RIGHT, - (float) 0.75, - editorArea); - layout.addActionSet(IDebugUIConstants.LAUNCH_ACTION_SET); layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET); - layout.addActionSet(PHPeclipsePlugin.PHP_CODING_ACTION_SET_ID); - - layout.addShowViewShortcut(org.eclipse.ui.console.IConsoleConstants.ID_CONSOLE_VIEW); -// if (SWT.getPlatform().equals("win32")) { -// layout.addShowViewShortcut(UpdatePerspective.ID_BROWSER); -// } layout.addShowViewShortcut(BrowserView.ID_BROWSER); - // layout.addShowViewShortcut(PHPeclipsePlugin.PHP_RESOURCES_VIEW_ID); - + // views - search + layout.addShowViewShortcut(SearchUI.SEARCH_RESULT_VIEW_ID); + // views - debugging + layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW); // views - standard workbench layout.addShowViewShortcut(IPageLayout.ID_OUTLINE); - layout.addShowViewShortcut(IPageLayout.ID_TASK_LIST); - layout.addShowViewShortcut(IPageLayout.ID_BOOKMARKS); - + layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW); + layout.addShowViewShortcut(IPageLayout.ID_RES_NAV); // new actions - PHP project creation wizards -// layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("net.sourceforge.phpeclipse.wizards.PHPFileWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder");//$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file");//$NON-NLS-1$ + // layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard"); + // //$NON-NLS-1$ + layout + .addNewWizardShortcut("net.sourceforge.phpeclipse.wizards.PHPFileWizard"); //$NON-NLS-1$ + layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder");//$NON-NLS-1$ + layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file");//$NON-NLS-1$ } - } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index d1febcd..1ec421e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -581,7 +581,8 @@ public class PHPeclipsePlugin extends AbstractUIPlugin IEditorRegistry registry = getWorkbench().getEditorRegistry(); IEditorDescriptor desc = registry.getDefaultEditor(filename); if (desc == null) { - desc = registry.getDefaultEditor(); + desc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); + // desc = registry.getDefaultEditor(); } IEditorInput input = new ExternalEditorInput(storage); editor = page.openEditor(input, desc.getId()); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/BasicJavaEditorActionContributor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/BasicJavaEditorActionContributor.java new file mode 100644 index 0000000..a6504c8 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/BasicJavaEditorActionContributor.java @@ -0,0 +1,231 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpeclipse.phpeditor; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ResourceBundle; + +import net.sourceforge.phpdt.ui.IContextMenuConstants; +import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction; +import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.actions.RetargetAction; +import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +import org.eclipse.ui.texteditor.RetargetTextEditorAction; + +/** + * Common base class for action contributors for Java editors. + */ +public class BasicJavaEditorActionContributor extends BasicTextEditorActionContributor { + + private List fPartListeners= new ArrayList(); + + private TogglePresentationAction fTogglePresentation; +// private GotoAnnotationAction fPreviousAnnotation; +// private GotoAnnotationAction fNextAnnotation; + + private RetargetTextEditorAction fGotoMatchingBracket; +// private RetargetTextEditorAction fShowOutline; +// private RetargetTextEditorAction fOpenStructure; +// private RetargetTextEditorAction fOpenHierarchy; + + private RetargetAction fRetargetShowJavaDoc; + private RetargetTextEditorAction fShowJavaDoc; + +// private RetargetTextEditorAction fStructureSelectEnclosingAction; +// private RetargetTextEditorAction fStructureSelectNextAction; +// private RetargetTextEditorAction fStructureSelectPreviousAction; +// private RetargetTextEditorAction fStructureSelectHistoryAction; + +// private RetargetTextEditorAction fGotoNextMemberAction; +// private RetargetTextEditorAction fGotoPreviousMemberAction; +// +// private RetargetTextEditorAction fRemoveOccurrenceAnnotationsAction; + + public BasicJavaEditorActionContributor() { + super(); + + ResourceBundle b= PHPEditorMessages.getResourceBundle(); + + fRetargetShowJavaDoc= new RetargetAction(PHPdtActionConstants.SHOW_JAVA_DOC, PHPEditorMessages.getString("ShowJavaDoc.label")); //$NON-NLS-1$ + fRetargetShowJavaDoc.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC); + markAsPartListener(fRetargetShowJavaDoc); + + // actions that are "contributed" to editors, they are considered belonging to the active editor + fTogglePresentation= new TogglePresentationAction(); + +// fPreviousAnnotation= new GotoAnnotationAction("PreviousAnnotation.", false); //$NON-NLS-1$ +// +// fNextAnnotation= new GotoAnnotationAction("NextAnnotation.", true); //$NON-NLS-1$ + + fGotoMatchingBracket= new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$ + fGotoMatchingBracket.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); + + fShowJavaDoc= new RetargetTextEditorAction(b, "ShowJavaDoc."); //$NON-NLS-1$ + fShowJavaDoc.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC); + +// fShowOutline= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ShowOutline."); //$NON-NLS-1$ +// fShowOutline.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE); +// +// fOpenHierarchy= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "OpenHierarchy."); //$NON-NLS-1$ +// fOpenHierarchy.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_HIERARCHY); +// +// fOpenStructure= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "OpenStructure."); //$NON-NLS-1$ +// fOpenStructure.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_STRUCTURE); + +// fStructureSelectEnclosingAction= new RetargetTextEditorAction(b, "StructureSelectEnclosing."); //$NON-NLS-1$ +// fStructureSelectEnclosingAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING); +// fStructureSelectNextAction= new RetargetTextEditorAction(b, "StructureSelectNext."); //$NON-NLS-1$ +// fStructureSelectNextAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT); +// fStructureSelectPreviousAction= new RetargetTextEditorAction(b, "StructureSelectPrevious."); //$NON-NLS-1$ +// fStructureSelectPreviousAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS); +// fStructureSelectHistoryAction= new RetargetTextEditorAction(b, "StructureSelectHistory."); //$NON-NLS-1$ +// fStructureSelectHistoryAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST); +// +// fGotoNextMemberAction= new RetargetTextEditorAction(b, "GotoNextMember."); //$NON-NLS-1$ +// fGotoNextMemberAction.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER); +// fGotoPreviousMemberAction= new RetargetTextEditorAction(b, "GotoPreviousMember."); //$NON-NLS-1$ +// fGotoPreviousMemberAction.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER); +// +// fRemoveOccurrenceAnnotationsAction= new RetargetTextEditorAction(b, "RemoveOccurrenceAnnotations."); //$NON-NLS-1$ +// fRemoveOccurrenceAnnotationsAction.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS); + } + + protected final void markAsPartListener(RetargetAction action) { + fPartListeners.add(action); + } + + /* + * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage) + */ + public void init(IActionBars bars, IWorkbenchPage page) { + Iterator e= fPartListeners.iterator(); + while (e.hasNext()) + page.addPartListener((RetargetAction) e.next()); + + super.init(bars, page); + + // register actions that have a dynamic editor. +// bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation); +// bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation); +// bars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, fNextAnnotation); +// bars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, fPreviousAnnotation); + bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation); + + bars.setGlobalActionHandler(PHPdtActionConstants.SHOW_JAVA_DOC, fShowJavaDoc); + } + + /* + * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager) + */ + public void contributeToMenu(IMenuManager menu) { + + super.contributeToMenu(menu); + + IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); + if (editMenu != null) { + + editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN)); + editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE)); + editMenu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS)); + +// MenuManager structureSelection= new MenuManager(PHPEditorMessages.getString("ExpandSelectionMenu.label"), "expandSelection"); //$NON-NLS-1$ //$NON-NLS-2$ +// structureSelection.add(fStructureSelectEnclosingAction); +// structureSelection.add(fStructureSelectNextAction); +// structureSelection.add(fStructureSelectPreviousAction); +// structureSelection.add(fStructureSelectHistoryAction); +// editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, structureSelection); + + editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetShowJavaDoc); + } + +// IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE); +// if (navigateMenu != null) { +// navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline); +// navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fOpenHierarchy); +// } + + IMenuManager gotoMenu= menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$ + if (gotoMenu != null) { + gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$ +// gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$ +// gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); //$NON-NLS-1$ + gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$ + } + } + + /* + * @see EditorActionBarContributor#setActiveEditor(IEditorPart) + */ + public void setActiveEditor(IEditorPart part) { + + super.setActiveEditor(part); + + IActionBars actionBars= getActionBars(); + IStatusLineManager manager= actionBars.getStatusLineManager(); + manager.setMessage(null); + manager.setErrorMessage(null); + + ITextEditor textEditor= null; + if (part instanceof ITextEditor) + textEditor= (ITextEditor) part; + + fTogglePresentation.setEditor(textEditor); +// fPreviousAnnotation.setEditor(textEditor); +// fNextAnnotation.setEditor(textEditor); + + fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET)); + fShowJavaDoc.setAction(getAction(textEditor, "ShowJavaDoc")); //$NON-NLS-1$ +// fShowOutline.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_OUTLINE)); +// fOpenHierarchy.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_HIERARCHY)); +// fOpenStructure.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_STRUCTURE)); + +// fStructureSelectEnclosingAction.setAction(getAction(textEditor, StructureSelectionAction.ENCLOSING)); +// fStructureSelectNextAction.setAction(getAction(textEditor, StructureSelectionAction.NEXT)); +// fStructureSelectPreviousAction.setAction(getAction(textEditor, StructureSelectionAction.PREVIOUS)); +// fStructureSelectHistoryAction.setAction(getAction(textEditor, StructureSelectionAction.HISTORY)); + +// fGotoNextMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER)); +// fGotoPreviousMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER)); + +// fRemoveOccurrenceAnnotationsAction.setAction(getAction(textEditor, "RemoveOccurrenceAnnotations")); //$NON-NLS-1$ + + if (part instanceof PHPEditor) { + PHPEditor javaEditor= (PHPEditor) part; + javaEditor.getActionGroup().fillActionBars(getActionBars()); + } + } + + /* + * @see IEditorActionBarContributor#dispose() + */ + public void dispose() { + + Iterator e= fPartListeners.iterator(); + while (e.hasNext()) + getPage().removePartListener((RetargetAction) e.next()); + fPartListeners.clear(); + + setActiveEditor(null); + super.dispose(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java index d4f26f2..733ba53 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java @@ -12,18 +12,18 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ResourceBundle; + +import net.sourceforge.phpdt.internal.ui.PHPUiImages; import net.sourceforge.phpdt.ui.IContextMenuConstants; -import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction; import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; + import org.eclipse.core.resources.IFile; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.SWT; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; @@ -32,23 +32,24 @@ import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.actions.RetargetAction; import org.eclipse.ui.editors.text.EncodingActionGroup; +import org.eclipse.ui.ide.IDEActionFactory; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.RetargetTextEditorAction; /** * Contributes interesting PHP actions to the desktop's Edit menu and the * toolbar. */ -public class PHPActionContributor extends BasicTextEditorActionContributor { - protected RetargetTextEditorAction fContentAssistTip; +public class PHPActionContributor extends BasicJavaEditorActionContributor { +// protected RetargetTextEditorAction fContentAssistTip; // protected TextEditorAction fTogglePresentation; protected RetargetAction fRetargetContentAssist; protected RetargetTextEditorAction fContentAssist; + protected RetargetTextEditorAction fContextInformation; private RetargetTextEditorAction fGotoMatchingBracket; private List fRetargetToolbarActions = new ArrayList(); - private List fPartListeners = new ArrayList(); +// private List fPartListeners = new ArrayList(); protected PHPParserAction fParserAction; protected ShowExternalPreviewAction fShowExternalPreviewAction; private EncodingActionGroup fEncodingActionGroup; @@ -58,38 +59,40 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { public PHPActionContributor() { super(); ResourceBundle b = PHPEditorMessages.getResourceBundle(); - fRetargetContentAssist = new RetargetAction( - PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages - .getString("ContentAssistProposal.label")); //$NON-NLS-1$ - fRetargetContentAssist - .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - markAsPartListener(fRetargetContentAssist); - fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$ - fContentAssist - .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - fGotoMatchingBracket = new RetargetTextEditorAction(b, - "GotoMatchingBracket."); //$NON-NLS-1$ - fGotoMatchingBracket - .setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); - // fContentAssist.setImageDescriptor(JavaPluginImages.DESC_CLCL_CODE_ASSIST); - // fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST); - // fContentAssist = new - // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), - // "ContentAssistProposal."); //$NON-NLS-1$ - fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages - .getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$ - // fTogglePresentation = new PresentationAction(); - // character encoding - fEncodingActionGroup = new EncodingActionGroup(); + +// fRetargetContentAssist = new RetargetAction( +// PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages +// .getString("ContentAssistProposal.label")); //$NON-NLS-1$ +// fRetargetContentAssist +// .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); +// markAsPartListener(fRetargetContentAssist); +// +// fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$ +// fContentAssist +// .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + + fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$ + fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + markAsPartListener(fRetargetContentAssist); + + fContentAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$ + fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + fContentAssist.setImageDescriptor(PHPUiImages.DESC_CLCL_CODE_ASSIST); + fContentAssist.setDisabledImageDescriptor(PHPUiImages.DESC_DLCL_CODE_ASSIST); + + fContextInformation= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistContextInformation."); //$NON-NLS-1$ + fContextInformation.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); + +// fCorrectionAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "CorrectionAssistProposal."); //$NON-NLS-1$ +// fCorrectionAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS); + + // character encoding + fEncodingActionGroup= new EncodingActionGroup(); + fParserAction = PHPParserAction.getInstance(); - if (SWT.getPlatform().equals("win32")) { - // ExternalPreview only available as ActiveX on win32 (Eclipse2.1) - fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance(); - } - } - protected final void markAsPartListener(RetargetAction action) { - fPartListeners.add(action); + fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance(); } + /* * @see EditorActionBarContributor#contributeToMenu(IMenuManager) */ @@ -139,85 +142,70 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { */ public void contributeToMenu(IMenuManager menu) { super.contributeToMenu(menu); - IMenuManager editMenu = menu - .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); - if (editMenu != null) { - editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN)); - editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE)); - editMenu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS)); - // editMenu.appendToGroup( - // IContextMenuConstants.GROUP_GENERATE, - // fRetargetContentAssist); - // MenuManager structureSelection= new - // MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label"), - // "expandSelection"); //$NON-NLS-1$ //$NON-NLS-2$ - // structureSelection.add(fStructureSelectEnclosingAction); - // structureSelection.add(fStructureSelectNextAction); - // structureSelection.add(fStructureSelectPreviousAction); - // structureSelection.add(fStructureSelectHistoryAction); - // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, - // structureSelection); - // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, - // fRetargetShowJavaDoc); - } - // IMenuManager navigateMenu= - // menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE); - // if (navigateMenu != null) { - // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, - // fShowOutline); - // } - IMenuManager gotoMenu = menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$ - if (gotoMenu != null) { - gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$ - // gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); - // //$NON-NLS-1$ - // gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); - // //$NON-NLS-1$ - gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$ - } - } - /* - * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager) - */ - public void contributeToToolBar(IToolBarManager tbm) { - tbm.add(new Separator()); - Iterator e = fRetargetToolbarActions.iterator(); - while (e.hasNext()) - tbm.add((IAction) e.next()); + + IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); + if (editMenu != null) { + editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist); +// editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fCorrectionAssist); + editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContextInformation); + } } +// /* +// * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager) +// */ +// public void contributeToToolBar(IToolBarManager tbm) { +// tbm.add(new Separator()); +// Iterator e = fRetargetToolbarActions.iterator(); +// while (e.hasNext()) +// tbm.add((IAction) e.next()); +// } /* * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage) */ - public void init(IActionBars bars, IWorkbenchPage page) { - Iterator e = fPartListeners.iterator(); - while (e.hasNext()) - page.addPartListener((RetargetAction) e.next()); - // character encoding - fEncodingActionGroup.fillActionBars(bars); - super.init(bars, page); - } - /* - * @see IEditorActionBarContributor#init(IActionBars) - */ - public void init(IActionBars bars) { - super.init(bars); - IMenuManager menuManager = bars.getMenuManager(); - IMenuManager editMenu = menuManager - .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); - if (editMenu != null) { - editMenu.add(new Separator()); - editMenu.add(fContentAssist); - // editMenu.add(fGotoMatchingBracket); - // editMenu.add(fContentAssistTip); - } - bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, - fContentAssist); - // IToolBarManager toolBarManager = bars.getToolBarManager(); - // if (toolBarManager != null) { - // toolBarManager.add(new Separator()); - // toolBarManager.add(fTogglePresentation); - // } - } +// public void init(IActionBars bars, IWorkbenchPage page) { +// Iterator e = fPartListeners.iterator(); +// while (e.hasNext()) +// page.addPartListener((RetargetAction) e.next()); +// // character encoding +// fEncodingActionGroup.fillActionBars(bars); +// super.init(bars, page); +// } + + /* + * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage) + */ + public void init(IActionBars bars, IWorkbenchPage page) { + super.init(bars, page); + + // register actions that have a dynamic editor. + bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist); + // character encoding + fEncodingActionGroup.fillActionBars(bars); + } + // /* +// * @see IEditorActionBarContributor#init(IActionBars) +// */ +// public void init(IActionBars bars) { +// super.init(bars); +// IMenuManager menuManager = bars.getMenuManager(); +// IMenuManager editMenu = menuManager +// .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); +// if (editMenu != null) { +// editMenu.add(new Separator()); +// editMenu.add(fContentAssist); +// // editMenu.add(fGotoMatchingBracket); +// // editMenu.add(fContentAssistTip); +// } +// bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, +// fContentAssist); +// // IToolBarManager toolBarManager = bars.getToolBarManager(); +// // if (toolBarManager != null) { +// // toolBarManager.add(new Separator()); +// // toolBarManager.add(fTogglePresentation); +// // } +// } + + /* * @see IEditorActionBarContributor#setActiveEditor(IEditorPart) */ @@ -227,37 +215,25 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { IStatusLineManager manager = bars.getStatusLineManager(); manager.setMessage(null); manager.setErrorMessage(null); - ITextEditor textEditor = null; + + ITextEditor textEditor = null; if (part instanceof ITextEditor) textEditor = (ITextEditor) part; - fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$ - fContentAssistTip.setAction(getAction(textEditor, "ContentAssistTip")); //$NON-NLS-1$ - fGotoMatchingBracket.setAction(getAction(textEditor, - GotoMatchingBracketAction.GOTO_MATCHING_BRACKET)); - bars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_RIGHT, getAction( - textEditor, "ShiftRight")); //$NON-NLS-1$ - bars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_LEFT, getAction( - textEditor, "ShiftLeft")); //$NON-NLS-1$ - // character encoding - fEncodingActionGroup.retarget(textEditor); - bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction( - textEditor, "Comment")); - bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction( - textEditor, "Uncomment")); - bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction( - textEditor, "Format")); - if (part instanceof PHPEditor) { - PHPEditor phpEditor = (PHPEditor) part; - phpEditor.getActionGroup().fillActionBars(getActionBars()); - } - // if (part instanceof PHPEditor) { - // PHPEditor cuEditor = (PHPEditor) part; - // ActionGroup group = cuEditor.getActionGroup(); - // if (group != null) - // group.fillActionBars(bars); - // } - // fTogglePresentation.setEditor(editor); - // fTogglePresentation.update(); + + fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$ + fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$ +// fCorrectionAssist.setAction(getAction(textEditor, "CorrectionAssistProposal")); //$NON-NLS-1$ + + IActionBars actionBars= getActionBars(); + actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_RIGHT, getAction(textEditor, "ShiftRight")); //$NON-NLS-1$ + actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_LEFT, getAction(textEditor, "ShiftLeft")); //$NON-NLS-1$ + + actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId())); //$NON-NLS-1$ + actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId())); //$NON-NLS-1$ + + // character encoding + fEncodingActionGroup.retarget(textEditor); + if (textEditor != null) { IFile file = null; IEditorInput editorInput = textEditor.getEditorInput(); @@ -276,15 +252,5 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { } } } - /* - * @see IEditorActionBarContributor#dispose() - */ - public void dispose() { - Iterator e = fPartListeners.iterator(); - while (e.hasNext()) - getPage().removePartListener((RetargetAction) e.next()); - fPartListeners.clear(); - setActiveEditor(null); - super.dispose(); - } + } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index acf9d5a..43295c7 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -24,20 +24,19 @@ import net.sourceforge.phpdt.core.IJavaElement; import net.sourceforge.phpdt.core.IMember; import net.sourceforge.phpdt.core.ISourceRange; import net.sourceforge.phpdt.core.ISourceReference; -import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.core.JavaCore; +import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup; import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter; +import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher; import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider; import net.sourceforge.phpdt.ui.IContextMenuConstants; import net.sourceforge.phpdt.ui.JavaUI; import net.sourceforge.phpdt.ui.PreferenceConstants; -import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction; import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; @@ -64,7 +63,6 @@ import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextOperationTarget; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.ITextViewerExtension2; @@ -127,13 +125,11 @@ import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.editors.text.DefaultEncodingSupport; import org.eclipse.ui.editors.text.IEncodingSupport; import org.eclipse.ui.part.IShowInTargetList; -import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.DefaultRangeIndicator; import org.eclipse.ui.texteditor.ExtendedTextEditor; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.ResourceAction; import org.eclipse.ui.texteditor.TextEditorAction; @@ -1132,6 +1128,12 @@ public abstract class PHPEditor extends ExtendedTextEditor implements IViewPart protected JavaOutlinePage fOutlinePage; /** Outliner context menu Id */ protected String fOutlinerContextMenuId; + /** + * The editor selection changed listener. + * + * @since 3.0 + */ +// private EditorSelectionChangedListener fEditorSelectionChangedListener; /** Indicates whether this editor should react on outline page selection changes */ private int fIgnoreOutlinePageSelection; @@ -1155,8 +1157,6 @@ public abstract class PHPEditor extends ExtendedTextEditor implements IViewPart private MouseClickListener fMouseListener; protected CompositeActionGroup fActionGroups; - /** The standard action groups added to the menu */ - protected GenerateActionGroup fGenerateActionGroup; protected CompositeActionGroup fContextMenuGroup; /** The information presenter. */ @@ -1193,32 +1193,20 @@ public abstract class PHPEditor extends ExtendedTextEditor implements IViewPart */ public PHPEditor() { super(); - JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); - setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this)); - setRangeIndicator(new DefaultRangeIndicator()); - setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore()); - - // don't activate this scope without synchronizing plugin.xml !!! - // setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$ - - if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE)) - fUpdater= new OutlinePageSelectionUpdater(); + JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools(); + setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this)); //, IJavaPartitions.JAVA_PARTITIONING)); + setRangeIndicator(new DefaultRangeIndicator()); + IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore(); + setPreferenceStore(store); + setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$ +// fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES); +// fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES); + + // TODO changed in 3.x ? + if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE)) + fUpdater= new OutlinePageSelectionUpdater(); } - // - // /** - // * @see IMember#getCompilationUnit() - // */ - // public ICompilationUnit getCompilationUnit() { - // return this; - // } - // /** - // * @see org.phpeclipse.phpdt.internal.compiler.env.ICompilationUnit#getContents() - // */ - // public char[] getContents() { - // IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput()); - // - // return doc.get().toCharArray(); - // } + /* * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions() */ @@ -1334,60 +1322,74 @@ public abstract class PHPEditor extends ExtendedTextEditor implements IViewPart */ protected void createActions() { super.createActions(); + + ResourceAction resAction= new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$ + resAction= new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$ + resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC); + setAction("ShowJavaDoc", resAction); //$NON-NLS-1$ +// WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION); + + Action action= new GotoMatchingBracketAction(this); + action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); + setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action); + +// action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.", this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$ +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE); +// setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action); +//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.SHOW_OUTLINE_ACTION); +// +// action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.", this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$ +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE); +// setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE, action); +//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.OPEN_STRUCTURE_ACTION); +// +// action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.", this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$ +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY); +// setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY, action); +//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.OPEN_HIERARCHY_ACTION); + + fEncodingSupport= new DefaultEncodingSupport(); + fEncodingSupport.initialize(this); + +// fSelectionHistory= new SelectionHistory(this); +// +// action= new StructureSelectEnclosingAction(this, fSelectionHistory); +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING); +// setAction(StructureSelectionAction.ENCLOSING, action); +// +// action= new StructureSelectNextAction(this, fSelectionHistory); +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT); +// setAction(StructureSelectionAction.NEXT, action); +// +// action= new StructureSelectPreviousAction(this, fSelectionHistory); +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS); +// setAction(StructureSelectionAction.PREVIOUS, action); +// +// StructureSelectHistoryAction historyAction= new StructureSelectHistoryAction(this, fSelectionHistory); +// historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST); +// setAction(StructureSelectionAction.HISTORY, historyAction); +// fSelectionHistory.setHistoryAction(historyAction); +// +// action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this); +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER); +// setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action); +// +// action= GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this); +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER); +// setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action); +// +// action= new QuickFormatAction(); +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT); +// setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action); +// +// action= new RemoveOccurrenceAnnotations(this); +// action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS); +// setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$ - ResourceAction resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$ - resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$ - resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC); - setAction("ShowJavaDoc", resAction); //$NON-NLS-1$ - // WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION); - - Action action; - - setAction( - "ContentAssistTip", - new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION)); - - action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$ - action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - setAction("ContentAssistProposal", action); //$NON-NLS-1$ - markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ - // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.CONTENT_ASSIST_ACTION); - - fEncodingSupport = new DefaultEncodingSupport(); - fEncodingSupport.initialize(this); - - action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$ - action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT); - setAction("Comment", action); //$NON-NLS-1$ - markAsStateDependentAction("Comment", true); //$NON-NLS-1$ - // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION); - - action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$ - action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT); - setAction("Uncomment", action); //$NON-NLS-1$ - markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$ - // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION); - - action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ - action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT); - setAction("Format", action); //$NON-NLS-1$ - markAsStateDependentAction("Format", true); //$NON-NLS-1$ - markAsSelectionDependentAction("Format", true); //$NON-NLS-1$ - // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION); - - action = new GotoMatchingBracketAction(this); - action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); - setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action); - - 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 over positioning - fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup }); - // rg, - // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)}); - + // add annotation actions + action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$ + setAction("AnnotationAction", action); //$NON-NLS-1$ + // add annotation actions action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$ setAction("AnnotationAction", action); //$NON-NLS-1$ @@ -1622,10 +1624,6 @@ public abstract class PHPEditor extends ExtendedTextEditor implements IViewPart fOutlinePage.addSelectionChangedListener(fSelectionChangedListener); } } - protected void updateStateDependentActions() { - super.updateStateDependentActions(); - fGenerateActionGroup.editorStateChanged(); - } protected void setSelection(ISourceReference reference, boolean moveCursor) { @@ -1943,6 +1941,44 @@ public abstract class PHPEditor extends ExtendedTextEditor implements IViewPart return; } +// if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) { +// if ((event.getNewValue() instanceof Boolean) && ((Boolean)event.getNewValue()).booleanValue()) +// fEditorSelectionChangedListener.selectionChanged(); +// return; +// } + + if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) { + if (event.getNewValue() instanceof Boolean) { + Boolean disable= (Boolean) event.getNewValue(); + configureInsertMode(OVERWRITE, !disable.booleanValue()); + } + } + +// if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) { +// if (event.getNewValue() instanceof Boolean) { +// boolean markOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue(); +// if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) { +// fMarkOccurrenceAnnotations= markOccurrenceAnnotations; +// if (!fMarkOccurrenceAnnotations) +// uninstallOccurrencesFinder(); +// else +// installOccurrencesFinder(); +// } +// } +// } +// if (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) { +// if (event.getNewValue() instanceof Boolean) { +// boolean stickyOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue(); +// if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations) { +// fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations; +//// if (!fMarkOccurrenceAnnotations) +//// uninstallOccurrencesFinder(); +//// else +//// installOccurrencesFinder(); +// } +// } +// } + } finally { super.handlePreferenceStoreChanged(event); } @@ -2393,7 +2429,7 @@ public abstract class PHPEditor extends ExtendedTextEditor implements IViewPart List segmentation = new ArrayList(); for (int i = 0; i < linePartitioning.length; i++) { - if (IPHPPartitionScannerConstants.PHP_STRING.equals(linePartitioning[i].getType())) + if (IPHPPartitions.PHP_STRING.equals(linePartitioning[i].getType())) segmentation.add(linePartitioning[i]); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditorActionDefinitionIds.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditorActionDefinitionIds.java index b9b7cd3..5022ea2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditorActionDefinitionIds.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditorActionDefinitionIds.java @@ -1,6 +1,8 @@ package net.sourceforge.phpeclipse.phpeditor; -public interface PHPEditorActionDefinitionIds { +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; + +public interface PHPEditorActionDefinitionIds extends ITextEditorActionDefinitionIds { /** * Action definition ID of the edit -> go to matching bracket action * (value "org.phpeclipse.phpdt.ui.edit.text.php.goto.matching.bracket"). @@ -18,7 +20,34 @@ public interface PHPEditorActionDefinitionIds { * Value: net.sourceforge.phpeclipse.phpeditor.uncomment */ public static final String UNCOMMENT = "net.sourceforge.phpeclipse.phpeditor.uncomment"; + /** + * Action definition ID of the source -> toggle comment action + * (value "org.eclipse.jdt.ui.edit.text.java.toggle.comment"). + * @since 3.0 + */ + public static final String TOGGLE_COMMENT= "net.sourceforge.phpeclipse.phpeditor.toggle.comment"; //$NON-NLS-1$ + + + /** + * Action definition ID of the source -> add block comment action + * (value "org.eclipse.jdt.ui.edit.text.java.add.block.comment"). + * @since 3.0 + */ + public static final String ADD_BLOCK_COMMENT= "net.sourceforge.phpeclipse.phpeditor.add.block.comment"; //$NON-NLS-1$ + /** + * Action definition ID of the source -> remove block comment action + * (value "org.eclipse.jdt.ui.edit.text.java.remove.block.comment"). + * @since 3.0 + */ + public static final String REMOVE_BLOCK_COMMENT= "net.sourceforge.phpeclipse.phpeditor.remove.block.comment"; //$NON-NLS-1$ + + /** + * Action definition ID of the source -> indent action + * (value "org.eclipse.jdt.ui.edit.text.java.indent"). + */ + public static final String INDENT= "net.sourceforge.phpeclipse.phpeditor.indent"; //$NON-NLS-1$ + /** * Action definition ID of the source -> format action */ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java index b8ab839..038abd3 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java @@ -15,6 +15,7 @@ import java.util.Vector; import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference; import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter; +import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover; import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider; import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl; @@ -29,7 +30,6 @@ import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy; import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor; -import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants; import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy; import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor; import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector; @@ -203,7 +203,7 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { */ public IAutoIndentStrategy getAutoIndentStrategy( ISourceViewer sourceViewer, String contentType) { - return (IPHPPartitionScannerConstants.PHP.equals(contentType) + return (IPHPPartitions.PHP_PARTITIONING.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy()); } @@ -333,16 +333,16 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { * (non-Javadoc) Method declared on SourceViewerConfiguration */ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return new String[]{IPHPPartitionScannerConstants.HTML, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.PHP, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.CSS, - IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.JAVASCRIPT, - IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.SMARTY, - IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT, + return new String[]{IPHPPartitions.HTML, + IPHPPartitions.HTML_MULTILINE_COMMENT, + IPHPPartitions.PHP_PARTITIONING, + IPHPPartitions.PHP_MULTILINE_COMMENT, + IPHPPartitions.CSS, + IPHPPartitions.CSS_MULTILINE_COMMENT, + IPHPPartitions.JAVASCRIPT, + IPHPPartitions.JS_MULTILINE_COMMENT, + IPHPPartitions.SMARTY, + IPHPPartitions.SMARTY_MULTILINE_COMMENT, IDocument.DEFAULT_CONTENT_TYPE}; } /* @@ -352,28 +352,28 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { ContentAssistant assistant = new ContentAssistant(); IContentAssistProcessor processor = new HTMLCompletionProcessor(); assistant.setContentAssistProcessor(processor, - IPHPPartitionScannerConstants.HTML); + IPHPPartitions.HTML); assistant.setContentAssistProcessor(processor, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + IPHPPartitions.HTML_MULTILINE_COMMENT); assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE); assistant.setContentAssistProcessor(processor, - IPHPPartitionScannerConstants.CSS); + IPHPPartitions.CSS); assistant.setContentAssistProcessor(processor, - IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + IPHPPartitions.CSS_MULTILINE_COMMENT); assistant.setContentAssistProcessor(processor, - IPHPPartitionScannerConstants.JAVASCRIPT); + IPHPPartitions.JAVASCRIPT); assistant.setContentAssistProcessor(processor, - IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + IPHPPartitions.JS_MULTILINE_COMMENT); // TODO define special smarty partition content assist assistant.setContentAssistProcessor(processor, - IPHPPartitionScannerConstants.SMARTY); + IPHPPartitions.SMARTY); assistant.setContentAssistProcessor(processor, - IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + IPHPPartitions.SMARTY_MULTILINE_COMMENT); assistant.setContentAssistProcessor(new PHPCompletionProcessor(), - IPHPPartitionScannerConstants.PHP); + IPHPPartitions.PHP_PARTITIONING); assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(), - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + IPHPPartitions.PHP_MULTILINE_COMMENT); // assistant.enableAutoActivation(true); // assistant.setAutoActivationDelay(500); // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY); @@ -458,47 +458,47 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML); + reconciler.setDamager(dr, IPHPPartitions.HTML); + reconciler.setRepairer(dr, IPHPPartitions.HTML); dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.CSS); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.CSS); + reconciler.setDamager(dr, IPHPPartitions.CSS); + reconciler.setRepairer(dr, IPHPPartitions.CSS); dr = new DefaultDamagerRepairer(getHTMLScanner()); reconciler.setDamager(dr, - IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + IPHPPartitions.CSS_MULTILINE_COMMENT); reconciler.setRepairer(dr, - IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + IPHPPartitions.CSS_MULTILINE_COMMENT); dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.JAVASCRIPT); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.JAVASCRIPT); + reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT); + reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT); dr = new DefaultDamagerRepairer(getHTMLScanner()); reconciler.setDamager(dr, - IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + IPHPPartitions.JS_MULTILINE_COMMENT); reconciler.setRepairer(dr, - IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + IPHPPartitions.JS_MULTILINE_COMMENT); dr = new DefaultDamagerRepairer(getSmartyScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.SMARTY); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.SMARTY); + reconciler.setDamager(dr, IPHPPartitions.SMARTY); + reconciler.setRepairer(dr, IPHPPartitions.SMARTY); dr = new DefaultDamagerRepairer(getSmartyDocScanner()); reconciler.setDamager(dr, - IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + IPHPPartitions.SMARTY_MULTILINE_COMMENT); reconciler.setRepairer(dr, - IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + IPHPPartitions.SMARTY_MULTILINE_COMMENT); dr = new DefaultDamagerRepairer(new SingleTokenScanner( new TextAttribute(fJavaTextTools.getColorManager().getColor( PHPColorProvider.MULTI_LINE_COMMENT)))); reconciler.setDamager(dr, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + IPHPPartitions.HTML_MULTILINE_COMMENT); reconciler.setRepairer(dr, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + IPHPPartitions.HTML_MULTILINE_COMMENT); dr = new DefaultDamagerRepairer(getCodeScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP); + reconciler.setDamager(dr, IPHPPartitions.PHP_PARTITIONING); + reconciler.setRepairer(dr, IPHPPartitions.PHP_PARTITIONING); dr = new DefaultDamagerRepairer(getPHPDocScanner()); reconciler.setDamager(dr, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + IPHPPartitions.PHP_MULTILINE_COMMENT); reconciler.setRepairer(dr, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + IPHPPartitions.PHP_MULTILINE_COMMENT); return reconciler; } /* @@ -622,15 +622,15 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE); presenter.setInformationProvider(provider, - IPHPPartitionScannerConstants.PHP); + IPHPPartitions.PHP_PARTITIONING); presenter.setInformationProvider(provider, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + IPHPPartitions.PHP_MULTILINE_COMMENT); presenter.setInformationProvider(provider, - IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + IPHPPartitions.SMARTY_MULTILINE_COMMENT); presenter.setInformationProvider(provider, - IPHPPartitionScannerConstants.HTML); + IPHPPartitions.HTML); presenter.setInformationProvider(provider, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + IPHPPartitions.HTML_MULTILINE_COMMENT); presenter.setSizeConstraints(40, 20, true, false); return presenter; } 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 442e5ce..df0ea7e 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,4 @@ package net.sourceforge.phpeclipse.phpeditor; - import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.ArrayList; @@ -10,19 +9,23 @@ import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.IJavaElement; import net.sourceforge.phpdt.core.ISourceRange; import net.sourceforge.phpdt.core.ISourceReference; -import net.sourceforge.phpdt.core.JavaModelException; 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; import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager; import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI; import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags; import net.sourceforge.phpdt.ui.IWorkingCopyManager; import net.sourceforge.phpdt.ui.PreferenceConstants; +import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IWorkspace; @@ -31,6 +34,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.ErrorDialog; @@ -44,6 +48,7 @@ import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ILineTracker; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextOperationTarget; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextViewerExtension; import org.eclipse.jface.text.ITypedRegion; @@ -56,6 +61,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.swt.SWT; import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.graphics.Color; @@ -67,33 +73,32 @@ import org.eclipse.swt.widgets.Shell; 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; import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.IDocumentProvider; - -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - IBM Corporation - Initial implementation - Klaus Hartlage - www.eclipseproject.de -**********************************************************************/ +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 + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: IBM Corporation - Initial implementation Klaus Hartlage - + * www.eclipseproject.de + ******************************************************************************/ /** * PHP specific text editor. */ public class PHPUnitEditor extends PHPEditor { - interface ITextConverter { void customizeDocumentCommand(IDocument document, DocumentCommand command); }; - // class AdaptedRulerLayout extends Layout { // // protected int fGap; @@ -104,9 +109,11 @@ public class PHPUnitEditor extends PHPEditor { // fAdaptedSourceViewer = asv; // } // - // protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { + // protected Point computeSize(Composite composite, int wHint, int hHint, + // boolean flushCache) { // Control[] children = composite.getChildren(); - // Point s = children[children.length - 1].computeSize(SWT.DEFAULT, SWT.DEFAULT, flushCache); + // Point s = children[children.length - 1].computeSize(SWT.DEFAULT, + // SWT.DEFAULT, flushCache); // if (fAdaptedSourceViewer.isVerticalRulerVisible()) // s.x += fAdaptedSourceViewer.getVerticalRuler().getWidth() + fGap; // return s; @@ -127,10 +134,12 @@ public class PHPUnitEditor extends PHPEditor { // if (fAdaptedSourceViewer.isOverviewRulerVisible()) { // OverviewRuler or = fAdaptedSourceViewer.getOverviewRuler(); // orWidth = or.getWidth(); - // or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight, orWidth, clArea.height - 3 * scrollbarHeight); + // or.getControl().setBounds(clArea.width - orWidth, scrollbarHeight, + // orWidth, clArea.height - 3 * scrollbarHeight); // } // - // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth - 2 * fGap, clArea.height); + // textWidget.setBounds(vrWidth + fGap, 0, clArea.width - vrWidth - orWidth - + // 2 * fGap, clArea.height); // vr.getControl().setBounds(0, 0, vrWidth, clArea.height - scrollbarHeight); // // } else { @@ -140,21 +149,24 @@ public class PHPUnitEditor extends PHPEditor { // } // }; // - // class AdaptedSourceViewer extends SourceViewer { // extends JavaCorrectionSourceViewer { + // class AdaptedSourceViewer extends SourceViewer { // extends + // JavaCorrectionSourceViewer { // // private List fTextConverters; // // private OverviewRuler fOverviewRuler; // private boolean fIsOverviewRulerVisible; // /** The viewer's overview ruler hovering controller */ - // private AbstractHoverInformationControlManager fOverviewRulerHoveringController; + // private AbstractHoverInformationControlManager + // fOverviewRulerHoveringController; // // private boolean fIgnoreTextConverters = false; // // private IVerticalRuler fCachedVerticalRuler; // private boolean fCachedIsVerticalRulerVisible; // - // public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { + // public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler, int + // styles) { // super(parent, ruler, styles); //, CompilationUnitEditor.this); // // fCachedVerticalRuler = ruler; @@ -169,7 +181,7 @@ public class PHPUnitEditor extends PHPEditor { // */ // public void showAnnotations(boolean show) { // fCachedIsVerticalRulerVisible = (show && fCachedVerticalRuler != null); - // // super.showAnnotations(show); + // // super.showAnnotations(show); // } // // public IContentAssistant getContentAssistant() { @@ -227,7 +239,8 @@ public class PHPUnitEditor extends PHPEditor { // super.customizeDocumentCommand(command); // if (!fIgnoreTextConverters && fTextConverters != null) { // for (Iterator e = fTextConverters.iterator(); e.hasNext();) - // ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), command); + // ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), + // command); // } // fIgnoreTextConverters = false; // } @@ -262,11 +275,12 @@ public class PHPUnitEditor extends PHPEditor { // fOverviewRuler.createControl(composite, this); // } // } - // protected void ensureOverviewHoverManagerInstalled() { - // if (fOverviewRulerHoveringController == null && fAnnotationHover != null && fHoverControlCreator != null) { + // if (fOverviewRulerHoveringController == null && fAnnotationHover != null + // && fHoverControlCreator != null) { // fOverviewRulerHoveringController = - // new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover, fHoverControlCreator); + // new OverviewRulerHoverManager(fOverviewRuler, this, fAnnotationHover, + // fHoverControlCreator); // fOverviewRulerHoveringController.install(fOverviewRuler.getControl()); // } // } @@ -306,7 +320,8 @@ public class PHPUnitEditor extends PHPEditor { // IAnnotationModel annotationModel, // int visibleRegionOffset, // int visibleRegionLength) { - // super.setDocument(document, annotationModel, visibleRegionOffset, visibleRegionLength); + // super.setDocument(document, annotationModel, visibleRegionOffset, + // visibleRegionLength); // fOverviewRuler.setModel(annotationModel); // } // @@ -331,11 +346,13 @@ public class PHPUnitEditor extends PHPEditor { // } // // /* - // * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration) + // * @see + // org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration) // */ // public void configure(SourceViewerConfiguration configuration) { // super.configure(configuration); - // // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this), IDocument.DEFAULT_CONTENT_TYPE); + // // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this), + // IDocument.DEFAULT_CONTENT_TYPE); // } // // protected void handleDispose() { @@ -350,42 +367,33 @@ 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) { - super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); + 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) */ public void doOperation(int operation) { - if (getTextWidget() == null) return; - switch (operation) { case CONTENTASSIST_PROPOSALS : String msg = fContentAssistant.showPossibleCompletions(); setStatusLineErrorMessage(msg); return; - // case CORRECTIONASSIST_PROPOSALS: - // fCorrectionAssistant.showPossibleCompletions(); - // return; + // case CORRECTIONASSIST_PROPOSALS: + // fCorrectionAssistant.showPossibleCompletions(); + // return; case UNDO : fIgnoreTextConverters = true; break; @@ -393,10 +401,8 @@ public class PHPUnitEditor extends PHPEditor { fIgnoreTextConverters = true; break; } - super.doOperation(operation); } - /* * @see ITextOperationTarget#canDoOperation(int) */ @@ -405,7 +411,6 @@ public class PHPUnitEditor extends PHPEditor { // return isEditable(); return super.canDoOperation(operation); } - /* * @see TextViewer#handleDispose() */ @@ -416,11 +421,9 @@ 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); @@ -428,7 +431,6 @@ public class PHPUnitEditor extends PHPEditor { } else if (!fTextConverters.contains(textConverter)) fTextConverters.add(textConverter); } - public void removeTextConverter(ITextConverter textConverter) { if (fTextConverters != null) { fTextConverters.remove(textConverter); @@ -436,7 +438,6 @@ public class PHPUnitEditor extends PHPEditor { fTextConverters = null; } } - /* * @see TextViewer#customizeDocumentCommand(DocumentCommand) */ @@ -444,11 +445,11 @@ public class PHPUnitEditor extends PHPEditor { super.customizeDocumentCommand(command); if (!fIgnoreTextConverters && fTextConverters != null) { for (Iterator e = fTextConverters.iterator(); e.hasNext();) - ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), command); + ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), + command); } fIgnoreTextConverters = false; } - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 public void updateIndentationPrefixes() { SourceViewerConfiguration configuration = getSourceViewerConfiguration(); @@ -459,7 +460,6 @@ public class PHPUnitEditor extends PHPEditor { setIndentPrefixes(prefixes, types[i]); } } - /* * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper) */ @@ -468,73 +468,60 @@ 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) */ public void configure(SourceViewerConfiguration configuration) { super.configure(configuration); - // fCorrectionAssistant= new JavaCorrectionAssistant(CompilationUnitEditor.this); + // fCorrectionAssistant= new + // JavaCorrectionAssistant(CompilationUnitEditor.this); // fCorrectionAssistant.install(this); //TODO install SmartBracesAutoEditStrategy - // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this), IDocument.DEFAULT_CONTENT_TYPE); + // prependAutoEditStrategy(new SmartBracesAutoEditStrategy(this), + // 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; - int remainder = offsetInLine % fTabRatio; remainder = fTabRatio - remainder; for (int i = 0; i < remainder; i++) buffer.append(' '); return remainder; } - - public void customizeDocumentCommand(IDocument document, DocumentCommand command) { + public void customizeDocumentCommand(IDocument document, + DocumentCommand command) { String text = command.text; if (text == null) return; - int index = text.indexOf('\t'); if (index > -1) { - StringBuffer buffer = new StringBuffer(); - fLineTracker.set(command.text); int lines = fLineTracker.getNumberOfLines(); - try { - for (int i = 0; i < lines; i++) { - int offset = fLineTracker.getLineOffset(i); int endOffset = offset + fLineTracker.getLineLength(i); String line = text.substring(offset, endOffset); - int position = 0; if (i == 0) { - IRegion firstLine = document.getLineInformationOfOffset(command.offset); + IRegion firstLine = document + .getLineInformationOfOffset(command.offset); position = command.offset - firstLine.getOffset(); } - int length = line.length(); for (int j = 0; j < length; j++) { char c = line.charAt(j); @@ -545,88 +532,73 @@ public class PHPUnitEditor extends PHPEditor { ++position; } } - } - command.text = buffer.toString(); - } catch (BadLocationException x) { } } } }; - 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) + * @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) */ - public ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event, int offset, int length) { - + public ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event, + int offset, int length) { if (event.character == fExitCharacter) { if (manager.anyPositionIncludes(offset, length)) - return new ExitFlags(LinkedPositionUI.COMMIT | LinkedPositionUI.UPDATE_CARET, false); + return new ExitFlags(LinkedPositionUI.COMMIT + | LinkedPositionUI.UPDATE_CARET, false); else 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 : 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; @@ -634,186 +606,162 @@ public class PHPUnitEditor extends PHPEditor { int maxEnd = endLine.getOffset() + endLine.getLength(); while (end != maxEnd && Character.isWhitespace(document.getChar(end))) ++end; - - return end != maxEnd && Scanner.isPHPIdentifierPart(document.getChar(end)); - + return end != maxEnd + && Scanner.isPHPIdentifierPart(document.getChar(end)); } catch (BadLocationException e) { // be conservative return true; } } - private boolean hasIdentifierToTheLeft(IDocument document, int offset) { try { int start = offset; IRegion startLine = document.getLineInformationOfOffset(start); int minStart = startLine.getOffset(); - while (start != minStart && Character.isWhitespace(document.getChar(start - 1))) + while (start != minStart + && Character.isWhitespace(document.getChar(start - 1))) --start; - - return start != minStart && Scanner.isPHPIdentifierPart(document.getChar(start - 1)); - + return start != minStart + && Scanner.isPHPIdentifierPart(document.getChar(start - 1)); } catch (BadLocationException e) { return true; } } - - private boolean hasCharacterToTheRight(IDocument document, int offset, char character) { + private boolean hasCharacterToTheRight(IDocument document, int offset, + char character) { try { int end = offset; IRegion endLine = document.getLineInformationOfOffset(end); int maxEnd = endLine.getOffset() + endLine.getLength(); while (end != maxEnd && Character.isWhitespace(document.getChar(end))) ++end; - return end != maxEnd && document.getChar(end) == character; - } catch (BadLocationException e) { // be conservative return true; } } - /* * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent) */ public void verifyKey(VerifyEvent event) { - if (!event.doit) return; - final ISourceViewer sourceViewer = getSourceViewer(); IDocument document = sourceViewer.getDocument(); - final Point selection = sourceViewer.getSelectedRange(); final int offset = selection.x; final int length = selection.y; - try { ITypedRegion partition = document.getPartition(offset); String type = partition.getType(); - if (type.equals(IPHPPartitionScannerConstants.PHP)) { + if (type.equals(IPHPPartitions.PHP_PARTITIONING)) { switch (event.character) { case '(' : if (hasCharacterToTheRight(document, offset + length, '(')) return; - - // fall through - + // fall through case '[' : if (!fCloseBracketsPHP) return; if (hasIdentifierToTheRight(document, offset + length)) return; - - // fall through - + // fall through case '"' : if (event.character == '"') { if (!fCloseStringsPHP) return; - // changed for statements like echo "" print "" - // if (hasIdentifierToTheLeft(document, offset) || hasIdentifierToTheRight(document, offset + length)) + // 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)) + // 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); + LinkedPositionManager manager = new LinkedPositionManager( + document); manager.addPosition(offset + 1, 0); - fOffset = offset; fLength = 2; - - LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, manager); + 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()); - + sourceViewer.setSelectedRange(newSelection.getOffset(), + newSelection.getLength()); event.doit = false; } - } else if (type.equals(IPHPPartitionScannerConstants.HTML) || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) { + } else if (type.equals(IPHPPartitions.HTML) + || type.equals(IDocument.DEFAULT_CONTENT_TYPE)) { switch (event.character) { case '(' : if (hasCharacterToTheRight(document, offset + length, '(')) return; - - // fall through - + // fall through case '[' : if (!fCloseBracketsHTML) return; if (hasIdentifierToTheRight(document, offset + length)) return; - - // fall through - + // fall through case '"' : if (event.character == '"') { if (!fCloseStringsHTML) return; - - if (hasIdentifierToTheLeft(document, offset) || hasIdentifierToTheRight(document, offset + length)) + 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)) + // 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); + LinkedPositionManager manager = new LinkedPositionManager( + document); manager.addPosition(offset + 1, 0); - fOffset = offset; fLength = 2; - - LinkedPositionUI editor = new LinkedPositionUI(sourceViewer, manager); + 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()); - + sourceViewer.setSelectedRange(newSelection.getOffset(), + newSelection.getLength()); event.doit = false; } } } catch (BadLocationException e) { } - } - /* * @see org.phpeclipse.phpdt.internal.ui.text.link.LinkedPositionUI.ExitListener#exit(boolean) */ public void exit(boolean accept) { if (accept) return; - // remove brackets try { final ISourceViewer sourceViewer = getSourceViewer(); @@ -822,14 +770,14 @@ public class PHPUnitEditor extends PHPEditor { } catch (BadLocationException e) { } } - } - /** 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 */ @@ -846,9 +794,9 @@ public class PHPUnitEditor extends PHPEditor { private TabConverter fTabConverter; /** History for structure select action */ //private SelectionHistory fSelectionHistory; - /** The preference property change listener for php core. */ - // private IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener(); + // private IPropertyChangeListener fPropertyChangeListener = new + // PropertyChangeListener(); /** The remembered java element */ private IJavaElement fRememberedElement; /** The remembered selection */ @@ -857,12 +805,17 @@ public class PHPUnitEditor extends PHPEditor { 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) // */ - // public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) { + // public void + // propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent + // event) { // handlePreferencePropertyChanged(event); // } // } @@ -885,13 +838,17 @@ public class PHPUnitEditor extends PHPEditor { /** 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; + // private final static String ERROR_INDICATION = + // PreferenceConstants.EDITOR_PROBLEM_INDICATION; /** Preference key for error color */ -// private final static String ERROR_INDICATION_COLOR = PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR; + // private final static String ERROR_INDICATION_COLOR = + // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR; /** Preference key for warning indication */ -// private final static String WARNING_INDICATION = PreferenceConstants.EDITOR_WARNING_INDICATION; + // private final static String WARNING_INDICATION = + // PreferenceConstants.EDITOR_WARNING_INDICATION; /** Preference key for warning color */ -// private final static String WARNING_INDICATION_COLOR = PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR; + // private final static String WARNING_INDICATION_COLOR = + // 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 */ @@ -912,23 +869,18 @@ public class PHPUnitEditor extends PHPEditor { 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; + 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; + 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; + 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; + 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 */ @@ -945,7 +897,6 @@ public class PHPUnitEditor extends PHPEditor { 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 { @@ -953,7 +904,6 @@ public class PHPUnitEditor extends PHPEditor { // public String fOverviewRulerPreference; // public String fEditorPreference; // }; - // private final static Map ANNOTATION_MAP; // static { // @@ -986,7 +936,8 @@ public class PHPUnitEditor extends PHPEditor { // // info = new AnnotationInfo(); // info.fColorPreference = SEARCH_RESULT_INDICATION_COLOR; - // info.fOverviewRulerPreference = SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER; + // info.fOverviewRulerPreference = + // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER; // info.fEditorPreference = SEARCH_RESULT_INDICATION; // ANNOTATION_MAP.put(AnnotationType.SEARCH, info); // @@ -1010,36 +961,153 @@ public class PHPUnitEditor extends PHPEditor { */ public PHPUnitEditor() { super(); - setDocumentProvider(PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider()); + setDocumentProvider(PHPeclipsePlugin.getDefault() + .getCompilationUnitDocumentProvider()); setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$ setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$ setOutlinerContextMenuId("#PHPOutlinerContext"); //$NON-NLS-1$ // don't set help contextId, we install our own help context fSavePolicy = null; - fJavaEditorErrorTickUpdater = new JavaEditorErrorTickUpdater(this); } - /* - * @see JavaEditor#getElementAt(int) - */ + * @see AbstractTextEditor#createActions() + */ + protected void createActions() { + super.createActions(); + Action action; + // Action action= new + // TextOperationAction(PHPEditorMessages.getResourceBundle(), + // "CorrectionAssistProposal.", this, CORRECTIONASSIST_PROPOSALS); + // //$NON-NLS-1$ + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS); + // setAction("CorrectionAssistProposal", action); //$NON-NLS-1$ + // markAsStateDependentAction("CorrectionAssistProposal", true); + // //$NON-NLS-1$ + //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.QUICK_FIX_ACTION); + action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), + "ContentAssistProposal.", this); //$NON-NLS-1$ + action + .setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", action); //$NON-NLS-1$ + 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$ + // WorkbenchHelp.setHelp(action, + // IJavaHelpContextIds.PARAMETER_HINTS_ACTION); + // action= new TextOperationAction(PHPEditorMessages.getResourceBundle(), + // "ContentAssistCompletePrefix.", this, CONTENTASSIST_COMPLETE_PREFIX); + // //$NON-NLS-1$ + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_COMPLETE_PREFIX); + // setAction("ContentAssistCompletePrefix", action); //$NON-NLS-1$ + // markAsStateDependentAction("ContentAssistCompletePrefix", true); + // //$NON-NLS-1$ + //// WorkbenchHelp.setHelp(action, + // IJavaHelpContextIds.PARAMETER_HINTS_ACTION); + action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), + "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$ + action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT); + setAction("Comment", action); //$NON-NLS-1$ + markAsStateDependentAction("Comment", true); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION); + action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), + "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$ + action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT); + 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$ + action.setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_COMMENT); + setAction("ToggleComment", action); //$NON-NLS-1$ + markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(action, + // IJavaHelpContextIds.TOGGLE_COMMENT_ACTION); + action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), + "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ + action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT); + setAction("Format", action); //$NON-NLS-1$ + 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$ + // WorkbenchHelp.setHelp(action, + // IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION); + // action= new IndentAction(PHPEditorMessages.getResourceBundle(), + // "Indent.", this, false); //$NON-NLS-1$ + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT); + // setAction("Indent", action); //$NON-NLS-1$ + // markAsStateDependentAction("Indent", true); //$NON-NLS-1$ + // markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$ + //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION); + // + // action= new IndentAction(PHPEditorMessages.getResourceBundle(), + // "Indent.", this, true); //$NON-NLS-1$ + // setAction("IndentOnTab", action); //$NON-NLS-1$ + // markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$ + // markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$ + // + if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_TAB)) { + // don't replace Shift Right - have to make sure their enablement is + // mutually exclusive + // removeActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT); + setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$ + } + 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 + // over positioning + 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 - * @param reconcile true if working copy should be reconciled + * @param offset + * the offset included by the retrieved element + * @param reconcile + * true if working copy should be reconciled */ protected IJavaElement getElementAt(int offset, boolean reconcile) { - IWorkingCopyManager manager = PHPeclipsePlugin.getDefault().getWorkingCopyManager(); + IWorkingCopyManager manager = PHPeclipsePlugin.getDefault() + .getWorkingCopyManager(); ICompilationUnit unit = manager.getWorkingCopy(getEditorInput()); - if (unit != null) { try { if (reconcile) { @@ -1049,16 +1117,13 @@ public class PHPUnitEditor extends PHPEditor { return unit.getElementAt(offset); } else if (unit.isConsistent()) return unit.getElementAt(offset); - } catch (JavaModelException x) { PHPeclipsePlugin.log(x.getStatus()); // nothing found, be tolerant and go on } } - return null; } - /* * @see JavaEditor#getCorrespondingElement(IJavaElement) */ @@ -1071,157 +1136,138 @@ public class PHPUnitEditor extends PHPEditor { } return null; } - public void createPartControl(Composite parent) { super.createPartControl(parent); - // fPaintManager = new PaintManager(getSourceViewer()); - LinePainter linePainter; linePainter = new LinePainter(getSourceViewer()); - - linePainter.setHighlightColor(new Color(Display.getCurrent(), 225, 235, 224)); - + linePainter + .setHighlightColor(new Color(Display.getCurrent(), 225, 235, 224)); // fPaintManager.addPainter(linePainter); - if (isBracketHighlightingEnabled()) startBracketHighlighting(); if (isLineHighlightingEnabled()) startLineHighlighting(); if (isPrintMarginVisible()) showPrintMargin(); - // Iterator e = ANNOTATION_MAP.keySet().iterator(); // while (e.hasNext()) { // AnnotationType type = (AnnotationType) e.next(); // if (isAnnotationIndicationEnabled(type)) // startAnnotationIndication(type); // } - if (isTabConversionEnabled()) startTabConversion(); - // if (isOverviewRulerVisible()) // showOverviewRuler(); // - // Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences(); + // Preferences preferences = + // PHPeclipsePlugin.getDefault().getPluginPreferences(); // preferences.addPropertyChangeListener(fPropertyChangeListener); - IPreferenceStore preferenceStore = getPreferenceStore(); boolean closeBracketsPHP = preferenceStore.getBoolean(CLOSE_BRACKETS_PHP); boolean closeStringsPHP = preferenceStore.getBoolean(CLOSE_STRINGS_PHP); boolean closeBracketsHTML = preferenceStore.getBoolean(CLOSE_BRACKETS_HTML); boolean closeStringsHTML = preferenceStore.getBoolean(CLOSE_STRINGS_HTML); - fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP); fBracketInserter.setCloseStringsPHPEnabled(closeStringsPHP); fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML); fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML); - ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer instanceof ITextViewerExtension) - ((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter); - + ((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(); } } /** - * 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 - */ + * 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; + 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$ + 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); + 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$ + 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$ + 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); } @@ -1232,7 +1278,6 @@ public class PHPUnitEditor extends PHPEditor { super.doSetInput(input); configureTabConverter(); } - private void startBracketHighlighting() { if (fBracketPainter == null) { ISourceViewer sourceViewer = getSourceViewer(); @@ -1241,7 +1286,6 @@ public class PHPUnitEditor extends PHPEditor { // fPaintManager.addPainter(fBracketPainter); } } - private void stopBracketHighlighting() { if (fBracketPainter != null) { // fPaintManager.removePainter(fBracketPainter); @@ -1250,12 +1294,10 @@ 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(); @@ -1264,7 +1306,6 @@ public class PHPUnitEditor extends PHPEditor { // fPaintManager.addPainter(fLinePainter); } } - private void stopLineHighlighting() { if (fLinePainter != null) { // fPaintManager.removePainter(fLinePainter); @@ -1273,21 +1314,19 @@ 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()); fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR)); - fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN)); + fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt( + PRINT_MARGIN_COLUMN)); // fPaintManager.addPainter(fPrintMarginPainter); } } - private void hidePrintMargin() { if (fPrintMarginPainter != null) { // fPaintManager.removePainter(fPrintMarginPainter); @@ -1296,16 +1335,14 @@ 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()); - //// fPaintManager.addPainter(fProblemPainter); + //// fPaintManager.addPainter(fProblemPainter); // } // fProblemPainter.setColor(annotationType, getColor(annotationType)); // fProblemPainter.paintAnnotations(annotationType, true); @@ -1316,7 +1353,7 @@ public class PHPUnitEditor extends PHPEditor { // if (fProblemPainter != null) { // // if (!fProblemPainter.isPaintingAnnotations()) { - //// fPaintManager.removePainter(fProblemPainter); + //// fPaintManager.removePainter(fProblemPainter); // fProblemPainter.deactivate(true); // fProblemPainter.dispose(); // fProblemPainter = null; @@ -1333,7 +1370,8 @@ public class PHPUnitEditor extends PHPEditor { // } // } // - // private boolean isAnnotationIndicationEnabled(AnnotationType annotationType) { + // private boolean isAnnotationIndicationEnabled(AnnotationType + // annotationType) { // IPreferenceStore store = getPreferenceStore(); // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType); // if (info != null) @@ -1341,7 +1379,9 @@ public class PHPUnitEditor extends PHPEditor { // return false; // } // - // private boolean isAnnotationIndicationInOverviewRulerEnabled(AnnotationType annotationType) { + // private boolean + // isAnnotationIndicationInOverviewRulerEnabled(AnnotationType + // annotationType) { // IPreferenceStore store = getPreferenceStore(); // AnnotationInfo info = (AnnotationInfo) ANNOTATION_MAP.get(annotationType); // if (info != null) @@ -1349,7 +1389,8 @@ public class PHPUnitEditor extends PHPEditor { // return false; // } // - // private void showAnnotationIndicationInOverviewRuler(AnnotationType annotationType, boolean show) { + // private void showAnnotationIndicationInOverviewRuler(AnnotationType + // annotationType, boolean show) { // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); // OverviewRuler ruler = asv.getOverviewRuler(); // if (ruler != null) { @@ -1359,7 +1400,8 @@ public class PHPUnitEditor extends PHPEditor { // } // } // - // private void setColorInOverviewRuler(AnnotationType annotationType, Color color) { + // private void setColorInOverviewRuler(AnnotationType annotationType, Color + // color) { // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); // OverviewRuler ruler = asv.getOverviewRuler(); // if (ruler != null) { @@ -1367,7 +1409,6 @@ public class PHPUnitEditor extends PHPEditor { // ruler.update(); // } // } - private void configureTabConverter() { if (fTabConverter != null) { IDocumentProvider provider = getDocumentProvider(); @@ -1377,12 +1418,11 @@ public class PHPUnitEditor extends PHPEditor { } } } - private int getTabSize() { - Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences(); + Preferences preferences = PHPeclipsePlugin.getDefault() + .getPluginPreferences(); return preferences.getInt(CODE_FORMATTER_TAB_SIZE); } - private void startTabConversion() { if (fTabConverter == null) { fTabConverter = new TabConverter(); @@ -1394,7 +1434,6 @@ public class PHPUnitEditor extends PHPEditor { asv.updateIndentationPrefixes(); } } - private void stopTabConversion() { if (fTabConverter != null) { AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); @@ -1404,12 +1443,10 @@ public class PHPUnitEditor extends PHPEditor { fTabConverter = null; } } - private boolean isTabConversionEnabled() { IPreferenceStore store = getPreferenceStore(); return store.getBoolean(SPACES_FOR_TABS); } - // private void showOverviewRuler() { // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); // asv.showOverviewRuler(); @@ -1434,56 +1471,47 @@ public class PHPUnitEditor extends PHPEditor { // IPreferenceStore store = getPreferenceStore(); // return store.getBoolean(OVERVIEW_RULER); // } - private Color getColor(String key) { 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); // if (info != null) // return getColor(info.fColorPreference); // return null; // } - public void dispose() { ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer instanceof ITextViewerExtension) - ((ITextViewerExtension) sourceViewer).removeVerifyKeyListener(fBracketInserter); - + ((ITextViewerExtension) sourceViewer) + .removeVerifyKeyListener(fBracketInserter); // if (fPropertyChangeListener != null) { - // Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences(); + // Preferences preferences = + // PHPeclipsePlugin.getDefault().getPluginPreferences(); // preferences.removePropertyChangeListener(fPropertyChangeListener); // fPropertyChangeListener = null; // } - if (fJavaEditorErrorTickUpdater != null) { fJavaEditorErrorTickUpdater.dispose(); fJavaEditorErrorTickUpdater = null; } - // if (fSelectionHistory != null) // fSelectionHistory.dispose(); - // if (fPaintManager != null) { // fPaintManager.dispose(); // fPaintManager = null; // } - if (fActionGroups != null) { fActionGroups.dispose(); fActionGroups = null; } - super.dispose(); } - // protected AnnotationType getAnnotationType(String preferenceKey) { // Iterator e = ANNOTATION_MAP.keySet().iterator(); // while (e.hasNext()) { @@ -1498,39 +1526,34 @@ public class PHPUnitEditor extends PHPEditor { // } // return null; // } - /* * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent) */ protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { - try { - AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); if (asv != null) { - String p = event.getProperty(); - if (CLOSE_BRACKETS_PHP.equals(p)) { - fBracketInserter.setCloseBracketsPHPEnabled(getPreferenceStore().getBoolean(p)); + fBracketInserter.setCloseBracketsPHPEnabled(getPreferenceStore() + .getBoolean(p)); return; } - if (CLOSE_STRINGS_PHP.equals(p)) { - fBracketInserter.setCloseStringsPHPEnabled(getPreferenceStore().getBoolean(p)); + fBracketInserter.setCloseStringsPHPEnabled(getPreferenceStore() + .getBoolean(p)); return; } - if (CLOSE_BRACKETS_HTML.equals(p)) { - fBracketInserter.setCloseBracketsHTMLEnabled(getPreferenceStore().getBoolean(p)); + fBracketInserter.setCloseBracketsHTMLEnabled(getPreferenceStore() + .getBoolean(p)); return; } - if (CLOSE_STRINGS_HTML.equals(p)) { - fBracketInserter.setCloseStringsHTMLEnabled(getPreferenceStore().getBoolean(p)); + fBracketInserter.setCloseStringsHTMLEnabled(getPreferenceStore() + .getBoolean(p)); return; } - if (SPACES_FOR_TABS.equals(p)) { if (isTabConversionEnabled()) startTabConversion(); @@ -1538,7 +1561,6 @@ public class PHPUnitEditor extends PHPEditor { stopTabConversion(); return; } - if (MATCHING_BRACKETS.equals(p)) { if (isBracketHighlightingEnabled()) startBracketHighlighting(); @@ -1546,13 +1568,12 @@ public class PHPUnitEditor extends PHPEditor { stopBracketHighlighting(); return; } - if (MATCHING_BRACKETS_COLOR.equals(p)) { if (fBracketPainter != null) - fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR)); + fBracketPainter + .setHighlightColor(getColor(MATCHING_BRACKETS_COLOR)); return; } - if (CURRENT_LINE.equals(p)) { if (isLineHighlightingEnabled()) startLineHighlighting(); @@ -1560,7 +1581,6 @@ public class PHPUnitEditor extends PHPEditor { stopLineHighlighting(); return; } - if (CURRENT_LINE_COLOR.equals(p)) { if (fLinePainter != null) { stopLineHighlighting(); @@ -1568,7 +1588,6 @@ public class PHPUnitEditor extends PHPEditor { } return; } - if (PRINT_MARGIN.equals(p)) { if (isPrintMarginVisible()) showPrintMargin(); @@ -1576,19 +1595,18 @@ public class PHPUnitEditor extends PHPEditor { hidePrintMargin(); return; } - if (PRINT_MARGIN_COLOR.equals(p)) { if (fPrintMarginPainter != null) - fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR)); + fPrintMarginPainter + .setMarginRulerColor(getColor(PRINT_MARGIN_COLOR)); return; } - if (PRINT_MARGIN_COLUMN.equals(p)) { if (fPrintMarginPainter != null) - fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN)); + fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore() + .getInt(PRINT_MARGIN_COLUMN)); return; } - // if (OVERVIEW_RULER.equals(p)) { // if (isOverviewRulerVisible()) // showOverviewRuler(); @@ -1596,7 +1614,6 @@ public class PHPUnitEditor extends PHPEditor { // hideOverviewRuler(); // return; // } - // AnnotationType type = getAnnotationType(p); // if (type != null) { // @@ -1627,21 +1644,20 @@ public class PHPUnitEditor extends PHPEditor { // return; // } // } - IContentAssistant c = asv.getContentAssistant(); if (c instanceof ContentAssistant) - ContentAssistPreference.changeConfiguration((ContentAssistant) c, getPreferenceStore(), event); + ContentAssistPreference.changeConfiguration((ContentAssistant) c, + getPreferenceStore(), event); } - } finally { super.handlePreferenceStoreChanged(event); } } - /* - * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) - */ - protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) { + * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) + */ + protected void handlePreferencePropertyChanged( + org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) { AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); if (asv != null) { String p = event.getProperty(); @@ -1653,15 +1669,16 @@ 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. + * 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 + * @param event + * the property change event */ - // protected void handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) { + // protected void + // handlePreferencePropertyChanged(org.eclipse.core.runtime.Preferences.PropertyChangeEvent + // event) { // AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); // if (asv != null) { // String p = event.getProperty(); @@ -1672,22 +1689,19 @@ public class PHPUnitEditor extends PHPEditor { // } // } // } - /* * @see PHPEditor#createJavaSourceViewer(Composite, IVerticalRuler, int) */ - protected ISourceViewer createJavaSourceViewer( - Composite parent, - IVerticalRuler verticalRuler, - IOverviewRuler overviewRuler, - boolean isOverviewRulerVisible, - int styles) { - return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler, isOverviewRulerVisible, styles); + protected ISourceViewer createJavaSourceViewer(Composite parent, + IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, + boolean isOverviewRulerVisible, int styles) { + return new AdaptedSourceViewer(parent, verticalRuler, overviewRuler, + isOverviewRulerVisible, styles); } - // protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { + // protected ISourceViewer createJavaSourceViewer(Composite parent, + // IVerticalRuler ruler, int styles) { // return new AdaptedSourceViewer(parent, ruler, styles); // } - private boolean isValidSelection(int offset, int length) { IDocumentProvider provider = getDocumentProvider(); if (provider != null) { @@ -1695,17 +1709,17 @@ public class PHPUnitEditor extends PHPEditor { if (document != null) { int end = offset + length; int documentLength = document.getLength(); - return 0 <= offset && offset <= documentLength && 0 <= end && end <= documentLength; + return 0 <= offset && offset <= documentLength && 0 <= end + && end <= documentLength; } } return false; } - /* * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput) */ - protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) { - + protected boolean canHandleMove(IEditorInput originalElement, + IEditorInput movedElement) { String oldExtension = ""; //$NON-NLS-1$ if (originalElement instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) originalElement).getFile(); @@ -1715,73 +1729,71 @@ public class PHPUnitEditor extends PHPEditor { oldExtension = ext; } } - String newExtension = ""; //$NON-NLS-1$ if (movedElement instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) movedElement).getFile(); if (file != null) newExtension = file.getFileExtension(); } - return oldExtension.equals(newExtension); } - /* * @see AbstractTextEditor#editorContextMenuAboutToShow(IMenuManager) */ public void editorContextMenuAboutToShow(IMenuManager menu) { super.editorContextMenuAboutToShow(menu); - - ActionContext context = new ActionContext(getSelectionProvider().getSelection()); + ActionContext context = new ActionContext(getSelectionProvider() + .getSelection()); fContextMenuGroup.setContext(context); fContextMenuGroup.fillContextMenu(menu); fContextMenuGroup.setContext(null); } - /* * @see JavaEditor#setOutlinePageInput(JavaOutlinePage, IEditorInput) */ protected void setOutlinePageInput(JavaOutlinePage page, IEditorInput input) { if (page != null) { - IWorkingCopyManager manager = PHPeclipsePlugin.getDefault().getWorkingCopyManager(); + IWorkingCopyManager manager = PHPeclipsePlugin.getDefault() + .getWorkingCopyManager(); page.setInput(manager.getWorkingCopy(input)); } } - /* - * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation, IProgressMonitor) + * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation, + * IProgressMonitor) */ -// protected void performSaveOperation(WorkspaceModifyOperation operation, IProgressMonitor progressMonitor) { -// IDocumentProvider p = getDocumentProvider(); -// if (p instanceof PHPDocumentProvider) { -// PHPDocumentProvider cp = (PHPDocumentProvider) p; -// cp.setSavePolicy(fSavePolicy); -// } -// -// try { -// super.performSaveOperation(operation, progressMonitor); -// } finally { -// if (p instanceof PHPDocumentProvider) { -// PHPDocumentProvider cp = (PHPDocumentProvider) p; -// cp.setSavePolicy(null); -// } -// } -// } - + // protected void performSaveOperation(WorkspaceModifyOperation operation, + // IProgressMonitor progressMonitor) { + // IDocumentProvider p = getDocumentProvider(); + // if (p instanceof PHPDocumentProvider) { + // PHPDocumentProvider cp = (PHPDocumentProvider) p; + // cp.setSavePolicy(fSavePolicy); + // } + // + // try { + // super.performSaveOperation(operation, progressMonitor); + // } finally { + // if (p instanceof PHPDocumentProvider) { + // PHPDocumentProvider cp = (PHPDocumentProvider) p; + // cp.setSavePolicy(null); + // } + // } + // } /* - * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean, org.eclipse.core.runtime.IProgressMonitor) + * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean, + * org.eclipse.core.runtime.IProgressMonitor) */ protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) { - IDocumentProvider p= getDocumentProvider(); + IDocumentProvider p = getDocumentProvider(); if (p instanceof PHPDocumentProvider) { - PHPDocumentProvider cp= (PHPDocumentProvider) p; + PHPDocumentProvider cp = (PHPDocumentProvider) p; cp.setSavePolicy(fSavePolicy); } try { super.performSave(overwrite, progressMonitor); } finally { if (p instanceof PHPDocumentProvider) { - PHPDocumentProvider cp= (PHPDocumentProvider) p; + PHPDocumentProvider cp = (PHPDocumentProvider) p; cp.setSavePolicy(null); } } @@ -1794,63 +1806,58 @@ public class PHPUnitEditor extends PHPEditor { super.doSaveAs(); } } - /* - * @see AbstractTextEditor#doSave(IProgressMonitor) - */ + * @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. + * 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$ + 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(); + // IWorkingCopyManager manager= + // JavaPlugin.getDefault().getWorkingCopyManager(); // ICompilationUnit unit= manager.getWorkingCopy(getEditorInput()); // // if (unit != null) { - // synchronized (unit) { - // performSaveOperation(createSaveOperation(false), progressMonitor); + // synchronized (unit) { + // performSaveOperation(createSaveOperation(false), progressMonitor); // } - // } else + // } else // performSaveOperation(createSaveOperation(false), progressMonitor); } } /** * Asks the user if it is ok to store in non-workbench encoding. - * @return if the user wants to continue + * + * @return if the user wants to continue */ private boolean askIfNonWorkbenchEncodingIsOk() { IDocumentProvider provider = getDocumentProvider(); @@ -1861,20 +1868,29 @@ public class PHPUnitEditor extends PHPEditor { String defaultEncoding = storageProvider.getDefaultEncoding(); if (encoding != null && !encoding.equals(defaultEncoding)) { Shell shell = getSite().getShell(); - String title = PHPEditorMessages.getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$ + String title = PHPEditorMessages + .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$ String msg; if (input != null) - msg = MessageFormat.format(PHPEditorMessages.getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"), new String[] { input.getName(), encoding }); //$NON-NLS-1$ + msg = MessageFormat + .format( + PHPEditorMessages + .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message1"), + 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$ + msg = MessageFormat + .format( + PHPEditorMessages + .getString("PHPUnitEditor.warning.save.nonWorkbenchEncoding.message2"), + new String[]{encoding}); //$NON-NLS-1$ return MessageDialog.openQuestion(shell, title, msg); } } return true; } /* - * @see IReconcilingParticipant#reconciled() - */ + * @see IReconcilingParticipant#reconciled() + */ public void reconciled() { if (synchronizeOutlineOnCursorMove()) { Shell shell = getSite().getShell(); @@ -1887,45 +1903,41 @@ public class PHPUnitEditor extends PHPEditor { } } } - - private boolean synchronizeOutlineOnCursorMove() { - return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE); - } + protected void updateStateDependentActions() { super.updateStateDependentActions(); fGenerateActionGroup.editorStateChanged(); } + + private boolean synchronizeOutlineOnCursorMove() { + return PreferenceConstants.getPreferenceStore().getBoolean( + PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE); + } /** * Returns the updated java element for the old java element. */ private IJavaElement findElement(IJavaElement element) { - if (element == null) return null; - - IWorkingCopyManager manager = PHPeclipsePlugin.getDefault().getWorkingCopyManager(); + IWorkingCopyManager manager = PHPeclipsePlugin.getDefault() + .getWorkingCopyManager(); ICompilationUnit unit = manager.getWorkingCopy(getEditorInput()); - if (unit != null) { try { - synchronized (unit) { unit.reconcile(); } IJavaElement[] findings = unit.findElements(element); if (findings != null && findings.length > 0) return findings[0]; - } catch (JavaModelException x) { PHPeclipsePlugin.log(x.getStatus()); // nothing found, be tolerant and go on } } - return null; } - /** * Returns the offset of the given Java element. */ @@ -1941,40 +1953,37 @@ public class PHPUnitEditor extends PHPEditor { } return -1; } - /* * @see AbstractTextEditor#rememberSelection() */ protected void rememberSelection() { ISelectionProvider sp = getSelectionProvider(); - fRememberedSelection = (sp == null ? null : (ITextSelection) sp.getSelection()); + fRememberedSelection = (sp == null ? null : (ITextSelection) sp + .getSelection()); if (fRememberedSelection != null) { fRememberedElement = getElementAt(fRememberedSelection.getOffset(), true); fRememberedElementOffset = getOffset(fRememberedElement); } } - /* * @see AbstractTextEditor#restoreSelection() */ protected void restoreSelection() { - try { - if (getSourceViewer() == null || fRememberedSelection == null) return; - IJavaElement newElement = findElement(fRememberedElement); int newOffset = getOffset(newElement); - int delta = (newOffset > -1 && fRememberedElementOffset > -1) ? newOffset - fRememberedElementOffset : 0; - if (isValidSelection(delta + fRememberedSelection.getOffset(), fRememberedSelection.getLength())) - selectAndReveal(delta + fRememberedSelection.getOffset(), fRememberedSelection.getLength()); - + int delta = (newOffset > -1 && fRememberedElementOffset > -1) ? newOffset + - fRememberedElementOffset : 0; + if (isValidSelection(delta + fRememberedSelection.getOffset(), + fRememberedSelection.getLength())) + selectAndReveal(delta + fRememberedSelection.getOffset(), + fRememberedSelection.getLength()); } finally { fRememberedSelection = null; fRememberedElement = null; fRememberedElementOffset = -1; } } - } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ToggleCommentAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ToggleCommentAction.java new file mode 100644 index 0000000..0ca710d --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ToggleCommentAction.java @@ -0,0 +1,163 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package net.sourceforge.phpeclipse.phpeditor; + +import java.util.ResourceBundle; + +import net.sourceforge.phpeclipse.PHPeclipsePlugin; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ResourceAction; +import org.eclipse.ui.texteditor.TextEditorAction; + + + +/** + * An action which toggles the single line comment prefixes on the selected lines. + * + * @since 3.0 + */ +public final class ToggleCommentAction extends TextEditorAction { + + /** The text operation target */ + private ITextOperationTarget fOperationTarget; + /** The comment prefixes */ + private String[] fCommentPrefixes; + + /** + * Creates and initializes the action for the given text editor. The action + * configures its visual representation from the given resource bundle. + * + * @param bundle the resource bundle + * @param prefix a prefix to be prepended to the various resource keys + * (described in ResourceAction constructor), or + * null if none + * @param editor the text editor + * @see ResourceAction#ResourceAction + */ + public ToggleCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor, String[] commentPrefixes) { + super(bundle, prefix, editor); + fCommentPrefixes= commentPrefixes; + } + + /** + * Implementation of the IAction prototype. Checks if the selected + * lines are all commented or not and uncomment/comments them respectively. + */ + public void run() { + if (fOperationTarget == null) + return; + + ITextEditor editor= getTextEditor(); + if (!(editor instanceof PHPEditor)) + return; + + if (!validateEditorInputState()) + return; + + final int operationCode; + if (isSelectionCommented(editor.getSelectionProvider().getSelection())) + operationCode= ITextOperationTarget.STRIP_PREFIX; + else + operationCode= ITextOperationTarget.PREFIX; + + Shell shell= editor.getSite().getShell(); + if (!fOperationTarget.canDoOperation(operationCode)) { + if (shell != null) + MessageDialog.openError(shell, PHPEditorMessages.getString("ToggleComment.error.title"), PHPEditorMessages.getString("ToggleComment.error.message")); //$NON-NLS-1$ //$NON-NLS-2$ + return; + } + + Display display= null; + if (shell != null && !shell.isDisposed()) + display= shell.getDisplay(); + + BusyIndicator.showWhile(display, new Runnable() { + public void run() { + fOperationTarget.doOperation(operationCode); + } + }); + } + + /** + * Is the given selection single-line commented? + * + * @param selection Selection to check + * @return true iff all selected lines are single-line commented + */ + private boolean isSelectionCommented(ISelection selection) { + if (!(selection instanceof ITextSelection)) + return false; + + ITextSelection ts= (ITextSelection) selection; + if (ts.getStartLine() < 0 || ts.getEndLine() < 0) + return false; + + IDocument document= getTextEditor().getDocumentProvider().getDocument(getTextEditor().getEditorInput()); + OUTER: for (int i= ts.getStartLine(); i <= ts.getEndLine(); i++) { + for (int j= 0; j < fCommentPrefixes.length; j++) { + try { + if (fCommentPrefixes[j].length() == 0) + continue; + String s= document.get(document.getLineOffset(i), document.getLineLength(i)); + int index= s.indexOf(fCommentPrefixes[j]); + if (index >= 0 && s.substring(0, index).trim().length() == 0) + continue OUTER; + } catch (BadLocationException e) { + // should not happen + PHPeclipsePlugin.log(e); + } + } + return false; + } + return true; + } + + /** + * Implementation of the IUpdate prototype method discovers + * the operation through the current editor's + * ITextOperationTarget adapter, and sets the enabled state + * accordingly. + */ + public void update() { + super.update(); + + if (!canModifyEditor()) { + setEnabled(false); + return; + } + + ITextEditor editor= getTextEditor(); + if (fOperationTarget == null && editor != null) + fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); + + boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(ITextOperationTarget.PREFIX) && fOperationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX)); + setEnabled(isEnabled); + } + + /* + * @see TextEditorAction#setEditor(ITextEditor) + */ + public void setEditor(ITextEditor editor) { + super.setEditor(editor); + fOperationTarget= null; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/IPHPPartitionScannerConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/IPHPPartitionScannerConstants.java deleted file mode 100644 index 2613a37..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/IPHPPartitionScannerConstants.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Created on 05.03.2003 - * - */ -package net.sourceforge.phpeclipse.phpeditor.php; - -/** - * @author Stefan Langer (musk) - * - */ -public interface IPHPPartitionScannerConstants -{ - public final static String PHP = "__php"; //$NON-NLS-1$ - public final static String PHP_MULTILINE_COMMENT = "__php_multiline_comment"; //$NON-NLS-1$ - public final static String PHP_STRING = "__php_string"; //$NON-NLS-1$ - public final static String JAVASCRIPT = "__javascript"; //$NON-NLS-1$ - public final static String JS_MULTILINE_COMMENT = "__js_multiline_comment"; //$NON-NLS-1$ - public final static String CSS = "__css"; //$NON-NLS-1$ - public final static String CSS_MULTILINE_COMMENT = "__css_multiline_comment"; //$NON-NLS-1$ - public final static String HTML = "__html"; //$NON-NLS-1$ - public final static String HTML_MULTILINE_COMMENT = "__html_multiline_comment"; //$NON-NLS-1$ - public final static String SMARTY = "__smarty"; //$NON-NLS-1$ - public final static String SMARTY_MULTILINE_COMMENT = "__smarty_multiline_comment"; //$NON-NLS-1$ - - public final static int PHP_FILE = 1; - public final static int HTML_FILE = 2; - public final static int XML_FILE = 3; - public final static int SMARTY_FILE = 4; -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java index e9e7998..08f9c08 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition.java @@ -4,11 +4,13 @@ */ package net.sourceforge.phpeclipse.phpeditor.php; +import net.sourceforge.phpdt.internal.ui.text.*; + import org.eclipse.jface.text.IDocument; /** * @author slanger - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ public class PHPPartition extends Partition { @@ -25,7 +27,7 @@ public class PHPPartition extends Partition super( document, new char[] { '<', '>' }, - IPHPPartitionScannerConstants.PHP, + IPHPPartitions.PHP_PARTITIONING, parentPartition); } @@ -36,7 +38,7 @@ public class PHPPartition extends Partition */ protected boolean allowedPartition(String type) { - if(type.equals(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT)) + if(type.equals(IPHPPartitions.PHP_MULTILINE_COMMENT)) return true; return false; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java index 0157acb..35d5208 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java @@ -6,7 +6,7 @@ * Created on 05.03.2003 * * @author Stefan Langer (musk) - * @version $Revision: 1.22 $ + * @version $Revision: 1.23 $ */ package net.sourceforge.phpeclipse.phpeditor.php; @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import net.sourceforge.phpdt.internal.ui.text.*; + import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; @@ -33,8 +35,8 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { private boolean fInDoubString = false; private IDocument fDocument = null; private int fOffset = -1; - private String fContentType = IPHPPartitionScannerConstants.HTML; - private String fPrevContentType = IPHPPartitionScannerConstants.HTML; + private String fContentType = IPHPPartitions.HTML; + private String fPrevContentType = IPHPPartitions.HTML; private boolean partitionBorder = false; private int fTokenOffset; private int fEnd = -1; @@ -44,23 +46,23 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { private Map tokens = new HashMap(); public PHPPartitionScanner() { - this(IPHPPartitionScannerConstants.PHP_FILE); + this(IPHPPartitions.PHP_FILE); } public PHPPartitionScanner(int fileType) { - this.tokens.put(IPHPPartitionScannerConstants.PHP, new Token(IPHPPartitionScannerConstants.PHP)); + this.tokens.put(IPHPPartitions.PHP_PARTITIONING, new Token(IPHPPartitions.PHP_PARTITIONING)); this.tokens.put( - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT, - new Token(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT)); - this.tokens.put(IPHPPartitionScannerConstants.HTML, new Token(IPHPPartitionScannerConstants.HTML)); + IPHPPartitions.PHP_MULTILINE_COMMENT, + new Token(IPHPPartitions.PHP_MULTILINE_COMMENT)); + this.tokens.put(IPHPPartitions.HTML, new Token(IPHPPartitions.HTML)); this.tokens.put( - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT, - new Token(IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT)); + IPHPPartitions.HTML_MULTILINE_COMMENT, + new Token(IPHPPartitions.HTML_MULTILINE_COMMENT)); - this.tokens.put(IPHPPartitionScannerConstants.SMARTY, new Token(IPHPPartitionScannerConstants.SMARTY)); + this.tokens.put(IPHPPartitions.SMARTY, new Token(IPHPPartitions.SMARTY)); this.tokens.put( - IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT, - new Token(IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT)); + IPHPPartitions.SMARTY_MULTILINE_COMMENT, + new Token(IPHPPartitions.SMARTY_MULTILINE_COMMENT)); this.tokens.put(IDocument.DEFAULT_CONTENT_TYPE, new Token(IDocument.DEFAULT_CONTENT_TYPE)); fFileType = fileType; @@ -158,82 +160,82 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { while ((c = read()) != ICharacterScanner.EOF) { switch (c) { case '<' : - if (!isInString(IPHPPartitionScannerConstants.PHP) - && fContentType != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT + if (!isInString(IPHPPartitions.PHP_PARTITIONING) + && fContentType != IPHPPartitions.PHP_MULTILINE_COMMENT && checkPattern(new char[] { '?', 'p', 'h', 'p' }, true)) { - if (fContentType != IPHPPartitionScannerConstants.PHP && fCurrentLength > 5) { + if (fContentType != IPHPPartitions.PHP_PARTITIONING && fCurrentLength > 5) { unread(5); IToken token = getToken(fContentType); // save previouse contenttype //TODO build stack for previouse contenttype fPrevContentType = fContentType; - fContentType = IPHPPartitionScannerConstants.PHP; + fContentType = IPHPPartitions.PHP_PARTITIONING; return token; } else - fContentType = IPHPPartitionScannerConstants.PHP; + fContentType = IPHPPartitions.PHP_PARTITIONING; // remember offset of this partition fTokenOffset = fOffset - 5; fCurrentLength = 5; } else if ( - !isInString(IPHPPartitionScannerConstants.PHP) - && fContentType != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT + !isInString(IPHPPartitions.PHP_PARTITIONING) + && fContentType != IPHPPartitions.PHP_MULTILINE_COMMENT && checkPattern(new char[] { '?' }, false)) { - if (fContentType != IPHPPartitionScannerConstants.PHP && fCurrentLength > 2) { + if (fContentType != IPHPPartitions.PHP_PARTITIONING && fCurrentLength > 2) { unread(2); IToken token = getToken(fContentType); // save previouse contenttype fPrevContentType = fContentType; - fContentType = IPHPPartitionScannerConstants.PHP; + fContentType = IPHPPartitions.PHP_PARTITIONING; return token; } else - fContentType = IPHPPartitionScannerConstants.PHP; + fContentType = IPHPPartitions.PHP_PARTITIONING; // remember offset of this partition fTokenOffset = fOffset - 2; fCurrentLength = 2; } else if ( - !isInString(IPHPPartitionScannerConstants.PHP) - && (fContentType != IPHPPartitionScannerConstants.PHP) // BUG #769044 - && (fContentType != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT) // BUG #769044 + !isInString(IPHPPartitions.PHP_PARTITIONING) + && (fContentType != IPHPPartitions.PHP_PARTITIONING) // BUG #769044 + && (fContentType != IPHPPartitions.PHP_MULTILINE_COMMENT) // BUG #769044 && checkPattern(new char[] { '!', '-', '-' })) { // return previouse partition - if (fContentType != IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT && fCurrentLength > 4) { + if (fContentType != IPHPPartitions.HTML_MULTILINE_COMMENT && fCurrentLength > 4) { unread(4); IToken token = getToken(fContentType); - fContentType = IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT; + fContentType = IPHPPartitions.HTML_MULTILINE_COMMENT; return token; } else - fContentType = IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT; + fContentType = IPHPPartitions.HTML_MULTILINE_COMMENT; fTokenOffset = fOffset - 4; fCurrentLength = 4; } break; case '?' : - if (!isInString(IPHPPartitionScannerConstants.PHP) && fContentType == IPHPPartitionScannerConstants.PHP) { + if (!isInString(IPHPPartitions.PHP_PARTITIONING) && fContentType == IPHPPartitions.PHP_PARTITIONING) { if ((c = read()) == '>') { if (fPrevContentType != null) fContentType = fPrevContentType; else - fContentType = IPHPPartitionScannerConstants.HTML; + fContentType = IPHPPartitions.HTML; partitionBorder = true; - return getToken(IPHPPartitionScannerConstants.PHP); + return getToken(IPHPPartitions.PHP_PARTITIONING); } else if (c != ICharacterScanner.EOF) unread(); } break; case '-' : - if (!isInString(IPHPPartitionScannerConstants.PHP) - && fContentType == IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT + if (!isInString(IPHPPartitions.PHP_PARTITIONING) + && fContentType == IPHPPartitions.HTML_MULTILINE_COMMENT && checkPattern(new char[] { '-', '>' })) { - fContentType = IPHPPartitionScannerConstants.HTML; + fContentType = IPHPPartitions.HTML; partitionBorder = true; - return getToken(IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + return getToken(IPHPPartitions.HTML_MULTILINE_COMMENT); } break; case '{' : // SMARTY code starts here ? - if (fFileType == IPHPPartitionScannerConstants.SMARTY_FILE) { + if (fFileType == IPHPPartitions.SMARTY_FILE) { if ((c = read()) == '*') { if (DEBUG) { System.out.println( @@ -248,16 +250,16 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { + " fCurrentLength=" + fCurrentLength); } - if (fContentType != IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT && fCurrentLength > 2) { + if (fContentType != IPHPPartitions.SMARTY_MULTILINE_COMMENT && fCurrentLength > 2) { // SMARTY doc code starts here unread(2); IToken token = getToken(fContentType); - fContentType = IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT; + fContentType = IPHPPartitions.SMARTY_MULTILINE_COMMENT; return token; // } else if (fContentType == IPHPPartitionScannerConstants.HTML && fOffset == 2) { // fContentType = IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT; } else { // if (fContentType == IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT) { - fContentType = IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT; + fContentType = IPHPPartitions.SMARTY_MULTILINE_COMMENT; fTokenOffset = fOffset - 2; fCurrentLength = 2; } @@ -277,22 +279,22 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { if (c != ICharacterScanner.EOF) { unread(); } - if (fContentType != IPHPPartitionScannerConstants.SMARTY && fCurrentLength > 1) { + if (fContentType != IPHPPartitions.SMARTY && fCurrentLength > 1) { unread(1); IToken token = getToken(fContentType); - fContentType = IPHPPartitionScannerConstants.SMARTY; + fContentType = IPHPPartitions.SMARTY; return token; // } else if (fContentType == IPHPPartitionScannerConstants.HTML && fOffset==1) { // fContentType = IPHPPartitionScannerConstants.SMARTY; } else { - fContentType = IPHPPartitionScannerConstants.SMARTY; + fContentType = IPHPPartitions.SMARTY; fTokenOffset = fOffset - 1; fCurrentLength = 1; } } break; case '}' : // SMARTY code ends here ? - if (fFileType == IPHPPartitionScannerConstants.SMARTY_FILE && fContentType == IPHPPartitionScannerConstants.SMARTY) { + if (fFileType == IPHPPartitions.SMARTY_FILE && fContentType == IPHPPartitions.SMARTY) { if (DEBUG) { System.out.println( "SMARTY_TOKEN end " @@ -304,36 +306,36 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { + " fOffset=" + fOffset); } - fContentType = IPHPPartitionScannerConstants.HTML; + fContentType = IPHPPartitions.HTML; partitionBorder = true; - return getToken(IPHPPartitionScannerConstants.SMARTY); + return getToken(IPHPPartitions.SMARTY); } break; case '/' : - if (!isInString(IPHPPartitionScannerConstants.PHP) && (c = read()) == '*') { // MULTINE COMMENT JAVASCRIPT, CSS, PHP - if (fContentType == IPHPPartitionScannerConstants.PHP && fCurrentLength > 2) { + if (!isInString(IPHPPartitions.PHP_PARTITIONING) && (c = read()) == '*') { // MULTINE COMMENT JAVASCRIPT, CSS, PHP + if (fContentType == IPHPPartitions.PHP_PARTITIONING && fCurrentLength > 2) { unread(2); IToken token = getToken(fContentType); - fContentType = IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT; + fContentType = IPHPPartitions.PHP_MULTILINE_COMMENT; return token; - } else if (fContentType == IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT) { + } else if (fContentType == IPHPPartitions.PHP_MULTILINE_COMMENT) { fTokenOffset = fOffset - 2; fCurrentLength = 2; } - } else if (!isInString(IPHPPartitionScannerConstants.PHP) && c != ICharacterScanner.EOF) + } else if (!isInString(IPHPPartitions.PHP_PARTITIONING) && c != ICharacterScanner.EOF) unread(); break; case '*' : - if (!isInString(IPHPPartitionScannerConstants.PHP) && (c = read()) == '/') { - if (fContentType == IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT) { - fContentType = IPHPPartitionScannerConstants.PHP; + if (!isInString(IPHPPartitions.PHP_PARTITIONING) && (c = read()) == '/') { + if (fContentType == IPHPPartitions.PHP_MULTILINE_COMMENT) { + fContentType = IPHPPartitions.PHP_PARTITIONING; partitionBorder = true; - return getToken(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); - } else if (fContentType == IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT) { - } else if (fContentType == IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT) { + return getToken(IPHPPartitions.PHP_MULTILINE_COMMENT); + } else if (fContentType == IPHPPartitions.CSS_MULTILINE_COMMENT) { + } else if (fContentType == IPHPPartitions.JS_MULTILINE_COMMENT) { } - } else if (fFileType == IPHPPartitionScannerConstants.SMARTY_FILE && (c = read()) == '}') { + } else if (fFileType == IPHPPartitions.SMARTY_FILE && (c = read()) == '}') { if (DEBUG) { System.out.println( "SMARTYDOC_TOKEN end " @@ -345,12 +347,12 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { + " fOffset=" + fOffset); } - if (fContentType == IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT) { - fContentType = IPHPPartitionScannerConstants.HTML; + if (fContentType == IPHPPartitions.SMARTY_MULTILINE_COMMENT) { + fContentType = IPHPPartitions.HTML; partitionBorder = true; - return getToken(IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + return getToken(IPHPPartitions.SMARTY_MULTILINE_COMMENT); } - } else if (!isInString(IPHPPartitionScannerConstants.PHP) && c != ICharacterScanner.EOF) { + } else if (!isInString(IPHPPartitions.PHP_PARTITIONING) && c != ICharacterScanner.EOF) { unread(); } break; @@ -384,7 +386,7 @@ public class PHPPartitionScanner implements IPartitionTokenScanner { fEnd = fOffset + length; fInString = false; fInDoubString = false; - fContentType = IPHPPartitionScannerConstants.HTML; + fContentType = IPHPPartitions.HTML; // String[] prev = getPartitionStack(offset); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java index 8f9dbe5..b682bc6 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/Partition.java @@ -4,6 +4,8 @@ */ package net.sourceforge.phpeclipse.phpeditor.php; +import net.sourceforge.phpdt.internal.ui.text.*; + import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.rules.ICharacterScanner; @@ -16,7 +18,7 @@ import org.eclipse.jface.text.rules.Token; * partitions contained within other partitions. * * @author Stefan Langer - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ public abstract class Partition { @@ -41,7 +43,7 @@ public abstract class Partition public Partition(IDocument document, char[] delim, String contentType) { - this(document, delim, contentType, IPHPPartitionScannerConstants.HTML); + this(document, delim, contentType, IPHPPartitions.HTML); } /** diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PartitionStack.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PartitionStack.java index de24d80..85b9774 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PartitionStack.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PartitionStack.java @@ -6,6 +6,8 @@ package net.sourceforge.phpeclipse.phpeditor.php; import java.util.ArrayList; +import net.sourceforge.phpdt.internal.ui.text.*; + import org.eclipse.jface.text.IDocument; /** @@ -13,7 +15,7 @@ import org.eclipse.jface.text.IDocument; * contain other partitions. * * @author Stefan Langer - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ public class PartitionStack { @@ -45,7 +47,7 @@ public class PartitionStack return (String)fPartitionStack.get(fStackTop--); } - return IPHPPartitionScannerConstants.HTML; + return IPHPPartitions.HTML; } public boolean isEmpty() -- 1.7.1