From fd88c0e77b5df9e89556f2183632504fab70a4ee Mon Sep 17 00:00:00 2001 From: gcasa Date: Sun, 16 Jan 2005 11:38:23 +0000 Subject: [PATCH] Further undo improvements. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20562 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 ++++++ Source/NSDocument.m | 50 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c2484775..1963d0a0a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-01-16 06:39 Gregory John Casamento + + * Source/NSDocument.m: In validateMenuItem: added code to + properly set the undo/redo title and disable the menus when + appropriate. + 2005-01-15 05:59 Gregory John Casamento * Source/NSDocument.m: Added undo:/redo: here. Smarter use diff --git a/Source/NSDocument.m b/Source/NSDocument.m index 5ce144c48..c2210ae41 100644 --- a/Source/NSDocument.m +++ b/Source/NSDocument.m @@ -579,12 +579,56 @@ - (BOOL)validateMenuItem: (NSMenuItem *)anItem { - if ([anItem action] == @selector(revertDocumentToSaved:)) - return ([self fileName] != nil && [self isDocumentEdited]); + BOOL result = YES; + SEL action = [anItem action]; // FIXME should validate spa popup items; return YES if it's a native type. + if (sel_eq(action, @selector(revertDocumentToSaved:))) + { + result = ([self fileName] != nil && [self isDocumentEdited]); + } + else if (sel_eq(action, @selector(undo:))) + { + if(_undoManager == nil) + { + result = NO; + } + else + { + if([_undoManager canUndo]) + { + [anItem setTitle: [_undoManager undoMenuItemTitle]]; + result = YES; + } + else + { + [anItem setTitle: [_undoManager undoMenuTitleForUndoActionName: @""]]; + result = NO; + } + } + } + else if (sel_eq(action, @selector(redo:))) + { + if(_undoManager == nil) + { + result = NO; + } + else + { + if([_undoManager canRedo]) + { + [anItem setTitle: [_undoManager redoMenuItemTitle]]; + result = YES; + } + else + { + [anItem setTitle: [_undoManager redoMenuTitleForUndoActionName: @""]]; + result = NO; + } + } + } - return YES; + return result; } - (BOOL)validateUserInterfaceItem: (id )anItem