Re: How to validate the Undo menu item?
Re: How to validate the Undo menu item?
- Subject: Re: How to validate the Undo menu item?
- From: Dustin Voss <email@hidden>
- Date: Wed, 7 Aug 2002 16:08:50 -0700
On Monday, August 5, 2002, at 07:00 AM, Bill Cheeseman wrote:
on 02-08-05 3:06 AM, Dustin Voss at email@hidden wrote:
So I checked NSView, NSTextView, NSResponder, NSWindow, and
NSApplication,
and found that NSWindow is the one that implements the undo: method. (I
used respondsToSelector: and instancesRespondToSelector:.)
Of course, the NSWindow docs and header file say nothing about undo:. I
guess it's a private API for NSWindow, which is why it doesn't show up in
the header file, but I would have liked to have known about it. I'm torn
whether to report this as a doc bug or not. What do you guys think?
Very interesting. And does it work for validating the Undo menu item?
It does indeed! I made a simple project with an NSTextView inside a window,
and sub-classed the window in IB and PB as follows:
---------------------b---------------------
@implementation WindowExt : NSWindow
- (IBAction)undo:(id)sender
{
[super undo:sender];
NSLog (@"--- NSWindow's undo: performed.");
}
- (BOOL)validateMenuItem:(id <NSMenuItem>)item
{
BOOL retval = [super validateMenuItem:item];
NSString *sel = NSStringFromSelector([item action]);
NSLog (@"--- NSWindow's validateMenuItem: performed for %@ action.",
sel);
if ([sel isEqualToString:@"undo:"])
[item setTitle:@"Make It Not So"];
return retval;
}
@end
---------------------b---------------------
When I compiled it, I got these warningsb&
WindowExt.m: In function `-[WindowExt undo:]':
WindowExt.m:15: warning: `NSWindow' does not respond to `undo:'
WindowExt.m:15: warning: passing arg 1 of `objc_msgSendSuper' from
incompatible pointer type
b&probably because the API is privatebthough, interestingly, I did not get
a warning for bvalidateMenuItem:b. I ran the program anyway, and it worked.
The bUndob menu item was titled bMake It Not Sob, was correctly enabled
or disabled, and kept the bbZb keyboard shortcut. When I selected it, it
undid my typing.
So, there's that mystery solved! Now, should this be documented?
P.S. Is there a better way to check for equality of SELs?
--
Dustin
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.