Tuesday, February 08, 2011 at 1:06 AM.


on newPost (title=nil, dir=nodirection) {
		<<2/5/11; 2:27:26 PM by DW
			<<Add optional param, dir. If it's not nodirection, the caller knows where the new node is to be inserted, so we don't screw with location and direction. 
		<<7/7/10; 7:35:24 AM by DW
			<<Add an optional parameter that allows the caller to tell us what the title of the new post is.
		<<6/29/10; 7:31:12 AM by DW
			<<Call scripting2Suite.editor.opInsertCallback to generate the attributes for a new paragraph line.
		<<6/1/10; 10:36:19 AM by DW
			<<Insert a new headline to the right when creating a new post.
	local (adrdata = scripting2suite.init (), serverAtts);
	bundle { //prompt the user for the title, if necessary
		if title == nil { //7/7/10 by DW
			if not dialog.ask ("Title for new post?", @adrdata^.prefs.lastNewPostTitle) {
			title = adrdata^.prefs.lastNewPostTitle}};
	bundle { //get the serverAtts for the new post, 7/3/10 by DW
		local (username = adrdata^.editor.prefs.username);
		local (password = string (adrdata^.editor.prefs.password));
		local (server = string (adrdata^.editor.prefs.server));
		serverAtts = [server].scripting2.newPost (username, password, title)};
	bundle { //insert the title headline
		if dir == nodirection { //2/5/11 by DW
			op.firstsummit ();
			if op.getlinetext () == "" {
				op.setlinetext (title)}
			else {
				op.insert (title, up)}}
		else {
			op.insert (title, dir)}};
	bundle { //attach the server atts
		scripting2Suite.editor.initPostAtts (@serverAtts);
		op.attributes.addgroup (@serverAtts)};
	bundle { //insert a blank line to start the post
		op.insert ("", right); //8/9/08 by DW
		scripting2Suite.editor.opInsertCallback (); //6/29/10 by DW
		wp.settextmode (true)}}; //8/9/08 by DW
bundle { //test code
	newPost ("Hello World")}

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.