1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 194208 - [Editor] External TUs cannot be opened via drag'n'drop

This commit is contained in:
Anton Leherbauer 2008-09-24 10:18:37 +00:00
parent 3dae068c33
commit e9f1594821

View file

@ -10,11 +10,15 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.navigator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
@ -23,22 +27,25 @@ import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
/**
* A Common Navigator drag assistant for <code>ICElement</code>s being also
* <code>ISourceReference</code>s.
* A Common Navigator drag assistant supporting <code>LocalSelectionTransfer</code> of
* <code>ICElement</code>s being also <code>ISourceReference</code>s and
* <code>FileTransfer</code> for external translation units.
*
* @see org.eclipse.cdt.internal.ui.cview.SelectionTransferDragAdapter
*/
public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
private static final Transfer[] TRANSFERS = new Transfer[] {
LocalSelectionTransfer.getTransfer(),
FileTransfer.getInstance()
};
/*
* @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes()
*/
@Override
public Transfer[] getSupportedTransferTypes() {
Transfer[] transfers= new Transfer[] {
LocalSelectionTransfer.getTransfer()
};
return transfers;
return TRANSFERS;
}
/*
@ -47,22 +54,40 @@ public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
@Override
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 (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
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;
}
if (!(element instanceof ISourceReference)) {
return false;
}
applicable= true;
}
}
if (applicable) {
event.data = selection;
return true;
if (applicable) {
event.data = selection;
return true;
}
} else if (FileTransfer.getInstance().isSupportedType(event.dataType)) {
List<String> files= new ArrayList<String>();
for (Iterator<?> iter= (selection).iterator(); iter.hasNext();) {
Object element= iter.next();
if (element instanceof ITranslationUnit) {
ITranslationUnit tu= (ITranslationUnit) element;
IPath location= tu.getLocation();
if (location != null) {
files.add(location.toOSString());
}
}
}
if (!files.isEmpty()) {
event.data = files.toArray(new String[files.size()]);
return true;
}
}
}
return false;