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:
parent
3dae068c33
commit
e9f1594821
1 changed files with 45 additions and 20 deletions
|
@ -10,11 +10,15 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.navigator;
|
package org.eclipse.cdt.internal.ui.navigator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.jface.util.LocalSelectionTransfer;
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.swt.dnd.DragSourceEvent;
|
import org.eclipse.swt.dnd.DragSourceEvent;
|
||||||
|
import org.eclipse.swt.dnd.FileTransfer;
|
||||||
import org.eclipse.swt.dnd.Transfer;
|
import org.eclipse.swt.dnd.Transfer;
|
||||||
import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
|
import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
|
||||||
|
|
||||||
|
@ -23,22 +27,25 @@ import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Common Navigator drag assistant for <code>ICElement</code>s being also
|
* A Common Navigator drag assistant supporting <code>LocalSelectionTransfer</code> of
|
||||||
* <code>ISourceReference</code>s.
|
* <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
|
* @see org.eclipse.cdt.internal.ui.cview.SelectionTransferDragAdapter
|
||||||
*/
|
*/
|
||||||
public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
|
public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
|
||||||
|
|
||||||
|
private static final Transfer[] TRANSFERS = new Transfer[] {
|
||||||
|
LocalSelectionTransfer.getTransfer(),
|
||||||
|
FileTransfer.getInstance()
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes()
|
* @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Transfer[] getSupportedTransferTypes() {
|
public Transfer[] getSupportedTransferTypes() {
|
||||||
Transfer[] transfers= new Transfer[] {
|
return TRANSFERS;
|
||||||
LocalSelectionTransfer.getTransfer()
|
|
||||||
};
|
|
||||||
return transfers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -47,6 +54,7 @@ public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
|
||||||
@Override
|
@Override
|
||||||
public boolean setDragData(DragSourceEvent event, IStructuredSelection selection) {
|
public boolean setDragData(DragSourceEvent event, IStructuredSelection selection) {
|
||||||
if (selection != null) {
|
if (selection != null) {
|
||||||
|
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
|
||||||
boolean applicable= false;
|
boolean applicable= false;
|
||||||
for (Iterator<?> iter= (selection).iterator(); iter.hasNext();) {
|
for (Iterator<?> iter= (selection).iterator(); iter.hasNext();) {
|
||||||
Object element= iter.next();
|
Object element= iter.next();
|
||||||
|
@ -64,6 +72,23 @@ public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
|
||||||
event.data = selection;
|
event.data = selection;
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue