PDA

View Full Version : Copy text link to Clipboard from Context Menu


thrash4life
11-03-2006, 09:31 AM
I am currently developing with 3.3.3. How can I leverage the context menu (Cut, Copy Paste, Clear) that is available over a <text selectable="true" /> in an instance where the text has a href / hyperlink on it. The solution has to be cross platform (I saw the other threads referencing the Windows notepad). In consideration that it may not be possible to leverage the context menu or that I could leverage it but I won't achieve the desired results (ex: the context menu will only enable copying the link title and not the link as well nor copying the link by itself), I created my own context menu for my customized <text> class. Could one of y'all hotshots help me "fill in the blanks" with how to create a handler that will copy the link (not just the title)? This customized <text> class is fed via XML where it takes a link title string and a link ref string to create the text link. I specify the <text>'s datapath when I instantiate it on the canvas. Many thanks in advance :) and perhaps someone could leverage this code if s/he is having problems creating a text link from a similar data source.

<class name='textLink' extends='text'>
<attribute name="width" value="${parent.width}" />
<attribute name="multiline" value="true" />
<attribute name="fgcolor" value="#227" />
<attribute name="selectable" value="true" />
<attribute name="onclick" value="LzBrowser.loadURL(href, '_blank')" />
<attribute name="onmouseover" value="this.setText( '&lt;u&gt;' + this.text + '&lt;/u&gt;' )" />
<attribute name="onmouseout" value="this.setText(this.defText)" />
<attribute name="text" value="$path{'./link_title/text()'}" />
<attribute name="href" value="$path{'./link_ref/text()'}" />
<attribute name="defText" value="$path{'./link_title/text()'}" />
<method event="oninit" >
var linkContextMenu = new LzContextMenu();
var copyLinkBoth = linkContextMenu.makeMenuItem('Copy Entire Link', new LzDelegate(this, "handlerightclick1"));
var copyLinkLocation = linkContextMenu.makeMenuItem('Copy Link Location', new LzDelegate(this, "handlerightclick2"));
var copyLinkTitle = linkContextMenu.makeMenuItem('Copy Link Title', new LzDelegate(this,
"handlerightclick3"));
linkContextMenu.addItem(copyLinkBoth);
linkContextMenu.addItem(copyLinkLocation);
linkContextMenu.addItem(copyLinkTitle);
linkContextMenu.hideBuiltInItems();
this.setContextMenu(linkContextMenu);
</method>
</class>

senshi
11-03-2006, 12:00 PM
Did you ever tried LzBrowser#setClipboard(..) ?
(see http://www.openlaszlo.org/lps/docs/reference/lzbrowser.html#meth-setClipboard

This will fit for your proposal to create a custom context menue.

thrash4life
11-06-2006, 01:53 PM
Duh - :rolleyes: I totally missed that. THANK YOU so much senshi for the help. :D

Now that I got my link copied to the clipboard I want to be able encode the text so that when I paste the copied link into an app like MS Outlook I DON'T see <a href="http://ima.putz">I'm a putz</a> but rather I ONLY see - I'm a putz - and the user can click on it to be redirected accordingly. How 'bout it?

How 'bout NO! Not even Laszlo Mail will paste HTML formatted code into a Compose New Message window. Go drag over and copy a link from this forum (for instance) and try pasting it into Laszlo Mail. No HTML formatted text, just the link title. Even the automatic context menu over the richinputtext only copies the href attribute of a link and not the entire HTML formatted link. One would assume that at least copying / pasting formatted HTML links would be implemented in Laszlo as this is one of the most common ways that folks share and exchange links. Thanks to Sensei pointing out the obvious to me, I have at least made an entire <a href="link.com">LINK</a> string to be copied and pasted; it's just not encoded to be pasted as HTML! BOO! Anyone have any ideas if this feature is a possible future enhancement or if there is a possible mod that would copy/paste HTML formatted text?