Monday, November 08, 2010 at 12:03 AM.
system.verbs.builtins.Frontier.tools.windowTypes.commands.saveAsPlainText
on saveAsPlainText (adr=nil, adrFilepath=nil) { <<Save as plain text. Remember that this document is a plain text document -- always save it as plain text. <<12/15/00; 5:04:18 PM by PBS <<Changes: <<12/29/00; 2:55:43 PM by PBS <<Save non file-based outlines -- such as the notepad -- as plain text. if adr == nil { adr = window.frontMost ()}; bundle { //run callbacks on runCallbacks (adrtable) { local (flConsumed = false); if defined (adrtable^) { local (adrcallback); for adrcallback in adrtable { try { //11/30/00 JES while typeOf (adrcallback^) == addressType { adrcallback = adrcallback^}; flConsumed = adrcallback^ (adr)}; if flConsumed { return (true)}}}; return (false)}; if runCallbacks (@user.tools.commandCallbacks.saveAsPlainText) { return (true)}; if system.environment.isRadio { if defined (user.pike.commandCallbacks.saveAsPlainText) { if runCallbacks (@user.pike.commandCallbacks.saveAsPlainText) { return (true)}}}}; local (adrType); bundle { //if there's a windowType that handles this command, call it if Frontier.tools.windowTypes.findWindowType (adradrtable:@adrtype, adrwindow:adr) { if defined (adrtype^.saveAsPlainText) { if adrtype^.saveAsPlainText (adr, adrFilepath) { return (false)}}}}; case typeOf (adr^) { //we only know how to render outlines and tables at this time scriptType; outlineType { local (adrtype); if Frontier.tools.windowTypes.findWindowType ("outlinerFile", @adrtype) { if defined (adrtype^.saveAsPlainText) { if not adrtype^.saveAsPlainText (adr) { return (false)}}}}}; <<bundle //old code <<local (adrParentTable = parentOf (adrItem^)) <<local (title = window.getTitle (adrItem)) <<if not window.attributes.getOne ("title", @title, adrItem) //base the filename on the window title <<local (l = string.parseAddress (adrItem)) <<local (ct = sizeOf (l)) <<if ct > 1 <<title = l[ct-1] + "." + l[ct] <<else <<title = l[ct] <<if system.environment.isMac //shorten the filename <<if sizeOf (title) > 27 <<title = l[ct] <<if sizeOf (title) > 27 <<title = string.mid (title, 1, 27) <<if string.lower (title) endsWith ".opml" <<title = string.popSuffix (title) <<if string.lower (title) endsWith ".txt" <<title = string.popSuffix (title) <<title = title + ".txt" <<local (fname = title) <<local (f = fname) <<if file.putFileDialog ("Save as plain text:", @f) <<pike.saveAsPlainText (adrItem, f) <<local (s = string (adrItem^)) <<if system.environment.isWindows //add linefeeds <<s = string.replaceAll (s, "\r", "\r\n") <<local (creator = 'Radu') <<if string.lower (f) endsWith ".py" //special case for Python scripts <<creator = 'Pyth' <<file.writeWholeFile (f, s, 'TEXT', creator, clock.now ()) <<bundle //old code fragment <<local (adrTable = parentOf (adrOutline^)) <<adrTable^.title = file.fileFromPath (f) <<window.setTitle (adrOutline, adrTable^.title) <<adrTable^.f = f <<adrTable^.lastSaved = clock.now () <<adrTable^.flOutlineDocument = false <<adrTable^.flPlainText = true <<return (Frontier.tools.windowTypes.commands.open (f)) <<else //not a local, file-based outline, but something like the notepad <<local (title = window.getTitle (adrItem)) <<local (adrTable = pike.newWindow (title, false, false)) <<adrTable^.outline = adrItem^ <<window.getPosition (adrItem, @horiz, @vert) <<edit (@adrTable^.outline, windowTitle:title) <<window.setPosition (@adrTable^.outline, horiz + 15, vert + 15) <<pike.commands.save (@adrTable^.outline) if adrFilepath != nil { //tell the caller where the file is -- used for View in Browser adrFilepath^ = f}; return (true)}; bundle { //debugging saveAsPlainText (window.frontmost ())}
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.