|
From: <caw...@us...> - 2007-09-07 15:12:54
|
Revision: 3106
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3106&view=rev
Author: cawilliams
Date: 2007-09-07 08:12:44 -0700 (Fri, 07 Sep 2007)
Log Message:
-----------
add copy/paste/delete right-click context options to new Ruby Explorer view
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CCPActionGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CopyAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/PasteAction.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java 2007-09-07 14:51:03 UTC (rev 3105)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java 2007-09-07 15:12:44 UTC (rev 3106)
@@ -46,6 +46,7 @@
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.navigator.ICommonMenuConstants;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.progress.WorkbenchJob;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
@@ -500,12 +501,11 @@
}
public static boolean isDebug() {
- // TODO set to true based on debugging/tracing!
- return false;
+ return getDefault().isDebugging();
}
/**
- * Creates the Java plugin standard groups in a context menu.
+ * Creates the Ruby plugin standard groups in a context menu.
*
* @param menu
* the menu manager to be populated
@@ -517,6 +517,7 @@
menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
+ menu.add(new Separator(ICommonMenuConstants.GROUP_EDIT));
menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java 2007-09-07 14:51:03 UTC (rev 3105)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java 2007-09-07 15:12:44 UTC (rev 3106)
@@ -56,10 +56,9 @@
import org.rubypeople.rdt.internal.ui.workingsets.ViewActionGroup;
import org.rubypeople.rdt.internal.ui.workingsets.WorkingSetActionGroup;
import org.rubypeople.rdt.ui.IContextMenuConstants;
-import org.rubypeople.rdt.ui.PreferenceConstants;
+import org.rubypeople.rdt.ui.actions.CCPActionGroup;
import org.rubypeople.rdt.ui.actions.CustomFiltersActionGroup;
import org.rubypeople.rdt.ui.actions.NavigateActionGroup;
-import org.rubypeople.rdt.ui.actions.RdtActionConstants;
import org.rubypeople.rdt.ui.actions.RubySearchActionGroup;
class PackageExplorerActionGroup extends CompositeActionGroup {
@@ -102,7 +101,7 @@
setGroups(new ActionGroup[] {
new NewWizardsActionGroup(site),
fNavigateActionGroup= new NavigateActionGroup(fPart),
-// new CCPActionGroup(fPart),
+ new CCPActionGroup(fPart),
new GenerateBuildPathActionGroup(fPart),
// new GenerateActionGroup(fPart),
// fRefactorActionGroup= new RefactorActionGroup(fPart),
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CCPActionGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CCPActionGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CCPActionGroup.java 2007-09-07 15:12:44 UTC (rev 3106)
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.actions.DeleteResourceAction;
+import org.eclipse.ui.actions.SelectionListenerAction;
+import org.eclipse.ui.navigator.ICommonMenuConstants;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+/**
+ * Action group that adds the copy, cut, paste actions to a view part's context
+ * menu and installs handlers for the corresponding global menu actions.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 2.0
+ */
+public class CCPActionGroup extends ActionGroup {
+
+ private IWorkbenchSite fSite;
+ private Clipboard fClipboard;
+
+ private SelectionListenerAction[] fActions;
+
+ private SelectionListenerAction fDeleteAction;
+ private SelectionListenerAction fCopyAction;
+// private SelectionDispatchAction fCopyQualifiedNameAction;
+ private PasteAction fPasteAction;
+// private SelectionListenerAction fCutAction;
+
+ /**
+ * Creates a new <code>CCPActionGroup</code>. The group requires that
+ * the selection provided by the view part's selection provider is of type
+ * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
+ *
+ * @param part the view part that owns this action group
+ */
+ public CCPActionGroup(IViewPart part) {
+ this(part.getSite());
+ }
+
+ /**
+ * Creates a new <code>CCPActionGroup</code>. The group requires that
+ * the selection provided by the page's selection provider is of type
+ * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
+ *
+ * @param page the page that owns this action group
+ */
+ public CCPActionGroup(Page page) {
+ this(page.getSite());
+ }
+
+ private CCPActionGroup(IWorkbenchSite site) {
+ fSite= site;
+ fClipboard= new Clipboard(site.getShell().getDisplay());
+
+ fPasteAction= new PasteAction(fSite.getShell(), fClipboard);
+ fPasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE);
+
+ fCopyAction= new CopyAction(fSite.getShell(), fClipboard, fPasteAction);
+ fCopyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY);
+
+// fCopyQualifiedNameAction= new CopyQualifiedNameAction(fSite, fClipboard, fPasteAction);
+// fCopyQualifiedNameAction.setActionDefinitionId(CopyQualifiedNameAction.JAVA_EDITOR_ACTION_DEFINITIONS_ID);
+
+// fCutAction= new CutAction(fSite.getShell(), fClipboard, fPasteAction);
+// fCutAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.CUT);
+
+ fDeleteAction= new DeleteResourceAction(fSite.getShell());
+ fDeleteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.DELETE);
+
+ fActions= new SelectionListenerAction[] { /*fCutAction,*/ fCopyAction, /*fCopyQualifiedNameAction,*/ fPasteAction, fDeleteAction };
+ registerActionsAsSelectionChangeListeners();
+ }
+
+ private void registerActionsAsSelectionChangeListeners() {
+ ISelectionProvider provider = fSite.getSelectionProvider();
+ ISelection selection= provider.getSelection();
+ for (int i= 0; i < fActions.length; i++) {
+ SelectionListenerAction action= fActions[i];
+ provider.addSelectionChangedListener(action);
+ }
+ }
+
+ private void deregisterActionsAsSelectionChangeListeners() {
+ ISelectionProvider provider = fSite.getSelectionProvider();
+ for (int i= 0; i < fActions.length; i++) {
+ provider.removeSelectionChangedListener(fActions[i]);
+ }
+ }
+
+
+ /**
+ * Returns the delete action managed by this action group.
+ *
+ * @return the delete action. Returns <code>null</code> if the group
+ * doesn't provide any delete action
+ */
+ public IAction getDeleteAction() {
+ return fDeleteAction;
+ }
+
+ /* (non-Javadoc)
+ * Method declared in ActionGroup
+ */
+ public void fillActionBars(IActionBars actionBars) {
+ super.fillActionBars(actionBars);
+ actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), fDeleteAction);
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction);
+// actionBars.setGlobalActionHandler(CopyQualifiedNameAction.ACTION_HANDLER_ID, fCopyQualifiedNameAction);
+// actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), fCutAction);
+ actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), fPasteAction);
+ }
+
+ /* (non-Javadoc)
+ * Method declared in ActionGroup
+ */
+ public void fillContextMenu(IMenuManager menu) {
+ super.fillContextMenu(menu);
+ for (int i= 0; i < fActions.length; i++) {
+ SelectionListenerAction action= fActions[i];
+// if (action == fCutAction && !fCutAction.isEnabled())
+// continue;
+ menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, action);
+ }
+ }
+
+ /*
+ * @see ActionGroup#dispose()
+ */
+ public void dispose() {
+ super.dispose();
+ if (fClipboard != null){
+ fClipboard.dispose();
+ fClipboard= null;
+ }
+ deregisterActionsAsSelectionChangeListeners();
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CCPActionGroup.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CopyAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CopyAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CopyAction.java 2007-09-07 15:12:44 UTC (rev 3106)
@@ -0,0 +1,234 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.SelectionListenerAction;
+import org.eclipse.ui.internal.views.navigator.ResourceNavigatorMessages;
+import org.eclipse.ui.part.ResourceTransfer;
+
+/**
+ * Standard action for copying the currently selected resources to the clipboard.
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 2.0
+ */
+/*package*/class CopyAction extends SelectionListenerAction {
+
+ /**
+ * The id of this action.
+ */
+ public static final String ID = PlatformUI.PLUGIN_ID + ".CopyAction"; //$NON-NLS-1$
+
+ /**
+ * The shell in which to show any dialogs.
+ */
+ private Shell shell;
+
+ /**
+ * System clipboard
+ */
+ private Clipboard clipboard;
+
+ /**
+ * Associated paste action. May be <code>null</code>
+ */
+ private PasteAction pasteAction;
+
+ /**
+ * Creates a new action.
+ *
+ * @param shell the shell for any dialogs
+ * @param clipboard a platform clipboard
+ */
+ public CopyAction(Shell shell, Clipboard clipboard) {
+ super(ResourceNavigatorMessages.CopyAction_title);
+ Assert.isNotNull(shell);
+ Assert.isNotNull(clipboard);
+ this.shell = shell;
+ this.clipboard = clipboard;
+ setToolTipText(ResourceNavigatorMessages.CopyAction_toolTip);
+ setId(CopyAction.ID);
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
+// INavigatorHelpContextIds.COPY_ACTION);
+ }
+
+ /**
+ * Creates a new action.
+ *
+ * @param shell the shell for any dialogs
+ * @param clipboard a platform clipboard
+ * @param pasteAction a paste action
+ *
+ * @since 2.0
+ */
+ public CopyAction(Shell shell, Clipboard clipboard, PasteAction pasteAction) {
+ this(shell, clipboard);
+ this.pasteAction = pasteAction;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run() {
+ /**
+ * The <code>CopyAction</code> implementation of this method defined
+ * on <code>IAction</code> copies the selected resources to the
+ * clipboard.
+ */
+ List selectedResources = getSelectedResources();
+ IResource[] resources = (IResource[]) selectedResources
+ .toArray(new IResource[selectedResources.size()]);
+
+ // Get the file names and a string representation
+ final int length = resources.length;
+ int actualLength = 0;
+ String[] fileNames = new String[length];
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < length; i++) {
+ IPath location = resources[i].getLocation();
+ // location may be null. See bug 29491.
+ if (location != null) {
+ fileNames[actualLength++] = location.toOSString();
+ }
+ if (i > 0) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+ buf.append(resources[i].getName());
+ }
+ // was one or more of the locations null?
+ if (actualLength < length) {
+ String[] tempFileNames = fileNames;
+ fileNames = new String[actualLength];
+ for (int i = 0; i < actualLength; i++) {
+ fileNames[i] = tempFileNames[i];
+ }
+ }
+ setClipboard(resources, fileNames, buf.toString());
+
+ // update the enablement of the paste action
+ // workaround since the clipboard does not suppot callbacks
+ if (pasteAction != null && pasteAction.getStructuredSelection() != null) {
+ pasteAction.selectionChanged(pasteAction.getStructuredSelection());
+ }
+ }
+
+ /**
+ * Set the clipboard contents. Prompt to retry if clipboard is busy.
+ *
+ * @param resources the resources to copy to the clipboard
+ * @param fileNames file names of the resources to copy to the clipboard
+ * @param names string representation of all names
+ */
+ private void setClipboard(IResource[] resources, String[] fileNames,
+ String names) {
+ try {
+ // set the clipboard contents
+ if (fileNames.length > 0) {
+ clipboard.setContents(new Object[] { resources, fileNames,
+ names },
+ new Transfer[] { ResourceTransfer.getInstance(),
+ FileTransfer.getInstance(),
+ TextTransfer.getInstance() });
+ } else {
+ clipboard.setContents(new Object[] { resources, names },
+ new Transfer[] { ResourceTransfer.getInstance(),
+ TextTransfer.getInstance() });
+ }
+ } catch (SWTError e) {
+ if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
+ throw e;
+ }
+ if (MessageDialog
+ .openQuestion(
+ shell,
+ ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, ResourceNavigatorMessages.CopyToClipboardProblemDialog_message)) {
+ setClipboard(resources, fileNames, names);
+ }
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ protected boolean updateSelection(IStructuredSelection selection) {
+
+ /**
+ * The <code>CopyAction</code> implementation of this
+ * <code>SelectionListenerAction</code> method enables this action if
+ * one or more resources of compatible types are selected.
+ */
+
+ if (!super.updateSelection(selection)) {
+ return false;
+ }
+
+ if (getSelectedNonResources().size() > 0) {
+ return false;
+ }
+
+ List selectedResources = getSelectedResources();
+ if (selectedResources.size() == 0) {
+ return false;
+ }
+
+ boolean projSelected = selectionIsOfType(IResource.PROJECT);
+ boolean fileFoldersSelected = selectionIsOfType(IResource.FILE
+ | IResource.FOLDER);
+ if (!projSelected && !fileFoldersSelected) {
+ return false;
+ }
+
+ // selection must be homogeneous
+ if (projSelected && fileFoldersSelected) {
+ return false;
+ }
+
+ // must have a common parent
+ IContainer firstParent = ((IResource) selectedResources.get(0))
+ .getParent();
+ if (firstParent == null) {
+ return false;
+ }
+
+ Iterator resourcesEnum = selectedResources.iterator();
+ while (resourcesEnum.hasNext()) {
+ IResource currentResource = (IResource) resourcesEnum.next();
+ if (!currentResource.getParent().equals(firstParent)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+}
+
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/CopyAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/PasteAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/PasteAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/PasteAction.java 2007-09-07 15:12:44 UTC (rev 3106)
@@ -0,0 +1,264 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
+import org.eclipse.ui.actions.CopyProjectOperation;
+import org.eclipse.ui.actions.SelectionListenerAction;
+import org.eclipse.ui.internal.views.navigator.ResourceNavigatorMessages;
+import org.eclipse.ui.part.ResourceTransfer;
+
+/**
+ * Standard action for pasting resources on the clipboard to the selected resource's location.
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 2.0
+ */
+/*package*/class PasteAction extends SelectionListenerAction {
+
+ /**
+ * The id of this action.
+ */
+ public static final String ID = PlatformUI.PLUGIN_ID + ".PasteAction";//$NON-NLS-1$
+
+ /**
+ * The shell in which to show any dialogs.
+ */
+ private Shell shell;
+
+ /**
+ * System clipboard
+ */
+ private Clipboard clipboard;
+
+ /**
+ * Creates a new action.
+ *
+ * @param shell the shell for any dialogs
+ * @param clipboard the clipboard
+ */
+ public PasteAction(Shell shell, Clipboard clipboard) {
+ super(ResourceNavigatorMessages.PasteAction_title);
+ Assert.isNotNull(shell);
+ Assert.isNotNull(clipboard);
+ this.shell = shell;
+ this.clipboard = clipboard;
+ setToolTipText(ResourceNavigatorMessages.PasteAction_toolTip);
+ setId(PasteAction.ID);
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
+// INavigatorHelpContextIds.PASTE_ACTION);
+ }
+
+ /**
+ * Returns the actual target of the paste action. Returns null
+ * if no valid target is selected.
+ *
+ * @return the actual target of the paste action
+ */
+ private IResource getTarget() {
+ List selectedResources = getSelectedResources();
+
+ for (int i = 0; i < selectedResources.size(); i++) {
+ IResource resource = (IResource) selectedResources.get(i);
+
+ if (resource instanceof IProject && !((IProject) resource).isOpen()) {
+ return null;
+ }
+ if (resource.getType() == IResource.FILE) {
+ resource = resource.getParent();
+ }
+ if (resource != null) {
+ return resource;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns whether any of the given resources are linked resources.
+ *
+ * @param resources resource to check for linked type. may be null
+ * @return true=one or more resources are linked. false=none of the
+ * resources are linked
+ */
+ private boolean isLinked(IResource[] resources) {
+ for (int i = 0; i < resources.length; i++) {
+ if (resources[i].isLinked()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Implementation of method defined on <code>IAction</code>.
+ */
+ public void run() {
+ // try a resource transfer
+ ResourceTransfer resTransfer = ResourceTransfer.getInstance();
+ IResource[] resourceData = (IResource[]) clipboard
+ .getContents(resTransfer);
+
+ if (resourceData != null && resourceData.length > 0) {
+ if (resourceData[0].getType() == IResource.PROJECT) {
+ // enablement checks for all projects
+ for (int i = 0; i < resourceData.length; i++) {
+ CopyProjectOperation operation = new CopyProjectOperation(
+ this.shell);
+ operation.copyProject((IProject) resourceData[i]);
+ }
+ } else {
+ // enablement should ensure that we always have access to a container
+ IContainer container = getContainer();
+
+ CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(
+ this.shell);
+ operation.copyResources(resourceData, container);
+ }
+ return;
+ }
+
+ // try a file transfer
+ FileTransfer fileTransfer = FileTransfer.getInstance();
+ String[] fileData = (String[]) clipboard.getContents(fileTransfer);
+
+ if (fileData != null) {
+ // enablement should ensure that we always have access to a container
+ IContainer container = getContainer();
+
+ CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(
+ this.shell);
+ operation.copyFiles(fileData, container);
+ }
+ }
+
+ /**
+ * Returns the container to hold the pasted resources.
+ */
+ private IContainer getContainer() {
+ List selection = getSelectedResources();
+ if (selection.get(0) instanceof IFile) {
+ return ((IFile) selection.get(0)).getParent();
+ } else {
+ return (IContainer) selection.get(0);
+ }
+ }
+
+ /**
+ * The <code>PasteAction</code> implementation of this
+ * <code>SelectionListenerAction</code> method enables this action if
+ * a resource compatible with what is on the clipboard is selected.
+ *
+ * -Clipboard must have IResource or java.io.File
+ * -Projects can always be pasted if they are open
+ * -Workspace folder may not be copied into itself
+ * -Files and folders may be pasted to a single selected folder in open
+ * project or multiple selected files in the same folder
+ */
+ protected boolean updateSelection(IStructuredSelection selection) {
+ if (!super.updateSelection(selection)) {
+ return false;
+ }
+
+ final IResource[][] clipboardData = new IResource[1][];
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ // clipboard must have resources or files
+ ResourceTransfer resTransfer = ResourceTransfer.getInstance();
+ clipboardData[0] = (IResource[]) clipboard
+ .getContents(resTransfer);
+ }
+ });
+ IResource[] resourceData = clipboardData[0];
+ boolean isProjectRes = resourceData != null && resourceData.length > 0
+ && resourceData[0].getType() == IResource.PROJECT;
+
+ if (isProjectRes) {
+ for (int i = 0; i < resourceData.length; i++) {
+ // make sure all resource data are open projects
+ // can paste open projects regardless of selection
+ if (resourceData[i].getType() != IResource.PROJECT
+ || ((IProject) resourceData[i]).isOpen() == false) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ if (getSelectedNonResources().size() > 0) {
+ return false;
+ }
+
+ IResource targetResource = getTarget();
+ // targetResource is null if no valid target is selected (e.g., open project)
+ // or selection is empty
+ if (targetResource == null) {
+ return false;
+ }
+
+ // can paste files and folders to a single selection (file, folder,
+ // open project) or multiple file selection with the same parent
+ List selectedResources = getSelectedResources();
+ if (selectedResources.size() > 1) {
+ for (int i = 0; i < selectedResources.size(); i++) {
+ IResource resource = (IResource) selectedResources.get(i);
+ if (resource.getType() != IResource.FILE) {
+ return false;
+ }
+ if (!targetResource.equals(resource.getParent())) {
+ return false;
+ }
+ }
+ }
+ if (resourceData != null) {
+ // linked resources can only be pasted into projects
+ if (isLinked(resourceData)
+ && targetResource.getType() != IResource.PROJECT
+ && targetResource.getType() != IResource.FOLDER) {
+ return false;
+ }
+
+ if (targetResource.getType() == IResource.FOLDER) {
+ // don't try to copy folder to self
+ for (int i = 0; i < resourceData.length; i++) {
+ if (targetResource.equals(resourceData[i])) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ TransferData[] transfers = clipboard.getAvailableTypes();
+ FileTransfer fileTransfer = FileTransfer.getInstance();
+ for (int i = 0; i < transfers.length; i++) {
+ if (fileTransfer.isSupportedType(transfers[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/PasteAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|