Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Chen2012-02-22 22:34:33 -0500
committerWilliam Chen2012-02-22 22:34:33 -0500
commit29d48f75011216cb66d6513209860f8a9db1a71c (patch)
treefdb6dd140a1809201945e7aa01cc56bee7468a18
parentc91d020c98b9bdf3d76c599bcec3b0412d1f46b0 (diff)
downloadorg.eclipse.tcf-29d48f75011216cb66d6513209860f8a9db1a71c.tar.gz
org.eclipse.tcf-29d48f75011216cb66d6513209860f8a9db1a71c.tar.xz
org.eclipse.tcf-29d48f75011216cb66d6513209860f8a9db1a71c.zip
Target Explorer: Add support for pasting files copied/cut in an external
program.
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/activator/UIPlugin.java1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/handlers/PasteFilesHandler.java16
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSClipboard.java24
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/testers/ClipboardPropertyTester.java30
5 files changed, 77 insertions, 2 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/activator/UIPlugin.java
index 70b2f7f6a..a4e465cf6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/activator/UIPlugin.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/activator/UIPlugin.java
@@ -127,6 +127,7 @@ public class UIPlugin extends AbstractUIPlugin {
Command saveAllCmd = commandService.getCommand(IWorkbenchCommandConstants.FILE_SAVE_ALL);
saveAllCmd.removeExecutionListener(saveAllListener);
}
+ clipboard.dispose();
clipboard = null;
plugin = null;
super.stop(context);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/handlers/PasteFilesHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/handlers/PasteFilesHandler.java
index 8652d69cd..20140ea8a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/handlers/PasteFilesHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/handlers/PasteFilesHandler.java
@@ -15,7 +15,11 @@ import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.tcf.te.tcf.filesystem.activator.UIPlugin;
+import org.eclipse.tcf.te.tcf.filesystem.internal.dnd.CommonDnD;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSClipboard;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSCopy;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSMove;
@@ -36,7 +40,17 @@ public class PasteFilesHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
FSClipboard cb = UIPlugin.getDefault().getClipboard();
- if (!cb.isEmpty()) {
+ Clipboard clipboard = cb.getSystemClipboard();
+ Object contents = clipboard.getContents(FileTransfer.getInstance());
+ if(contents != null) {
+ String[] files = (String[]) contents;
+ // Get the files/folders from the clip board.
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ FSTreeNode hovered = (FSTreeNode) selection.getFirstElement();
+ CommonDnD dnd = new CommonDnD();
+ dnd.dropFiles(null, files, DND.DROP_COPY, hovered);
+ }
+ else if (!cb.isEmpty()) {
// Get the files/folders from the clip board.
int operations = cb.getOperation();
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSClipboard.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSClipboard.java
index e2dbe2861..ee5db53a3 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSClipboard.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSClipboard.java
@@ -12,8 +12,10 @@ package org.eclipse.tcf.te.tcf.filesystem.internal.operations;
import java.util.List;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode;
import org.eclipse.tcf.te.ui.utils.PropertyChangeProvider;
+import org.eclipse.ui.PlatformUI;
/**
* The clip board to which copy or cut files/folders.
@@ -27,12 +29,15 @@ public class FSClipboard extends PropertyChangeProvider {
private int operation;
// The currently selected files/folders.
private List<FSTreeNode> files;
+ // The system clipboard.
+ private Clipboard clipboard;
/**
* Create a clip board instance.
*/
public FSClipboard() {
operation = NONE;
+ clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
}
/**
@@ -70,6 +75,7 @@ public class FSClipboard extends PropertyChangeProvider {
public void cutFiles(List<FSTreeNode> files) {
operation = CUT;
this.files = files;
+ clipboard.clearContents();
PropertyChangeEvent event = new PropertyChangeEvent(this, "cut", null, null); //$NON-NLS-1$
firePropertyChange(event);
}
@@ -82,6 +88,7 @@ public class FSClipboard extends PropertyChangeProvider {
public void copyFiles(List<FSTreeNode> files) {
operation = COPY;
this.files = files;
+ clipboard.clearContents();
PropertyChangeEvent event = new PropertyChangeEvent(this, "copy", null, null); //$NON-NLS-1$
firePropertyChange(event);
}
@@ -92,7 +99,24 @@ public class FSClipboard extends PropertyChangeProvider {
public void clear() {
operation = NONE;
this.files = null;
+ clipboard.clearContents();
PropertyChangeEvent event = new PropertyChangeEvent(this, "clear", null, null); //$NON-NLS-1$
firePropertyChange(event);
}
+
+ /**
+ * Dispose the clipboard.
+ */
+ public void dispose() {
+ if (!clipboard.isDisposed()) clipboard.dispose();
+ }
+
+ /**
+ * Get the system clipboard.
+ *
+ * @return The system clipboard.
+ */
+ public Clipboard getSystemClipboard() {
+ return clipboard;
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java
index f31a5b537..e6fefd649 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSUpload.java
@@ -99,6 +99,10 @@ public class FSUpload extends FSUIOperation implements IConfirmCallback {
return status;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.filesystem.interfaces.IConfirmCallback#requires(java.lang.Object)
+ */
@Override
public boolean requires(Object object) {
File file = (File) object;
@@ -110,6 +114,10 @@ public class FSUpload extends FSUIOperation implements IConfirmCallback {
return false;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.filesystem.interfaces.IConfirmCallback#confirms(java.lang.Object)
+ */
@Override
public int confirms(Object object) {
final int[] results = new int[1];
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/testers/ClipboardPropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/testers/ClipboardPropertyTester.java
index 436e7d5b4..57dee255b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/testers/ClipboardPropertyTester.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/testers/ClipboardPropertyTester.java
@@ -14,6 +14,8 @@ import java.util.List;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.tcf.te.tcf.filesystem.activator.UIPlugin;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSClipboard;
import org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode;
@@ -37,7 +39,33 @@ public class ClipboardPropertyTester extends PropertyTester {
Assert.isTrue(receiver instanceof IStructuredSelection);
if (property.equals("canPaste")) { //$NON-NLS-1$
FSClipboard cb = UIPlugin.getDefault().getClipboard();
- if (!cb.isEmpty()) {
+ Clipboard clipboard = cb.getSystemClipboard();
+ Object contents = clipboard.getContents(FileTransfer.getInstance());
+ if(contents != null) {
+ List<FSTreeNode> selection = ((IStructuredSelection) receiver).toList();
+ FSTreeNode hovered = null;
+ Assert.isTrue(!selection.isEmpty());
+ if (selection.size() == 1) {
+ FSTreeNode node = selection.get(0);
+ if (node.isFile()) {
+ hovered = node.parent;
+ }
+ else {
+ hovered = node;
+ }
+ }
+ else {
+ for (FSTreeNode node : selection) {
+ if (hovered == null) hovered = node.parent;
+ else if (hovered != node.parent) return false;
+ }
+ }
+ if (hovered.isDirectory() && hovered.isWritable()) {
+ return true;
+ }
+ return false;
+ }
+ else if (!cb.isEmpty()) {
List<FSTreeNode> nodes = cb.getFiles();
int operation = cb.getOperation();
boolean moving = operation == FSClipboard.CUT;

Back to the top