Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPActionContributor.java
index 10e9170..f97f1dd 100644 (file)
@@ -37,11 +37,11 @@ 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.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.
  */
@@ -59,6 +59,7 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
   protected PHPParserAction fParserAction;
   protected ShowExternalPreviewAction fShowExternalPreviewAction;
 
+  private EncodingActionGroup fEncodingActionGroup;
   /**
    * Default constructor.
    */
@@ -68,17 +69,14 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
     ResourceBundle b = PHPEditorMessages.getResourceBundle();
 
     fRetargetContentAssist = new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
-    fRetargetContentAssist.setActionDefinitionId(
-      PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
+    fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
     markAsPartListener(fRetargetContentAssist);
 
     fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$
-    fContentAssist.setActionDefinitionId(
-      PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
+    fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
 
     fGotoMatchingBracket = new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
-    fGotoMatchingBracket.setActionDefinitionId(
-      PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
+    fGotoMatchingBracket.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
 
     // fContentAssist.setImageDescriptor(JavaPluginImages.DESC_CLCL_CODE_ASSIST);
     // fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST);
@@ -87,6 +85,9 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
     fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
     //  fTogglePresentation = new PresentationAction();
 
+    // character encoding
+    fEncodingActionGroup = new EncodingActionGroup();
+
     fParserAction = PHPParserAction.getInstance();
 
     if (SWT.getPlatform().equals("win32")) {
@@ -142,16 +143,15 @@ 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.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
 
-//      editMenu.appendToGroup(
-//        IContextMenuConstants.GROUP_GENERATE,
-//        fRetargetContentAssist);
+      //      editMenu.appendToGroup(
+      //        IContextMenuConstants.GROUP_GENERATE,
+      //        fRetargetContentAssist);
 
       //                               MenuManager structureSelection= new MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label"), "expandSelection"); //$NON-NLS-1$ //$NON-NLS-2$ 
       //                               structureSelection.add(fStructureSelectEnclosingAction);
@@ -193,7 +193,8 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
     Iterator e = fPartListeners.iterator();
     while (e.hasNext())
       page.addPartListener((RetargetAction) e.next());
-
+    // character encoding
+    fEncodingActionGroup.fillActionBars(bars);
     super.init(bars, page);
   }
   /*
@@ -203,8 +204,7 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
     super.init(bars);
 
     IMenuManager menuManager = bars.getMenuManager();
-    IMenuManager editMenu =
-      menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
+    IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
     if (editMenu != null) {
       editMenu.add(new Separator());
       editMenu.add(fContentAssist);
@@ -212,9 +212,7 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
       //   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());
@@ -222,7 +220,10 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
     //    }
   }
 
-  private void doSetActiveEditor(IEditorPart part) {
+  /*
+   * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
+   */
+  public void setActiveEditor(IEditorPart part) {
     super.setActiveEditor(part);
 
     IActionBars bars = getActionBars();
@@ -236,21 +237,16 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
 
     fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
     fContentAssistTip.setAction(getAction(textEditor, "ContentAssistTip")); //$NON-NLS-1$
-    fGotoMatchingBracket.setAction(
-      getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
+    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"));
+    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;
@@ -277,12 +273,10 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
       PHPeclipsePlugin.getDefault().setLastEditorFile(file);
       fParserAction.setEditor(textEditor);
       fParserAction.update();
-      if (SWT.getPlatform().equals("win32")
-        && textEditor instanceof AbstractTextEditor) {
+      if (SWT.getPlatform().equals("win32") && textEditor instanceof AbstractTextEditor) {
         fShowExternalPreviewAction.setEditor(textEditor);
         fShowExternalPreviewAction.update();
-        IPreferenceStore store =
-          PHPeclipsePlugin.getDefault().getPreferenceStore();
+        IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
         if (store.getBoolean(PHPeclipsePlugin.SHOW_EXTERNAL_PREVIEW_PREF)) {
           IAction a = ShowExternalPreviewAction.getInstance();
           if (a != null)
@@ -290,14 +284,6 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
         }
       }
     }
-
-  }
-
-  /*
-   * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
-   */
-  public void setActiveEditor(IEditorPart part) {
-    doSetActiveEditor(part);
   }
 
   /*
@@ -309,7 +295,7 @@ public class PHPActionContributor extends BasicTextEditorActionContributor {
       getPage().removePartListener((RetargetAction) e.next());
     fPartListeners.clear();
 
-    doSetActiveEditor(null);
+    setActiveEditor(null);
     super.dispose();
   }
 }