"undo:" action vs. NSWindow
"undo:" action vs. NSWindow
- Subject: "undo:" action vs. NSWindow
- From: Robb Olsen-Albright <email@hidden>
- Date: Tue, 21 Nov 2006 09:51:40 -0800
I'm having an issue with undo support in a non-document-based app.
I 'm working on converting the OS layer of a cross platform app to
Cocoa.
So, we have a cross-platform undo manager in our C++ logic code. this
means I don't need or want an app level NSUndoManager.
I do, however, want Undo/Redo to automatically work in dialogue text
fields.
In order to do that, we have undo: & redo: methods in the Application
delegate, that just reroute to the cross platform command handler.
(We also do menu validation in a validateMenuItem: method in the same
app delegate.)
The problem is, NSWindow gets in the way. When the menu validation
code goes through the responder chain, it gets to NSWindow and ends
up using a default NSUndoManager that NSWindow provides. Then
validateMenuItem gets sent to the window since it (or a delegate)
implements undo:, which since the undo manager it's using doesn't
have anything to undo, returns NO.
Thus, my undo/redo menu items are never enabled
From http://developer.apple.com/documentation/Cocoa/Conceptual/
UndoArchitecture/Tasks/UsingUndoAppKit.html :
NSResponder declares the undoManager method for most objects that
inherit from it (namely, windows and views). When the first
responder of an application receives an undo or redo message,
NSResponder goes up the responder chain looking for a next
responder that returns an NSUndoManager object from undoManager .
Any returned NSUndoManager object is used for the undo or redo
operation. If the undoManager message wends its way up the
responder chain to the window, the NSWindow object queries its
delegate with windowWillReturnUndoManager: to see if the delegate
has an NSUndoManager. If the delegate does not implement this
method, the NSWindow creates an NSUndoManager for the window and
all its views.
Based on this info, i tried returning nil from
windowWillReturnUndoManager: in the app delegate, but the same thing
happens.
So, I determined that I can subclass NSWindow, override
validateMenuItem, then call cross platform code to set the undo menu
item string and return the actual status.
However, I have no other reason to subclass NSWindow, and it seems to
me to split the menu behaviour too much to do that just for this issue.
NSDocument has a setHasUndoManager:NO , but I 'm not doc-based (from
a cocoa standpoint), so can't do that, and handling the delegate
message to return nil when asked for Undo manager doesn't turn this off.
So , o wise list denizens, does anyone know of a way to turn off
NSWindow's behaviour noted in the last quoted sentence above?
That is, to disable all automatic handling of undo by NSWindow.
Thanks very much for any help anyone can provide, or directions
towards which you can point me.
-robb
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins (at) lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden