1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 11:55:40 +02:00

Project Explorer: Fix for drop in folder

This commit is contained in:
Anton Leherbauer 2007-04-18 12:28:55 +00:00
parent 1f5832d033
commit 78a7a6be39
2 changed files with 71 additions and 51 deletions

View file

@ -2000,7 +2000,7 @@
<instanceof value="org.eclipse.cdt.core.model.ISourceReference"/>
<instanceof value="org.eclipse.cdt.core.model.ICContainer"/>
<instanceof value="org.eclipse.cdt.core.model.ICProject"/>
<adapt type="org.eclipse.core.resources.IResource"/>
<instanceof value="org.eclipse.core.resources.IResource"/>
</or>
</possibleDropTargets>
</dropAssistant>

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 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
@ -17,6 +17,7 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
@ -75,14 +76,21 @@ public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
public IStatus handleDrop(CommonDropAdapter dropAdapter,
DropTargetEvent event, Object target) {
// special case: drop in C source folder
if (target instanceof ICContainer || target instanceof ICProject) {
try {
// drop in folder
if (target instanceof ICContainer ||
target instanceof ICProject ||
target instanceof IContainer ||
(event.detail == DND.DROP_COPY && (
target instanceof IFile ||
target instanceof ITranslationUnit))) {
final Object data= event.data;
if (data == null) {
return Status.CANCEL_STATUS;
}
final IContainer destination= getDestination(target);
if (target == null) {
if (destination == null) {
return Status.CANCEL_STATUS;
}
IResource[] resources = null;
@ -90,6 +98,12 @@ public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
if (LocalSelectionTransfer.getTransfer().isSupportedType(
currentTransfer)) {
resources = getSelectedResources();
if (target instanceof ITranslationUnit) {
if (handleDropCopy(target, event).isOK()) {
// drop inside translation unit - we are done
return Status.OK_STATUS;
}
}
} else if (ResourceTransfer.getInstance().isSupportedType(
currentTransfer)) {
resources = (IResource[]) event.data;
@ -121,7 +135,6 @@ public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
return Status.OK_STATUS;
}
try {
switch(event.detail) {
case DND.DROP_MOVE:
return handleDropMove(target, event);
@ -151,8 +164,13 @@ public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
public IStatus validateDrop(Object target, int operation,
TransferData transferType) {
// special case: drop in C source folder
if (target instanceof ICContainer || target instanceof ICProject) {
// drop in folder
if (target instanceof ICContainer ||
target instanceof ICProject ||
target instanceof IContainer ||
(operation == DND.DROP_COPY && (
target instanceof IFile ||
target instanceof ITranslationUnit))) {
IContainer destination= getDestination(target);
if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
IResource[] selectedResources= getSelectedResources();
@ -251,7 +269,7 @@ public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
final ICElement[] cElements= getCElements(selection);
if (target instanceof ICElement) {
if (target instanceof ICElement && cElements.length > 0) {
ICElement cTarget = (ICElement)target;
ICElement parent = cTarget;
boolean isTargetTranslationUnit = cTarget instanceof ITranslationUnit;
@ -379,6 +397,8 @@ public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
return (IContainer)dropTarget;
} else if (dropTarget instanceof ICElement) {
return getDestination(((ICElement)dropTarget).getResource());
} else if (dropTarget instanceof IFile) {
return ((IFile)dropTarget).getParent();
}
return null;
}