mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-14 03:35:37 +02:00
Fix for 65132: moving folder onto itself deletes entire project
This commit is contained in:
parent
ffe287c848
commit
29ae5e1c22
2 changed files with 101 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2004-06-10 Bogdan Gheorghe
|
||||||
|
Fix for Bug 65132: moving folder onto itself deletes entire project
|
||||||
|
|
||||||
|
* src/org/eclipse/cdt/internal/ui/cview/CViewDropAdapter.java
|
||||||
|
|
||||||
2004-06-10 Hoda Amer
|
2004-06-10 Hoda Amer
|
||||||
Fix for PR 66289: [Content assist] menu item contains red square icon
|
Fix for PR 66289: [Content assist] menu item contains red square icon
|
||||||
|
|
||||||
|
|
|
@ -9,18 +9,24 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.MultiStatus;
|
import org.eclipse.core.runtime.MultiStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.dialogs.ErrorDialog;
|
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||||
import org.eclipse.jface.dialogs.MessageDialog;
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.jface.viewers.StructuredSelection;
|
||||||
import org.eclipse.jface.viewers.StructuredViewer;
|
import org.eclipse.jface.viewers.StructuredViewer;
|
||||||
import org.eclipse.swt.dnd.DND;
|
import org.eclipse.swt.dnd.DND;
|
||||||
import org.eclipse.swt.dnd.DropTargetEvent;
|
import org.eclipse.swt.dnd.DropTargetEvent;
|
||||||
|
@ -61,14 +67,95 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
||||||
* @see org.eclipse.swt.dnd.DropTargetListener#dragEnter(org.eclipse.swt.dnd.DropTargetEvent)
|
* @see org.eclipse.swt.dnd.DropTargetListener#dragEnter(org.eclipse.swt.dnd.DropTargetEvent)
|
||||||
*/
|
*/
|
||||||
public void dragEnter(DropTargetEvent event) {
|
public void dragEnter(DropTargetEvent event) {
|
||||||
|
|
||||||
if (FileTransfer.getInstance().isSupportedType(event.currentDataType) &&
|
if (FileTransfer.getInstance().isSupportedType(event.currentDataType) &&
|
||||||
event.detail == DND.DROP_DEFAULT) {
|
event.detail == DND.DROP_DEFAULT) {
|
||||||
// default to copy when dragging from outside Eclipse. Fixes bug 16308.
|
// default to copy when dragging from outside Eclipse. Fixes bug 16308.
|
||||||
event.detail = DND.DROP_COPY;
|
event.detail = DND.DROP_COPY;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dragEnter(event);
|
super.dragEnter(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void dropAccept(DropTargetEvent event){
|
||||||
|
if (getCurrentOperation() == DND.DROP_MOVE){
|
||||||
|
validateMove(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
private void validateMove(DropTargetEvent event) {
|
||||||
|
ICElement currentContainer = null;
|
||||||
|
|
||||||
|
Object currentTarget = getCurrentTarget();
|
||||||
|
if (currentTarget instanceof ICElement){
|
||||||
|
currentContainer =(ICElement) currentTarget;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!((currentContainer instanceof ICContainer) ||
|
||||||
|
(currentContainer instanceof ICProject))) ||
|
||||||
|
currentContainer.isReadOnly()){
|
||||||
|
event.detail = DND.DROP_NONE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ISelection sel = this.getViewer().getSelection();
|
||||||
|
if (sel instanceof IStructuredSelection){
|
||||||
|
StructuredSelection structSel = (StructuredSelection) sel;
|
||||||
|
Iterator iter=structSel.iterator();
|
||||||
|
while (iter.hasNext()){
|
||||||
|
Object tempSelection = iter.next();
|
||||||
|
if (tempSelection instanceof ICElement){
|
||||||
|
|
||||||
|
if (tempSelection instanceof ICProject){
|
||||||
|
event.detail = DND.DROP_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICElement tempElement = (ICElement) tempSelection;
|
||||||
|
ICElement tempElementParent = tempElement.getParent();
|
||||||
|
|
||||||
|
if (tempElementParent.equals(currentContainer) ||
|
||||||
|
tempElement.equals(currentContainer) ||
|
||||||
|
tempElement.equals(currentContainer.getParent()) ||
|
||||||
|
tempElement.isReadOnly()){
|
||||||
|
event.detail = DND.DROP_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tempSelection instanceof IResource){
|
||||||
|
|
||||||
|
if (tempSelection instanceof IProject){
|
||||||
|
event.detail = DND.DROP_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IResource tempResource = (IResource) tempSelection;
|
||||||
|
IResource tempResourceParent = tempResource.getParent();
|
||||||
|
//Apples to apples...
|
||||||
|
IResource resourceCurrentContainer = currentContainer.getResource();
|
||||||
|
|
||||||
|
if (tempResourceParent.equals(resourceCurrentContainer) ||
|
||||||
|
tempResource.equals(resourceCurrentContainer) ||
|
||||||
|
tempResource.equals(resourceCurrentContainer.getParent()) ||
|
||||||
|
tempResource.isReadOnly()){
|
||||||
|
event.detail = DND.DROP_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an error status with the given info.
|
* Returns an error status with the given info.
|
||||||
*/
|
*/
|
||||||
|
@ -273,6 +360,8 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
openError(status);
|
openError(status);
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,6 +478,7 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
||||||
* Ensures that the drop target meets certain criteria
|
* Ensures that the drop target meets certain criteria
|
||||||
*/
|
*/
|
||||||
private IStatus validateTarget(Object target, TransferData transferType) {
|
private IStatus validateTarget(Object target, TransferData transferType) {
|
||||||
|
|
||||||
if (target instanceof IAdaptable) {
|
if (target instanceof IAdaptable) {
|
||||||
IResource r = (IResource)((IAdaptable) target).getAdapter(IResource.class);
|
IResource r = (IResource)((IAdaptable) target).getAdapter(IResource.class);
|
||||||
if (r == null)
|
if (r == null)
|
||||||
|
@ -407,6 +497,7 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
||||||
if (destination.getType() == IResource.ROOT) {
|
if (destination.getType() == IResource.ROOT) {
|
||||||
return error("Resources Can Not Be Siblings"); //$NON-NLS-1$
|
return error("Resources Can Not Be Siblings"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = null;
|
String message = null;
|
||||||
// drag within Eclipse?
|
// drag within Eclipse?
|
||||||
if (LocalSelectionTransfer.getInstance().isSupportedType(transferType)) {
|
if (LocalSelectionTransfer.getInstance().isSupportedType(transferType)) {
|
||||||
|
@ -423,6 +514,7 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
||||||
operation = new MoveFilesAndFoldersOperation(getShell());
|
operation = new MoveFilesAndFoldersOperation(getShell());
|
||||||
}
|
}
|
||||||
message = operation.validateDestination(destination, selectedResources);
|
message = operation.validateDestination(destination, selectedResources);
|
||||||
|
|
||||||
}
|
}
|
||||||
} // file import?
|
} // file import?
|
||||||
else if (FileTransfer.getInstance().isSupportedType(transferType)) {
|
else if (FileTransfer.getInstance().isSupportedType(transferType)) {
|
||||||
|
@ -435,9 +527,11 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
||||||
CopyFilesAndFoldersOperation copyOperation = new CopyFilesAndFoldersOperation(getShell());
|
CopyFilesAndFoldersOperation copyOperation = new CopyFilesAndFoldersOperation(getShell());
|
||||||
message = copyOperation.validateImportDestination(destination, sourceNames);
|
message = copyOperation.validateImportDestination(destination, sourceNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
return error(message);
|
return error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue