X-Git-Url: http://git.phpeclipse.com 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 1fbefe5..7c6d220 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java @@ -12,86 +12,133 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ -import java.util.ResourceBundle; +import net.sourceforge.phpdt.ui.IContextMenuConstants; +import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants; + import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; 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.editors.text.TextEditorActionContributor; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.actions.RetargetAction; import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.RetargetTextEditorAction; -import org.eclipse.ui.texteditor.TextEditorAction; /** - * Contributes interesting Java actions to the desktop's Edit menu and the toolbar. + * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar. */ -public class PHPActionContributor extends TextEditorActionContributor { - - protected RetargetTextEditorAction fContentAssistProposal; - protected RetargetTextEditorAction fContentAssistTip; - protected TextEditorAction fTogglePresentation; - - /** - * Default constructor. - */ - public PHPActionContributor() { - super(); - fContentAssistProposal= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$ - fContentAssistTip= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$ - fTogglePresentation= new PresentationAction(); - } +public class PHPActionContributor extends BasicTextEditorActionContributor { + + // protected RetargetTextEditorAction fContentAssistTip; + // protected TextEditorAction fTogglePresentation; + protected RetargetAction fRetargetContentAssist; - /* - * @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(fContentAssistProposal); - editMenu.add(fContentAssistTip); - } + protected RetargetTextEditorAction fContentAssist; + + protected PHPParserAction parserAction; + + /** + * Default constructor. + */ + public PHPActionContributor() { + super(); + + fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$ + fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - IToolBarManager toolBarManager= bars.getToolBarManager(); - if (toolBarManager != null) { - toolBarManager.add(new Separator()); - toolBarManager.add(fTogglePresentation); - } - } + fContentAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$ + fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); +// 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(); + - private void doSetActiveEditor(IEditorPart part) { - super.setActiveEditor(part); + parserAction = PHPParserAction.getInstance(); + } - ITextEditor editor= null; - if (part instanceof ITextEditor) - editor= (ITextEditor) part; + /* + * @see EditorActionBarContributor#contributeToMenu(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.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist); +// } +// } + + /* + * @see IEditorActionBarContributor#init(IActionBars) + */ + public void init(IActionBars bars) { + super.init(bars); - fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$ - fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$ + IMenuManager menuManager = bars.getMenuManager(); + IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); + if (editMenu != null) { + editMenu.add(new Separator()); + editMenu.add(fContentAssist); + // editMenu.add(fContentAssistTip); + } - fTogglePresentation.setEditor(editor); - fTogglePresentation.update(); - } - - /* - * @see IEditorActionBarContributor#setActiveEditor(IEditorPart) - */ - public void setActiveEditor(IEditorPart part) { - super.setActiveEditor(part); - doSetActiveEditor(part); - } - - /* - * @see IEditorActionBarContributor#dispose() - */ - public void dispose() { - doSetActiveEditor(null); - super.dispose(); - } + bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist); + // IToolBarManager toolBarManager = bars.getToolBarManager(); + // if (toolBarManager != null) { + // toolBarManager.add(new Separator()); + // toolBarManager.add(fTogglePresentation); + // } + } + + private void doSetActiveEditor(IEditorPart part) { + super.setActiveEditor(part); + + ITextEditor textEditor = null; + if (part instanceof ITextEditor) + textEditor = (ITextEditor) part; + + fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$ + // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$ + + IActionBars bars = getActionBars(); + bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment")); + bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment")); + + if (part instanceof PHPEditor) { + PHPEditor cuEditor= (PHPEditor)part; + ActionGroup group= cuEditor.getActionGroup(); + if (group != null) + group.fillActionBars(bars); + } + // fTogglePresentation.setEditor(editor); + // fTogglePresentation.update(); + + parserAction.setEditor(textEditor); + parserAction.update(); + } + + /* + * @see IEditorActionBarContributor#setActiveEditor(IEditorPart) + */ + public void setActiveEditor(IEditorPart part) { + doSetActiveEditor(part); + } + + /* + * @see IEditorActionBarContributor#dispose() + */ + public void dispose() { + doSetActiveEditor(null); + super.dispose(); + } }