Monday, November 08, 2010 at 12:02 AM.

system.verbs.builtins.Frontier.tools.commands.addLink

<<Add a link to a headline.
	<<Changes:
		<<08/14/00; 10:41:04 PM by PBS
			<<Turn off display, set the refcon, then turn display back on -- this causes the note icon to be drawn immediately.
		<<08/16/00; 6:47:45 PM by JES
			<<Encode the url using string.urlEncode, but not the /, ?, &, $ and = characters.
		<<Mon, Sep 11, 2000 at 2:41:22 AM by JES
			<<Don't url-encode the + character.
		<<Thu, Sep 21, 2000 at 12:34:09 PM by JES
			<<Don't url-encode the % character
		<<10/16/00; 2:22:52 PM by JES
			<<Don't url-encode the # character
		<<01/04/01; 2:19:27 AM by JES
			<<If the clipboard contains a URL, make it the default URL for adding a link.
		<<01/08/01; 2:52:43 PM by JES
			<<Make sure that user.playlist.prefs.lastUrlToLinkTo is defined.
		<<3/18/01; 4:39:29 PM by PBS
			<<Provide a better error message when the link is in an incorrect form. Can't add link because the URL is not of the form 'http://www.server.com/hello.html.'
		<<8/3/01; 10:51:07 PM by JES
			<<Allow relative links.
if not defined (user.tools.prefs.lastUrlToLinkTo) {
	user.tools.prefs.lastUrlToLinkTo = "http://"};
local (url = user.tools.prefs.lastUrlToLinkTo);
local (clipboardValue = clipboard.getValue (stringType));
if string.lower (clipboardValue) beginswith "http://" {
	url = clipboardValue};
if op.attributes.getOne ("url", @url) {
	user.tools.prefs.lastUrlToLinkTo = url};
if dialog.ask ("Link \"" + op.getlinetext () + "\" to what URL?", @url) {
	<<if not (url contains "://")
		<<url = "http://" + url
	user.tools.prefs.lastUrlToLinkTo = url;
	local (atts);
	new (tabletype, @atts);
	atts.type = "link";
	local (urlParts);
	if url contains "://" {
		try {
			urlParts = string.urlSplit (url)}
		else {
			try { //add a trailing slash
				urlParts = string.urlSplit (url + "/")}
			else {
				scriptError ("Can't add link because the URL is not of the form 'http://www.server.com/hello.html.'")}};
		local (path = urlParts[3]);
		bundle { // properly encode the path part
			path = string.urlEncode (path);
			path = string.replaceAll (path, "%2F", "/");
			path = string.replaceAll (path, "%3F", "?");
			path = string.replaceAll (path, "%26", "&");
			path = string.replaceAll (path, "%24", "$");
			path = string.replaceAll (path, "%3D", "=");
			path = string.replaceAll (path, "%2B", "+");
			path = string.replaceAll (path, "%25", "%");
			path = string.replaceAll (path, "%23", "#")};
		atts.url = urlParts[1] + urlParts[2] + "/" + path}
	else {
		atts.url = url};
	op.setDisplay (false); //PBS 08/14/00: turn off display -- this will cause the note icon to get drawn when display is turned back on
	op.attributes.addGroup (@atts);
	op.setDisplay (true)} //PBS 08/14/00: turn on display -- and the note icon gets drawn



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.