Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-patch] CDT/UI Fix CView Drag&Drop

Alain,

Here's a patch for CViewDragAdapter that re-enables dragging non-resource 
selections from the "C/C++ Projects" view.

Yes, the non-resource selections I'm particularly interested in are 
children of ITranslationUnit.



-Keith




"Alain Magloire" <alain@xxxxxxx> 
Sent by: cdt-patch-admin@xxxxxxxxxxx
2003/09/02 16:56
Please respond to
cdt-patch@xxxxxxxxxxx


To
cdt-patch@xxxxxxxxxxx
Cc

Subject
Re: [cdt-patch] CDT/UI Fix CView Drag&Drop






> Alain,
> 
> This patch changes CViewDragAdapter.java in ways that disable drag and 
> drop for non-resource selections (the only reason for my previous 
patch).
> 
> The problems are in dragSetData where the method returns (because there 
> are no resources selected) before the LocalSelectionTransfer is queried 
> and in dragStart where doit is set to false if any members of the 
> selection are not resources.
> 
> What's the policy here: Should I submit a new patch or should we ask the 

> author of this patch to do so?

8-)
Do you have a patch handy, please submit.

When you say non-resource selections, do you mean children of 
ITranslationUnit
like IInclude, IVariable etc .. to also work with Drag&Drop.  It was on
my TODO list.

Let me know, to not duplicate.

Thanks for the heads up.

_______________________________________________
cdt-patch mailing list
cdt-patch@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/cdt-patch

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.161
diff -u -r1.161 ChangeLog
--- ChangeLog	4 Sep 2003 20:47:01 -0000	1.161
+++ ChangeLog	5 Sep 2003 16:23:27 -0000
@@ -1,3 +1,8 @@
+2003-09-05 Keith Campbell
+	Other changes to CViewDragAdapter broke my introduction of drag
+	support for non-resource selections (See entry dated 2003-08-19).
+	* src/org/eclipse/cdt/internal/ui/cview/CViewDragAdapter.java
+
 2003-09-04 John Camelon
     First pass of parsing function bodies with X-Reference information.
     Updated IASTFactory/ISourceElementRequestor to include IASTCodeScope
Index: src/org/eclipse/cdt/internal/ui/cview/CViewDragAdapter.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewDragAdapter.java,v
retrieving revision 1.6
diff -u -r1.6 CViewDragAdapter.java
--- src/org/eclipse/cdt/internal/ui/cview/CViewDragAdapter.java	1 Sep 2003 21:49:44 -0000	1.6
+++ src/org/eclipse/cdt/internal/ui/cview/CViewDragAdapter.java	5 Sep 2003 16:23:27 -0000
@@ -9,8 +9,6 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdaptable;
@@ -37,13 +35,12 @@
 class CViewDragAdapter extends DragSourceAdapter {
 	private final ISelectionProvider selectionProvider;
 	private static final int typeMask = IResource.FOLDER | IResource.FILE;
-	private TransferData lastDataType; 	
+	private TransferData lastDataType;
 	private static final String CHECK_MOVE_TITLE = "Drag and Drop Problem"; //$NON-NLS-1$
 	private static final String CHECK_DELETE_MESSAGE = "{0} is read only. Do you still wish to delete it?"; //$NON-NLS-1$
 
-
 	/**
-	 * Invoked when an action occurs. 
+	 * Invoked when an action occurs.
 	 * Argument context is the Window which contains the UI from which this action was fired.
 	 * This default implementation prints the name of this class and its label.
 	 * @see DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
@@ -55,24 +52,27 @@
 			return;
 
 		if (event.detail == DND.DROP_MOVE) {
-			//never delete resources when dragging outside Eclipse. 
+			//never delete resources when dragging outside Eclipse.
 			//workaround for bug 30543.
 			if (lastDataType != null && FileTransfer.getInstance().isSupportedType(lastDataType))
 				return;
-			
-			IResource[] resources = getSelectedResources();	
+
+			IResource[] resources = getSelectedResources();
+
+			if (resources.length == 0)
+				return;
+
 			DragSource dragSource = (DragSource) event.widget;
 			Control control = dragSource.getControl();
 			Shell shell = control.getShell();
-			ReadOnlyStateChecker checker;
-			
-			if (resources == null || resources.length == 0)
-				return;
-			
-			checker = new ReadOnlyStateChecker(shell, CHECK_MOVE_TITLE, CHECK_DELETE_MESSAGE);
-			resources = checker.checkReadOnlyResources(resources);		
+
+			ReadOnlyStateChecker checker =
+				new ReadOnlyStateChecker(shell, CHECK_MOVE_TITLE, CHECK_DELETE_MESSAGE);
+
+			resources = checker.checkReadOnlyResources(resources);
+
 			//delete the old elements
-			for (int i = 0; i < resources.length; i++) {
+			for (int i = 0; i < resources.length; ++i) {
 				try {
 					resources[i].delete(IResource.KEEP_HISTORY | IResource.FORCE, null);
 				} catch (CoreException e) {
@@ -82,11 +82,10 @@
 		} else if (event.detail == DND.DROP_TARGET_MOVE) {
 			IResource[] resources = getSelectedResources();
 
-			// file moved for us by OS, no need to delete the resources, just
-			// update the view
-			if (resources == null)
-				return;
-			for (int i = 0; i < resources.length; i++) {
+			// file moved for us by OS, no need to delete the resources,
+			// just update the view
+
+			for (int i = 0; i < resources.length; ++i) {
 				try {
 					resources[i].refreshLocal(IResource.DEPTH_INFINITE, null);
 				} catch (CoreException e) {
@@ -100,46 +99,42 @@
 	 * @see DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
 	 */
 	public void dragSetData(DragSourceEvent event) {
-		IResource[] resources = getSelectedResources();
-		
-		if (resources == null || resources.length == 0)
-			return;
-
 		lastDataType = event.dataType;
+
 		//use local selection transfer if possible
 		if (LocalSelectionTransfer.getInstance().isSupportedType(event.dataType)) {
 			event.data = LocalSelectionTransfer.getInstance().getSelection();
-			return;
 		}
+
 		//use resource transfer if possible
-		if (ResourceTransfer.getInstance().isSupportedType(event.dataType)) {
-			event.data = resources;
-			return;
+		else if (ResourceTransfer.getInstance().isSupportedType(event.dataType)) {
+			event.data = getSelectedResources();
 		}
+
 		//resort to a file transfer
-		if (!FileTransfer.getInstance().isSupportedType(event.dataType))
-			return;
+		else if (FileTransfer.getInstance().isSupportedType(event.dataType)) {
+			// Get the path of each file and set as the drag data
+			final IResource[] resources = getSelectedResources();
+			final int length = resources.length;
+			String[] fileNames = new String[length];
+			int actualLength = 0;
+
+			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();
+			}
 
-		// Get the path of each file and set as the drag data
-		final int length = resources.length;
-		int actualLength = 0; 
-		String[] fileNames = new String[length];
-		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 (actualLength == 0)
-			return;
-		// 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];
+			// was one or more of the locations null?
+			if (actualLength < length) {
+				String[] tempFileNames = fileNames;
+				fileNames = new String[actualLength];
+				System.arraycopy(tempFileNames, 0, fileNames, 0, actualLength);
+			}
+
+			event.data = fileNames;
 		}
-		event.data = fileNames;
 	}
 
 	/*
@@ -147,59 +142,42 @@
 	 */
 	public void dragStart(DragSourceEvent event) {
 		lastDataType = null;
+
 		// Workaround for 1GEUS9V
 		DragSource dragSource = (DragSource) event.widget;
 		Control control = dragSource.getControl();
-		if (control != control.getDisplay().getFocusControl()) {
+
+		if (control != control.getDisplay().getFocusControl())
 			event.doit = false;
-			return;
-		}
+		else {
+			ISelection selection = selectionProvider.getSelection();
 
-		IStructuredSelection selection =
-			(IStructuredSelection) selectionProvider.getSelection();
-		for (Iterator i = selection.iterator(); i.hasNext();) {
-			Object next = i.next();
-			if (next instanceof IAdaptable) {
-				next = ((IAdaptable) next).getAdapter(IResource.class);
-			}
-			if (!(next instanceof IFile || next instanceof IFolder)) {
+			if (selection.isEmpty())
 				event.doit = false;
-				return;
-			}
+			else
+				LocalSelectionTransfer.getInstance().setSelection(selection);
 		}
-		if (selection.isEmpty()) {
-			event.doit = false;
-			return;
-		}
-		LocalSelectionTransfer.getInstance().setSelection(selection);
-		event.doit = true;
 	}
-	
-
 
 	private IResource[] getSelectedResources() {
 		ISelection selection = selectionProvider.getSelection();
 		List resources = new ArrayList();
 
-		// Sanity checks
-		if (selection == null || !(selection instanceof IStructuredSelection) || selection.isEmpty()) {
-			return null;
-		}
+		if (selection instanceof IStructuredSelection) {
+			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
 
-		IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+			// loop through list and look for matching items
+			for (Iterator iterator = structuredSelection.iterator(); iterator.hasNext();) {
+				Object object = iterator.next();
+				IResource resource = null;
+
+				if (object instanceof IResource)
+					resource = (IResource) object;
+				else if (object instanceof IAdaptable)
+					resource = (IResource) ((IAdaptable) object).getAdapter(IResource.class);
 
-		// loop through list and look for matching items
-		for (Iterator enum = structuredSelection.iterator(); enum.hasNext();) {
-			Object object = enum.next();
-			IResource resource = null;
-
-			if (object instanceof IResource) {
-				resource = (IResource) object;
-			} else if (object instanceof IAdaptable) {
-				resource = (IResource) ((IAdaptable) object).getAdapter(IResource.class);
-			}
-			if (resource != null && (resource.getType() & typeMask) != 0) {
-				resources.add(resource);
+				if (resource != null && (resource.getType() & typeMask) != 0)
+					resources.add(resource);
 			}
 		}

Back to the top