diff options
author | Dani Megert | 2002-05-06 12:05:23 +0000 |
---|---|---|
committer | Dani Megert | 2002-05-06 12:05:23 +0000 |
commit | c5d5ee53939ac9a7843f6607db3931431f3f4cc2 (patch) | |
tree | 7b9106f90c3691a65a50d1b4c68e47c8214708ba /org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java | |
parent | c3dd79fbd4bac739933c57b0c0981c25ccc95e7a (diff) | |
download | eclipse.platform.text-c5d5ee53939ac9a7843f6607db3931431f3f4cc2.tar.gz eclipse.platform.text-c5d5ee53939ac9a7843f6607db3931431f3f4cc2.tar.xz eclipse.platform.text-c5d5ee53939ac9a7843f6607db3931431f3f4cc2.zip |
Fixed 14498: clipboards must be disposed
Diffstat (limited to 'org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java')
-rw-r--r-- | org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java index 68e660bc52c..f484877d113 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java @@ -6,13 +6,15 @@ package org.eclipse.search.internal.ui;
import java.util.Collections;
import java.util.Iterator;
+import org.eclipse.swt.SWTError;
import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
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.Action;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -47,8 +49,14 @@ public class CopyToClipboardAction extends Action { buf.append(labelProvider.getText(iter.next()));
}
- if (buf.length() > 0)
- copyToClipbard(shell.getDisplay(), buf.toString());
+ if (buf.length() > 0) {
+ Clipboard clipboard= new Clipboard(shell.getDisplay());
+ try {
+ copyToClipbard(clipboard, buf.toString(), shell);
+ } finally {
+ clipboard.dispose();
+ }
+ }
}
private Iterator getSelection() {
@@ -58,8 +66,16 @@ public class CopyToClipboardAction extends Action { 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()});
+ private void copyToClipbard(Clipboard clipboard, String str, Shell shell) {
+ try {
+ clipboard.setContents(new String[] { str }, new Transfer[] { TextTransfer.getInstance() });
+ } catch (SWTError ex) {
+ if (ex.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
+ throw ex;
+ String title= SearchMessages.getString("CopyToClipboardAction.error.title"); //$NON-NLS-1$
+ String message= SearchMessages.getString("CopyToClipboardAction.error.title"); //$NON-NLS-1$
+ if (MessageDialog.openQuestion(shell, title, message))
+ copyToClipbard(clipboard, str, shell);
+ }
}
}
\ No newline at end of file |