Implement undo: and redo: responder actions in NSWindow as on Mac OS X.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27218 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2008-12-06 10:58:38 +00:00
parent 7f9939a624
commit fe56e4959d
3 changed files with 85 additions and 50 deletions

View file

@ -1,3 +1,10 @@
2008-12-06 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSDocument.m (-undo:, -redo:, -validateMenuItem:): Move
implementation from here ...
* Source/NSWindow.m (-undo:, -redo:, -validateMenuItem:): ... to
here. Also validate close, miniaturize, and zoom actions.
2008-12-06 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSSound.m:

View file

@ -1319,46 +1319,6 @@ originalContentsURL: (NSURL *)orig
{
result = ([self fileName] != nil && [self isDocumentEdited]);
}
else if (sel_eq(action, @selector(undo:)))
{
if (_undo_manager == nil)
{
result = NO;
}
else
{
if ([_undo_manager canUndo])
{
[anItem setTitle: [_undo_manager undoMenuItemTitle]];
result = YES;
}
else
{
[anItem setTitle: [_undo_manager undoMenuTitleForUndoActionName: @""]];
result = NO;
}
}
}
else if (sel_eq(action, @selector(redo:)))
{
if (_undo_manager == nil)
{
result = NO;
}
else
{
if ([_undo_manager canRedo])
{
[anItem setTitle: [_undo_manager redoMenuItemTitle]];
result = YES;
}
else
{
[anItem setTitle: [_undo_manager redoMenuTitleForUndoActionName: @""]];
result = NO;
}
}
}
return result;
}
@ -1743,14 +1703,4 @@ originalContentsURL: (NSURL *)orig
[self updateChangeCount: NSChangeDone];
}
- (void) undo: (id)sender
{
[[self undoManager] undo];
}
- (void) redo: (id)sender
{
[[self undoManager] redo];
}
@end

View file

@ -50,6 +50,7 @@
#include <Foundation/NSSet.h>
#include <Foundation/NSLock.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSUndoManager.h>
#include "AppKit/NSApplication.h"
#include "AppKit/NSButton.h"
@ -2979,6 +2980,16 @@ resetCursorRectsForView(NSView *theView)
}
}
- (void) undo: (id)sender
{
[[self undoManager] undo];
}
- (void) redo: (id)sender
{
[[self undoManager] redo];
}
/**
If YES, then the window is released when the close method is called.
*/
@ -4753,6 +4764,73 @@ current key view.<br />
_f.displays_when_screen_profile_changes = flag;
}
/*
* Menu item validation
*/
- (BOOL)validateMenuItem: (NSMenuItem *)anItem
{
BOOL result = YES;
SEL action = [anItem action];
if (sel_eq(action, @selector(performClose:)))
{
result = ([self styleMask] & NSClosableWindowMask) ? YES : NO;
}
else if (sel_eq(action, @selector(performMiniaturize:)))
{
result = ([self styleMask] & NSMiniaturizableWindowMask) ? YES : NO;
}
else if (sel_eq(action, @selector(performZoom:)))
{
result = ([self styleMask] & NSResizableWindowMask) ? YES : NO;
}
else if (sel_eq(action, @selector(undo:)))
{
NSUndoManager *undo = [self undoManager];
if (undo == nil)
{
result = NO;
}
else
{
if ([undo canUndo])
{
[anItem setTitle: [undo undoMenuItemTitle]];
result = YES;
}
else
{
[anItem setTitle: [undo undoMenuTitleForUndoActionName: @""]];
result = NO;
}
}
}
else if (sel_eq(action, @selector(redo:)))
{
NSUndoManager *undo = [self undoManager];
if (undo == nil)
{
result = NO;
}
else
{
if ([undo canRedo])
{
[anItem setTitle: [undo redoMenuItemTitle]];
result = YES;
}
else
{
[anItem setTitle: [undo redoMenuTitleForUndoActionName: @""]];
result = NO;
}
}
}
return result;
}
/*
* Assigning a delegate
*/