Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2007-02-06 13:56:43 -0500
committerDoug Schaefer2007-02-06 13:56:43 -0500
commitaee1e8c34ee7c840bbb28d575576af3c15eff9f9 (patch)
treee87b17699fcde7ffd4f463657ce5bd6e470a7277
parent078808bcbe5b133a6b50b537bee22415a7df0923 (diff)
downloadorg.eclipse.cdt-aee1e8c34ee7c840bbb28d575576af3c15eff9f9.tar.gz
org.eclipse.cdt-aee1e8c34ee7c840bbb28d575576af3c15eff9f9.tar.xz
org.eclipse.cdt-aee1e8c34ee7c840bbb28d575576af3c15eff9f9.zip
Patch for Alex C, Bug 165553 - Fix CView drop adapter to accept unknown types.
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java6
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/DelegatingDropAdapter.java61
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java3
3 files changed, 53 insertions, 17 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java
index 58ffecb47c..18b3c2ea4e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java
@@ -103,6 +103,7 @@ import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.part.ISetSelectionTarget;
import org.eclipse.ui.part.IShowInSource;
import org.eclipse.ui.part.IShowInTarget;
+import org.eclipse.ui.part.PluginTransfer;
import org.eclipse.ui.part.ResourceTransfer;
import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.part.ViewPart;
@@ -407,13 +408,14 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
Transfer[] transfers= new Transfer[] {
LocalSelectionTransfer.getInstance(),
ResourceTransfer.getInstance(),
- FileTransfer.getInstance()};
+ FileTransfer.getInstance(),
+ PluginTransfer.getInstance()};
TransferDropTargetListener[] dropListeners= new TransferDropTargetListener[] {
new SelectionTransferDropAdapter(viewer),
new ResourceTransferDropAdapter(viewer),
new FileTransferDropAdapter(viewer)
};
- viewer.addDropSupport(ops, transfers, new DelegatingDropAdapter(dropListeners));
+ viewer.addDropSupport(ops, transfers, new DelegatingDropAdapter(viewer, dropListeners));
}
/**
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/DelegatingDropAdapter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/DelegatingDropAdapter.java
index 102ccc8b96..49246ea82b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/DelegatingDropAdapter.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dnd/DelegatingDropAdapter.java
@@ -11,19 +11,23 @@
package org.eclipse.cdt.internal.ui.dnd;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.ui.part.PluginDropAdapter;
/**
* DelegatingDropAdapter
*/
-public class DelegatingDropAdapter implements DropTargetListener {
+public class DelegatingDropAdapter extends PluginDropAdapter { // implements DropTargetListener {
private TransferDropTargetListener[] fListeners;
TransferDropTargetListener fCurrentListener;
private int fOriginalDropType;
@@ -33,7 +37,8 @@ public class DelegatingDropAdapter implements DropTargetListener {
*
* @param listeners an array of potential listeners
*/
- public DelegatingDropAdapter(TransferDropTargetListener[] listeners) {
+ public DelegatingDropAdapter(StructuredViewer viewer, TransferDropTargetListener[] listeners) {
+ super(viewer);
Assert.isNotNull(listeners);
fListeners= listeners;
}
@@ -49,6 +54,7 @@ public class DelegatingDropAdapter implements DropTargetListener {
public void dragEnter(DropTargetEvent event) {
fOriginalDropType= event.detail;
updateCurrentListener(event);
+ super.dragEnter(event);
}
/**
@@ -78,13 +84,14 @@ public class DelegatingDropAdapter implements DropTargetListener {
// only notify the current listener if it hasn't changed based on the
// operation change. otherwise the new listener would get a dragEnter
// followed by a dragOperationChanged with the exact same event.
- if (newListener != null && newListener == oldListener) {
+ if ((newListener != null) && (newListener == oldListener)) {
Platform.run(new SafeRunnable() {
public void run() throws Exception {
newListener.dragOperationChanged(event);
}
});
}
+ super.dragOperationChanged(event);
}
/**
@@ -104,12 +111,16 @@ public class DelegatingDropAdapter implements DropTargetListener {
// only notify the current listener if it hasn't changed based on the
// drag over. otherwise the new listener would get a dragEnter
// followed by a dragOver with the exact same event.
- if (newListener != null && newListener == oldListener) {
- Platform.run(new SafeRunnable() {
- public void run() throws Exception {
- newListener.dragOver(event);
- }
- });
+ if (newListener != null) {
+ if(newListener == oldListener) {
+ Platform.run(new SafeRunnable() {
+ public void run() throws Exception {
+ newListener.dragOver(event);
+ }
+ });
+ }
+ } else {
+ super.dragOver(event);
}
}
@@ -128,7 +139,8 @@ public class DelegatingDropAdapter implements DropTargetListener {
getCurrentListener().drop(event);
}
});
- }
+ } else
+ super.drop(event);
setCurrentListener(null, event);
}
@@ -139,13 +151,18 @@ public class DelegatingDropAdapter implements DropTargetListener {
* @see DropTargetListener#dropAccept(DropTargetEvent)
*/
public void dropAccept(final DropTargetEvent event) {
+ updateCurrentListener(event);
if (getCurrentListener() != null) {
Platform.run(new SafeRunnable() {
public void run() throws Exception {
getCurrentListener().dropAccept(event);
}
});
- }
+ } else
+ super.dropAccept(event);
+ // Copy is the default operation
+ if(DND.DROP_DEFAULT == event.detail)
+ event.detail = DND.DROP_COPY;
}
/**
@@ -231,7 +248,7 @@ public class DelegatingDropAdapter implements DropTargetListener {
*
* @param event the drop target event
*/
- private void updateCurrentListener(DropTargetEvent event) {
+ private boolean updateCurrentListener(DropTargetEvent event) {
int originalDetail= event.detail;
// Revert the detail to the "original" drop type that the User
// indicated. This is necessary because the previous listener
@@ -252,13 +269,29 @@ public class DelegatingDropAdapter implements DropTargetListener {
// event detail
if (!setCurrentListener(listener, event))
event.detail= originalDetail;
- return;
+ return true;
}
event.currentDataType= originalDataType;
}
}
setCurrentListener(null, event);
- event.detail= DND.DROP_NONE;
+ // event.detail= DND.DROP_NONE;
+ return false;
+ }
+
+ protected Object determineTarget(DropTargetEvent event) {
+ Object dropTarget = super.determineTarget(event);
+ if (dropTarget instanceof ICElement)
+ dropTarget = ((ICElement)dropTarget).getResource();
+ return dropTarget;
+ }
+
+ protected Object getCurrentTarget() {
+ Object dropTarget = super.getCurrentTarget();
+ if (dropTarget instanceof IContainer) {
+ return dropTarget;
+ } else
+ return null;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
index 8eef208b54..9c3de8f185 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
@@ -456,7 +456,8 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
TransferDropTargetListener[] dropListeners= new TransferDropTargetListener[] {
new SelectionTransferDropAdapter(fTreeViewer)
};
- fTreeViewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers, new DelegatingDropAdapter(dropListeners));
+ fTreeViewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers,
+ new DelegatingDropAdapter(fTreeViewer, dropListeners));
// Drag Adapter
TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] {

Back to the top