mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 290499 - Generating Getter, Setter and Implementing Methods should by available through the Outline context menus
Patch by Marc-Andre Laperle
This commit is contained in:
parent
a50078bfdf
commit
897e40ab49
3 changed files with 73 additions and 7 deletions
|
@ -253,6 +253,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
private ActionGroup fMemberFilterActionGroup;
|
||||
private ActionGroup fSelectionSearchGroup;
|
||||
private ActionGroup fRefactoringActionGroup;
|
||||
private ActionGroup fSourceActionGroup;
|
||||
private ActionGroup fOpenViewActionGroup;
|
||||
/**
|
||||
* Custom filter action group.
|
||||
|
@ -403,6 +404,10 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
fSelectionSearchGroup.fillContextMenu(menu);
|
||||
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||
}
|
||||
|
||||
if (fSourceActionGroup != null) {
|
||||
fSourceActionGroup.fillContextMenu(menu);
|
||||
}
|
||||
|
||||
if (fRefactoringActionGroup != null) {
|
||||
fRefactoringActionGroup.fillContextMenu(menu);
|
||||
|
@ -464,6 +469,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
|
||||
fSelectionSearchGroup = createSearchActionGroup();
|
||||
fOpenViewActionGroup = createOpenViewActionGroup();
|
||||
fSourceActionGroup = createSourceActionGroup();
|
||||
fRefactoringActionGroup= createRefactoringActionGroup();
|
||||
// Custom filter group
|
||||
fCustomFiltersActionGroup= createCustomFiltersActionGroup();
|
||||
|
@ -587,6 +593,15 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
// default: no refactoring actions
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an ActionGroup contributing source actions or
|
||||
* <code>null</code> if source actions are not supported
|
||||
*/
|
||||
protected ActionGroup createSourceActionGroup() {
|
||||
// default: no source actions
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an ActionGroup instance to provide custom filters or
|
||||
|
@ -628,6 +643,11 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
fRefactoringActionGroup.setContext(new ActionContext(selection));
|
||||
fRefactoringActionGroup.updateActionBars();
|
||||
}
|
||||
|
||||
if (fSourceActionGroup != null) {
|
||||
fSourceActionGroup.setContext(new ActionContext(selection));
|
||||
fSourceActionGroup.updateActionBars();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.ui.dialogs.PreferencesUtil;
|
|||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.GenerateActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
|
||||
|
@ -134,6 +135,12 @@ public class CContentOutlinePage extends AbstractCModelOutlinePage {
|
|||
protected ActionGroup createRefactoringActionGroup() {
|
||||
return new CRefactoringActionGroup(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ActionGroup createSourceActionGroup() {
|
||||
return new GenerateActionGroup(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionGroup createCustomFiltersActionGroup() {
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.eclipse.jface.viewers.ISelection;
|
|||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.IWorkbenchCommandConstants;
|
||||
|
@ -38,8 +39,12 @@ import org.eclipse.ui.ide.IDEActionFactory;
|
|||
import org.eclipse.ui.part.Page;
|
||||
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.GettersAndSettersAction;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.ImplementMethodAction;
|
||||
import org.eclipse.cdt.ui.refactoring.actions.RefactoringAction;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.actions.ActionMessages;
|
||||
|
@ -59,7 +64,7 @@ import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
|
|||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @since 4.0
|
||||
*/
|
||||
public class GenerateActionGroup extends ActionGroup {
|
||||
public class GenerateActionGroup extends ActionGroup implements ISelectionChangedListener {
|
||||
|
||||
/**
|
||||
* Pop-up menu: id of the source sub menu (value <code>org.eclipse.cdt.ui.source.menu</code>).
|
||||
|
@ -106,6 +111,7 @@ public class GenerateActionGroup extends ActionGroup {
|
|||
private IWorkbenchSite fSite;
|
||||
private String fGroupName= IContextMenuConstants.GROUP_REORGANIZE;
|
||||
private List<ISelectionChangedListener> fRegisteredSelectionListeners;
|
||||
private List<RefactoringAction> fRefactorActions= new ArrayList<RefactoringAction>();
|
||||
|
||||
private AddIncludeOnSelectionAction fAddInclude;
|
||||
// private OverrideMethodsAction fOverrideMethods;
|
||||
|
@ -234,9 +240,16 @@ public class GenerateActionGroup extends ActionGroup {
|
|||
// fOverrideMethods= new OverrideMethodsAction(site);
|
||||
// fOverrideMethods.setActionDefinitionId(ICEditorActionDefinitionIds.OVERRIDE_METHODS);
|
||||
//
|
||||
// fAddGetterSetter= new AddGetterSetterAction(site);
|
||||
// fAddGetterSetter.setActionDefinitionId(ICEditorActionDefinitionIds.CREATE_GETTER_SETTER);
|
||||
//
|
||||
fAddGetterSetter = new GettersAndSettersAction();
|
||||
fAddGetterSetter.setActionDefinitionId(ICEditorActionDefinitionIds.GETTERS_AND_SETTERS);
|
||||
fAddGetterSetter.setSite(fSite);
|
||||
fRefactorActions.add(fAddGetterSetter);
|
||||
|
||||
fImplementMethod = new ImplementMethodAction();
|
||||
fImplementMethod.setActionDefinitionId(ICEditorActionDefinitionIds.IMPLEMENT_METHOD);
|
||||
fImplementMethod.setSite(fSite);
|
||||
fRefactorActions.add(fImplementMethod);
|
||||
|
||||
// fAddDelegateMethods= new AddDelegateMethodsAction(site);
|
||||
// fAddDelegateMethods.setActionDefinitionId(ICEditorActionDefinitionIds.CREATE_DELEGATE_METHODS);
|
||||
//
|
||||
|
@ -275,7 +288,6 @@ public class GenerateActionGroup extends ActionGroup {
|
|||
|
||||
|
||||
// fOverrideMethods.update(selection);
|
||||
// fAddGetterSetter.update(selection);
|
||||
// fAddDelegateMethods.update(selection);
|
||||
// fAddUnimplementedConstructors.update(selection);
|
||||
// fGenerateConstructorUsingFields.update(selection);
|
||||
|
@ -297,7 +309,6 @@ public class GenerateActionGroup extends ActionGroup {
|
|||
}
|
||||
|
||||
// registerSelectionListener(provider, fOverrideMethods);
|
||||
// registerSelectionListener(provider, fAddGetterSetter);
|
||||
// registerSelectionListener(provider, fAddDelegateMethods);
|
||||
// registerSelectionListener(provider, fAddUnimplementedConstructors);
|
||||
// registerSelectionListener(provider, fGenerateConstructorUsingFields);
|
||||
|
@ -312,6 +323,9 @@ public class GenerateActionGroup extends ActionGroup {
|
|||
registerSelectionListener(provider, fAddTaskAction);
|
||||
// registerSelectionListener(provider, fCleanUp);
|
||||
|
||||
selectionChanged(new SelectionChangedEvent(provider, selection));
|
||||
registerSelectionListener(provider, this);
|
||||
|
||||
installQuickAccessAction();
|
||||
}
|
||||
|
||||
|
@ -509,5 +523,30 @@ public class GenerateActionGroup extends ActionGroup {
|
|||
|
||||
private boolean isEditorOwner() {
|
||||
return fEditor != null;
|
||||
}
|
||||
}
|
||||
|
||||
private ICElement getCElement(ISelection selection) {
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
IStructuredSelection ss = (IStructuredSelection) selection;
|
||||
if (ss.size() == 1) {
|
||||
Object o = ss.getFirstElement();
|
||||
if (o instanceof ICElement && o instanceof ISourceReference) {
|
||||
return (ICElement) o;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 5.2
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
ICElement celem = getCElement(event.getSelection());
|
||||
for (RefactoringAction action : fRefactorActions) {
|
||||
action.updateSelection(celem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue