Panorama X uses Apple’s code for all opening, saving and reverting of files. This is done thru an Objective-C class called NSDocument. When a program uses NSDocument, it automatically gets all of the standard document handling features – auto-save, versioning, etc. The problem is that Apple designed this in such a way that it is very difficult to get in and customize what is happening, and Apple’s engineers never imagined that an application would offer a programming language that would allow end-users to get in an try to make customizations.
When using NSDocument, the revert command rewinds the file back to the last time File>Save was used. I think the problem may be that the save statement in Panorama’s programming language isn’t quite the same thing as using File>Save. Unfortunately, Apple’s documentation on this is poor – non-existant really.
There is a way that you can invoke the File>Save command in programming code, using the sendaction statement. Here’s a possible revised version of your code:
You should try this, but my guess is that it won’t work, or won’t work reliably. I believe that the File>Save command is asynchronous – in other words, the saving happens in the background. So it’s possible that the save operation might still be going at the time the revert statement is run.
The saving code used by the save statement is also asynchronous, but this statement has code that waits until the save is complete before letting the program advance to the next statement.
As you mention, there is no undo statement, but you can use sendaction to trigger an undo. So you might try this.
startdatabasechange "currentrecord" // adjust this if more than one record will change, your app probably needs "allrecords"
Again, there may be an asynchronous aspect of undo, I’m not sure, so if there are additional statements after the sendaction, they may run before the undo is finished. Probably best if the undo can be the final statement in the code.
The sendaction statement is basically a way to access internal code in Panorama and the operating system. In fact, in both of these examples, Apple code is being directly triggered. So this isn’t something that I can support, but it does give you options to try.