mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
Patch for Markus: turn off old refactoring UI if new refactoring plugin loaded. Hook up new refactoring UI.
This commit is contained in:
parent
7c8ce5b42e
commit
bac2cf5297
1 changed files with 96 additions and 84 deletions
|
@ -21,6 +21,7 @@ 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.RedoRefactoringAction;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.actions.RenameRefactoringAction;
|
import org.eclipse.cdt.internal.ui.refactoring.actions.RenameRefactoringAction;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.actions.UndoRefactoringAction;
|
import org.eclipse.cdt.internal.ui.refactoring.actions.UndoRefactoringAction;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.action.IMenuManager;
|
import org.eclipse.jface.action.IMenuManager;
|
||||||
|
@ -138,49 +139,56 @@ public class RefactoringActionGroup extends ActionGroup {
|
||||||
* Note: This constructor is for internal use only. Clients should not call this constructor.
|
* Note: This constructor is for internal use only. Clients should not call this constructor.
|
||||||
*/
|
*/
|
||||||
public RefactoringActionGroup(CEditor editor, String groupName) {
|
public RefactoringActionGroup(CEditor editor, String groupName) {
|
||||||
fSite= editor.getEditorSite();
|
if (!isRefactoringPluginLoaded()) {
|
||||||
fEditor= editor;
|
fSite= editor.getEditorSite();
|
||||||
if((groupName != null) && (groupName.length() > 0))
|
fEditor= editor;
|
||||||
fGroupName= groupName;
|
if((groupName != null) && (groupName.length() > 0))
|
||||||
|
fGroupName= groupName;
|
||||||
ISelectionProvider provider= editor.getSelectionProvider();
|
|
||||||
ISelection selection= provider.getSelection();
|
ISelectionProvider provider= editor.getSelectionProvider();
|
||||||
fEditorActions= new ArrayList(3);
|
ISelection selection= provider.getSelection();
|
||||||
|
fEditorActions= new ArrayList(3);
|
||||||
fRenameAction= new RenameRefactoringAction(editor);
|
|
||||||
fRenameAction.update(selection);
|
fRenameAction= new RenameRefactoringAction(editor);
|
||||||
editor.setAction("RenameElement", fRenameAction); //$NON-NLS-1$
|
fRenameAction.update(selection);
|
||||||
fEditorActions.add(fRenameAction);
|
editor.setAction("RenameElement", fRenameAction); //$NON-NLS-1$
|
||||||
|
fEditorActions.add(fRenameAction);
|
||||||
fUndoAction= new UndoRefactoringAction(editor);
|
|
||||||
fUndoAction.update(selection);
|
fUndoAction= new UndoRefactoringAction(editor);
|
||||||
editor.setAction("UndoAction", fUndoAction); //$NON-NLS-1$
|
fUndoAction.update(selection);
|
||||||
fEditorActions.add(fUndoAction);
|
editor.setAction("UndoAction", fUndoAction); //$NON-NLS-1$
|
||||||
|
fEditorActions.add(fUndoAction);
|
||||||
fRedoAction= new RedoRefactoringAction(editor);
|
|
||||||
fRedoAction.update(selection);
|
fRedoAction= new RedoRefactoringAction(editor);
|
||||||
editor.setAction("RedoAction", fRedoAction); //$NON-NLS-1$
|
fRedoAction.update(selection);
|
||||||
fEditorActions.add(fRedoAction);
|
editor.setAction("RedoAction", fRedoAction); //$NON-NLS-1$
|
||||||
|
fEditorActions.add(fRedoAction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefactoringActionGroup(IWorkbenchSite site, String groupName) {
|
public RefactoringActionGroup(IWorkbenchSite site, String groupName) {
|
||||||
fSite= site;
|
if (!isRefactoringPluginLoaded()) {
|
||||||
if((groupName != null) && (groupName.length() > 0))
|
fSite= site;
|
||||||
fGroupName= groupName;
|
if((groupName != null) && (groupName.length() > 0))
|
||||||
ISelectionProvider provider= fSite.getSelectionProvider();
|
fGroupName= groupName;
|
||||||
ISelection selection= provider.getSelection();
|
ISelectionProvider provider= fSite.getSelectionProvider();
|
||||||
|
ISelection selection= provider.getSelection();
|
||||||
fRenameAction= new RenameRefactoringAction(site);
|
|
||||||
initAction(fRenameAction, provider, selection);
|
fRenameAction= new RenameRefactoringAction(site);
|
||||||
|
initAction(fRenameAction, provider, selection);
|
||||||
fUndoAction= new UndoRefactoringAction(site);
|
|
||||||
initAction(fUndoAction, provider, selection);
|
fUndoAction= new UndoRefactoringAction(site);
|
||||||
|
initAction(fUndoAction, provider, selection);
|
||||||
fRedoAction= new RedoRefactoringAction(site);
|
|
||||||
initAction(fRedoAction, provider, selection);
|
fRedoAction= new RedoRefactoringAction(site);
|
||||||
|
initAction(fRedoAction, provider, selection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isRefactoringPluginLoaded() {
|
||||||
|
return Platform.getBundle("org.eclipse.cdt.refactoring") != null; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
private static void initAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection){
|
private static void initAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection){
|
||||||
action.update(selection);
|
action.update(selection);
|
||||||
provider.addSelectionChangedListener(action);
|
provider.addSelectionChangedListener(action);
|
||||||
|
@ -191,9 +199,11 @@ public class RefactoringActionGroup extends ActionGroup {
|
||||||
*/
|
*/
|
||||||
public void fillActionBars(IActionBars actionBars) {
|
public void fillActionBars(IActionBars actionBars) {
|
||||||
super.fillActionBars(actionBars);
|
super.fillActionBars(actionBars);
|
||||||
actionBars.setGlobalActionHandler(REFACTOR_RENAME, fRenameAction);
|
if (fSite != null) {
|
||||||
actionBars.setGlobalActionHandler(REFACTOR_UNDO, fUndoAction);
|
actionBars.setGlobalActionHandler(REFACTOR_RENAME, fRenameAction);
|
||||||
actionBars.setGlobalActionHandler(REFACTOR_REDO, fRedoAction);
|
actionBars.setGlobalActionHandler(REFACTOR_UNDO, fUndoAction);
|
||||||
|
actionBars.setGlobalActionHandler(REFACTOR_REDO, fRedoAction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -201,37 +211,40 @@ public class RefactoringActionGroup extends ActionGroup {
|
||||||
*/
|
*/
|
||||||
public void fillContextMenu(IMenuManager menu) {
|
public void fillContextMenu(IMenuManager menu) {
|
||||||
super.fillContextMenu(menu);
|
super.fillContextMenu(menu);
|
||||||
addRefactorSubmenu(menu);
|
if (fSite != null) {
|
||||||
|
addRefactorSubmenu(menu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see ActionGroup#dispose()
|
* @see ActionGroup#dispose()
|
||||||
*/
|
*/
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
ISelectionProvider provider= fSite.getSelectionProvider();
|
if (fSite != null) {
|
||||||
|
ISelectionProvider provider= fSite.getSelectionProvider();
|
||||||
if (fRenameAction != null) {
|
|
||||||
disposeAction(fRenameAction, provider);
|
if (fRenameAction != null) {
|
||||||
fRenameAction= null;
|
disposeAction(fRenameAction, provider);
|
||||||
}
|
fRenameAction= null;
|
||||||
|
}
|
||||||
if (fUndoAction != null) {
|
|
||||||
disposeAction(fUndoAction, provider);
|
if (fUndoAction != null) {
|
||||||
fUndoAction.dispose();
|
disposeAction(fUndoAction, provider);
|
||||||
fUndoAction= null;
|
fUndoAction.dispose();
|
||||||
}
|
fUndoAction= null;
|
||||||
|
}
|
||||||
if (fRedoAction != null) {
|
|
||||||
disposeAction(fRedoAction, provider);
|
if (fRedoAction != null) {
|
||||||
fRedoAction.dispose();
|
disposeAction(fRedoAction, provider);
|
||||||
fRedoAction= null;
|
fRedoAction.dispose();
|
||||||
}
|
fRedoAction= null;
|
||||||
|
}
|
||||||
if (fEditorActions != null) {
|
|
||||||
fEditorActions.clear();
|
if (fEditorActions != null) {
|
||||||
fEditorActions= null;
|
fEditorActions.clear();
|
||||||
}
|
fEditorActions= null;
|
||||||
|
}
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,22 +253,22 @@ public class RefactoringActionGroup extends ActionGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRefactorSubmenu(IMenuManager menu) {
|
private void addRefactorSubmenu(IMenuManager menu) {
|
||||||
IMenuManager refactorSubmenu= new MenuManager(ActionMessages.getString("RefactorMenu.label"), MENU_ID); //$NON-NLS-1$
|
IMenuManager refactorSubmenu= new MenuManager(ActionMessages.getString("RefactorMenu.label"), MENU_ID); //$NON-NLS-1$
|
||||||
if (fEditor != null) {
|
if (fEditor != null) {
|
||||||
ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection();
|
ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection();
|
||||||
for (Iterator iter= fEditorActions.iterator(); iter.hasNext(); ) {
|
for (Iterator iter= fEditorActions.iterator(); iter.hasNext(); ) {
|
||||||
SelectionDispatchAction action= (SelectionDispatchAction)iter.next();
|
SelectionDispatchAction action= (SelectionDispatchAction)iter.next();
|
||||||
action.update(textSelection);
|
action.update(textSelection);
|
||||||
}
|
}
|
||||||
refactorSubmenu.removeAll();
|
refactorSubmenu.removeAll();
|
||||||
if (fillRefactorMenu(refactorSubmenu) == 0)
|
if (fillRefactorMenu(refactorSubmenu) == 0)
|
||||||
refactorSubmenu.add(fNoActionAvailable);
|
refactorSubmenu.add(fNoActionAvailable);
|
||||||
menu.appendToGroup(fGroupName, refactorSubmenu);
|
menu.appendToGroup(fGroupName, refactorSubmenu);
|
||||||
} else {
|
} else {
|
||||||
if (fillRefactorMenu(refactorSubmenu) > 0){
|
if (fillRefactorMenu(refactorSubmenu) > 0){
|
||||||
menu.appendToGroup(fGroupName, refactorSubmenu);
|
menu.appendToGroup(fGroupName, refactorSubmenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fillRefactorMenu(IMenuManager refactorSubmenu) {
|
private int fillRefactorMenu(IMenuManager refactorSubmenu) {
|
||||||
|
@ -274,5 +287,4 @@ public class RefactoringActionGroup extends ActionGroup {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue