Monday, November 08, 2010 at 12:01 AM.
system.verbs.apps.Manila.windowTypes.types.manilaMessage.save
on save (adr, flClosing=false, subject=nil) {
<<Save a manila message.
<<7/8/01; 12:21:11 AM by JES
<<Cribbed from various places, primarily pike.commands.save.
<<9/22/01; 5:48:19 PM by JES
<<Fixed a bug when doing a Save As, where the msg in the about window would display the old subject, instead of the new one.
local (atts);
window.attributes.getAll (@atts, adr);
if atts.flReadOnly { //read only windows can't be saved
return (true)};
try { //if tcp.isOffline, show a dialog, and then return false
if tcp.isOffline () {
dialog.alert ("Can't save " + atts.title + " because you are working offline.");
return (false)}};
local (adrinfo = atts.adrSiteInfo, username, password);
if manila.windowTypes.getUsernameAndPassword (adrinfo, @username, @password) {
manila.windowTypes.setUsernameAndPassword (adrinfo, username, password)}
else { //the user cancelled the password dialog -- return false
return (false)};
local (siteInfoTable = adrinfo^);
siteInfoTable.username = username;
siteInfoTable.password = password;
if subject != nil { //this is a Save As: set the subject and window title
atts.subject = subject};
msg ("Saving \"" + adrinfo^.displaySiteName + ": " + atts.subject + "\"...");
local (bodyType);
if adrinfo^.flAcceptsOpml { //set bodyType to text/x-opml
bodyType = "text/x-opml"}
else { //set bodyType to text/x-outline-tabbed
bodyType = "text/x-outline-tabbed"};
local (windowInfo = manila.windowTypes.getWindowInfoTable (adr));
local (rendererInfo);
if defined (atts.rendererInfo) { //preserve rendererInfo
rendererInfo = atts.rendererInfo};
on error (s) {
window.attributes.setOne ("savingError", s, adr);
dialog.alert (tryError);
return (false)};
local (response);
if defined (atts.msgnum) { //save a pre-existing message
try { //do the RPC call to save the message
if adrinfo^.flAcceptsOpml { //send the opml to the server
local (opmlText = op.outlineToXml (adr, ownerEmail:adrinfo^.username));
response = manila.message.set (adrinfo, atts.msgnum, atts.subject, opmlText, bodyType, windowInfo, rendererInfo)}
else { //send the tabbed-outline to the server
response = manila.message.set (adrinfo, atts.msgnum, atts.subject, string (adrItem^), bodyType, windowInfo, rendererInfo)}}
else { //error making the RPC call
return (error (tryError))};
bundle { //set attributes, window title, needed for Save As to work
local (t); new (tableType, @t);
local (windowTitle = adrinfo^.displaySiteName + ": " + atts.subject);
window.setTitle (adr, windowTitle);
t.title = windowTitle;
t.subject = atts.subject;
window.attributes.addGroup (@t, adr)}}
else { //save a new message
try { //do the RPC call to save the message
if adrinfo^.flAcceptsOpml { //send the opml to the server
local (opmlText = op.outlineToXml (adr, ownerEmail:adrinfo^.username));
response = manila.message.create (adrinfo, atts.subject, opmlText, bodyType, atts.inResponseTo, windowInfo, rendererInfo)}
else { //send the tabbed-outline to the server
response = manila.message.create (adrinfo, subject, string (adr^), bodyType, inResponseTo, windowInfo, rendererInfo)}}
else { //error making the RPC call
msg (""); //clear the about window
return (error (tryError))};
bundle { //add attributes
local (t); new (tableType, @t);
t.msgnum = response.msgnum;
t.url = response.url;
window.attributes.addGroup (@t, adr)};
if atts.flAddToStoriesList {
manila.message.addToStoriesList (adrinfo, response.msgnum)};
if not flClosing { //check out the message
manila.message.checkOut (adrinfo, response.msgnum)}};
msg ("");
return (true);
};
<<bundle //old code
<<local (windowType = pike.getWindowType (adrItem))
<<if windowType != ""
<<
<<if not (playlist.tcpOkay ()) //PBS 09/22/00: check offline status
<<return (false)
<<
<<local (adrTable = parentOf (adrItem^))
<<
<<local (bodyType = "text/x-outline-tabbed")
<<
<<local (windowInfoTable = pike.buildWindowInfoTable (adrItem)) //PBS 02/05/00: get the window info table
<<
<<local (flServerAcceptsOpml = false)
<<if defined (adrTable^.siteInfo.flAcceptsOpml) //11/03/00 JES
<<flServerAcceptsOpml = adrTable^.siteInfo.flAcceptsOpml
<<case windowType
<<"advancedItems"
<<local (itemTypeName = nameOf (adrTable^))
<<msg ("Saving " + itemTypeName + "...")
<<local (handlerName = pike.advancedItemToHandlerName (itemTypeName))
<<try
<<local (s = string (adrItem^))
<<if defined (adrTable^.itemInfo.adrSerializeRoutine) //PBS 08/23/00: call serialization routine if there is one
<<if defined (adrTable^.itemInfo.adrSerializeRoutine^)
<<s = adrTable^.itemInfo.adrSerializeRoutine^ (adrTable)
<<if defined (manila.[handlerName].set)
<<manila.[handlerName].set (@adrTable^.siteinfo, s, windowInfoTable)
<<else //PBS 11/20/00: use generic save routine
<<manila.advancedPref.set (@adrTable^.siteInfo, itemTypeName, s, windowInfoTable)
<<else
<<savingError ("the " + itemTypeName)
<<adrTable^.lastSaved = clock.now ()
<<"savedStories"
<<if flServerAcceptsOpml
<<bodyType = "text/x-opml"
<<local (subject = adrTable^.storyinfo.subject)
<<msg ("Saving \"" + subject + "\"...")
<<local (adrStory = @adrTable^.storyinfo)
<<try
<<if flServerAcceptsOpml //11/03/00 JES
<<local (opmlText = op.outlineToXml (adrItem, ownerEmail:adrTable^.siteInfo.username))
<<manila.message.set (@adrTable^.siteinfo, adrStory^.msgnum, adrStory^.subject, opmlText, bodyType, windowInfoTable) //PBS 02/05/00: added windowInfoTable parameter
<<else
<<manila.message.set (@adrTable^.siteinfo, adrStory^.msgnum, adrStory^.subject, string (adrItem^), bodyType, windowInfoTable) //PBS 02/05/00: added windowInfoTable parameter
<<else
<<temp.errorText = tryError
<<savingError ("\"" + subject + "\"")
<<adrTable^.lastSaved = clock.now ()
<<"newStories"
<<if flServerAcceptsOpml
<<bodyType = "text/x-opml"
<<local (subject = adrTable^.storyinfo.subject)
<<msg ("Saving \"" + subject + "\"...")
<<
<<local (resulttable)
<<try
<<local (inResponseTo = 0)
<<if defined (adrTable^.storyInfo.inResponseTo)
<<inResponseTo = adrTable^.storyInfo.inResponseTo
<<if flServerAcceptsOpml //11/03/00 JES
<<local (opmlText = op.outlineToXml (adrItem, ownerEmail:adrTable^.siteInfo.username))
<<resulttable = manila.message.create (@adrTable^.siteinfo, subject, opmlText, bodyType, inResponseTo, windowInfoTable)
<<else
<<resulttable = manila.message.create (@adrTable^.siteinfo, subject, string (adrItem^), bodyType, inResponseTo, windowInfoTable)
<<else
<<temp.errorText = tryError
<<savingError ("\"" + subject + "\"")
<<
<<if not flClosing //copy to savedStories
<<local (adrStoryTable = pike.getStoryTableAddress (@adrTable^.siteinfo, resulttable.msgnum))
<<adrStoryTable^.siteinfo = adrTable^.siteinfo
<<adrStoryTable^.storyinfo = resulttable
<<
<<table.move (adrItem, adrStoryTable)
<<pike.setWindowTitle (adrStoryTable)
<<
<<adrTable^.storyinfo.url = adrStoryTable^.storyinfo.url //12/20/00 JES: make view in browser work for new stories
<<
<<adrStoryTable^.lastSaved = clock.now ()
<<
<<local (flAddToStoriesList = true) //PBS 08/22/00: if flAddToStoriesList exists and is false, don't add to stories. This way we can have messages that aren't stories.
<<if defined (adrTable^.storyInfo.flAddToStoriesList)
<<if not (adrTable^.storyInfo.flAddToStoriesList)
<<flAddToStoriesList = false
<<if flAddToStoriesList
<<manila.message.addToStoriesList (@adrTable^.siteinfo, resulttable.msgnum)
bundle { //debugging
save (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.