Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2001-09-03 13:31:05 +0000
committerDani Megert2001-09-03 13:31:05 +0000
commit166a1e898eef59abff1521f459de6984f1837193 (patch)
tree8c3caec5a9fefe5f3c197772e389a735b54fcf62 /org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardActionDelegate.java
parentcd7a1c18c2488fa2b1cc0db31466f84993133629 (diff)
downloadeclipse.platform.text-166a1e898eef59abff1521f459de6984f1837193.tar.gz
eclipse.platform.text-166a1e898eef59abff1521f459de6984f1837193.tar.xz
eclipse.platform.text-166a1e898eef59abff1521f459de6984f1837193.zip
Copy to Clipboard
Diffstat (limited to 'org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardActionDelegate.java')
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardActionDelegate.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardActionDelegate.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardActionDelegate.java
new file mode 100644
index 00000000000..47164fd5886
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardActionDelegate.java
@@ -0,0 +1,75 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.search.internal.ui;
+ import java.util.Collections;
+import java.util.Iterator;
+
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+public class CopyToClipboardActionDelegate implements IViewActionDelegate {
+
+ public CopyToClipboardActionDelegate() {
+ }
+
+ /*
+ * Implements method from IActionDelegate
+ */
+ public void run(IAction action) {
+ Shell shell= SearchPlugin.getActiveWorkbenchShell();
+ if (shell == null)
+ return;
+
+ SearchResultLabelProvider labelProvider= SearchResultLabelProvider.getInstance();
+ String lineDelim= System.getProperty("line.separator");
+ StringBuffer buf= new StringBuffer();
+ Iterator iter= getSelection();
+ while (iter.hasNext()) {
+ if (buf.length() > 0) {
+ buf.append(lineDelim);
+ }
+ buf.append(labelProvider.getText(iter.next()));
+ }
+
+ if (buf.length() > 0)
+ copyToClipbard(shell.getDisplay(), buf.toString());
+ }
+
+ /*
+ * Implements method from IViewActionDelegate
+ */
+ public void init(IViewPart view) {
+ }
+
+ /*
+ * Implements method from IActionDelegate
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+ private Iterator getSelection() {
+ if (SearchPlugin.getActivePage() != null) {
+ ISelection s= SearchPlugin.getActivePage().getSelection();
+ if (s instanceof IStructuredSelection)
+ return ((IStructuredSelection)s).iterator();
+ }
+ return Collections.EMPTY_LIST.iterator();
+ }
+
+ private void copyToClipbard(Display display, String str) {
+ Clipboard clipboard = new Clipboard(display);
+ clipboard.setContents(new String[] { str }, new Transfer[] { TextTransfer.getInstance()});
+ }
+} \ No newline at end of file

Back to the top