Community
Participate
Working Groups
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>
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.
Come to thik of it this is not JDT specific. The ${clipboard} template variable should be supported in all text editors.
See bug 198886 comment 1. *** This bug has been marked as a duplicate of bug 198886 ***