X-Git-Url: http://git.phpeclipse.com 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 b3e4656..479f880 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -12,13 +12,12 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup; -import net.sourceforge.phpdt.ui.actions.*; import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; import net.sourceforge.phpeclipse.IPreferenceConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner; -import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor; import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.action.Action; @@ -26,7 +25,6 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextOperationTarget; import org.eclipse.jface.text.source.AnnotationRulerColumn; @@ -37,12 +35,12 @@ import org.eclipse.jface.text.source.IVerticalRulerColumn; import org.eclipse.jface.text.source.LineNumberRulerColumn; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.DefaultRangeIndicator; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.TextOperationAction; @@ -71,14 +69,40 @@ public class PHPEditor extends TextEditor { super(); setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$ } + // + // /** + // * @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(); + // } + + /** + * Returns this document's complete text. + * + * @return the document's complete text + */ + public String get() { + IDocument doc = + this.getDocumentProvider().getDocument(this.getEditorInput()); + return doc.get(); + } /** * Returns the standard action group of this editor. */ protected ActionGroup getActionGroup() { return fActionGroups; - } - + } + public PHPContentOutlinePage getfOutlinePage() { return fOutlinePage; } @@ -89,13 +113,23 @@ public class PHPEditor extends TextEditor { */ protected void createActions() { super.createActions(); - setAction( - "ContentAssistProposal", - new TextOperationAction( - PHPEditorMessages.getResourceBundle(), - "ContentAssistProposal.", - this, - ISourceViewer.CONTENTASSIST_PROPOSALS)); + + Action action; + // setAction( + // "ContentAssistProposal", + // new TextOperationAction( + // PHPEditorMessages.getResourceBundle(), + // "ContentAssistProposal.", + // this, + // ISourceViewer.CONTENTASSIST_PROPOSALS)); + action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$ + action.setActionDefinitionId( + PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", action); //$NON-NLS-1$ + + // System.out.println(action.getId()); + // System.out.println(action.getActionDefinitionId()); + setAction( "ContentAssistTip", new TextOperationAction( @@ -104,31 +138,52 @@ public class PHPEditor extends TextEditor { this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION)); - Action action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); + action = + new TextOperationAction( + PHPEditorMessages.getResourceBundle(), + "Comment.", + this, + ITextOperationTarget.PREFIX); action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT); setAction("Comment", action); - action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); + // System.out.println(action.getId()); + // System.out.println(action.getActionDefinitionId()); + + action = + new TextOperationAction( + PHPEditorMessages.getResourceBundle(), + "Uncomment.", + this, + ITextOperationTarget.STRIP_PREFIX); action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT); setAction("Uncomment", action); - // fActionGroups = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); + action = new TextOperationAction( + PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ + action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT); + setAction("Format", action); //$NON-NLS-1$ + + // System.out.println(action.getId()); + // System.out.println(action.getActionDefinitionId()); + + // fActionGroups = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); markAsStateDependentAction("Comment", true); //$NON-NLS-1$ markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$ + markAsStateDependentAction("Format", true); //$NON-NLS-1$ + + fGenerateActionGroup = + new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); - fGenerateActionGroup= new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); + fActionGroups = + new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup }); - 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)}); + fContextMenuGroup = + new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup }); + // rg, + // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)}); } /** The PHPEditor implementation of this @@ -139,10 +194,10 @@ public class PHPEditor extends TextEditor { PHPEditorEnvironment.disconnect(this); if (fOutlinePage != null) fOutlinePage.setInput(null); - + if (fActionGroups != null) - fActionGroups.dispose(); - + fActionGroups.dispose(); + super.dispose(); } @@ -201,10 +256,12 @@ public class PHPEditor extends TextEditor { super.editorContextMenuAboutToShow(menu); // addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$ // addAction(menu, "ContentAssistTip"); //$NON-NLS-1$ + addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$ // fActionGroups.fillContextMenu(menu); - ActionContext context= new ActionContext(getSelectionProvider().getSelection()); + ActionContext context = + new ActionContext(getSelectionProvider().getSelection()); fContextMenuGroup.setContext(context); fContextMenuGroup.fillContextMenu(menu); fContextMenuGroup.setContext(null); @@ -214,7 +271,7 @@ public class PHPEditor extends TextEditor { super.updateStateDependentActions(); fGenerateActionGroup.editorStateChanged(); } - + /** The PHPEditor implementation of this * AbstractTextEditor method performs gets * the java content outline page if request is for a an @@ -254,16 +311,16 @@ public class PHPEditor extends TextEditor { // } // } - private String getFunctionName(IDocument doc, int pos) { - Point word = PHPWordExtractor.findWord(doc, pos); - if (word != null) { - try { - return doc.get(word.x, word.y).replace('_', '-'); - } catch (BadLocationException e) { - } - } - return ""; - } + // private String getFunctionName(IDocument doc, int pos) { + // Point word = PHPWordExtractor.findWord(doc, pos); + // if (word != null) { + // try { + // return doc.get(word.x, word.y).replace('_', '-'); + // } catch (BadLocationException e) { + // } + // } + // return ""; + // } /* * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent) @@ -356,20 +413,36 @@ public class PHPEditor extends TextEditor { // foreground color if (phpPrefStore.contains(IPreferenceConstants.LINE_NUMBER_COLOR)) { if (phpPrefStore.isDefault(IPreferenceConstants.LINE_NUMBER_COLOR)) - rgb = PreferenceConverter.getDefaultColor(phpPrefStore, IPreferenceConstants.LINE_NUMBER_COLOR); + rgb = + PreferenceConverter.getDefaultColor( + phpPrefStore, + IPreferenceConstants.LINE_NUMBER_COLOR); else - rgb = PreferenceConverter.getColor(phpPrefStore, IPreferenceConstants.LINE_NUMBER_COLOR); + rgb = + PreferenceConverter.getColor( + phpPrefStore, + IPreferenceConstants.LINE_NUMBER_COLOR); } rulerColumn.setForeground(manager.getColor(rgb)); rgb = null; // background color - if (!phpPrefStore.getBoolean(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) { - if (phpPrefStore.contains(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) { - if (phpPrefStore.isDefault(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) - rgb = PreferenceConverter.getDefaultColor(phpPrefStore, IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND); + if (!phpPrefStore + .getBoolean( + IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) { + if (phpPrefStore + .contains(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) { + if (phpPrefStore + .isDefault(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) + rgb = + PreferenceConverter.getDefaultColor( + phpPrefStore, + IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND); else - rgb = PreferenceConverter.getColor(phpPrefStore, IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND); + rgb = + PreferenceConverter.getColor( + phpPrefStore, + IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND); } rulerColumn.setBackground(manager.getColor(rgb)); } @@ -403,7 +476,7 @@ public class PHPEditor extends TextEditor { protected void initializeEditor() { PHPEditorEnvironment.connect(this); - setSourceViewerConfiguration(new PHPSourceViewerConfiguration()); + setSourceViewerConfiguration(new PHPSourceViewerConfiguration(this)); setRangeIndicator(new DefaultRangeIndicator()); setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$ setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$