[Openmcl-devel] Forwarding main menu action to the hemlock-listener-document

Paul Krueger plkrueger at comcast.net
Wed Jul 20 14:43:20 PDT 2011


Let me start by assuming you're on a Mac using Cocoa. I have no idea how such things work on Cocotron.

By default undo and redo don't DO anything other than invoke a function that you've already provided. At the time some action is taken by your app code it needs to register an appropriate "undo" function that reverses that action with the document's undo manager (each document has its own). So in principle you shouldn't want or need those menu items to do anything different from what they already do. You just want to register the proper undo function in the first place. In my contrib 
directory I have examples, helper code, sample code, and quite a bit of documentation about how to implement undo/redo in Lisp code. See the InterfaceBuilderWithCCLTutorial file in the document directory for some of this. The undo.lisp source file in my contrib has some easy code to register an undo function, but it's specific to subclasses of my lisp-document class. A search should turn up examples of how that is used. More primitive usage of the base undo functionality is shown in other examples (search for prepareWithInvocationTarget:) in my files.

If you have your own type of document, this could be fairly straight-forward (you might consider inheriting from my lisp-document class to get an easy lisp interface for undo functionality). 

If you are trying to piggy-back on top of a hemlock window and modify the way that it does undo/redo by default, then things will get trickier. Doing a little search, it looks to me like Hemlock windows make calls to register things with the undo manager in four places in the code (search files for prepareWithInvocationTarget: and you will find those). These are Objective-C methods specialized for hemlock-text-storage objects. If it makes sense for your app to create a subclass of that class and convince a hemlock window to use your class somehow, then I imagine that you could create your own objective-C method that superseded that of the parent class and when desired called the parent method. Each would be the Objective-C equivalent of a Lisp :around method. Remember that this method is just registering an undo method not actually taking some action to undo something. It's not clear to me whether your application would want to register an undo function in exactly the same place that Hemlock does, so none of this may make sense for your app.

If you dig through the way that I implemented undo in various examples, that should give you a start. Let me know if you have specific questions that I can help with after that. 

Apple also has documentation about undo/redo functionality. See http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/UndoArchitecture/UndoArchitecture.html 

I'm not sure, you may need to be a registered Apple developer to see these.


On Jul 20, 2011, at 1:11 PM, Michael Minerva wrote:

> Hello All,
> I am working on creating the main menu for my application and I ran into a little problem.  My application is going to need special functionality for for some main menu items like undo and redo but I would also like to be able forward these actions to the default implementation of #/undo: and #/redo:.  Is there any documentation about how one might do this (I had trouble finding any)?  Would it be best to override either the hemlock-listener-document or the hemlock-listener-document-controller?  
> --Mike
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list