Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 83177 Details for
Bug 203994
Create image attachments from clipboard
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
experimental patch
clipboard.txt (text/plain), 8.59 KB, created by
Eugene Kuleshov
on 2007-11-18 01:33:02 EST
(
hide
)
Description:
experimental patch
Filename:
MIME Type:
Creator:
Eugene Kuleshov
Created:
2007-11-18 01:33:02 EST
Size:
8.59 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.tasks.ui >Index: src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentWizard.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentWizard.java,v >retrieving revision 1.36 >diff -u -r1.36 NewAttachmentWizard.java >--- src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentWizard.java 9 Oct 2007 04:27:12 -0000 1.36 >+++ src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentWizard.java 18 Nov 2007 06:21:50 -0000 >@@ -8,6 +8,7 @@ > > package org.eclipse.mylyn.internal.tasks.ui.wizards; > >+import java.io.ByteArrayOutputStream; > import java.io.File; > import java.lang.reflect.InvocationTargetException; > >@@ -172,14 +173,33 @@ > attachment.setFile(new File(fileName)); > attachment.setFilename(SCREENSHOT_FILENAME); > } else if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(path)) { >- String contents = inputPage.getClipboardContents(); >+ Object contents = inputPage.getClipboardContents(); > if (contents == null) { > throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR, > TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Clipboard is empty", > null))); > } >- attachment.setContent(contents.getBytes()); >- attachment.setFilename(CLIPBOARD_FILENAME); >+ >+ if(contents instanceof String) { >+ attachment.setContent(((String) contents).getBytes()); >+ attachment.setContentType("text/plain"); >+ attachment.setFilename(CLIPBOARD_FILENAME); >+ } else if(contents instanceof ImageData) { >+ ImageData data = (ImageData) contents; >+ >+ ByteArrayOutputStream bos = new ByteArrayOutputStream(); >+ ImageLoader loader = new ImageLoader(); >+ loader.data = new ImageData[] {data}; >+ loader.save(bos, SWT.IMAGE_PNG); >+ >+ attachment.setContent(bos.toByteArray()); >+ attachment.setContentType("image/png"); >+ attachment.setFilename("clipboard.png"); >+ } else { >+ throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR, >+ TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Unsupported clipboard type", >+ null))); >+ } > } else { > File file = new File(path); > attachment.setFile(file); >@@ -338,7 +358,7 @@ > this.dialog = dialog; > } > >- public String getClipboardContents() { >+ public Object getClipboardContents() { > return inputPage.getClipboardContents(); > } > >Index: src/org/eclipse/mylyn/internal/tasks/ui/wizards/PreviewAttachmentPage.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/PreviewAttachmentPage.java,v >retrieving revision 1.9 >diff -u -r1.9 PreviewAttachmentPage.java >--- src/org/eclipse/mylyn/internal/tasks/ui/wizards/PreviewAttachmentPage.java 20 Sep 2007 15:21:47 -0000 1.9 >+++ src/org/eclipse/mylyn/internal/tasks/ui/wizards/PreviewAttachmentPage.java 18 Nov 2007 06:21:50 -0000 >@@ -29,6 +29,7 @@ > import org.eclipse.swt.events.PaintListener; > import org.eclipse.swt.graphics.GC; > import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.ImageData; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; >@@ -94,11 +95,18 @@ > setControl(composite); > > if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(attachment.getFilePath())) { >- createTextPreview(composite, ((NewAttachmentWizard) getWizard()).getClipboardContents()); >+ Object contents = ((NewAttachmentWizard) getWizard()).getClipboardContents(); >+ if(contents instanceof String) { >+ createTextPreview(composite, (String) contents); >+ } else if(contents instanceof ImageData) { >+ Image originalImage = new Image(composite.getDisplay(), (ImageData) contents); >+ createImagePreview(composite, originalImage); >+ } > } else if (PreviewAttachmentPage.isTextAttachment(attachment.getContentType())) { > createTextPreview(composite, attachment); > } else if (PreviewAttachmentPage.isImageAttachment(attachment.getContentType())) { >- createImagePreview(composite, attachment); >+ Image originalImage = new Image(composite.getDisplay(), attachment.getFilePath()); >+ createImagePreview(composite, originalImage); > } else { > createGenericPreview(composite, attachment); > } >@@ -132,10 +140,9 @@ > } > } > >- private void createImagePreview(Composite composite, LocalAttachment attachment) { >+ private void createImagePreview(Composite composite, Image originalImage) { > // Uses double buffering to paint the image; there was a weird behavior > // with transparent images and flicker with large images >- Image originalImage = new Image(composite.getDisplay(), attachment.getFilePath()); > final Image bufferedImage = new Image(composite.getDisplay(), originalImage.getBounds()); > GC gc = new GC(bufferedImage); > gc.setBackground(composite.getBackground()); >Index: src/org/eclipse/mylyn/internal/tasks/ui/wizards/InputAttachmentSourcePage.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/InputAttachmentSourcePage.java,v >retrieving revision 1.10 >diff -u -r1.10 InputAttachmentSourcePage.java >--- src/org/eclipse/mylyn/internal/tasks/ui/wizards/InputAttachmentSourcePage.java 9 Oct 2007 04:27:12 -0000 1.10 >+++ src/org/eclipse/mylyn/internal/tasks/ui/wizards/InputAttachmentSourcePage.java 18 Nov 2007 06:21:50 -0000 >@@ -41,6 +41,7 @@ > import org.eclipse.jface.wizard.WizardPage; > import org.eclipse.swt.SWT; > import org.eclipse.swt.dnd.Clipboard; >+import org.eclipse.swt.dnd.ImageTransfer; > import org.eclipse.swt.dnd.TextTransfer; > import org.eclipse.swt.events.ModifyEvent; > import org.eclipse.swt.events.ModifyListener; >@@ -48,6 +49,7 @@ > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.events.ShellAdapter; > import org.eclipse.swt.events.ShellEvent; >+import org.eclipse.swt.graphics.ImageData; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; >@@ -114,7 +116,7 @@ > > private NewAttachmentWizard wizard; > >- private String clipboardContents; >+ private Object clipboardContents; > > private boolean initUseClipboard = false; > >@@ -424,19 +426,22 @@ > if (inputMethod == CLIPBOARD) { > Control c = getControl(); > if (c != null) { >- Clipboard clipboard = new Clipboard(c.getDisplay()); >- Object o = clipboard.getContents(TextTransfer.getInstance()); >- clipboard.dispose(); >+ Object o = retrieveClipboardContents(); > if (o instanceof String) { > String s = ((String) o).trim(); >- if (s.length() > 0) >+ if (s.length() > 0) { > attachmentFound = true; >- else >+ } else { > error = "Clipboard is empty"; >- } else >- error = "Clipboard does not contain text"; >- } else >+ } >+ } else if(o instanceof ImageData) { >+ attachmentFound = true; >+ } else { >+ error = "Unsupported clipboard content"; >+ } >+ } else { > error = "Cannot retrieve clipboard contents"; >+ } > } else if (inputMethod == SCREENSHOT) { > attachmentFound = true; > } else if (inputMethod == FILE) { >@@ -620,22 +625,34 @@ > } > > private void storeClipboardContents() { >+ clipboardContents = retrieveClipboardContents(); >+ } >+ >+ private Object retrieveClipboardContents() { > Control c = getControl(); > if (c != null) { > Clipboard clipboard = new Clipboard(c.getDisplay()); >- Object o = clipboard.getContents(TextTransfer.getInstance()); >- clipboard.dispose(); >- if (o instanceof String) { >- clipboardContents = ((String) o).trim(); >+ >+ Object o = clipboard.getContents(ImageTransfer.getInstance()); >+ if(o instanceof ImageData) { >+ return o; >+ } else { >+ o = clipboard.getContents(TextTransfer.getInstance()); >+ if (o instanceof String) { >+ return ((String) o).trim(); >+ } > } >+ >+ clipboard.dispose(); > } >+ return null; > } > >- public String getClipboardContents() { >+ public Object getClipboardContents() { > return clipboardContents; > } > >- public void setClipboardContents(String attachContents) { >+ public void setClipboardContents(Object attachContents) { > clipboardContents = attachContents; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 203994
: 83177 |
83178