mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Minor fixes to Common Navigator
- Make managed project wizards appear in New menu - Override clipboard and refactor actions from resourceContent to enable them for non-resources.
This commit is contained in:
parent
644a6205fb
commit
3b95e39b47
5 changed files with 302 additions and 39 deletions
|
@ -415,6 +415,8 @@
|
|||
name="%GCCPerFileProfile.name"
|
||||
profileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/>
|
||||
</extension>
|
||||
|
||||
<!-- Common Navigator extensions -->
|
||||
<extension
|
||||
point="org.eclipse.ui.navigator.navigatorContent">
|
||||
<commonWizard
|
||||
|
|
|
@ -227,18 +227,24 @@
|
|||
<actionSet id="org.eclipse.cdt.managedbuilder.ui.buildSelectedFilesActionSet"/>
|
||||
</perspectiveExtension>
|
||||
</extension>
|
||||
|
||||
<!-- Common Navigator extensions -->
|
||||
<extension
|
||||
point="org.eclipse.ui.navigator.navigatorContent">
|
||||
<commonWizard
|
||||
associatedExtensionId="org.eclipse.cdt.ui.navigator.content"
|
||||
menuGroupId="org.eclipse.cdt.ui.newCWizards"
|
||||
type="new"
|
||||
wizardId="org.eclipse.cdt.managedbuilder.ui.wizards.StdCCWizard"/>
|
||||
wizardId="org.eclipse.cdt.managedbuilder.ui.wizards.StdCCWizard">
|
||||
<enablement/>
|
||||
</commonWizard>
|
||||
<commonWizard
|
||||
associatedExtensionId="org.eclipse.cdt.ui.navigator.content"
|
||||
menuGroupId="org.eclipse.cdt.ui.newCWizards"
|
||||
type="new"
|
||||
wizardId="org.eclipse.cdt.managedbuilder.ui.wizards.StdCWizard"/>
|
||||
wizardId="org.eclipse.cdt.managedbuilder.ui.wizards.StdCWizard">
|
||||
<enablement/>
|
||||
</commonWizard>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.navigator.viewer">
|
||||
|
|
|
@ -1398,14 +1398,9 @@
|
|||
<triggerPoints>
|
||||
<or>
|
||||
<adapt type="org.eclipse.core.resources.IProject">
|
||||
<or>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.ccnature"/>
|
||||
</or>
|
||||
</adapt>
|
||||
<instanceof value="org.eclipse.core.resources.IWorkspaceRoot"/>
|
||||
<instanceof value="org.eclipse.core.resources.IFolder" />
|
||||
|
@ -1460,6 +1455,14 @@
|
|||
<enablement>
|
||||
<instanceof value="org.eclipse.cdt.core.model.ICElement"/>
|
||||
</enablement>
|
||||
</actionProvider>
|
||||
<actionProvider
|
||||
class="org.eclipse.cdt.internal.ui.navigator.CNavigatorRefactorActionProvider"
|
||||
id="org.eclipse.cdt.ui.navigator.actions.refactor"
|
||||
overrides="org.eclipse.ui.navigator.resources.actions.RefactorActions">
|
||||
<enablement>
|
||||
<adapt type="org.eclipse.core.resources.IResource"/>
|
||||
</enablement>
|
||||
</actionProvider>
|
||||
<commonWizard
|
||||
associatedExtensionId="org.eclipse.cdt.ui.navigator.content"
|
||||
|
@ -1470,14 +1473,9 @@
|
|||
<or>
|
||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||
<adapt type="org.eclipse.core.resources.IProject">
|
||||
<or>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.ccnature"/>
|
||||
</or>
|
||||
</adapt>
|
||||
</or>
|
||||
</enablement>
|
||||
|
@ -1491,14 +1489,9 @@
|
|||
<or>
|
||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||
<adapt type="org.eclipse.core.resources.IProject">
|
||||
<or>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.ccnature"/>
|
||||
</or>
|
||||
</adapt>
|
||||
</or>
|
||||
</enablement>
|
||||
|
@ -1512,14 +1505,9 @@
|
|||
<or>
|
||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||
<adapt type="org.eclipse.core.resources.IProject">
|
||||
<or>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.ccnature"/>
|
||||
</or>
|
||||
</adapt>
|
||||
</or>
|
||||
</enablement>
|
||||
|
@ -1533,11 +1521,9 @@
|
|||
<or>
|
||||
<instanceof value="org.eclipse.cdt.core.model.ICElement" />
|
||||
<adapt type="org.eclipse.core.resources.IProject">
|
||||
<or>
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.ccnature"/>
|
||||
</or>
|
||||
</adapt>
|
||||
</or>
|
||||
</enablement>
|
||||
|
|
|
@ -0,0 +1,193 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Sebastian Davids <sdavids@gmx.de> - Images for menu items (27481)
|
||||
*******************************************************************************/
|
||||
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.SWT;
|
||||
import org.eclipse.swt.dnd.Clipboard;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
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.MoveResourceAction;
|
||||
import org.eclipse.ui.actions.RenameResourceAction;
|
||||
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.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
|
||||
* handlers for copy, paste and delete.
|
||||
*
|
||||
* A clone of org.eclipse.ui.internal.navigator.resources.actions.RefactorActionGroup.
|
||||
*/
|
||||
public class CNavigatorRefactorActionGroup extends ActionGroup {
|
||||
|
||||
private Clipboard clipboard;
|
||||
|
||||
private CopyAction copyAction;
|
||||
|
||||
private DeleteResourceAction deleteAction;
|
||||
|
||||
private PasteAction pasteAction;
|
||||
|
||||
private RenameResourceAction renameAction;
|
||||
|
||||
private MoveResourceAction moveAction;
|
||||
|
||||
private TextActionHandler textActionHandler;
|
||||
|
||||
private Shell shell;
|
||||
|
||||
private Tree tree;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param aShell
|
||||
* @param aTree
|
||||
*/
|
||||
public CNavigatorRefactorActionGroup(Shell aShell, Tree aTree) {
|
||||
shell = aShell;
|
||||
tree = aTree;
|
||||
makeActions();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (clipboard != null) {
|
||||
clipboard.dispose();
|
||||
clipboard = null;
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public void fillContextMenu(IMenuManager menu) {
|
||||
IStructuredSelection selection = SelectionConverter
|
||||
.convertSelectionToResources(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);
|
||||
|
||||
if (anyResourceSelected) {
|
||||
deleteAction.selectionChanged(selection);
|
||||
menu.insertAfter(pasteAction.getId(), deleteAction);
|
||||
moveAction.selectionChanged(selection);
|
||||
menu.insertAfter(deleteAction.getId(), moveAction);
|
||||
renameAction.selectionChanged(selection);
|
||||
menu.insertAfter(moveAction.getId(), renameAction);
|
||||
}
|
||||
}
|
||||
|
||||
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.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() {
|
||||
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.setActionDefinitionId(IWorkbenchActionDefinitionIds.MOVE);
|
||||
|
||||
renameAction = new RenameResourceAction(shell, tree);
|
||||
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() {
|
||||
IStructuredSelection selection = (IStructuredSelection) getContext()
|
||||
.getSelection();
|
||||
|
||||
copyAction.selectionChanged(selection);
|
||||
pasteAction.selectionChanged(selection);
|
||||
deleteAction.selectionChanged(selection);
|
||||
moveAction.selectionChanged(selection);
|
||||
renameAction.selectionChanged(selection);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.navigator;
|
||||
|
||||
import org.eclipse.core.commands.operations.IUndoContext;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
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.ui.navigator.ICommonViewerWorkbenchSite;
|
||||
import org.eclipse.ui.operations.UndoRedoActionGroup;
|
||||
|
||||
/**
|
||||
* A clone of org.eclipse.ui.internal.navigator.resources.actions.RefactorActionProvider.
|
||||
*/
|
||||
public class CNavigatorRefactorActionProvider extends CommonActionProvider {
|
||||
|
||||
private UndoRedoActionGroup undoRedoGroup;
|
||||
|
||||
private CNavigatorRefactorActionGroup refactorGroup;
|
||||
|
||||
private ICommonActionExtensionSite site;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
|
||||
*/
|
||||
public void init(ICommonActionExtensionSite anActionSite) {
|
||||
site = anActionSite;
|
||||
refactorGroup = new CNavigatorRefactorActionGroup(site.getViewSite().getShell(), (Tree)site.getStructuredViewer().getControl());
|
||||
|
||||
IUndoContext workspaceContext = (IUndoContext) ResourcesPlugin
|
||||
.getWorkspace().getAdapter(IUndoContext.class);
|
||||
undoRedoGroup = new UndoRedoActionGroup(((ICommonViewerWorkbenchSite) anActionSite.getViewSite()).getSite(),
|
||||
workspaceContext, true);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
undoRedoGroup.dispose();
|
||||
refactorGroup.dispose();
|
||||
}
|
||||
|
||||
public void fillActionBars(IActionBars actionBars) {
|
||||
undoRedoGroup.fillActionBars(actionBars);
|
||||
refactorGroup.fillActionBars(actionBars);
|
||||
}
|
||||
|
||||
public void fillContextMenu(IMenuManager menu) {
|
||||
undoRedoGroup.fillContextMenu(menu);
|
||||
refactorGroup.fillContextMenu(menu);
|
||||
}
|
||||
|
||||
public void setContext(ActionContext context) {
|
||||
undoRedoGroup.setContext(context);
|
||||
refactorGroup.setContext(context);
|
||||
}
|
||||
|
||||
public void updateActionBars() {
|
||||
undoRedoGroup.updateActionBars();
|
||||
refactorGroup.updateActionBars();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue