From e74475bdbe1af2214756df90ce45bab60e6181ef Mon Sep 17 00:00:00 2001 From: Hoda Amer Date: Mon, 15 Mar 2004 21:17:47 +0000 Subject: [PATCH] Fix for [Bug 54323] Refactor: Menu item from outline view --- core/org.eclipse.cdt.ui/ChangeLog | 3 + core/org.eclipse.cdt.ui/plugin.properties | 2 +- core/org.eclipse.cdt.ui/plugin.xml | 84 ++--- .../corext/refactoring/UndoManager.java | 2 +- .../rename/RenameElementProcessor.java | 8 +- .../actions/RedoRefactoringAction.java | 52 +-- .../actions/RenameRefactoringAction.java | 8 + .../actions/UndoManagerAction.java | 58 ++-- .../actions/UndoRefactoringAction.java | 54 ++-- .../ui/refactoring/refactoringui.properties | 13 +- .../cdt/ui/refactoring/RedoAction.java | 86 ----- .../cdt/ui/refactoring/RenameAction.java | 84 ----- .../cdt/ui/refactoring/UndoAction.java | 86 ----- .../internal/ui/cview/MainActionGroup.java | 7 +- .../ui/editor/CContentOutlinePage.java | 12 +- .../editor/ICEditorActionDefinitionIds.java | 16 +- .../src/org/eclipse/cdt/ui/CUIPlugin.java | 26 ++ .../ui/actions/RefactoringActionGroup.java | 304 ++++++++++++++++++ .../eclipse/cdt/ui/actions/RenameAction.java | 77 ----- 19 files changed, 511 insertions(+), 471 deletions(-) delete mode 100644 core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/RedoAction.java delete mode 100644 core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/RenameAction.java delete mode 100644 core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/UndoAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/RefactoringActionGroup.java delete mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/RenameAction.java diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index bba784befb5..7483aada39d 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,6 @@ +2004-03-15 Hoda Amer + Fix for [Bug 54323] Refactor: Menu item from outline view + 2004-03-15 Alain Magloire The (Re)Build action were always disable. diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index e9fe7303cc1..2c4f18b39b6 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -102,7 +102,7 @@ refactoringMenu.label= Re&factor # Refactoring Refactoring.renameAction.label= Re&name Refactoring.undoAction.label= &Undo -Refactoring.redoAction.label= Re&do +Refactoring.redoAction.label= &Redo # Open Type OpenTypeAction.label= Open &Type... diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 4a013da6c40..e62b1c67226 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -160,35 +160,35 @@ id="org.eclipse.cdt.ui.ceditor" point="org.eclipse.ui.editors"> @@ -257,16 +257,16 @@ @@ -277,49 +277,20 @@ - - - - - - - - - - - - @@ -345,24 +316,24 @@ @@ -403,8 +374,8 @@ @@ -463,8 +434,8 @@ @@ -476,24 +447,24 @@ pageId="org.eclipse.cdt.ui.CSearchPage" label="%ElementNameSorter.label" icon="icons/full/clcl16/search_sortmatch.gif" - class="org.eclipse.cdt.internal.ui.search.ElementNameSorter" tooltip="%ElementNameSorter.tooltip" + class="org.eclipse.cdt.internal.ui.search.ElementNameSorter" id="org.eclipse.cdt.search.internal.ui.ElementNameSorter"> @@ -546,16 +517,16 @@ @@ -579,4 +550,5 @@ + diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/corext/refactoring/UndoManager.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/corext/refactoring/UndoManager.java index 0fd0767c41f..8e3f988d32e 100644 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/corext/refactoring/UndoManager.java +++ b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/corext/refactoring/UndoManager.java @@ -70,7 +70,7 @@ public class UndoManager implements IUndoManager { case ICElement.C_CCONTAINER: // If we did something different than changing a child we flush the the undo / redo stack. if (kind != ICElementDelta.CHANGED - || ((details & ICElementDelta.F_CHILDREN) == 0)) { + && ((details & ICElementDelta.F_CHILDREN) == 0)) { flush(); return false; } diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/corext/refactoring/rename/RenameElementProcessor.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/corext/refactoring/rename/RenameElementProcessor.java index 85a08f8838d..223b7526e26 100644 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/corext/refactoring/rename/RenameElementProcessor.java +++ b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/corext/refactoring/rename/RenameElementProcessor.java @@ -383,6 +383,10 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.REFERENCES, false )); } + else if(fCElement instanceof IEnumeration){ + orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, + ICSearchConstants.ENUM, ICSearchConstants.REFERENCES, false )); + } else if(fCElement instanceof IField){ orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.FIELD, ICSearchConstants.REFERENCES, false )); @@ -395,10 +399,6 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.NAMESPACE, ICSearchConstants.REFERENCES, false )); } - else if(fCElement instanceof IEnumeration){ - orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, - ICSearchConstants.ENUM, ICSearchConstants.REFERENCES, false )); - } else { orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.UNKNOWN_SEARCH_FOR, ICSearchConstants.REFERENCES, false )); diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RedoRefactoringAction.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RedoRefactoringAction.java index 7a692d4b57a..e03f9a66bae 100644 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RedoRefactoringAction.java +++ b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RedoRefactoringAction.java @@ -13,26 +13,33 @@ package org.eclipse.cdt.internal.ui.refactoring.actions; import java.lang.reflect.InvocationTargetException; -import org.eclipse.core.runtime.IProgressMonitor; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.ISelection; - import org.eclipse.cdt.core.model.CModelException; - import org.eclipse.cdt.internal.corext.refactoring.base.ChangeAbortException; import org.eclipse.cdt.internal.corext.refactoring.base.ChangeContext; import org.eclipse.cdt.internal.corext.refactoring.base.IUndoManager; import org.eclipse.cdt.internal.corext.refactoring.base.Refactoring; import org.eclipse.cdt.internal.corext.refactoring.base.UndoManagerAdapter; +import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchSite; public class RedoRefactoringAction extends UndoManagerAction { private int fPatternLength; + private CEditor fEditor; - public RedoRefactoringAction() { + public RedoRefactoringAction(CEditor editor) { + this(editor.getEditorSite()); + fEditor= editor; + } + + public RedoRefactoringAction(IWorkbenchSite site) { + super(site); + init(site.getWorkbenchWindow()); } /* (non-Javadoc) @@ -86,21 +93,26 @@ public class RedoRefactoringAction extends UndoManagerAction { } /* (non-Javadoc) - * Method declared in IActionDelegate + */ + public void selectionChanged(ISelection s) { + selectionChanged(this, s); + } + + /* (non-Javadoc) */ public void selectionChanged(IAction action, ISelection s) { -// if (!isHooked()) { + if (!isHooked()) { hookListener(action); - fPatternLength= RefactoringMessages.getString("RedoRefactoringAction.extendedLabel").length(); //$NON-NLS-1$ - IUndoManager undoManager = Refactoring.getUndoManager(); - if (undoManager.anythingToRedo()) { - if (undoManager.peekRedoName() != null) - action.setText(getActionText()); - action.setEnabled(true); - } else { - action.setEnabled(false); - } -// } + } + fPatternLength= RefactoringMessages.getString("RedoRefactoringAction.extendedLabel").length(); //$NON-NLS-1$ + IUndoManager undoManager = Refactoring.getUndoManager(); + if (undoManager.anythingToRedo()) { + if (undoManager.peekRedoName() != null) + action.setText(getActionText()); + action.setEnabled(true); + } else { + action.setEnabled(false); + } } private String getActionText() { diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringAction.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringAction.java index 269daa3bfd4..9a76895f5f6 100644 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringAction.java +++ b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringAction.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.refactoring.actions; import org.eclipse.cdt.internal.corext.refactoring.RenameRefactoring; +import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.cdt.internal.ui.refactoring.UserInterfaceStarter; import org.eclipse.cdt.internal.ui.util.ExceptionHandler; @@ -27,6 +28,13 @@ import org.eclipse.ui.IWorkbenchSite; public class RenameRefactoringAction extends SelectionDispatchAction { + private CEditor fEditor; + + public RenameRefactoringAction(CEditor editor) { + this(editor.getEditorSite()); + fEditor= editor; + } + public RenameRefactoringAction(IWorkbenchSite site) { super(site); setText(RefactoringMessages.getString("RenameRefactoringAction.text"));//$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/UndoManagerAction.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/UndoManagerAction.java index 2efd357c0c3..8ab2f4615a3 100644 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/UndoManagerAction.java +++ b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/UndoManagerAction.java @@ -16,36 +16,34 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; - -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.operation.IRunnableWithProgress; - -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowActionDelegate; -import org.eclipse.ui.PlatformUI; - import org.eclipse.cdt.internal.corext.refactoring.base.ChangeContext; import org.eclipse.cdt.internal.corext.refactoring.base.Refactoring; import org.eclipse.cdt.internal.corext.refactoring.base.RefactoringStatus; import org.eclipse.cdt.internal.corext.refactoring.base.RefactoringStatusEntry; import org.eclipse.cdt.internal.corext.refactoring.base.UndoManagerAdapter; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.cdt.internal.ui.refactoring.AbortChangeExceptionHandler; +import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.actions.SelectionDispatchAction; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; -abstract class UndoManagerAction implements IWorkbenchWindowActionDelegate { +abstract class UndoManagerAction extends SelectionDispatchAction { private static final int MAX_LENGTH= 30; @@ -54,7 +52,8 @@ abstract class UndoManagerAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow fWorkbenchWindow; private UndoManagerAdapter fUndoManagerListener; - public UndoManagerAction() { + public UndoManagerAction(IWorkbenchSite site) { + super(site); } protected abstract IRunnableWithProgress createOperation(ChangeContext context); @@ -108,16 +107,19 @@ abstract class UndoManagerAction implements IWorkbenchWindowActionDelegate { } /* (non-Javadoc) - * Method declared in IActionDelegate */ public void init(IWorkbenchWindow window) { fWorkbenchWindow= window; } - - /* (non-Javadoc) - * Method declared in IActionDelegate - */ + public void run(IStructuredSelection selection) { + run(); + } public void run(IAction action) { + run(); + } + /* (non-Javadoc) + */ + public void run() { Shell parent= fWorkbenchWindow.getShell(); ChangeContext context= new ChangeContext(new AbortChangeExceptionHandler(), getUnsavedFiles()); IRunnableWithProgress op= createOperation(context); diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/UndoRefactoringAction.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/UndoRefactoringAction.java index 7c297a283a4..242662afac4 100644 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/UndoRefactoringAction.java +++ b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/actions/UndoRefactoringAction.java @@ -13,26 +13,33 @@ package org.eclipse.cdt.internal.ui.refactoring.actions; import java.lang.reflect.InvocationTargetException; -import org.eclipse.core.runtime.IProgressMonitor; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.ISelection; - import org.eclipse.cdt.core.model.CModelException; - import org.eclipse.cdt.internal.corext.refactoring.base.ChangeAbortException; import org.eclipse.cdt.internal.corext.refactoring.base.ChangeContext; import org.eclipse.cdt.internal.corext.refactoring.base.IUndoManager; import org.eclipse.cdt.internal.corext.refactoring.base.Refactoring; import org.eclipse.cdt.internal.corext.refactoring.base.UndoManagerAdapter; +import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchSite; public class UndoRefactoringAction extends UndoManagerAction { private int fPatternLength; + private CEditor fEditor; - public UndoRefactoringAction() { + public UndoRefactoringAction(CEditor editor) { + this(editor.getEditorSite()); + fEditor= editor; + } + + public UndoRefactoringAction(IWorkbenchSite site) { + super(site); + init(site.getWorkbenchWindow()); } /* (non-Javadoc) @@ -84,23 +91,26 @@ public class UndoRefactoringAction extends UndoManagerAction { } }; } - /* (non-Javadoc) - * Method declared in IActionDelegate + */ + public void selectionChanged(ISelection s) { + selectionChanged(this, s); + } + /* (non-Javadoc) */ public void selectionChanged(IAction action, ISelection s) { -// if (!isHooked()) { - hookListener(action); - fPatternLength= RefactoringMessages.getString("UndoRefactoringAction.extendedLabel").length(); //$NON-NLS-1$ - IUndoManager undoManager = Refactoring.getUndoManager(); - if (undoManager.anythingToUndo()) { - if (undoManager.peekUndoName() != null) - action.setText(getActionText()); - action.setEnabled(true); - } else { - action.setEnabled(false); - } -// } + if (!isHooked()) { + hookListener(this); + } + fPatternLength= RefactoringMessages.getString("UndoRefactoringAction.extendedLabel").length(); //$NON-NLS-1$ + IUndoManager undoManager = Refactoring.getUndoManager(); + if (undoManager.anythingToUndo()) { + if (undoManager.peekUndoName() != null) + action.setText(getActionText()); + action.setEnabled(true); + } else { + action.setEnabled(false); + } } private String getActionText() { diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/refactoringui.properties b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/refactoringui.properties index a83de52d2be..c230d633d4e 100644 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/refactoringui.properties +++ b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/internal/ui/refactoring/refactoringui.properties @@ -227,8 +227,17 @@ InlineTempAction.inline_temp=Inline Local Variable InlineTempAction.label=&Inline Local Variable... RenameAction.rename=Rename -RenameAction.unavailable=Operation unavailable on the current selection.\nSelect a java project, source folder, resource, package or a translation unit, or a non binary type, field, method, parameter or a local variable. -RenameAction.text=Rena&me... +RenameAction.unavailable=Operation unavailable on the current selection.\nSelect a C/C++ project, source folder, resource or a translation unit, or a non binary type, field, method, parameter or a local variable. +RenameAction.text=Re&name... + +UndoAction.rename=Undo Action +UndoAction.unavailable=Operation unavailable. +UndoAction.text=&Undo... + +RedoAction.rename=Redo Action +RedoAction.unavailable=Operation unavailable. +RedoAction.text=&Redo... + RenameInputDialog.update_references=&Update references to the renamed element diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/RedoAction.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/RedoAction.java deleted file mode 100644 index ae8bd556c6a..00000000000 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/RedoAction.java +++ /dev/null @@ -1,86 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.ui.refactoring; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.internal.ui.refactoring.actions.RedoRefactoringAction; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; - -/** - * TODO: Provide description for "RefactoringRenameAction". - */ -public class RedoAction extends Action implements IViewActionDelegate { -// private IViewPart fView; -// private IAction fAction; - RedoRefactoringAction refactoringAction = new RedoRefactoringAction(); - -// protected IViewPart getView() { -// return fView; -// } - -// protected void setView(IViewPart view) { -// fView = view; -// } -// protected IAction getAction() { -// return fAction; -// } - -// protected void setAction(IAction action) { -// fAction = action; -// } - /** - * TODO: Implement the "RefactoringRenameAction" constructor. - */ - public RedoAction() { - } - /* (non-Javadoc) - * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) - */ - public void init(IViewPart view) { -// setView(view); - refactoringAction.init(view.getSite().getWorkbenchWindow()); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - refactoringAction.run(action); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - refactoringAction.selectionChanged(action, selection); -// setAction(action); -// if (!(selection instanceof IStructuredSelection)) { -// return; -// } -// IStructuredSelection sel= (IStructuredSelection)selection; -// Object o= sel.getFirstElement(); -// if (!(o instanceof ICElement)) { -// return; -// } - } - -// private IStructuredSelection getSelection() { -// return (IStructuredSelection)getView().getViewSite().getSelectionProvider().getSelection(); -// } - -} - diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/RenameAction.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/RenameAction.java deleted file mode 100644 index e0d84e21728..00000000000 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/RenameAction.java +++ /dev/null @@ -1,84 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.ui.refactoring; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.internal.ui.refactoring.actions.RenameRefactoringAction; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; - -/** - * TODO: Provide description for "RefactoringRenameAction". - */ -public class RenameAction extends Action implements IViewActionDelegate { - private IViewPart fView; - private IAction fAction; - - protected IViewPart getView() { - return fView; - } - - protected void setView(IViewPart view) { - fView = view; - } - protected IAction getAction() { - return fAction; - } - - protected void setAction(IAction action) { - fAction = action; - } - /** - * TODO: Implement the "RefactoringRenameAction" constructor. - */ - public RenameAction() { - } - /* (non-Javadoc) - * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) - */ - public void init(IViewPart view) { - setView(view); - - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - RenameRefactoringAction refactoringAction = new RenameRefactoringAction(getView().getSite()); - refactoringAction.run(getSelection()); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - setAction(action); - if (!(selection instanceof IStructuredSelection)) { - return; - } - IStructuredSelection sel= (IStructuredSelection)selection; - Object o= sel.getFirstElement(); - if (!(o instanceof ICElement)) { - return; - } - } - - private IStructuredSelection getSelection() { - return (IStructuredSelection)getView().getViewSite().getSelectionProvider().getSelection(); - } - -} diff --git a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/UndoAction.java b/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/UndoAction.java deleted file mode 100644 index 8fe179052d7..00000000000 --- a/core/org.eclipse.cdt.ui/refactor/org/eclipse/cdt/ui/refactoring/UndoAction.java +++ /dev/null @@ -1,86 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.ui.refactoring; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.internal.ui.refactoring.actions.UndoRefactoringAction; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; - -/** - * TODO: Provide description for "RefactoringRenameAction". - */ -public class UndoAction extends Action implements IViewActionDelegate { -// private IViewPart fView; -// private IAction fAction; - UndoRefactoringAction refactoringAction = new UndoRefactoringAction(); - -// protected IViewPart getView() { -// return fView; -// } - -// protected void setView(IViewPart view) { -// fView = view; -// } -// protected IAction getAction() { -// return fAction; -// } - -// protected void setAction(IAction action) { -// fAction = action; -// } - /** - * TODO: Implement the "RefactoringRenameAction" constructor. - */ - public UndoAction() { - } - /* (non-Javadoc) - * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) - */ - public void init(IViewPart view) { -// setView(view); - refactoringAction.init(view.getSite().getWorkbenchWindow()); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - refactoringAction.run(action); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - refactoringAction.selectionChanged(action, selection); -// setAction(action); -// if (!(selection instanceof IStructuredSelection)) { -// return; -// } -// IStructuredSelection sel= (IStructuredSelection)selection; -// Object o= sel.getFirstElement(); -// if (!(o instanceof ICElement)) { -// return; -// } - } - -// private IStructuredSelection getSelection() { -// return (IStructuredSelection)getView().getViewSite().getSelectionProvider().getSelection(); -// } - -} - diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java index 1264e53c22a..b8f8da17651 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.internal.ui.editor.OpenIncludeAction; import org.eclipse.cdt.internal.ui.editor.SearchDialogAction; import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.actions.RefactoringActionGroup; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; @@ -82,6 +83,7 @@ public class MainActionGroup extends CViewActionGroup { WorkingSetFilterActionGroup workingSetGroup; SelectionSearchGroup selectionSearchGroup; + RefactoringActionGroup refactoringActionGroup; public MainActionGroup(CView cview) { super(cview); @@ -164,7 +166,7 @@ public class MainActionGroup extends CViewActionGroup { fSearchDialogAction = new SearchDialogAction(viewer, getCView().getViewSite().getWorkbenchWindow()); selectionSearchGroup = new SelectionSearchGroup(getCView().getSite()); - + refactoringActionGroup = new RefactoringActionGroup(getCView().getSite()); } @@ -178,6 +180,8 @@ public class MainActionGroup extends CViewActionGroup { if (resources.isEmpty()) { new NewWizardMenu(menu, getCView().getSite().getWorkbenchWindow(), false); + menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE)); + refactoringActionGroup.fillContextMenu(menu); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ menu.add(new Separator()); @@ -207,6 +211,7 @@ public class MainActionGroup extends CViewActionGroup { menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ addPropertyMenu(menu, resources); + } /** * Extends the superclass implementation to set the context in the diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java index 9083232d6c6..58a814c010d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.ui.CElementContentProvider; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.actions.MemberFilterActionGroup; +import org.eclipse.cdt.ui.actions.RefactoringActionGroup; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -66,6 +67,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS private MemberFilterActionGroup fMemberFilterActionGroup; private ActionGroup fSelectionSearchGroup; + private ActionGroup fRefactoringActionGroup; public CContentOutlinePage(CEditor editor) { this("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$ @@ -130,7 +132,9 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS /** * called to create the context menu of the outline */ - protected void contextMenuAboutToShow(IMenuManager menu) { + protected void contextMenuAboutToShow(IMenuManager menu) { + CUIPlugin.createStandardGroups(menu); + if (OpenIncludeAction.canActionBeAdded(getSelection())) { menu.add(fOpenIncludeAction); } @@ -149,6 +153,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS+"-end"));//$NON-NLS-1$ fSelectionSearchGroup.fillContextMenu(menu); + fRefactoringActionGroup.fillContextMenu(menu); } /** @@ -176,7 +181,6 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS Menu menu= manager.createContextMenu(control); control.setMenu(menu); - fSelectionSearchGroup = new SelectionSearchGroup(this); // register global actions IPageSite site= getSite(); @@ -186,6 +190,10 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS bars.setGlobalActionHandler(ICEditorActionDefinitionIds.TOGGLE_PRESENTATION, fTogglePresentation); registerToolbarActions(); + + fSelectionSearchGroup = new SelectionSearchGroup(this); + fRefactoringActionGroup = new RefactoringActionGroup(this); + IEditorInput editorInput= (IEditorInput)fEditor.getEditorInput(); IDocumentProvider provider= fEditor.getDocumentProvider(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java index 048beaf08e3..0c704462497 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java @@ -64,5 +64,19 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition * (value "org.eclipse.cdt.ui.edit.opencview"). */ 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 "org.eclipse.cdt.ui.edit.text.rename.element"). + */ + public static final String RENAME_ELEMENT= "org.eclipse.cdt.ui.edit.text.rename.element"; //$NON-NLS-1$ + /** + * Action definition ID of the refactor -> undo action + * (value "org.eclipse.cdt.ui.edit.text.undo.action"). + */ + public static final String UNDO_ACTION= "org.eclipse.cdt.ui.edit.text.undo.action"; //$NON-NLS-1$ + /** + * Action definition ID of the refactor -> redo action + * (value "org.eclipse.cdt.ui.edit.text.redo.action"). + */ + public static final String REDO_ACTION= "org.eclipse.cdt.ui.edit.text.redo.action"; //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java index 00738699111..534263f83c4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.corext.refactoring.base.Refactoring; import org.eclipse.cdt.internal.ui.CElementAdapterFactory; import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.IContextMenuConstants; import org.eclipse.cdt.internal.ui.ResourceAdapterFactory; import org.eclipse.cdt.internal.ui.buildconsole.BuildConsoleManager; import org.eclipse.cdt.internal.ui.cview.CView; @@ -52,6 +53,9 @@ import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.GroupMarker; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.source.ISharedTextColors; @@ -469,4 +473,26 @@ public class CUIPlugin extends AbstractUIPlugin { } return display; } + + /** + * Creates the CUIplugin standard groups in a context menu. + */ + public static void createStandardGroups(IMenuManager menu) { + if (!menu.isEmpty()) + return; + + menu.add(new Separator(IContextMenuConstants.GROUP_NEW)); + menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO)); + menu.add(new Separator(IContextMenuConstants.GROUP_OPEN)); + menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW)); + menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE)); + menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE)); + menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH)); + menu.add(new Separator(IContextMenuConstants.GROUP_BUILD)); + menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS)); + menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP)); + menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES)); + } + + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/RefactoringActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/RefactoringActionGroup.java new file mode 100644 index 00000000000..f626d530e0b --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/RefactoringActionGroup.java @@ -0,0 +1,304 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation 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 API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.actions; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.IContextMenuConstants; +import org.eclipse.cdt.internal.ui.actions.ActionMessages; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds; +import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; +import org.eclipse.cdt.internal.ui.refactoring.actions.RedoRefactoringAction; +import org.eclipse.cdt.internal.ui.refactoring.actions.RenameRefactoringAction; +import org.eclipse.cdt.internal.ui.refactoring.actions.UndoRefactoringAction; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.swt.events.MenuAdapter; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.part.Page; + +/** + * Action group that adds refactor actions (for example Rename..., Move..., etc) + * to a context menu and the global menu bar. + * + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ * + * @since 2.0 + */ +public class RefactoringActionGroup extends ActionGroup { + + /** + * Pop-up menu: id of the refactor sub menu (value org.eclipse.cdt.ui.refactoring.menu). + * + * @since 2.1 + */ + public static final String MENU_ID= "org.eclipse.cdt.ui.refactoring.menu"; //$NON-NLS-1$ + + /** + * Pop-up menu: id of the reorg group of the refactor sub menu (value + * reorgGroup). + * + * @since 2.1 + */ + public static final String GROUP_REORG= "reorgGroup"; //$NON-NLS-1$ + + /** + * Pop-up menu: id of the type group of the refactor sub menu (value + * typeGroup). + * + * @since 2.1 + */ + public static final String GROUP_TYPE= "typeGroup"; //$NON-NLS-1$ + + /** + * Pop-up menu: id of the coding group of the refactor sub menu (value + * codingGroup). + * + * @since 2.1 + */ + public static final String GROUP_CODING= "codingGroup"; //$NON-NLS-1$ + + /** + * Refactor menu: name of standard Rename Element global action + * (value "org.eclipse.cdt.ui.actions.refactor.Rename"). + */ + public static final String REFACTOR_RENAME= "org.eclipse.cdt.ui.actions.refactor.RenameAction"; //$NON-NLS-1$ + /** + * Refactor menu: name of standard Undo global action + * (value "org.eclipse.cdt.ui.actions.refactor.undo"). + */ + public static final String REFACTOR_UNDO= "org.eclipse.cdt.ui.actions.refactor.UndoAction"; //$NON-NLS-1$ + /** + * Refactor menu: name of standard Redo global action + * (value "org.eclipse.cdt.ui.actions.refactor.redo"). + */ + public static final String REFACTOR_REDO= "org.eclipse.cdt.ui.actions.refactor.RedoAction"; //$NON-NLS-1$ + + private IWorkbenchSite fSite; + private CEditor fEditor; + private String fGroupName= IContextMenuConstants.GROUP_REORGANIZE; + + private SelectionDispatchAction fRenameAction; + private SelectionDispatchAction fRedoAction; + private SelectionDispatchAction fUndoAction; + private List fEditorActions; + + private static class NoActionAvailable extends Action { + public NoActionAvailable() { + setEnabled(false); + setText(RefactoringMessages.getString("RefactorActionGroup.no_refactoring_available")); //$NON-NLS-1$ + } + } + private Action fNoActionAvailable= new NoActionAvailable(); + + /** + * Creates a new RefactorActionGroup. The group requires + * that the selection provided by the part's selection provider is of type + * org.eclipse.jface.viewers.IStructuredSelection. + * + * @param part the view part that owns this action group + */ + public RefactoringActionGroup(IViewPart part) { + this(part.getSite()); + } + + /** + * Creates a new RefactorActionGroup. The action requires + * that the selection provided by the page's selection provider is of type + * org.eclipse.jface.viewers.IStructuredSelection. + * + * @param page the page that owns this action group + */ + public RefactoringActionGroup(Page page) { + this(page.getSite()); + } + + /** + * Note: This constructor is for internal use only. Clients should not call this constructor. + */ + public RefactoringActionGroup(CEditor editor, String groupName) { + fSite= editor.getEditorSite(); + fEditor= editor; + fGroupName= groupName; + ISelectionProvider provider= editor.getSelectionProvider(); + ISelection selection= provider.getSelection(); + fEditorActions= new ArrayList(); + + fRenameAction= new RenameRefactoringAction(editor); + fRenameAction.setActionDefinitionId(ICEditorActionDefinitionIds.RENAME_ELEMENT); + fRenameAction.update(selection); + editor.setAction("RenameElement", fRenameAction); //$NON-NLS-1$ + fEditorActions.add(fRenameAction); + + fUndoAction= new UndoRefactoringAction(editor); + fUndoAction.setActionDefinitionId(ICEditorActionDefinitionIds.UNDO_ACTION); + fUndoAction.update(selection); + editor.setAction("UndoAction", fUndoAction); //$NON-NLS-1$ + fEditorActions.add(fUndoAction); + + fRedoAction= new RedoRefactoringAction(editor); + fRedoAction.setActionDefinitionId(ICEditorActionDefinitionIds.REDO_ACTION); + fRedoAction.update(selection); + editor.setAction("RedoAction", fRedoAction); //$NON-NLS-1$ + fEditorActions.add(fRedoAction); +} + + public RefactoringActionGroup(IWorkbenchSite site) { + fSite= site; + ISelectionProvider provider= fSite.getSelectionProvider(); + ISelection selection= provider.getSelection(); + + fRenameAction= new RenameRefactoringAction(site); + initAction(fRenameAction, provider, selection); + + fUndoAction= new UndoRefactoringAction(site); + initAction(fUndoAction, provider, selection); + + fRedoAction= new RedoRefactoringAction(site); + initAction(fRedoAction, provider, selection); + + } + + private static void initAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection){ + action.update(selection); + provider.addSelectionChangedListener(action); + } + + /* (non-Javadoc) + * Method declared in ActionGroup + */ + public void fillActionBars(IActionBars actionBars) { + super.fillActionBars(actionBars); + actionBars.setGlobalActionHandler(REFACTOR_RENAME, fRenameAction); + actionBars.setGlobalActionHandler(REFACTOR_UNDO, fUndoAction); + actionBars.setGlobalActionHandler(REFACTOR_REDO, fRedoAction); + } + + /* (non-Javadoc) + * Method declared in ActionGroup + */ + public void fillContextMenu(IMenuManager menu) { + super.fillContextMenu(menu); + addRefactorSubmenu(menu); + } + + /* + * @see ActionGroup#dispose() + */ + public void dispose() { + ISelectionProvider provider= fSite.getSelectionProvider(); + disposeAction(fRenameAction, provider); + disposeAction(fUndoAction, provider); + disposeAction(fRedoAction, provider); + super.dispose(); + } + + private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) { + if (action != null) + provider.removeSelectionChangedListener(action); + } + + private void addRefactorSubmenu(IMenuManager menu) { + IMenuManager refactorSubmenu= new MenuManager(ActionMessages.getString("RefactorMenu.label"), MENU_ID); //$NON-NLS-1$ + if (fEditor != null) { + refactorSubmenu.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + refactorMenuShown(manager); + } + }); + refactorSubmenu.add(fNoActionAvailable); + menu.appendToGroup(fGroupName, refactorSubmenu); + } else { + if (fillRefactorMenu(refactorSubmenu) > 0){ + menu.appendToGroup(fGroupName, refactorSubmenu); + } + + } + } + + private int fillRefactorMenu(IMenuManager refactorSubmenu) { + int added= 0; + refactorSubmenu.add(new Separator(GROUP_REORG)); + added+= addAction(refactorSubmenu, fRenameAction); + added+= addAction(refactorSubmenu, fUndoAction); + added+= addAction(refactorSubmenu, fRedoAction); + return added; + } + + private int addAction(IMenuManager menu, IAction action) { + if (action != null && action.isEnabled()) { + menu.add(action); + return 1; + } + return 0; + } + + private void refactorMenuShown(final IMenuManager refactorSubmenu) { + // we know that we have an MenuManager since we created it in + // addRefactorSubmenu. + Menu menu= ((MenuManager)refactorSubmenu).getMenu(); + menu.addMenuListener(new MenuAdapter() { + public void menuHidden(MenuEvent e) { + refactorMenuHidden(refactorSubmenu); + } + }); + ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection(); +// CTextSelection javaSelection= new CTextSelection( +// getEditorInput(), getDocument(), textSelection.getOffset(), textSelection.getLength()); + + for (Iterator iter= fEditorActions.iterator(); iter.hasNext(); ) { + SelectionDispatchAction action= (SelectionDispatchAction)iter.next(); +// action.update(javaSelection); + } + refactorSubmenu.removeAll(); + if (fillRefactorMenu(refactorSubmenu) == 0) + refactorSubmenu.add(fNoActionAvailable); + } + + private void refactorMenuHidden(IMenuManager manager) { + ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection(); + for (Iterator iter= fEditorActions.iterator(); iter.hasNext(); ) { + SelectionDispatchAction action= (SelectionDispatchAction)iter.next(); + action.update(textSelection); + } + } + + private ICElement getEditorInput() { + return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy( + fEditor.getEditorInput()); + } + + private IDocument getDocument() { + return CUIPlugin.getDefault().getDocumentProvider(). + getDocument(fEditor.getEditorInput()); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/RenameAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/RenameAction.java deleted file mode 100644 index ee8b7ffa0eb..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/RenameAction.java +++ /dev/null @@ -1,77 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/ -package org.eclipse.cdt.ui.actions; - -import org.eclipse.cdt.internal.ui.ICHelpContextIds; -import org.eclipse.cdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.cdt.internal.ui.refactoring.actions.RenameRefactoringAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.help.WorkbenchHelp; - - -/** - * Renames a C element or workbench resource. - *

- * Action is applicable to selections containing elements of type - * ICElement. - * - *

- * This class may be instantiated; it is not intended to be subclassed. - *

- * - * @since 2.0 - */ -public class RenameAction extends SelectionDispatchAction { - - private RenameRefactoringAction fRenameCElement; - /** - * Creates a new RenameAction. The action requires - * that the selection provided by the site's selection provider is of type - * org.eclipse.jface.viewers.IStructuredSelection. - * - * @param site the site providing context information for this action - */ - public RenameAction(IWorkbenchSite site) { - super(site); - setText(RefactoringMessages.getString("RenameAction.text")); //$NON-NLS-1$ - fRenameCElement= new RenameRefactoringAction(site); - fRenameCElement.setText(getText()); - WorkbenchHelp.setHelp(this, ICHelpContextIds.RENAME_ACTION); - } - /* - * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - fRenameCElement.selectionChanged(event); - setEnabled(computeEnabledState()); - } - - /* - * @see SelectionDispatchAction#update(ISelection) - */ - public void update(ISelection selection) { - fRenameCElement.update(selection); - - setEnabled(computeEnabledState()); - } - - private boolean computeEnabledState(){ - return fRenameCElement.isEnabled(); - } - - public void run(IStructuredSelection selection) { - if (fRenameCElement.isEnabled()) - fRenameCElement.run(selection); - } -}