*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / ui / actions / GenerateActionGroup.java
index fa14ba5..0607a3e 100644 (file)
@@ -17,10 +17,12 @@ import java.util.List;
 import net.sourceforge.phpdt.internal.ui.actions.AddTaskAction;
 import net.sourceforge.phpdt.ui.IContextMenuConstants;
 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
+
 import org.eclipse.debug.internal.ui.actions.ActionMessages;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.util.Assert;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -35,6 +37,7 @@ import org.eclipse.ui.actions.AddBookmarkAction;
 import org.eclipse.ui.part.Page;
 import org.eclipse.ui.texteditor.ConvertLineDelimitersAction;
 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.texteditor.IUpdate;
 
 /**
  * Action group that adds the source and generate actions to a part's context
@@ -48,6 +51,7 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
  */
 public class GenerateActionGroup extends ActionGroup {
        
+  private PHPEditor fEditor;
        private boolean fEditorIsOwner;
        private IWorkbenchSite fSite;
        private String fGroupName= IContextMenuConstants.GROUP_SOURCE;
@@ -75,6 +79,7 @@ public class GenerateActionGroup extends ActionGroup {
         */
        public GenerateActionGroup(PHPEditor editor, String groupName) {
                fSite= editor.getSite();
+    fEditor= editor;
                fEditorIsOwner= true;
                fGroupName= groupName;
                ISelectionProvider provider= fSite.getSelectionProvider();
@@ -212,14 +217,6 @@ public class GenerateActionGroup extends ActionGroup {
         */
        public void editorStateChanged() {
                Assert.isTrue(fEditorIsOwner);
-//             fAddImport.update();
-//             fExternalizeStrings.editorStateChanged();
-//             fOrganizeImports.editorStateChanged();
-//             fOverrideMethods.editorStateChanged();
-//             fAddUnimplementedConstructors.editorStateChanged();
-//             fAddJavaDocStub.editorStateChanged();
-//             fSurroundWithTryCatch.editorStateChanged();
-//             fAddGetterSetter.editorStateChanged();
                
                // http://dev.eclipse.org/bugs/show_bug.cgi?id=17709
                fConvertToMac.update();
@@ -254,25 +251,27 @@ public class GenerateActionGroup extends ActionGroup {
                }
        }
        
-       private IMenuManager createEditorSubMenu(IMenuManager mainMenu) {
-               IMenuManager result= new MenuManager(ActionMessages.getString("SourceMenu.label")); //$NON-NLS-1$
-               int added= 0;
-//             added+= addAction(result, fOrganizeImports);
-//             added+= addAction(result, fAddImport);
-//             result.add(new Separator());
-//             added+= addAction(result, fOverrideMethods);
-//             added+= addAction(result, fAddGetterSetter);
-//             added+= addAction(result, fAddUnimplementedConstructors);
-//             added+= addAction(result, fAddJavaDocStub);
-               added+= addAction(result, fAddBookmark);
-//             result.add(new Separator());            
-//             added+= addAction(result, fSurroundWithTryCatch);
-//             added+= addAction(result, fExternalizeStrings);
-               if (added == 0)
-                       result= null;
-               return result;
-       }
-
+  private IMenuManager createEditorSubMenu(IMenuManager mainMenu) {
+    IMenuManager result= new MenuManager(ActionMessages.getString("SourceMenu.label")); //$NON-NLS-1$
+    int added= 0;
+    added+= addEditorAction(result, "Comment"); //$NON-NLS-1$
+    added+= addEditorAction(result, "Uncomment"); //$NON-NLS-1$
+//    result.add(new Separator());
+//    added+= addAction(result, fOrganizeImports);
+//    added+= addAction(result, fAddImport);
+    result.add(new Separator());
+//    added+= addAction(result, fOverrideMethods);
+//    added+= addAction(result, fAddGetterSetter);
+//    added+= addAction(result, fAddUnimplementedConstructors);
+//    added+= addAction(result, fAddJavaDocStub);
+    added+= addAction(result, fAddBookmark);
+//    result.add(new Separator());             
+//    added+= addAction(result, fSurroundWithTryCatch);
+//    added+= addAction(result, fExternalizeStrings);
+    if (added == 0)
+      result= null;
+    return result;
+  }
        /* (non-Javadoc)
         * Method declared in ActionGroup
         */
@@ -284,6 +283,7 @@ public class GenerateActionGroup extends ActionGroup {
                                provider.removeSelectionChangedListener(listener);
                        }
                }
+    fEditor= null;
                super.dispose();
        }
        
@@ -297,9 +297,9 @@ public class GenerateActionGroup extends ActionGroup {
 //             actionBar.setGlobalActionHandler(JdtActionConstants.EXTERNALIZE_STRINGS, fExternalizeStrings);
 //             actionBar.setGlobalActionHandler(JdtActionConstants.FIND_STRINGS_TO_EXTERNALIZE, fFindStringsToExternalize);
 //             actionBar.setGlobalActionHandler(JdtActionConstants.ORGANIZE_IMPORTS, fOrganizeImports);
-//             actionBar.setGlobalActionHandler(JdtActionConstants.CONVERT_LINE_DELIMITERS_TO_WINDOWS, fConvertToWindows);
-//             actionBar.setGlobalActionHandler(JdtActionConstants.CONVERT_LINE_DELIMITERS_TO_UNIX, fConvertToUNIX);
-//             actionBar.setGlobalActionHandler(JdtActionConstants.CONVERT_LINE_DELIMITERS_TO_MAC, fConvertToMac);
+               actionBar.setGlobalActionHandler(PHPdtActionConstants.CONVERT_LINE_DELIMITERS_TO_WINDOWS, fConvertToWindows);
+               actionBar.setGlobalActionHandler(PHPdtActionConstants.CONVERT_LINE_DELIMITERS_TO_UNIX, fConvertToUNIX);
+               actionBar.setGlobalActionHandler(PHPdtActionConstants.CONVERT_LINE_DELIMITERS_TO_MAC, fConvertToMac);
                if (!fEditorIsOwner) {
                        // editor provides its own implementation of these actions.
                        actionBar.setGlobalActionHandler(IWorkbenchActionConstants.BOOKMARK, fAddBookmark);
@@ -322,4 +322,23 @@ public class GenerateActionGroup extends ActionGroup {
                }
                return 0;
        }       
+       
+  private int addEditorAction(IMenuManager menu, String actionID) {
+    if (fEditor == null)
+      return 0;
+    IAction action= fEditor.getAction(actionID);
+    if (action == null)
+      return 0;
+    if (action instanceof IUpdate)
+      ((IUpdate)action).update();
+    if (action.isEnabled()) {
+      menu.add(action);
+      return 1;
+    }
+    return 0;
+  }
+  
+  private boolean isEditorOwner() {
+    return fEditor != null;
+  }    
 }