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

on revert (adr = nil) {
	<<Revert a window.
			<<03/24/00; 7:24:20 PM by PBS
				<<This command was seriously broken -- now it's fixed. It works again for advanced items and stories.
			<<Fri, Jul 7, 2000 at 11:00:09 PM by AR
				<<Call any scripts in user.pike.commandCallbacks.revert
				<<If one of the scripts returns true, we're done
			<<07/24/00; 12:37:39 PM by PBS
				<<Handle reverting local XML outline documents.
			<<10/03/00; 6:39:09 PM by PBS
				<<Callbacks can be addresses.
			<<11/30/00; 12:17:04 AM by JES
				<<Dereference callback addresses in a try block in case a tool's odb is not opened
	if adr == nil {
		try {
			adr = window.frontmost ()}
		else {
			return (false)}};
	on askForConfirmation (s) {
		return (dialog.twoWay ("Discard all changes made to " + s + "?", "Discard", "Cancel"))};
	on runCallbacks (adrcallbacks) {
		if defined (adrcallbacks^) {
			local (adrcallback);
			for adrcallback in adrcallbacks {
				try { //11/30/00 JES
					while typeOf (adrcallback^) == addressType { //follow addresses
						adrcallback = adrcallback^};
					flConsumed = adrcallback^ (adr)};
				if flConsumed {
					return (true)}}};
		return (false)};
	if runCallbacks ( {
		return (true)};
	if system.environment.isRadio {
		if defined (user.pike.commandCallbacks) {
			if runCallbacks (@user.pike.commandCallbacks.revert) {
				return (true)}}};
	bundle { //run the windowType script if it exists
		local (type);
		if window.attributes.getOne ("type", @type, adr) {
			local (adrtype);
			if (type, @adrtype, adr) {
				if defined (adrtype^.revert) {
					if (adr) {
						local (title = window.getTitle (adr));
						window.attributes.getOne ("title", @title, adr); //we don't care if this doesn't work
						if askForConfirmation (title) {
							local (adrNewWindow);
							if adrtype^.revert (adr, @adrNewWindow) {
								<<lastSaved may already have been set by the windowType, but we do it here too just in case.
								window.attributes.setOne ("lastSaved", timeModified (adrNewWindow), adrNewWindow);
								return (true)}}}}}}};
	return (false);
	<<bundle //old code for reverting Manila windows
		<<if adrItem!= nil
			<<local (flConsumed = false)
			<<if defined (user.pike.commandCallbacks.revert)
				<<local (adrcallback)
				<<for adrcallback in @user.pike.commandCallbacks.revert
					<<try //11/30/00 JES
						<<while typeOf (adrcallback^) == addressType //follow addresses
							<<adrcallback = adrcallback^
						<<flConsumed = adrcallback^ (adrItem)
					<<if flConsumed
			<<if not flConsumed
				<<on askForConfirmation (s)
					<<return (dialog.twoWay ("Discard all changes made to " + s + "?", "Discard", "Cancel"))
				<<bundle //PBS 07/24/00: handle local outlines
					<<if pike.isLocalOutline (adrItem)
						<<local (adrTable = parentOf (adrItem^))
						<<if defined (adrTable^.f)
							<<if file.exists (adrTable^.f)
								<<local (title = adrTable^.title)
								<<if askForConfirmation (title)
									<<window.close (adrItem)
									<< (adrTable^.f)
									<< ()
									<<return (true)
				<<local (windowType = pike.getWindowType (adrItem))
				<<if windowType != ""
					<<local (adrTable = parentOf (adrItem^))
					<<case windowType //can't revert "newStories"
							<<if not askForConfirmation ("the " + adrTable^.iteminfo.type)
								<<return (false)
							<<local (handlerName = pike.advancedItemToHandlerName (adrTable^.itemInfo.type))
							<<local (t = manila.[handlerName].get (@adrTable^.siteInfo))
							<<adrTable^.itemInfo.body = string (t.body)
							<<pike.commands.editAdvancedItem (adrTable^.siteInfo, adrTable^.itemInfo, false)
							<<local (adrStory = @adrTable^.storyinfo)
							<<if not askForConfirmation ("\"" + adrStory^.subject + "\"")
								<<return (false)
							<<adrStory^ = manila.message.get (@adrTable^.siteinfo, adrStory^.msgnum)
							<<if defined (adrStory^.bodyType)
								<<if string.lower (adrStory^.bodyType) == "text/x-outline-tabbed"
									<<adrStory^.body = string (adrStory^.outline)
							<<pike.commands.editStory (adrTable^.siteInfo, adrTable^.storyInfo, false)
		<< ()
		<<return (true)

bundle { //debugging
	revert (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.