Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2011-12-16 08:19:18 -0500
committerUwe Stieber2011-12-16 08:19:18 -0500
commitc83143083c3dd734a9d702b63e1d5e1aa6333708 (patch)
tree3c7c236404ffdcd647aa3e4e569f54761366f7da /target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views
parent5c6c5b909e03913e23d8d9e93a56d3b818cbf3d8 (diff)
downloadorg.eclipse.tcf-c83143083c3dd734a9d702b63e1d5e1aa6333708.tar.gz
org.eclipse.tcf-c83143083c3dd734a9d702b63e1d5e1aa6333708.tar.xz
org.eclipse.tcf-c83143083c3dd734a9d702b63e1d5e1aa6333708.zip
Target Explorer: Add DND support to Script Pad
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java48
1 files changed, 47 insertions, 1 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java
index 74bf8d34c..54f63cd94 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui.views/src/org/eclipse/tcf/te/tcf/ui/views/scriptpad/ScriptPad.java
@@ -41,6 +41,13 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CaretEvent;
import org.eclipse.swt.custom.CaretListener;
import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.DropTargetAdapter;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
@@ -81,7 +88,7 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
// Reference to the header line
private Label head;
// Reference to the Text widget
- private StyledText text;
+ /* default */ StyledText text;
// The list of registered selection changed listeners
private final List<ISelectionChangedListener> listeners = new ArrayList<ISelectionChangedListener>();
@@ -168,6 +175,9 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
// Hook the global actions
hookGlobalActions();
+ // Setup Drag n Drop
+ setupDnD();
+
// Update the action bars
getViewSite().getActionBars().updateActionBars();
}
@@ -244,6 +254,42 @@ public class ScriptPad extends ViewPart implements ISelectionProvider, Selection
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
+ /**
+ * Setup Drag n Drop support.
+ */
+ private void setupDnD() {
+ DropTarget target = new DropTarget(text, DND.DROP_DEFAULT | DND.DROP_COPY);
+ target.setTransfer(new Transfer[] { TextTransfer.getInstance(), FileTransfer.getInstance() });
+ target.addDropListener(new DropTargetAdapter() {
+
+ @Override
+ public void drop(DropTargetEvent event) {
+ if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
+ String[] names = (String[]) FileTransfer.getInstance().nativeToJava(event.currentDataType);
+ if (names != null && names.length > 0) {
+ openFile(names[0]);
+ }
+ }
+ else if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
+ String content = (String) TextTransfer.getInstance().nativeToJava(event.currentDataType);
+ if (content != null && !"".equals(content)) { //$NON-NLS-1$
+ if (text != null && !text.isDisposed()) text.setText(content);
+ }
+ }
+ }
+
+ @Override
+ public void dragOperationChanged(DropTargetEvent event) {
+ if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY;
+ }
+
+ @Override
+ public void dragEnter(DropTargetEvent event) {
+ if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY;
+ }
+ });
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/

Back to the top