Bug 245790 - Add a template variable ${clipboard}
Summary: Add a template variable ${clipboard}
Status: RESOLVED DUPLICATE of bug 198886
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-31 13:14 EDT by Sandip Chitale CLA
Modified: 2008-09-01 03:03 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sandip Chitale CLA 2008-08-31 13:14:16 EDT
Add a template variable${clipboard}. This replaces whatever the text content the clipboard contains. Here is the scenario:

I have a long complex URL in the clipboard that was copied from the browser's address bar. 


Then I could define a templatte like this:

template name: hyperlink
template pattern:

<a href="${clipboard}" target="_blank">${cursor}</a>


[For simplicity let us assume I had a "http://www.google.com" in the clipboard]
Now when I invoke the template I get:
 
<a href="http://www.google.com" target="_blank">|</a>

where | shows the cursor position.

Here is the implementation of template variable resolver for ${clipboard}:

package somepackage;

import org.eclipse.jface.text.templates.TemplateContext;
import org.eclipse.jface.text.templates.TemplateVariableResolver;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.ui.PlatformUI;

public class ClipboardVariableResolver extends TemplateVariableResolver {

	protected String resolve(TemplateContext context) {
		Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getShell().getDisplay());
		Object content = clipboard.getContents(TextTransfer.getInstance());
		if (content != null) {
			return (String) content;
		}
		return getType();
	}

}

and the extension:

   <extension
         point="org.eclipse.ui.editors.templates">
      <resolver
            class="somepackage.ClipboardVariableResolver"
            contextTypeId="java"
            description="Resolves to the content of the clipboard."
            icon="icons/clipboard.gif"
            name="clipboard content"
            type="clipboard">
      </resolver>
   </extension>
Comment 1 Sandip Chitale CLA 2008-08-31 13:19:50 EDT
In fact this will work great with the enhancement # 245788 which asks for a template variable called ${selection}. Then the user could do the following:

Tweak the template pattern to:

<a href="${clipboard}" target="_blank">${selection}</a>${cursor}

With the text:


Google


selected in the text editor and invoking the template with Surround with... action yields:

<a href="http://www.google.com" target="_blank">Google</a>|

where | shows the cursor position.

I can imagine many uses of these.
Comment 2 Sandip Chitale CLA 2008-08-31 13:41:43 EDT
Come to thik of it this is not JDT specific. The ${clipboard} template variable
should be supported in all text editors.
Comment 3 Dani Megert CLA 2008-09-01 03:03:22 EDT
See bug 198886 comment 1.

*** This bug has been marked as a duplicate of bug 198886 ***