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 587bc9d..501813f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java @@ -12,16 +12,30 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ -import net.sourceforge.phpdt.ui.IContextMenuConstants; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ResourceBundle; + +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.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; +import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.actions.RetargetAction; +import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.RetargetTextEditorAction; @@ -29,55 +43,96 @@ import org.eclipse.ui.texteditor.RetargetTextEditorAction; /** * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar. */ -public class PHPActionContributor extends BasicTextEditorActionContributor { +public class PHPActionContributor extends BasicTextEditorActionContributor { // protected RetargetTextEditorAction fContentAssistTip; // protected TextEditorAction fTogglePresentation; protected RetargetAction fRetargetContentAssist; - + protected RetargetTextEditorAction fContentAssist; - - protected PHPParserAction parserAction; + private RetargetTextEditorAction fGotoMatchingBracket; + private List fRetargetToolbarActions = new ArrayList(); + + protected PHPParserAction fParserAction; + protected ShowExternalPreviewAction fShowExternalPreviewAction; /** * Default constructor. */ public PHPActionContributor() { super(); - - fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$ - fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - - 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); - - + + ResourceBundle b = PHPEditorMessages.getResourceBundle(); + + fRetargetContentAssist = new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$ + fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + + fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$ + fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.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(); - - - parserAction = PHPParserAction.getInstance(); + + fParserAction = PHPParserAction.getInstance(); + + if (SWT.getPlatform().equals("win32")) { + fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance(); + } } /* * @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); -// } -// } - + // public void contributeToMenu(IMenuManager menu) { + // super.contributeToMenu(menu); + // IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); + // if (editMenu != null) { + // MenuManager structureSelection= new MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label")); //$NON-NLS-1$ + // structureSelection.add(fStructureSelectEnclosingAction); + // structureSelection.add(fStructureSelectNextAction); + // structureSelection.add(fStructureSelectPreviousAction); + // structureSelection.add(fStructureSelectHistoryAction); + // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, structureSelection); + // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoPreviousMemberAction); + // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoNextMemberAction); + // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fGotoMatchingBracket); + + // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fShowOutline); + // } + // } + /* + * @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 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) */ @@ -89,10 +144,12 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { if (editMenu != null) { editMenu.add(new Separator()); editMenu.add(fContentAssist); + editMenu.add(fGotoMatchingBracket); + // editMenu.add(fContentAssistTip); } - bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist); + bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist); // IToolBarManager toolBarManager = bars.getToolBarManager(); // if (toolBarManager != null) { // toolBarManager.add(new Separator()); @@ -109,30 +166,49 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$ // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$ - + fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET)); + IActionBars bars = getActionBars(); 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 cuEditor= (PHPEditor)part; - ActionGroup group= cuEditor.getActionGroup(); + PHPEditor cuEditor = (PHPEditor) part; + ActionGroup group = cuEditor.getActionGroup(); if (group != null) group.fillActionBars(bars); } // fTogglePresentation.setEditor(editor); // fTogglePresentation.update(); - parserAction.setEditor(textEditor); - parserAction.update(); + IFile file = null; + IEditorInput editorInput = textEditor.getEditorInput(); + + if (editorInput instanceof IFileEditorInput) { + file = ((IFileEditorInput) editorInput).getFile(); + } + + PHPeclipsePlugin.getDefault().setLastEditorFile(file); + fParserAction.setEditor(textEditor); + fParserAction.update(); + if (SWT.getPlatform().equals("win32") && textEditor instanceof AbstractTextEditor) { + fShowExternalPreviewAction.setEditor(textEditor); + fShowExternalPreviewAction.update(); + IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + if (store.getBoolean(PHPeclipsePlugin.SHOW_EXTERNAL_PREVIEW_PREF)) { + IAction a = ShowExternalPreviewAction.getInstance(); + if (a != null) + a.run(); + } + } } /* * @see IEditorActionBarContributor#setActiveEditor(IEditorPart) */ public void setActiveEditor(IEditorPart part) { - doSetActiveEditor(part); + doSetActiveEditor(part); } /*