mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for Bug 170180 - [Common Navigator] Copy/Paste/... actions not visible for mixed IResource/ICElement
This commit is contained in:
parent
de4edf812e
commit
9d4d90e217
5 changed files with 265 additions and 131 deletions
|
@ -1499,12 +1499,26 @@
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ICElement"/>
|
<instanceof value="org.eclipse.cdt.core.model.ICElement"/>
|
||||||
</enablement>
|
</enablement>
|
||||||
</actionProvider>
|
</actionProvider>
|
||||||
|
<actionProvider
|
||||||
|
class="org.eclipse.cdt.internal.ui.navigator.CNavigatorEditActionProvider"
|
||||||
|
id="org.eclipse.cdt.ui.navigator.actions.edit"
|
||||||
|
overrides="org.eclipse.ui.navigator.resources.actions.EditActions">
|
||||||
|
<enablement>
|
||||||
|
<or>
|
||||||
|
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||||
|
<instanceof value="org.eclipse.core.resources.IResource" />
|
||||||
|
</or>
|
||||||
|
</enablement>
|
||||||
|
</actionProvider>
|
||||||
<actionProvider
|
<actionProvider
|
||||||
class="org.eclipse.cdt.internal.ui.navigator.CNavigatorRefactorActionProvider"
|
class="org.eclipse.cdt.internal.ui.navigator.CNavigatorRefactorActionProvider"
|
||||||
id="org.eclipse.cdt.ui.navigator.actions.refactor"
|
id="org.eclipse.cdt.ui.navigator.actions.refactor"
|
||||||
overrides="org.eclipse.ui.navigator.resources.actions.RefactorActions">
|
overrides="org.eclipse.ui.navigator.resources.actions.RefactorActions">
|
||||||
<enablement>
|
<enablement>
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
<or>
|
||||||
|
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||||
|
<instanceof value="org.eclipse.core.resources.IResource" />
|
||||||
|
</or>
|
||||||
</enablement>
|
</enablement>
|
||||||
</actionProvider>
|
</actionProvider>
|
||||||
<commonWizard
|
<commonWizard
|
||||||
|
@ -1514,7 +1528,7 @@
|
||||||
wizardId="org.eclipse.cdt.ui.wizards.NewSourceFileCreationWizard">
|
wizardId="org.eclipse.cdt.ui.wizards.NewSourceFileCreationWizard">
|
||||||
<enablement>
|
<enablement>
|
||||||
<or>
|
<or>
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||||
<adapt type="org.eclipse.core.resources.IProject">
|
<adapt type="org.eclipse.core.resources.IProject">
|
||||||
<test
|
<test
|
||||||
property="org.eclipse.core.resources.projectNature"
|
property="org.eclipse.core.resources.projectNature"
|
||||||
|
@ -1530,7 +1544,7 @@
|
||||||
wizardId="org.eclipse.cdt.ui.wizards.NewHeaderFileCreationWizard">
|
wizardId="org.eclipse.cdt.ui.wizards.NewHeaderFileCreationWizard">
|
||||||
<enablement>
|
<enablement>
|
||||||
<or>
|
<or>
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||||
<adapt type="org.eclipse.core.resources.IProject">
|
<adapt type="org.eclipse.core.resources.IProject">
|
||||||
<test
|
<test
|
||||||
property="org.eclipse.core.resources.projectNature"
|
property="org.eclipse.core.resources.projectNature"
|
||||||
|
@ -1546,7 +1560,7 @@
|
||||||
wizardId="org.eclipse.cdt.ui.wizards.NewSourceFolderCreationWizard">
|
wizardId="org.eclipse.cdt.ui.wizards.NewSourceFolderCreationWizard">
|
||||||
<enablement>
|
<enablement>
|
||||||
<or>
|
<or>
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||||
<adapt type="org.eclipse.core.resources.IProject">
|
<adapt type="org.eclipse.core.resources.IProject">
|
||||||
<test
|
<test
|
||||||
property="org.eclipse.core.resources.projectNature"
|
property="org.eclipse.core.resources.projectNature"
|
||||||
|
@ -1562,7 +1576,7 @@
|
||||||
wizardId="org.eclipse.cdt.ui.wizards.NewClassCreationWizard">
|
wizardId="org.eclipse.cdt.ui.wizards.NewClassCreationWizard">
|
||||||
<enablement>
|
<enablement>
|
||||||
<or>
|
<or>
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||||
<adapt type="org.eclipse.core.resources.IProject">
|
<adapt type="org.eclipse.core.resources.IProject">
|
||||||
<test
|
<test
|
||||||
property="org.eclipse.core.resources.projectNature"
|
property="org.eclipse.core.resources.projectNature"
|
||||||
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.ui.navigator;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.jface.action.IMenuManager;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.swt.dnd.Clipboard;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.eclipse.ui.IActionBars;
|
||||||
|
import org.eclipse.ui.ISharedImages;
|
||||||
|
import org.eclipse.ui.PlatformUI;
|
||||||
|
import org.eclipse.ui.actions.ActionFactory;
|
||||||
|
import org.eclipse.ui.actions.ActionGroup;
|
||||||
|
import org.eclipse.ui.actions.DeleteResourceAction;
|
||||||
|
import org.eclipse.ui.actions.TextActionHandler;
|
||||||
|
import org.eclipse.ui.navigator.ICommonMenuConstants;
|
||||||
|
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
|
||||||
|
import org.eclipse.ui.views.navigator.ResourceSelectionUtil;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.cview.CopyAction;
|
||||||
|
import org.eclipse.cdt.internal.ui.cview.PasteAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides clipboard actions.
|
||||||
|
*
|
||||||
|
* A clone of org.eclipse.ui.internal.navigator.resources.actions.EditActionGroup.
|
||||||
|
*/
|
||||||
|
public class CNavigatorEditActionGroup extends ActionGroup {
|
||||||
|
|
||||||
|
|
||||||
|
private Clipboard clipboard;
|
||||||
|
|
||||||
|
private CopyAction copyAction;
|
||||||
|
|
||||||
|
private DeleteResourceAction deleteAction;
|
||||||
|
|
||||||
|
private PasteAction pasteAction;
|
||||||
|
|
||||||
|
private TextActionHandler textActionHandler;
|
||||||
|
|
||||||
|
private Shell shell;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param aShell
|
||||||
|
*/
|
||||||
|
public CNavigatorEditActionGroup(Shell aShell) {
|
||||||
|
shell = aShell;
|
||||||
|
makeActions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
if (clipboard != null) {
|
||||||
|
clipboard.dispose();
|
||||||
|
clipboard = null;
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillContextMenu(IMenuManager menu) {
|
||||||
|
IStructuredSelection selection = (IStructuredSelection) getContext()
|
||||||
|
.getSelection();
|
||||||
|
|
||||||
|
boolean anyResourceSelected = !selection.isEmpty()
|
||||||
|
&& ResourceSelectionUtil.allResourcesAreOfType(selection,
|
||||||
|
IResource.PROJECT | IResource.FOLDER | IResource.FILE);
|
||||||
|
|
||||||
|
copyAction.selectionChanged(selection);
|
||||||
|
menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, copyAction);
|
||||||
|
pasteAction.selectionChanged(selection);
|
||||||
|
//menu.insertAfter(copyAction.getId(), pasteAction);
|
||||||
|
menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, pasteAction);
|
||||||
|
|
||||||
|
if (anyResourceSelected) {
|
||||||
|
deleteAction.selectionChanged(selection);
|
||||||
|
//menu.insertAfter(pasteAction.getId(), deleteAction);
|
||||||
|
menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, deleteAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillActionBars(IActionBars actionBars) {
|
||||||
|
|
||||||
|
if (textActionHandler == null) {
|
||||||
|
textActionHandler = new TextActionHandler(actionBars); // hook handlers
|
||||||
|
}
|
||||||
|
textActionHandler.setCopyAction(copyAction);
|
||||||
|
textActionHandler.setPasteAction(pasteAction);
|
||||||
|
textActionHandler.setDeleteAction(deleteAction);
|
||||||
|
//renameAction.setTextActionHandler(textActionHandler);
|
||||||
|
updateActionBars();
|
||||||
|
|
||||||
|
// textActionHandler.updateActionBars();
|
||||||
|
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
|
||||||
|
copyAction);
|
||||||
|
actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
|
||||||
|
pasteAction);
|
||||||
|
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
|
||||||
|
deleteAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void makeActions() {
|
||||||
|
clipboard = new Clipboard(shell.getDisplay());
|
||||||
|
|
||||||
|
pasteAction = new PasteAction(shell, clipboard);
|
||||||
|
ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
|
||||||
|
pasteAction.setDisabledImageDescriptor(images
|
||||||
|
.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
|
||||||
|
pasteAction.setImageDescriptor(images
|
||||||
|
.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
|
||||||
|
pasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE);
|
||||||
|
|
||||||
|
copyAction = new CopyAction(shell, clipboard, pasteAction);
|
||||||
|
copyAction.setDisabledImageDescriptor(images
|
||||||
|
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
|
||||||
|
copyAction.setImageDescriptor(images
|
||||||
|
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
|
||||||
|
copyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY);
|
||||||
|
|
||||||
|
deleteAction = new DeleteResourceAction(shell);
|
||||||
|
deleteAction.setDisabledImageDescriptor(images
|
||||||
|
.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
|
||||||
|
deleteAction.setImageDescriptor(images
|
||||||
|
.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
|
||||||
|
deleteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.DELETE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateActionBars() {
|
||||||
|
IStructuredSelection selection = (IStructuredSelection) getContext()
|
||||||
|
.getSelection();
|
||||||
|
|
||||||
|
copyAction.selectionChanged(selection);
|
||||||
|
pasteAction.selectionChanged(selection);
|
||||||
|
deleteAction.selectionChanged(selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.ui.navigator;
|
||||||
|
|
||||||
|
import org.eclipse.jface.action.IMenuManager;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.ui.IActionBars;
|
||||||
|
import org.eclipse.ui.actions.ActionContext;
|
||||||
|
import org.eclipse.ui.navigator.CommonActionProvider;
|
||||||
|
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common Navigator action provider for clipboard actions.
|
||||||
|
*/
|
||||||
|
public class CNavigatorEditActionProvider extends CommonActionProvider {
|
||||||
|
|
||||||
|
private CNavigatorEditActionGroup fEditGroup;
|
||||||
|
|
||||||
|
private ICommonActionExtensionSite fSite;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
|
||||||
|
*/
|
||||||
|
public void init(ICommonActionExtensionSite anActionSite) {
|
||||||
|
fSite = anActionSite;
|
||||||
|
fEditGroup = new CNavigatorEditActionGroup(fSite.getViewSite().getShell());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.actions.ActionGroup#dispose()
|
||||||
|
*/
|
||||||
|
public void dispose() {
|
||||||
|
fEditGroup.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
|
||||||
|
*/
|
||||||
|
public void fillActionBars(IActionBars actionBars) {
|
||||||
|
fEditGroup.fillActionBars(actionBars);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
|
||||||
|
*/
|
||||||
|
public void fillContextMenu(IMenuManager menu) {
|
||||||
|
fEditGroup.fillContextMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
|
||||||
|
*/
|
||||||
|
public void setContext(ActionContext context) {
|
||||||
|
if (context != null) {
|
||||||
|
// convert non-IResource to IResources on the fly
|
||||||
|
ISelection selection = SelectionConverter.convertSelectionToResources(context.getSelection());
|
||||||
|
fEditGroup.setContext(new ActionContext(selection));
|
||||||
|
} else {
|
||||||
|
fEditGroup.setContext(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
|
||||||
|
*/
|
||||||
|
public void updateActionBars() {
|
||||||
|
fEditGroup.updateActionBars();
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,53 +13,29 @@ package org.eclipse.cdt.internal.ui.navigator;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.jface.action.IMenuManager;
|
import org.eclipse.jface.action.IMenuManager;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.swt.SWT;
|
|
||||||
import org.eclipse.swt.dnd.Clipboard;
|
|
||||||
import org.eclipse.swt.events.KeyEvent;
|
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.swt.widgets.Tree;
|
import org.eclipse.swt.widgets.Tree;
|
||||||
import org.eclipse.ui.IActionBars;
|
import org.eclipse.ui.IActionBars;
|
||||||
import org.eclipse.ui.ISharedImages;
|
|
||||||
import org.eclipse.ui.PlatformUI;
|
|
||||||
import org.eclipse.ui.actions.ActionContext;
|
|
||||||
import org.eclipse.ui.actions.ActionFactory;
|
import org.eclipse.ui.actions.ActionFactory;
|
||||||
import org.eclipse.ui.actions.ActionGroup;
|
import org.eclipse.ui.actions.ActionGroup;
|
||||||
import org.eclipse.ui.actions.DeleteResourceAction;
|
|
||||||
import org.eclipse.ui.actions.MoveResourceAction;
|
import org.eclipse.ui.actions.MoveResourceAction;
|
||||||
import org.eclipse.ui.actions.RenameResourceAction;
|
import org.eclipse.ui.actions.RenameResourceAction;
|
||||||
import org.eclipse.ui.actions.TextActionHandler;
|
|
||||||
import org.eclipse.ui.navigator.ICommonMenuConstants;
|
import org.eclipse.ui.navigator.ICommonMenuConstants;
|
||||||
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
|
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
|
||||||
import org.eclipse.ui.views.navigator.ResourceSelectionUtil;
|
import org.eclipse.ui.views.navigator.ResourceSelectionUtil;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
|
|
||||||
import org.eclipse.cdt.internal.ui.cview.CopyAction;
|
|
||||||
import org.eclipse.cdt.internal.ui.cview.PasteAction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the action group for refactor actions, including global action
|
* This is the action group for refactor actions move and rename.
|
||||||
* handlers for copy, paste and delete.
|
|
||||||
*
|
*
|
||||||
* A clone of org.eclipse.ui.internal.navigator.resources.actions.RefactorActionGroup.
|
* A clone of org.eclipse.ui.internal.navigator.resources.actions.RefactorActionGroup.
|
||||||
*/
|
*/
|
||||||
public class CNavigatorRefactorActionGroup extends ActionGroup {
|
public class CNavigatorRefactorActionGroup extends ActionGroup {
|
||||||
|
|
||||||
private Clipboard clipboard;
|
|
||||||
|
|
||||||
private CopyAction copyAction;
|
|
||||||
|
|
||||||
private DeleteResourceAction deleteAction;
|
|
||||||
|
|
||||||
private PasteAction pasteAction;
|
|
||||||
|
|
||||||
private RenameResourceAction renameAction;
|
private RenameResourceAction renameAction;
|
||||||
|
|
||||||
private MoveResourceAction moveAction;
|
private MoveResourceAction moveAction;
|
||||||
|
|
||||||
private TextActionHandler textActionHandler;
|
|
||||||
|
|
||||||
private Shell shell;
|
private Shell shell;
|
||||||
|
|
||||||
private Tree tree;
|
private Tree tree;
|
||||||
|
@ -75,136 +51,39 @@ public class CNavigatorRefactorActionGroup extends ActionGroup {
|
||||||
makeActions();
|
makeActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
|
||||||
if (clipboard != null) {
|
|
||||||
clipboard.dispose();
|
|
||||||
clipboard = null;
|
|
||||||
}
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
|
|
||||||
*/
|
|
||||||
public void setContext(ActionContext context) {
|
|
||||||
if (context != null) {
|
|
||||||
// convert non-IResource to IResources on the fly
|
|
||||||
ISelection selection = SelectionConverter.convertSelectionToResources(context.getSelection());
|
|
||||||
super.setContext(new ActionContext(selection));
|
|
||||||
} else {
|
|
||||||
super.setContext(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillContextMenu(IMenuManager menu) {
|
public void fillContextMenu(IMenuManager menu) {
|
||||||
IStructuredSelection selection = (IStructuredSelection)getContext().getSelection();
|
IStructuredSelection selection = (IStructuredSelection)getContext().getSelection();
|
||||||
boolean anyResourceSelected = !selection.isEmpty()
|
boolean anyResourceSelected = !selection.isEmpty()
|
||||||
&& ResourceSelectionUtil.allResourcesAreOfType(selection,
|
&& ResourceSelectionUtil.allResourcesAreOfType(selection,
|
||||||
IResource.PROJECT | IResource.FOLDER | IResource.FILE);
|
IResource.PROJECT | IResource.FOLDER | IResource.FILE);
|
||||||
|
|
||||||
copyAction.selectionChanged(selection);
|
|
||||||
menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, copyAction);
|
|
||||||
pasteAction.selectionChanged(selection);
|
|
||||||
menu.insertAfter(copyAction.getId(), pasteAction);
|
|
||||||
|
|
||||||
if (anyResourceSelected) {
|
if (anyResourceSelected) {
|
||||||
deleteAction.selectionChanged(selection);
|
|
||||||
menu.insertAfter(pasteAction.getId(), deleteAction);
|
|
||||||
moveAction.selectionChanged(selection);
|
moveAction.selectionChanged(selection);
|
||||||
menu.insertAfter(deleteAction.getId(), moveAction);
|
menu.appendToGroup(ICommonMenuConstants.GROUP_REORGANIZE, moveAction);
|
||||||
renameAction.selectionChanged(selection);
|
renameAction.selectionChanged(selection);
|
||||||
menu.insertAfter(moveAction.getId(), renameAction);
|
menu.insertAfter(moveAction.getId(), renameAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillActionBars(IActionBars actionBars) {
|
public void fillActionBars(IActionBars actionBars) {
|
||||||
|
|
||||||
if (textActionHandler == null) {
|
|
||||||
textActionHandler = new TextActionHandler(actionBars); // hook handlers
|
|
||||||
}
|
|
||||||
textActionHandler.setCopyAction(copyAction);
|
|
||||||
textActionHandler.setPasteAction(pasteAction);
|
|
||||||
textActionHandler.setDeleteAction(deleteAction);
|
|
||||||
renameAction.setTextActionHandler(textActionHandler);
|
|
||||||
updateActionBars();
|
updateActionBars();
|
||||||
|
|
||||||
// textActionHandler.updateActionBars();
|
// textActionHandler.updateActionBars();
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
|
actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), moveAction);
|
||||||
copyAction);
|
actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
|
|
||||||
pasteAction);
|
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
|
|
||||||
deleteAction);
|
|
||||||
|
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(),
|
|
||||||
moveAction);
|
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(),
|
|
||||||
renameAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles a key pressed event by invoking the appropriate action.
|
|
||||||
*
|
|
||||||
* @param event
|
|
||||||
* The Key Event
|
|
||||||
*/
|
|
||||||
public void handleKeyPressed(KeyEvent event) {
|
|
||||||
if (event.character == SWT.DEL && event.stateMask == 0) {
|
|
||||||
if (deleteAction.isEnabled()) {
|
|
||||||
deleteAction.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Swallow the event.
|
|
||||||
event.doit = false;
|
|
||||||
|
|
||||||
} else if (event.keyCode == SWT.F2 && event.stateMask == 0) {
|
|
||||||
if (renameAction.isEnabled()) {
|
|
||||||
renameAction.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Swallow the event.
|
|
||||||
event.doit = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void makeActions() {
|
protected void makeActions() {
|
||||||
clipboard = new Clipboard(shell.getDisplay());
|
|
||||||
|
|
||||||
pasteAction = new PasteAction(shell, clipboard);
|
|
||||||
ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
|
|
||||||
pasteAction.setDisabledImageDescriptor(images
|
|
||||||
.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
|
|
||||||
pasteAction.setImageDescriptor(images
|
|
||||||
.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
|
|
||||||
pasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE);
|
|
||||||
|
|
||||||
copyAction = new CopyAction(shell, clipboard, pasteAction);
|
|
||||||
copyAction.setDisabledImageDescriptor(images
|
|
||||||
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
|
|
||||||
copyAction.setImageDescriptor(images
|
|
||||||
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
|
|
||||||
copyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY);
|
|
||||||
|
|
||||||
moveAction = new MoveResourceAction(shell);
|
moveAction = new MoveResourceAction(shell);
|
||||||
moveAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.MOVE);
|
moveAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.MOVE);
|
||||||
|
|
||||||
renameAction = new RenameResourceAction(shell, tree);
|
renameAction = new RenameResourceAction(shell, tree);
|
||||||
renameAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.RENAME);
|
renameAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.RENAME);
|
||||||
|
|
||||||
deleteAction = new DeleteResourceAction(shell);
|
|
||||||
deleteAction.setDisabledImageDescriptor(images
|
|
||||||
.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
|
|
||||||
deleteAction.setImageDescriptor(images
|
|
||||||
.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
|
|
||||||
deleteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.DELETE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateActionBars() {
|
public void updateActionBars() {
|
||||||
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
|
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
|
||||||
|
|
||||||
copyAction.selectionChanged(selection);
|
|
||||||
pasteAction.selectionChanged(selection);
|
|
||||||
deleteAction.selectionChanged(selection);
|
|
||||||
moveAction.selectionChanged(selection);
|
moveAction.selectionChanged(selection);
|
||||||
renameAction.selectionChanged(selection);
|
renameAction.selectionChanged(selection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.navigator;
|
||||||
import org.eclipse.core.commands.operations.IUndoContext;
|
import org.eclipse.core.commands.operations.IUndoContext;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.jface.action.IMenuManager;
|
import org.eclipse.jface.action.IMenuManager;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.swt.widgets.Tree;
|
import org.eclipse.swt.widgets.Tree;
|
||||||
import org.eclipse.ui.IActionBars;
|
import org.eclipse.ui.IActionBars;
|
||||||
import org.eclipse.ui.actions.ActionContext;
|
import org.eclipse.ui.actions.ActionContext;
|
||||||
|
@ -24,6 +25,8 @@ import org.eclipse.ui.operations.UndoRedoActionGroup;
|
||||||
|
|
||||||
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A clone of org.eclipse.ui.internal.navigator.resources.actions.RefactorActionProvider.
|
* A clone of org.eclipse.ui.internal.navigator.resources.actions.RefactorActionProvider.
|
||||||
*/
|
*/
|
||||||
|
@ -73,7 +76,7 @@ public class CNavigatorRefactorActionProvider extends CommonActionProvider {
|
||||||
|
|
||||||
public void setContext(ActionContext context) {
|
public void setContext(ActionContext context) {
|
||||||
undoRedoGroup.setContext(context);
|
undoRedoGroup.setContext(context);
|
||||||
resourceRefactorGroup.setContext(context);
|
resourceRefactorGroup.setContext(convertToResources(context));
|
||||||
cElementRefactorGroup.setContext(context);
|
cElementRefactorGroup.setContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,4 +86,17 @@ public class CNavigatorRefactorActionProvider extends CommonActionProvider {
|
||||||
cElementRefactorGroup.updateActionBars();
|
cElementRefactorGroup.updateActionBars();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param context
|
||||||
|
* @return context with selection elements converted to IResources
|
||||||
|
*/
|
||||||
|
private ActionContext convertToResources(ActionContext context) {
|
||||||
|
if (context != null) {
|
||||||
|
// convert non-IResource to IResources
|
||||||
|
ISelection selection = SelectionConverter.convertSelectionToResources(context.getSelection());
|
||||||
|
return new ActionContext(selection);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue