Skip navigation.
 
mlRe: Undo manager
FROM : Lorenzo
DATE : Wed Apr 06 15:28:16 2005

Hi,
I habe been trying 2 points where to create the undoManager with
   
    gMyUndoManager = [[NSUndoManager alloc] init];
   
    1. in the awakeFromNib of an NSObject which is the window's delegate.
    2. in the awakeFromNib of the window subclass itself.

Same result: the undo works, but the Undo and Redo menu item titles report
all the time a simple "Undo" and "Redo". And more, the Undo and Redo
commands are always enabled.
I have found that the problem is related to the fact that the window is
subclassed. In fact, if I don't subclass the window, everything works fine.
When I subclass the window I also override the method validateMenuItem
because I need that. So, now in order to see the complete Undo menu item
title and to activate and deactvate these menu items now I have to add these
code lines in the validateMenuItem method.

- (BOOL)validateMenuItem:(NSMenuItem*)theItem
{
    int tag = [theItem tag];
    switch(tag){
        case kMenuTagEditUndo :
            if([[self undoManager] canUndo]){
                [theItem setTitle:[[self undoManager] undoMenuItemTitle]];
                return YES;
            }
            else return NO;
        break;

        // other cases...
    }
    return YES; // this caused the 2 menu ites were always enabled
    // now it is return NO;
}


The PROBLEM now is that the method undoMenuItemTitle returns a string
starting with a "&" (amazing, why?) so I get something like
    "&Undo Move Object"
    "&Redo Move Object"

This seems to be a Cocoa bug. Anyway, why should I manage the undo menu
items by myself? Just because I override the validateMenuItem method?


Best Regards
--
Lorenzo
email: <email_removed>

> From: Jonathon Mah <<email_removed>>
> Date: Wed, 06 Apr 2005 20:59:04 +0930
> To: Lorenzo <<email_removed>>
> Cc: Cocoa List <<email_removed>>
> Subject: Re: Undo manager
>
> On 6 Apr 2005, at 20:53, Lorenzo wrote:
>

>> Also, I have seen that, when I launch the application, the menus
>> "Undo" and
>> "Redo" are deactivated. This is right. But when I activate that window
>> (even
>> clicking on its window bar), the "Undo" and "Redo" menu items become
>> activated. And no action (obvious) is performed when I call them. Why?

>
> When/where are you creating the undo manager?
>
>
> Jonathon Mah
> <email_removed>
>

Related mailsAuthorDate
mlUndo manager Lorenzo Mar 16, 00:01
mlRe: Undo manager Robert Clair Mar 16, 00:42
mlRe: Undo manager Lorenzo Apr 6, 10:56
mlRe: Undo manager Lorenzo Apr 6, 13:23
mlRe: Undo manager Jonathon Mah Apr 6, 13:29
mlRe: Undo manager Lorenzo Apr 6, 15:28
mlRe: Undo manager Jonathon Mah Apr 6, 16:57
mlRe: Undo manager Lorenzo Apr 6, 17:40