Monday, November 08, 2010 at 12:00 AM.
scripting2Suite.editor.save
on save (adroutline=nil) {
<<Changes
<<7/10/10; 9:22:10 AM by DW
<<Add username and server atts to the summit of the OPML sent to the server.
<<7/7/10; 8:14:32 AM by DW
<<FInally nailed the duplicate text attribute thing and at the same time unbroke the ability to change the title of a post. Here's the deal...
<<When you shoot the outline over to the server it gets the title of the post from the text attribute of the summit headline. But in actuality, inside the OPML Editor, the headline doesn't have a text attribute. It's created by op.outlinetoxml.
<<When the server returns the attributes, we dutifully attach the attributes it sends us back, including a text attribute. Now the summit has a text attribute.
<<Next time op.outlinetoxml sees it, it generates TWO text attributes, the one that came from teh linetext and the other, the text attribute the server put there. By random chance, the one the server pays attention to is the one it put there. Ooops. It can never change, no matter what happens to the linetext. As Steve Jobs says: Boom!
<<To fix it, I just delete the text attribute the server put there. Keep things the way they're supposed to work in our little world. :-)
<<7/4/10; 5:12:26 AM by DW
<<Various cleanups. Set the title of the OPML we generate and the dateCreated. Also it generates, for some unknown reason, a second text attribute on the summit headline. We get rid of it using string processing. Working around a bug somewhere.
<<7/3/10; 5:38:20 AM by DW
<<Add optional parameter, adroutline -- so it can be called from scripting2windowtypes.scripting2post.save.
<<6/14/10; 10:47:16 AM by DW
<<Save the whole workspace out as a backup.
<<6/13/10; 6:59:21 PM by DW
<<Save a local backup of the OPML file for the post.
<<8/9/08; 7:40:07 AM by DW
<<Created.
local (adrdata = scripting2suite.init (), opmltext, username, password, server, atts, data, posttext);
bundle { //set username, password, server
username = adrdata^.editor.prefs.username;
password = string (adrdata^.editor.prefs.password);
server = string (adrdata^.editor.prefs.server)};
if adroutline == nil {
adroutline = address (window.frontmost ())};
local (winhoriz, winvert, winleft, wintop);
bundle { //get window dimensions
window.getsize (adroutline, @winhoriz, @winvert);
window.getposition (adroutline, @winleft, @wintop)};
local (lo = adroutline^);
<<wp.newtextobject (op.outlinetoxml (@lo), @scratchpad.lotext)
local (oldtarget = target.set (@lo));
bundle { //set copied window position
window.setsize (@lo, winhoriz, winvert);
window.setposition (@lo, winleft, wintop)};
op.go (left, infinity);
op.attributes.getall (@atts);
local (title = op.getlinetext (), whenCreated); //7/4/10 by DW
bundle { //init atts if not already set
if not defined (atts.type) {
scripting2Suite.editor.initPostAtts (@atts);
op.attributes.addgroup (@atts)}};
bundle { //add username and server atts
local (newatts);
new (tabletype, @newatts);
newatts.username = username;
newatts.server = server;
op.attributes.addgroup (@newatts)};
bundle { //set whenCreated
if defined (atts.created) {
whenCreated = date (atts.created)}
else {
if defined (atts.whenCreated) {
whenCreated = date (atts.whenCreated)}
else {
whenCreated = clock.now ()}}};
bundle { //get opmltext
op.reorg (up, infinity);
if op.go (down, 1) {
op.demote ();
op.deleteline ()};
bundle { //set title of lo, 7/7/10 by DW
local (oldtarget = target.set (@lo));
window.settitle (@lo, title);
target.set (oldtarget)};
settimecreated (@lo, whenCreated); //7/4/10 by DW
opmltext = op.outlinetoxml (@lo);
wp.newtextobject (opmltext, @scratchpad.lotext)};
bundle { //do the save
atts = [server].scripting2.savePost (username, password, opmltext);
<<atts.flSaved = true
<<atts.whenLastSave = clock.now ()
target.set (oldtarget)};
bundle { //set the attributes
local (oldcursor = op.getcursor ());
op.go (left, infinity);
op.attributes.makeEmpty ();
if defined (atts.text) { //7/7/10 by DW
delete (@atts.text)};
op.attributes.addgroup (@atts);
op.setcursor (oldcursor)};
bundle { //save data about live-blog, 7/10/10 by DW
if defined (atts.flLiveBlog) {
if atts.flLiveBlog {
adrdata^.editor.stats.urlLiveBlog = atts.url}}};
bundle { //save the local outline
filemenu.savemyroot (adroutline)};
bundle { //local backup, 6/13/10 by DW
local (pc = file.getpathchar ());
local (folder = adrdata^.editor.prefs.backupFolder + "outlines" + pc + adrdata^.editor.prefs.username + pc);
local (fname = string.nthfield (string.lastfield (atts.url, "/"), ".", 1));
local (f = folder + file.getdatepath (thedate:date (atts.created)) + fname + ".opml");
file.surefilepath (f);
file.writewholefile (f, opmltext)};
bundle { //backup workspace, 6/14/10 by DW
scripting2Suite.editor.backupOutline ("workspace", op.outlinetoxml (@adrdata^.editor.workspace.outline))};
speaker.ouch ()}; //8/9/08 by DW
bundle { //test code
target.set (@scripting2data.editor.workspace.outline);
save ()}
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.