diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index fc5ed10d6f1..47b847ec0e9 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -1535,6 +1535,7 @@
+
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDragAdapterAssistant.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDragAdapterAssistant.java
index f7ce4fbc26a..fe100e5cef2 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDragAdapterAssistant.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDragAdapterAssistant.java
@@ -12,14 +12,15 @@ package org.eclipse.cdt.internal.ui.navigator;
import java.util.Iterator;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.ISourceReference;
+import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
-import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ISourceReference;
+import org.eclipse.cdt.core.model.ITranslationUnit;
/**
* A Common Navigator drag assistant for ICElement
s being also
@@ -34,7 +35,7 @@ public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
*/
public Transfer[] getSupportedTransferTypes() {
Transfer[] transfers= new Transfer[] {
- LocalSelectionTransfer.getInstance()
+ LocalSelectionTransfer.getTransfer()
};
return transfers;
}
@@ -45,16 +46,23 @@ public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
public boolean setDragData(DragSourceEvent event,
IStructuredSelection selection) {
if (selection != null) {
+ boolean applicable= false;
for (Iterator iter= (selection).iterator(); iter.hasNext();) {
Object element= iter.next();
if (element instanceof ICElement) {
+ if (element instanceof ITranslationUnit) {
+ continue;
+ }
if (!(element instanceof ISourceReference)) {
return false;
}
+ applicable= true;
}
}
- event.data = selection;
- return true;
+ if (applicable) {
+ event.data = selection;
+ return true;
+ }
}
return false;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDropAdapterAssistant.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDropAdapterAssistant.java
index 6c0391f68ff..329235fc07f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDropAdapterAssistant.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDropAdapterAssistant.java
@@ -15,13 +15,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.cdt.core.model.CModelException;
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.ISourceReference;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.internal.ui.cview.CViewMessages;
-import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -33,9 +29,25 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
+import org.eclipse.ui.actions.MoveFilesAndFoldersOperation;
+import org.eclipse.ui.actions.ReadOnlyStateChecker;
import org.eclipse.ui.navigator.CommonDropAdapter;
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
+import org.eclipse.ui.part.ResourceTransfer;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICContainer;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ISourceReference;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+
+import org.eclipse.cdt.internal.ui.cview.CViewMessages;
+import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
/**
* A Common Navigator drop adapter assistant handling dropping of ICElement
s.
@@ -44,11 +56,69 @@ import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
*/
public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
+ private static final IResource[] NO_RESOURCES = new IResource[0];
+
+ /*
+ * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#isSupportedType(org.eclipse.swt.dnd.TransferData)
+ */
+ public boolean isSupportedType(TransferData transferType) {
+ return super.isSupportedType(transferType)
+ || ResourceTransfer.getInstance().isSupportedType(transferType)
+ || FileTransfer.getInstance().isSupportedType(transferType);
+ }
+
/*
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object)
*/
public IStatus handleDrop(CommonDropAdapter dropAdapter,
DropTargetEvent event, Object target) {
+
+ // special case: drop in C source folder
+ if (target instanceof ICContainer) {
+ final Object data= event.data;
+ if (data == null) {
+ return Status.CANCEL_STATUS;
+ }
+ final IContainer destination= getDestination(target);
+ if (target == null) {
+ return Status.CANCEL_STATUS;
+ }
+ IResource[] resources = null;
+ TransferData currentTransfer = dropAdapter.getCurrentTransfer();
+ if (LocalSelectionTransfer.getTransfer().isSupportedType(
+ currentTransfer)) {
+ resources = getSelectedResources();
+ } else if (ResourceTransfer.getInstance().isSupportedType(
+ currentTransfer)) {
+ resources = (IResource[]) event.data;
+ }
+ if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
+ final String[] names = (String[]) data;
+ // Run the import operation asynchronously.
+ // Otherwise the drag source (e.g., Windows Explorer) will be blocked
+ // while the operation executes. Fixes bug 35796.
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ getShell().forceActive();
+ CopyFilesAndFoldersOperation op= new CopyFilesAndFoldersOperation(getShell());
+ op.copyFiles(names, destination);
+ }
+ });
+ } else if (event.detail == DND.DROP_COPY) {
+ CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(getShell());
+ operation.copyResources(resources, destination);
+ } else {
+ ReadOnlyStateChecker checker = new ReadOnlyStateChecker(
+ getShell(),
+ "Move Resource Action", //$NON-NLS-1$
+ "Move Resource Action");//$NON-NLS-1$
+ resources = checker.checkReadOnlyResources(resources);
+ MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation(getShell());
+ operation.copyResources(resources, destination);
+ }
+ return Status.OK_STATUS;
+ }
+
try {
switch(event.detail) {
case DND.DROP_MOVE:
@@ -78,18 +148,56 @@ public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
*/
public IStatus validateDrop(Object target, int operation,
TransferData transferType) {
- try {
- switch(operation) {
- case DND.DROP_DEFAULT:
- return handleValidateMove(target);
- case DND.DROP_COPY:
- return handleValidateCopy(target);
- case DND.DROP_MOVE:
- return handleValidateMove(target);
+
+ // special case: drop in C source folder
+ if (target instanceof ICContainer) {
+ IContainer destination= getDestination(target);
+ if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
+ IResource[] selectedResources= getSelectedResources();
+ if (selectedResources.length > 0) {
+ if (operation == DND.DROP_COPY) {
+ CopyFilesAndFoldersOperation op = new CopyFilesAndFoldersOperation(getShell());
+ if (op.validateDestination(destination, selectedResources) == null) {
+ return Status.OK_STATUS;
+ }
+ } else {
+ MoveFilesAndFoldersOperation op = new MoveFilesAndFoldersOperation(getShell());
+ if (op.validateDestination(destination, selectedResources) == null) {
+ return Status.OK_STATUS;
+ }
+ }
+ }
+ } else if (FileTransfer.getInstance().isSupportedType(transferType)) {
+ String[] sourceNames = (String[]) FileTransfer.getInstance().nativeToJava(transferType);
+ if (sourceNames == null) {
+ // source names will be null on Linux. Use empty names to do
+ // destination validation.
+ // Fixes bug 29778
+ sourceNames = new String[0];
+ }
+ CopyFilesAndFoldersOperation copyOperation = new CopyFilesAndFoldersOperation(
+ getShell());
+ if (null != copyOperation.validateImportDestination(destination,
+ sourceNames)) {
+ return Status.CANCEL_STATUS;
+ }
}
- } catch (CModelException e){
- ExceptionHandler.handle(e, CViewMessages.getString("SelectionTransferDropAdapter.error.title"), CViewMessages.getString("SelectionTransferDropAdapter.error.message")); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ }
+
+ if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
+ try {
+ switch(operation) {
+ case DND.DROP_DEFAULT:
+ return handleValidateMove(target);
+ case DND.DROP_COPY:
+ return handleValidateCopy(target);
+ case DND.DROP_MOVE:
+ return handleValidateMove(target);
+ }
+ } catch (CModelException e){
+ ExceptionHandler.handle(e, CViewMessages.getString("SelectionTransferDropAdapter.error.title"), CViewMessages.getString("SelectionTransferDropAdapter.error.message")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
return Status.CANCEL_STATUS;
}
@@ -254,4 +362,52 @@ public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
return true;
}
+ private IContainer getDestination(Object dropTarget) {
+ if (dropTarget instanceof IContainer) {
+ return (IContainer)dropTarget;
+ } else if (dropTarget instanceof ICElement) {
+ return getDestination(((ICElement)dropTarget).getResource());
+ }
+ return null;
+ }
+
+ /**
+ * Returns the resource selection from the LocalSelectionTransfer.
+ *
+ * @return the resource selection from the LocalSelectionTransfer
+ */
+ private IResource[] getSelectedResources() {
+
+ ISelection selection = LocalSelectionTransfer.getTransfer()
+ .getSelection();
+ if (selection instanceof IStructuredSelection) {
+ return getSelectedResources((IStructuredSelection)selection);
+ }
+ return NO_RESOURCES;
+ }
+
+ /**
+ * Returns the resource selection from the LocalSelectionTransfer.
+ *
+ * @return the resource selection from the LocalSelectionTransfer
+ */
+ private IResource[] getSelectedResources(IStructuredSelection selection) {
+ ArrayList selectedResources = new ArrayList();
+
+ for (Iterator i = selection.iterator(); i.hasNext();) {
+ Object o = i.next();
+ if (o instanceof IResource) {
+ selectedResources.add(o);
+ } else if (o instanceof IAdaptable) {
+ IAdaptable a = (IAdaptable) o;
+ IResource r = (IResource) a.getAdapter(IResource.class);
+ if (r != null) {
+ selectedResources.add(r);
+ }
+ }
+ }
+ return (IResource[]) selectedResources
+ .toArray(new IResource[selectedResources.size()]);
+ }
+
}
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
index 9355b5bbe03..eb2c72267c3 100644
--- 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
@@ -115,6 +115,12 @@ public class CNavigatorRefactorActionGroup extends ActionGroup {
updateActionBars();
// textActionHandler.updateActionBars();
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
+ copyAction);
+ actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
+ pasteAction);
+ actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
+ deleteAction);
actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(),
moveAction);