mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
In NSMenu compare target for identity not equality.
Decoding and encoding for NSWindowController. Extend the responder chain of a window beyond itself. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@26959 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
56388864db
commit
2b3ec299c9
4 changed files with 103 additions and 81 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2008-10-24 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSMenu.m (-indexOfItemWithTarget:andAction:): Compare the
|
||||
target for identity not equality.
|
||||
* Source/NSWindowController.m (+initialize,
|
||||
-initWithCoder:,-encodeWithCoder:): Add encoding and decoding, just
|
||||
calling super.
|
||||
Patch by Wolfgang Lux <wolfgang.lux@gmail.com>.
|
||||
* Source/NSApplication.m (-targetForAction:forWindow:): New helper
|
||||
method. Don't stop at the window itself, when going up the
|
||||
responder chain.
|
||||
* Source/NSApplication.m (-targetForAction:): Use the new helper
|
||||
method.
|
||||
|
||||
2008-10-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/AppKit/NSWindowController.h: Make a subclass of NSResponder.
|
||||
|
|
|
@ -2036,6 +2036,43 @@ IF_NO_GC(NSAssert([event retainCount] > 0, NSInternalInconsistencyException));
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper method to avoid duplicating code for key and main window
|
||||
*/
|
||||
- (id) targetForAction: (SEL)aSelector forWindow: (NSWindow *)window
|
||||
{
|
||||
id resp;
|
||||
|
||||
resp = [window firstResponder];
|
||||
while (resp != nil && resp != self)
|
||||
{
|
||||
if ([resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
resp = [resp nextResponder];
|
||||
}
|
||||
|
||||
resp = [window delegate];
|
||||
if (resp != nil && [resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
|
||||
if ([NSDocumentController isDocumentBasedApplication])
|
||||
{
|
||||
resp = [[NSDocumentController sharedDocumentController]
|
||||
documentForWindow: window];
|
||||
|
||||
if (resp != nil && [resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns the target object that will respond to aSelector, if any. The
|
||||
|
@ -2047,43 +2084,19 @@ IF_NO_GC(NSAssert([event retainCount] > 0, NSInternalInconsistencyException));
|
|||
*/
|
||||
- (id) targetForAction: (SEL)aSelector
|
||||
{
|
||||
NSWindow *keyWindow;
|
||||
NSWindow *mainWindow;
|
||||
id resp;
|
||||
NSWindow *keyWindow;
|
||||
NSWindow *mainWindow;
|
||||
id resp;
|
||||
|
||||
if (aSelector == NULL)
|
||||
return nil;
|
||||
|
||||
keyWindow = [self keyWindow];
|
||||
if (keyWindow != nil)
|
||||
{
|
||||
resp = [keyWindow firstResponder];
|
||||
while (resp != nil && resp != keyWindow)
|
||||
{
|
||||
if ([resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
resp = [resp nextResponder];
|
||||
}
|
||||
if ([keyWindow respondsToSelector: aSelector])
|
||||
{
|
||||
return keyWindow;
|
||||
}
|
||||
|
||||
resp = [keyWindow delegate];
|
||||
if (resp != nil && [resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
|
||||
if ([NSDocumentController isDocumentBasedApplication])
|
||||
{
|
||||
resp = [[NSDocumentController sharedDocumentController]
|
||||
documentForWindow: keyWindow];
|
||||
|
||||
if (resp != nil && [resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
resp = [self targetForAction: aSelector forWindow: keyWindow];
|
||||
if (resp != nil)
|
||||
return resp;
|
||||
}
|
||||
|
||||
if (_session != 0)
|
||||
|
@ -2092,50 +2105,25 @@ IF_NO_GC(NSAssert([event retainCount] > 0, NSInternalInconsistencyException));
|
|||
mainWindow = [self mainWindow];
|
||||
if (keyWindow != mainWindow && mainWindow != nil)
|
||||
{
|
||||
resp = [mainWindow firstResponder];
|
||||
while (resp != nil && resp != mainWindow)
|
||||
{
|
||||
if ([resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
resp = [resp nextResponder];
|
||||
}
|
||||
if ([mainWindow respondsToSelector: aSelector])
|
||||
{
|
||||
return mainWindow;
|
||||
}
|
||||
|
||||
resp = [mainWindow delegate];
|
||||
if (resp != nil && [resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
|
||||
if ([NSDocumentController isDocumentBasedApplication])
|
||||
{
|
||||
resp = [[NSDocumentController sharedDocumentController]
|
||||
documentForWindow: mainWindow];
|
||||
|
||||
if (resp != nil && [resp respondsToSelector: aSelector])
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
resp = [self targetForAction: aSelector forWindow: mainWindow];
|
||||
if (resp != nil)
|
||||
return resp;
|
||||
}
|
||||
|
||||
if ([self respondsToSelector: aSelector])
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
if (_delegate != nil && [_delegate respondsToSelector: aSelector])
|
||||
{
|
||||
return _delegate;
|
||||
}
|
||||
|
||||
if ([NSDocumentController isDocumentBasedApplication]
|
||||
&& [[NSDocumentController sharedDocumentController]
|
||||
respondsToSelector: aSelector])
|
||||
{
|
||||
&& [[NSDocumentController sharedDocumentController]
|
||||
respondsToSelector: aSelector])
|
||||
{
|
||||
return [NSDocumentController sharedDocumentController];
|
||||
}
|
||||
|
||||
|
|
|
@ -816,12 +816,13 @@ static BOOL menuBarVisible = YES;
|
|||
NSMenuItem *menuItem = [_items objectAtIndex: i];
|
||||
|
||||
if (actionSelector == 0 || sel_eq([menuItem action], actionSelector))
|
||||
{
|
||||
if ([[menuItem target] isEqual: anObject])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
{
|
||||
// There are different possibilities to implement the check here
|
||||
if ([menuItem target] == anObject)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -834,10 +835,10 @@ static BOOL menuBarVisible = YES;
|
|||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if ([[[_items objectAtIndex: i] representedObject]
|
||||
isEqual: anObject])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
isEqual: anObject])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -852,10 +853,10 @@ static BOOL menuBarVisible = YES;
|
|||
id item = [_items objectAtIndex: i];
|
||||
|
||||
if ([item hasSubmenu] &&
|
||||
[[item submenu] isEqual: anObject])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
[[item submenu] isEqual: anObject])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
|
|
@ -40,6 +40,14 @@
|
|||
|
||||
@implementation NSWindowController
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSWindowController class])
|
||||
{
|
||||
[self setVersion: 1];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithWindowNibName: (NSString *)windowNibName
|
||||
{
|
||||
return [self initWithWindowNibName: windowNibName owner: self];
|
||||
|
@ -476,7 +484,16 @@
|
|||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
return [self init];
|
||||
if ([coder versionForClassName: @"NSWindowController"] >= 1)
|
||||
{
|
||||
return [super initWithCoder: coder];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* backward compatibility: old NSWindowController instances are not
|
||||
subclasses of NSResponder, but of NSObject */
|
||||
return [self init];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)coder
|
||||
|
@ -484,6 +501,8 @@
|
|||
// What are we supposed to encode? Window nib name? Or should these
|
||||
// be empty, just to conform to NSCoding, so we do an -init on
|
||||
// unarchival. ?
|
||||
|
||||
[super encodeWithCoder: coder];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue