Use the first responder's undo manager in an NSWindow's undo: and

redo: actions if available. Avoids the need for overriding these
methods in any responder class which supports undo/redo and is
compatible with OS X.
Generalize user interface validation for NSWindow.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29158 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2009-12-22 00:14:16 +00:00
parent a059f4a0c9
commit 126f60f6db
2 changed files with 41 additions and 29 deletions

View file

@ -1,3 +1,14 @@
2009-12-22 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSWindow.m (-validateUserInterfaceItem):
* Source/NSWindow.m (-validateMenuItem): Generalize user interface
validation for NSWindow.
* Source/NSWindow.m (-undo:, -redo:): Use the first responder's
undo manager if available. Avoids the need for overriding these
methods in any responder class which supports undo/redo and is
compatible with OS X.
2009-12-22 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSAlert.m (makeScrollViewWithRect):

View file

@ -3045,12 +3045,12 @@ resetCursorRectsForView(NSView *theView)
- (void) undo: (id)sender
{
[[self undoManager] undo];
[[_firstResponder undoManager] undo];
}
- (void) redo: (id)sender
{
[[self undoManager] redo];
[[_firstResponder undoManager] redo];
}
/**
@ -4908,7 +4908,7 @@ current key view.<br />
* Menu item validation
*/
- (BOOL) validateMenuItem: (NSMenuItem *)anItem
- (BOOL) validateUserInterfaceItem: (id <NSValidatedUserInterfaceItem>)anItem
{
BOOL result = YES;
SEL action = [anItem action];
@ -4927,43 +4927,41 @@ current key view.<br />
}
else if (sel_eq(action, @selector(undo:)))
{
NSUndoManager *undo = [self undoManager];
NSUndoManager *undo = [_firstResponder undoManager];
if (undo == nil)
{
result = NO;
}
else
{
if ([undo canUndo])
result = [undo canUndo];
if ([(id)anItem respondsToSelector: @selector(setTitle:)])
{
[anItem setTitle: [undo undoMenuItemTitle]];
result = YES;
}
else
{
[anItem setTitle: [undo undoMenuTitleForUndoActionName: @""]];
result = NO;
if (result)
[(id)anItem setTitle: [undo undoMenuItemTitle]];
else
[(id)anItem setTitle:
[undo undoMenuTitleForUndoActionName: @""]];
}
}
}
else if (sel_eq(action, @selector(redo:)))
{
NSUndoManager *undo = [self undoManager];
NSUndoManager *undo = [_firstResponder undoManager];
if (undo == nil)
{
result = NO;
}
else
{
if ([undo canRedo])
result = [undo canRedo];
if ([(id)anItem respondsToSelector: @selector(setTitle:)])
{
[anItem setTitle: [undo redoMenuItemTitle]];
result = YES;
}
else
{
[anItem setTitle: [undo redoMenuTitleForUndoActionName: @""]];
result = NO;
if (result)
[(id)anItem setTitle: [undo redoMenuItemTitle]];
else
[(id)anItem setTitle:
[undo redoMenuTitleForUndoActionName: @""]];
}
}
}
@ -4977,15 +4975,13 @@ current key view.<br />
}
else
{
if ([toolbar isVisible])
result = YES;
if ([(id)anItem respondsToSelector: @selector(setTitle:)])
{
[anItem setTitle: _(@"Hide Toolbar")];
result = YES;
}
else
{
[anItem setTitle: _(@"Show Toolbar")];
result = YES;
if ([toolbar isVisible])
[(id)anItem setTitle: _(@"Hide Toolbar")];
else
[(id)anItem setTitle: _(@"Show Toolbar")];
}
}
}
@ -4993,6 +4989,11 @@ current key view.<br />
return result;
}
- (BOOL) validateMenuItem: (NSMenuItem *)anItem
{
return [self validateUserInterfaceItem: anItem];
}
/*
* Assigning a delegate
*/