misc changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPActionContributor.java
index 10e9170..733ba53 100644 (file)
@@ -1,24 +1,20 @@
 package net.sourceforge.phpeclipse.phpeditor;
-
-/**********************************************************************
-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
-**********************************************************************/
-
+/*******************************************************************************
+ * 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 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;
 
@@ -28,8 +24,6 @@ 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;
@@ -37,86 +31,93 @@ import org.eclipse.ui.IFileEditorInput;
 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.RetargetTextEditorAction;
-
 /**
- * Contributes interesting PHP 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 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;
   /**
    * Default constructor.
    */
   public PHPActionContributor() {
     super();
-
     ResourceBundle b = PHPEditorMessages.getResourceBundle();
-
-    fRetargetContentAssist = new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
-    fRetargetContentAssist.setActionDefinitionId(
-      PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
-    markAsPartListener(fRetargetContentAssist);
-
-    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();
+    
+//    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)
    */
-  //  public void contributeToMenu(IMenuManager menu) {                
+  //  public void contributeToMenu(IMenuManager menu) {
   //    super.contributeToMenu(menu);
-  //    IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
+  //    IMenuManager editMenu=
+  // menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
   //    if (editMenu != null) {
-  //      MenuManager structureSelection= new MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label")); //$NON-NLS-1$
+  //      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);
+  //      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);
   //    }
   //  }
   /*
@@ -126,190 +127,130 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
   //           
   //     super.contributeToMenu(menu);
   //           
-  //     IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
+  //     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);
-  //     }             
+  //             editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
+  // fRetargetContentAssist);
+  //     }
   //  }
-
   /*
-        * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
-        */
+   * @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));
-
-//      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$
-    }
+       
+       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 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());
+//  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);
+//    //    }
+//  }
+  
 
-    super.init(bars, page);
-  }
   /*
-   * @see IEditorActionBarContributor#init(IActionBars)
+   * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
    */
-  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);
-    //    }
-  }
-
-  private void doSetActiveEditor(IEditorPart part) {
+  public void setActiveEditor(IEditorPart part) {
     super.setActiveEditor(part);
-
     IActionBars bars = getActionBars();
     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$
-
-    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();
-
       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) {
+      if (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();
-        }
+        IAction a = ShowExternalPreviewAction.getInstance();
+        if (a != null)
+          a.run();
       }
     }
-
-  }
-
-  /*
-   * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
-   */
-  public void setActiveEditor(IEditorPart part) {
-    doSetActiveEditor(part);
-  }
-
-  /*
-   * @see IEditorActionBarContributor#dispose()
-   */
-  public void dispose() {
-    Iterator e = fPartListeners.iterator();
-    while (e.hasNext())
-      getPage().removePartListener((RetargetAction) e.next());
-    fPartListeners.clear();
-
-    doSetActiveEditor(null);
-    super.dispose();
   }
+  
 }