Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] actionSet vs. menu/commands/handlers for refactorings

Dear CDT crew

Is there a reason why CDT refactoring menus are hardcoded in
CRefactoringActionGroup? It's hard to get a new refactoring in there not
touching this code.

It seems easy to change the code to use the menus/commands/halders
extension points. I've attached a patch that changes the rename
refactoring to clarify what I mean. Would the community accept such a
change?

Background: I'd like to lower the integration barrier for new
refactorings because it seems there was much work done in the past and
never integrated.

Regards,

Martin
### Eclipse Workspace Patch 1.0
#P org.eclipse.cdt.ui
Index: plugin.xml
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/plugin.xml,v
retrieving revision 1.385
diff -u -r1.385 plugin.xml
--- plugin.xml	13 Aug 2010 01:01:12 -0000	1.385
+++ plugin.xml	28 Aug 2010 09:30:14 -0000
@@ -1166,6 +1166,23 @@
             </dynamic>
          </menu>
       </menuContribution>
+      <menuContribution
+            allPopups="false"
+            locationURI="menu:org.eclipse.ui.main.menu?after=edit">
+         <menu
+               id="refactor"
+               label="%Refactoring.menu.label">
+         </menu>
+      </menuContribution>
+      <menuContribution
+            allPopups="false"
+            locationURI="menu:refactor">
+         <command
+               commandId="org.eclipse.cdt.ui.edit.text.rename.element"
+               label="%Refactoring.renameAction.label"
+               style="push">
+         </command>
+      </menuContribution>
    </extension>
    <extension
          point="org.eclipse.ui.actionSets">
@@ -1178,7 +1195,6 @@
                label="%Refactoring.menu.label"
                path="edit"
                id="org.eclipse.jdt.ui.refactoring.menu">
-            <separator name="reorgGroup"/>
             <separator name="codingGroup"/>
             <separator name="reorgGroup2"/>
             <separator name="typeGroup"/>
@@ -1191,13 +1207,6 @@
          </menu>
          <!-- reorg group  -->
          <action
-               definitionId="org.eclipse.cdt.ui.edit.text.rename.element"
-               label="%Refactoring.renameAction.label"
-               menubarPath="org.eclipse.jdt.ui.refactoring.menu/reorgGroup"
-               id="org.eclipse.cdt.ui.actions.Rename"
-               retarget="true">
-         </action>
-         <action
                definitionId="org.eclipse.cdt.ui.refactor.hide.method"
                label="%Refactoring.hideMethod.label"
                menubarPath="org.eclipse.jdt.ui.refactoring.menu/codingGroup"
@@ -3680,6 +3689,10 @@
           class="org.eclipse.cdt.internal.ui.actions.ExcludeFromBuildHandler"
           commandId="org.eclipse.cdt.ui.excludeCommand">
     </handler>
+    <handler
+          class="org.eclipse.cdt.ui.refactoring.actions.CRenameAction"
+          commandId="org.eclipse.cdt.ui.edit.text.rename.element">
+    </handler>
  </extension>
  <extension
        point="org.eclipse.ui.menus">
Index: src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java,v
retrieving revision 1.42
diff -u -r1.42 ICEditorActionDefinitionIds.java
--- src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java	13 Aug 2010 01:01:12 -0000	1.42
+++ src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java	28 Aug 2010 09:30:14 -0000
@@ -87,12 +87,6 @@
 	public static final String OPEN_CVIEW= "org.eclipse.cdt.ui.edit.opencview"; //$NON-NLS-1$
 	
 	/**
-	 * Action definition ID of the refactor -> rename element action
-	 * (value <code>"org.eclipse.cdt.ui.edit.text.rename.element"</code>).
-	 */
-	public static final String RENAME_ELEMENT= "org.eclipse.cdt.ui.edit.text.rename.element"; //$NON-NLS-1$
-
-	/**
 	 * Action definition ID of the refactor -> extract constant action
 	 * (value <code>"org.eclipse.cdt.ui.refactor.extract.constant"</code>).
 	 */
Index: src/org/eclipse/cdt/ui/actions/CdtActionConstants.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CdtActionConstants.java,v
retrieving revision 1.15
diff -u -r1.15 CdtActionConstants.java
--- src/org/eclipse/cdt/ui/actions/CdtActionConstants.java	2 Jun 2010 19:10:21 -0000	1.15
+++ src/org/eclipse/cdt/ui/actions/CdtActionConstants.java	28 Aug 2010 09:30:14 -0000
@@ -237,13 +237,7 @@
 	 * (value <code>"org.eclipse.cdt.ui.actions.Move"</code>).
 	 */
 	public static final String MOVE= "org.eclipse.cdt.ui.actions.Move"; //$NON-NLS-1$
-	
-	/**
-	 * Refactor menu: name of standard Rename Element global action
-	 * (value <code>"org.eclipse.cdt.ui.actions.Rename"</code>).
-	 */
-	public static final String RENAME= "org.eclipse.cdt.ui.actions.Rename"; //$NON-NLS-1$
-	
+
 	/**
 	 * Refactor menu: name of standard Extract Temp global action
 	 * (value <code>"org.eclipse.cdt.ui.actions.ExtractTemp"</code>).
Index: src/org/eclipse/cdt/ui/refactoring/actions/CRefactoringActionGroup.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/CRefactoringActionGroup.java,v
retrieving revision 1.9
diff -u -r1.9 CRefactoringActionGroup.java
--- src/org/eclipse/cdt/ui/refactoring/actions/CRefactoringActionGroup.java	24 Apr 2009 08:19:29 -0000	1.9
+++ src/org/eclipse/cdt/ui/refactoring/actions/CRefactoringActionGroup.java	28 Aug 2010 09:30:14 -0000
@@ -112,7 +112,6 @@
 	public static final String GROUP_TYPE3= "typeGroup3"; //$NON-NLS-1$
 
     private String fGroupName= IWorkbenchActionConstants.GROUP_REORGANIZE;
-    private CRenameAction fRenameAction;
     private RefactoringAction fExtractConstantAction;
     private RefactoringAction fExtractLocalVariableAction;
     private RefactoringAction fExtractFunctionAction;
@@ -144,10 +143,6 @@
     }
 
 	private void createActions(boolean forEditor) {
-		fRenameAction = new CRenameAction();
-        fRenameAction.setActionDefinitionId(ICEditorActionDefinitionIds.RENAME_ELEMENT);
-        fAllActions.add(fRenameAction);
-        
         if (forEditor) {
         	fExtractConstantAction= new ExtractConstantAction();
         	fExtractConstantAction.setActionDefinitionId(ICEditorActionDefinitionIds.EXTRACT_CONSTANT);
@@ -199,7 +194,6 @@
 	@Override
 	public void fillActionBars(IActionBars actionBar) {
 		super.fillActionBars(actionBar);
-		setActionHandler(actionBar, CdtActionConstants.RENAME, fRenameAction);
 		setActionHandler(actionBar, CdtActionConstants.EXTRACT_CONSTANT, fExtractConstantAction);
 		setActionHandler(actionBar, CdtActionConstants.EXTRACT_LOCAL_VARIABLE, fExtractLocalVariableAction);
 		setActionHandler(actionBar, CdtActionConstants.EXTRACT_METHOD, fExtractFunctionAction);
@@ -229,7 +223,6 @@
 		if (needMenu) {
 			IMenuManager refactorSubmenu = new MenuManager(Messages.CRefactoringActionGroup_menu, MENU_ID); 
 			refactorSubmenu.add(new Separator(GROUP_REORG));
-			addAction(refactorSubmenu, fRenameAction);
 			refactorSubmenu.add(new Separator(GROUP_CODING));
 			addAction(refactorSubmenu, fExtractConstantAction);
 			addAction(refactorSubmenu, fExtractLocalVariableAction);
Index: src/org/eclipse/cdt/ui/refactoring/actions/CRenameAction.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/CRenameAction.java,v
retrieving revision 1.3
diff -u -r1.3 CRenameAction.java
--- src/org/eclipse/cdt/ui/refactoring/actions/CRenameAction.java	31 Jul 2010 17:50:56 -0000	1.3
+++ src/org/eclipse/cdt/ui/refactoring/actions/CRenameAction.java	28 Aug 2010 09:30:14 -0000
@@ -11,8 +11,13 @@
 
 package org.eclipse.cdt.ui.refactoring.actions;
 
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
 import org.eclipse.jface.text.ITextSelection;
 import org.eclipse.jface.window.IShellProvider;
+import org.eclipse.ui.PlatformUI;
 
 import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.model.IInclude;
@@ -26,7 +31,7 @@
  * 
  * @noextend This class is not intended to be subclassed by clients.
  */          
-public class CRenameAction extends RefactoringAction {
+public class CRenameAction extends RefactoringAction implements IHandler {
     
     public CRenameAction() {
         super(Messages.CRenameAction_label); 
@@ -51,4 +56,19 @@
     		setEnabled(true);
     	}
     }
+
+	public void addHandlerListener(IHandlerListener handlerListener) {
+	}
+
+	public void dispose() {
+	}
+
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		setEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor());
+		run();
+		return null;
+	}
+	
+	public void removeHandlerListener(IHandlerListener handlerListener) {
+	}
 }


Back to the top