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

system.verbs.apps.Manila.nodeTypes.types.manilaMessageReadOnly.expand

<<Expand a manilaMessageReadOnly nodeType.
	<<Insert the text of the message into the outline.
<<Changes
	<<Tue, Aug 22, 2000 at 11:31:52 AM by PBS
		<<Created. Display a Manila discussion group message in-line.
	<<Saturday, September 30, 2000 at 4:09:26 PM by DW
		<<When expanding a message add the responses after the message body.
	<<11/03/00; 1:11:02 AM by JES
		<<If the message contains an opml document, use that to build the outline.
	<<12/31/00; 5:06:20 PM by JES
		<<On Macs, convert opml text to Mac text before converting to an outline.

local (oldTarget = target.set (window.frontmost ()));
local (oldDisplay = op.getDisplay ());
op.setDisplay (false);

local (atts);
op.attributes.getAll (@atts);
local (siteUrl = atts.siteUrl);
local (msgNum = atts.msgnum);
local (baseDiscussUrl = atts.baseDiscussUrl);

local (username, password);
on createInfoCallback (adrinfo) {
	if manila.windowTypes.getUsernameAndPassword (adrinfo, @username, @password) {
		manila.windowTypes.setUsernameAndPassword (adrinfo, username, password)}
	else {
		bundle { //don't leave stale data lying around
			local (adrtempinfo = @system.temp.manila.data.sites.[nameOf (adrinfo^)]);
			if defined (adrtempinfo^) {delete (adrtempinfo)};
			delete (adrinfo)};
		dialog.alert ("Can't display this message for because your username and password are not set.");
		return (false)}};

local (adrinfo);
if not manila.windowTypes.findSiteInfo (siteUrl, @adrinfo, @createInfoCallback) {
	return (false)}; //the user cancelled the username/password dialog
if not manila.windowTypes.getUsernameAndPassword (adrinfo, @username, @password) {
	return (false)}; //the user cancelled the password dialog
local (siteinfo = adrinfo^);
siteinfo.username = username;
siteinfo.password = password;

local (messageTable = manila.message.get (@siteinfo, atts.msgNum));

op.deleteSubs ();

local (s);

local (posted = messageTable.postTime);
local (author = messageTable.memberName);
if author != messageTable.member {
	<<JES: changed parens to carets becuase they can be pasted into email programs -- it's a sendmail standard format
	author = author + " <" + messageTable.member + ">"};
if system.environment.isMac { //convert author to Mac text
	author = string.latinToMac (author)};

if defined (messageTable.opml) { //11/01/00 JES: insert opml instead of plain outline
	local (localOutline);
	if system.environment.isMac { //12/31/00 JES: convert to Mac text
		op.xmlToOutline (latinToMac.convert (messageTable.opml), @localOutline)}
	else {
		op.xmlToOutline (messageTable.opml, @localOutline)};
	bundle { //delete <rules> from the outline
		local (oldTarget = target.set (@localOutline));
		op.fullExpand ();
		op.firstSummit ();
		op.go (down, infinity);
		op.go (right, infinity);
		loop {
			if op.getLineText () beginsWith "<rules>" {
				op.deleteLine ();
				continue};
			if not op.go (flatup, 1) {
				break}};
		try {target.set (oldTarget)}};
	op.insertOutline (@localOutline, right)}
else { //tabbed outline, or html text
	if defined (messageTable.outline) {
		if system.environment.isMac {
			s = string.latinToMac (messageTable.outline)}
		else {
			s = messageTable.outline};
		local (localOutline);
		op.newOutlineObject (s, @localOutline);
		op.insertOutline (@localOutline, right)}
	else {
		s = messageTable.body;
		s = string.replaceAll (s, "\r\r", "\r"); //collapse blank lines
		s = string.replaceAll (s, "\r\n\r\n", "\r"); //collapse blank lines
		op.insert (s, right);
		op.go (left, 1)}};

bundle { //add the responses to the message
	local (flGoneRight = true);
	on addMessage (adrTable, flLastMessage=false) {
		local (linetext = adrTable^.subject);
		local (author = adrTable^.memberName);
		if author != adrTable^.member {
			author = author + " <" + adrTable^.member + ">"};
		linetext = linetext + " -- " + author;
		if system.environment.isMac {
			linetext = string.latinToMac (linetext)};
		local (dir = down);
		if not flGoneRight {
			dir = right;
			flGoneRight = true};
		op.insert (linetext, dir);
		
		adrTable^.siteUrl = siteUrl;
		adrTable^.baseDiscussUrl = baseDiscussUrl;
		adrTable^.type = "manilaMessageReadOnly";
		adrTable^.flLastMessage = flLastMessage;
		manila.nodeTypes.addSitePrefsToAtts (adrinfo, adrTable);
		op.attributes.addGroup (adrTable)};
	local (messageHeaders = manila.message.getResponsesHeaders (@siteinfo, msgNum));
	op.go (right, 1);
	op.go (down, infinity);
	local (i);
	for i = 1 to sizeOf (messageHeaders) {
		local (flLastMessage = false);
		if i == 1 {
			flLastMessage = true};
		addMessage (@messageHeaders [i], flLastMessage)};
	op.go (left, 1)};

op.setDisplay (oldDisplay);
try {oldTarget = target.set (oldTarget)};

return (true)



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.