mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 18:55:38 +02:00
Bug 483602 - Implement deletion of elements from Outline view
Adding the delete refactor to the refactor context menu in the Outline View. Change-Id: I208078d2200853389bf4eb114756cf4e9b719134 Signed-off-by: ljyanesm <yanes.luis@gmail.com>
This commit is contained in:
parent
b6bda6636c
commit
f034a69fb7
6 changed files with 89 additions and 2 deletions
|
@ -181,6 +181,7 @@ Refactoring.toggleFunction.label=Toggle Function
|
||||||
Refactoring.hideMethod.label=Hide Method...
|
Refactoring.hideMethod.label=Hide Method...
|
||||||
Refactoring.implementMethod.label=Impl&ement Method...
|
Refactoring.implementMethod.label=Impl&ement Method...
|
||||||
Refactoring.gettersAndSetters.label=Gene&rate Getters and Setters...
|
Refactoring.gettersAndSetters.label=Gene&rate Getters and Setters...
|
||||||
|
Refactoring.deleteAction.label=&Delete
|
||||||
|
|
||||||
Source.menu.label = &Source
|
Source.menu.label = &Source
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,12 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
||||||
*/
|
*/
|
||||||
public static final String RENAME_ELEMENT= "org.eclipse.cdt.ui.edit.text.rename.element"; //$NON-NLS-1$
|
public static final String RENAME_ELEMENT= "org.eclipse.cdt.ui.edit.text.rename.element"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action definition ID of the refactor -> delete element action
|
||||||
|
* (value <code>"org.eclipse.cdt.ui.edit.text.delete.element"</code>).
|
||||||
|
*/
|
||||||
|
public static final String DELETE_ELEMENT = "org.eclipse.cdt.ui.edit.text.delete.element"; //$NON-NLS-1$}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action definition ID of the refactor -> extract constant action
|
* Action definition ID of the refactor -> extract constant action
|
||||||
* (value <code>"org.eclipse.cdt.ui.refactor.extract.constant"</code>).
|
* (value <code>"org.eclipse.cdt.ui.refactor.extract.constant"</code>).
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2016 Luis Yanes.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.refactoring.actions;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||||
|
import org.eclipse.jface.operation.IRunnableContext;
|
||||||
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||||
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
import org.eclipse.jface.window.IShellProvider;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launches a delete refactoring.
|
||||||
|
*
|
||||||
|
* @since 5.12
|
||||||
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
|
* @author Luis Yanes
|
||||||
|
*/
|
||||||
|
public class CDeleteAction extends RefactoringAction {
|
||||||
|
|
||||||
|
public CDeleteAction() {
|
||||||
|
super(Messages.CDeleteAction_label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(IShellProvider shellProvider, IWorkingCopy wc, ITextSelection s) {
|
||||||
|
throw new UnsupportedOperationException("Invoking this action from the editor is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(IShellProvider shellProvider, ICElement elem) {
|
||||||
|
final ICElement[] elements = new ICElement[] { elem };
|
||||||
|
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
||||||
|
@Override
|
||||||
|
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||||
|
try {
|
||||||
|
CoreModel.getDefault().getCModel().delete(elements, false, monitor);
|
||||||
|
} catch (CModelException e) {
|
||||||
|
throw new InvocationTargetException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
IRunnableContext context = new ProgressMonitorDialog(shellProvider.getShell());
|
||||||
|
context.run(true, true, runnable);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
ExceptionHandler.handle(e, Messages.CDeleteAction_error_title, Messages.CDeleteAction_error_message);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// Safely ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import org.eclipse.ui.IActionBars;
|
||||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
import org.eclipse.ui.IWorkbenchSite;
|
import org.eclipse.ui.IWorkbenchSite;
|
||||||
|
import org.eclipse.ui.actions.ActionFactory;
|
||||||
import org.eclipse.ui.actions.ActionGroup;
|
import org.eclipse.ui.actions.ActionGroup;
|
||||||
import org.eclipse.ui.part.Page;
|
import org.eclipse.ui.part.Page;
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
@ -113,6 +114,7 @@ public class CRefactoringActionGroup extends ActionGroup implements ISelectionCh
|
||||||
|
|
||||||
private String fGroupName= IWorkbenchActionConstants.GROUP_REORGANIZE;
|
private String fGroupName= IWorkbenchActionConstants.GROUP_REORGANIZE;
|
||||||
private CRenameAction fRenameAction;
|
private CRenameAction fRenameAction;
|
||||||
|
private CDeleteAction fDeleteAction;
|
||||||
private RefactoringAction fExtractConstantAction;
|
private RefactoringAction fExtractConstantAction;
|
||||||
private RefactoringAction fExtractLocalVariableAction;
|
private RefactoringAction fExtractLocalVariableAction;
|
||||||
private RefactoringAction fExtractFunctionAction;
|
private RefactoringAction fExtractFunctionAction;
|
||||||
|
@ -165,8 +167,12 @@ public class CRefactoringActionGroup extends ActionGroup implements ISelectionCh
|
||||||
fToggleFunctionAction = new ToggleFunctionAction();
|
fToggleFunctionAction = new ToggleFunctionAction();
|
||||||
fToggleFunctionAction.setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_FUNCTION);
|
fToggleFunctionAction.setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_FUNCTION);
|
||||||
fAllActions.add(fToggleFunctionAction);
|
fAllActions.add(fToggleFunctionAction);
|
||||||
|
} else {
|
||||||
|
fDeleteAction = new CDeleteAction();
|
||||||
|
fDeleteAction.setActionDefinitionId(ICEditorActionDefinitionIds.DELETE_ELEMENT);
|
||||||
|
fAllActions.add(fDeleteAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
fHideMethodAction = new HideMethodAction();
|
fHideMethodAction = new HideMethodAction();
|
||||||
fHideMethodAction.setActionDefinitionId(ICEditorActionDefinitionIds.HIDE_METHOD);
|
fHideMethodAction.setActionDefinitionId(ICEditorActionDefinitionIds.HIDE_METHOD);
|
||||||
fAllActions.add(fHideMethodAction);
|
fAllActions.add(fHideMethodAction);
|
||||||
|
@ -236,6 +242,7 @@ public class CRefactoringActionGroup extends ActionGroup implements ISelectionCh
|
||||||
IMenuManager refactorSubmenu = new MenuManager(Messages.CRefactoringActionGroup_menu, MENU_ID);
|
IMenuManager refactorSubmenu = new MenuManager(Messages.CRefactoringActionGroup_menu, MENU_ID);
|
||||||
refactorSubmenu.add(new Separator(GROUP_REORG));
|
refactorSubmenu.add(new Separator(GROUP_REORG));
|
||||||
addAction(refactorSubmenu, fRenameAction);
|
addAction(refactorSubmenu, fRenameAction);
|
||||||
|
addAction(refactorSubmenu, fDeleteAction);
|
||||||
refactorSubmenu.add(new Separator(GROUP_CODING));
|
refactorSubmenu.add(new Separator(GROUP_CODING));
|
||||||
addAction(refactorSubmenu, fExtractConstantAction);
|
addAction(refactorSubmenu, fExtractConstantAction);
|
||||||
addAction(refactorSubmenu, fExtractLocalVariableAction);
|
addAction(refactorSubmenu, fExtractLocalVariableAction);
|
||||||
|
|
|
@ -22,7 +22,10 @@ class Messages extends NLS {
|
||||||
public static String ImplementMethodAction_label;
|
public static String ImplementMethodAction_label;
|
||||||
public static String GettersAndSetters_label;
|
public static String GettersAndSetters_label;
|
||||||
public static String ToggleFunctionAction_label;
|
public static String ToggleFunctionAction_label;
|
||||||
|
public static String CDeleteAction_label;
|
||||||
|
public static String CDeleteAction_error_title;
|
||||||
|
public static String CDeleteAction_error_message;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
NLS.initializeMessages(Messages.class.getName(), Messages.class);
|
NLS.initializeMessages(Messages.class.getName(), Messages.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,3 +18,6 @@ ImplementMethodAction_label=Implement Method...
|
||||||
HideMethodAction_label=Hide Method...
|
HideMethodAction_label=Hide Method...
|
||||||
ExtractFunctionAction_label=Extract Function...
|
ExtractFunctionAction_label=Extract Function...
|
||||||
ToggleFunctionAction_label=Toggle Function Definition
|
ToggleFunctionAction_label=Toggle Function Definition
|
||||||
|
CDeleteAction_label=&Delete
|
||||||
|
CDeleteAction_error_title=Delete Element Problem
|
||||||
|
CDeleteAction_error_message=There was a problem while trying to delete the element.
|
Loading…
Add table
Reference in a new issue