Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2006-07-19 13:52:18 +0000
committerAnton Leherbauer2006-07-19 13:52:18 +0000
commit3b95e39b47c191b9ac5388f346d8644bb8f48619 (patch)
treec757ea2984a21694bbbda98c87c3c74650b7dc05 /core/org.eclipse.cdt.ui
parent644a6205fb7b5562fac900c43560f1d382885225 (diff)
downloadorg.eclipse.cdt-3b95e39b47c191b9ac5388f346d8644bb8f48619.tar.gz
org.eclipse.cdt-3b95e39b47c191b9ac5388f346d8644bb8f48619.tar.xz
org.eclipse.cdt-3b95e39b47c191b9ac5388f346d8644bb8f48619.zip
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.
Diffstat (limited to 'core/org.eclipse.cdt.ui')
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml60
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionGroup.java193
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java76
3 files changed, 292 insertions, 37 deletions
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 8d89b7328f5..782c7c32b69 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -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>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.cdt.core.cnature"/>
</adapt>
<instanceof value="org.eclipse.core.resources.IWorkspaceRoot"/>
<instanceof value="org.eclipse.core.resources.IFolder" />
@@ -1461,6 +1456,14 @@
<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"
menuGroupId="org.eclipse.cdt.ui"
@@ -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>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.cdt.core.cnature"/>
</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>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.cdt.core.cnature"/>
</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>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.cdt.core.cnature"/>
</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>
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.cdt.core.ccnature"/>
</adapt>
</or>
</enablement>
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionGroup.java
new file mode 100644
index 00000000000..9355b5bbe03
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionGroup.java
@@ -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);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java
new file mode 100644
index 00000000000..be42638b5df
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java
@@ -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();
+ }
+
+}

Back to the top