mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 01:11:07 +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
5a50f7ad69
commit
3b4cc1196a
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>
|
2008-10-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/AppKit/NSWindowController.h: Make a subclass of NSResponder.
|
* 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>
|
* <p>
|
||||||
* Returns the target object that will respond to aSelector, if any. The
|
* 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
|
- (id) targetForAction: (SEL)aSelector
|
||||||
{
|
{
|
||||||
NSWindow *keyWindow;
|
NSWindow *keyWindow;
|
||||||
NSWindow *mainWindow;
|
NSWindow *mainWindow;
|
||||||
id resp;
|
id resp;
|
||||||
|
|
||||||
|
if (aSelector == NULL)
|
||||||
|
return nil;
|
||||||
|
|
||||||
keyWindow = [self keyWindow];
|
keyWindow = [self keyWindow];
|
||||||
if (keyWindow != nil)
|
if (keyWindow != nil)
|
||||||
{
|
{
|
||||||
resp = [keyWindow firstResponder];
|
resp = [self targetForAction: aSelector forWindow: keyWindow];
|
||||||
while (resp != nil && resp != keyWindow)
|
if (resp != nil)
|
||||||
{
|
return resp;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_session != 0)
|
if (_session != 0)
|
||||||
|
@ -2092,50 +2105,25 @@ IF_NO_GC(NSAssert([event retainCount] > 0, NSInternalInconsistencyException));
|
||||||
mainWindow = [self mainWindow];
|
mainWindow = [self mainWindow];
|
||||||
if (keyWindow != mainWindow && mainWindow != nil)
|
if (keyWindow != mainWindow && mainWindow != nil)
|
||||||
{
|
{
|
||||||
resp = [mainWindow firstResponder];
|
resp = [self targetForAction: aSelector forWindow: mainWindow];
|
||||||
while (resp != nil && resp != mainWindow)
|
if (resp != nil)
|
||||||
{
|
return resp;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([self respondsToSelector: aSelector])
|
if ([self respondsToSelector: aSelector])
|
||||||
{
|
{
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_delegate != nil && [_delegate respondsToSelector: aSelector])
|
if (_delegate != nil && [_delegate respondsToSelector: aSelector])
|
||||||
{
|
{
|
||||||
return _delegate;
|
return _delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([NSDocumentController isDocumentBasedApplication]
|
if ([NSDocumentController isDocumentBasedApplication]
|
||||||
&& [[NSDocumentController sharedDocumentController]
|
&& [[NSDocumentController sharedDocumentController]
|
||||||
respondsToSelector: aSelector])
|
respondsToSelector: aSelector])
|
||||||
{
|
{
|
||||||
return [NSDocumentController sharedDocumentController];
|
return [NSDocumentController sharedDocumentController];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -816,12 +816,13 @@ static BOOL menuBarVisible = YES;
|
||||||
NSMenuItem *menuItem = [_items objectAtIndex: i];
|
NSMenuItem *menuItem = [_items objectAtIndex: i];
|
||||||
|
|
||||||
if (actionSelector == 0 || sel_eq([menuItem action], actionSelector))
|
if (actionSelector == 0 || sel_eq([menuItem action], actionSelector))
|
||||||
{
|
{
|
||||||
if ([[menuItem target] isEqual: anObject])
|
// There are different possibilities to implement the check here
|
||||||
{
|
if ([menuItem target] == anObject)
|
||||||
return i;
|
{
|
||||||
}
|
return i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -834,10 +835,10 @@ static BOOL menuBarVisible = YES;
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
if ([[[_items objectAtIndex: i] representedObject]
|
if ([[[_items objectAtIndex: i] representedObject]
|
||||||
isEqual: anObject])
|
isEqual: anObject])
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -852,10 +853,10 @@ static BOOL menuBarVisible = YES;
|
||||||
id item = [_items objectAtIndex: i];
|
id item = [_items objectAtIndex: i];
|
||||||
|
|
||||||
if ([item hasSubmenu] &&
|
if ([item hasSubmenu] &&
|
||||||
[[item submenu] isEqual: anObject])
|
[[item submenu] isEqual: anObject])
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -40,6 +40,14 @@
|
||||||
|
|
||||||
@implementation NSWindowController
|
@implementation NSWindowController
|
||||||
|
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
if (self == [NSWindowController class])
|
||||||
|
{
|
||||||
|
[self setVersion: 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (id) initWithWindowNibName: (NSString *)windowNibName
|
- (id) initWithWindowNibName: (NSString *)windowNibName
|
||||||
{
|
{
|
||||||
return [self initWithWindowNibName: windowNibName owner: self];
|
return [self initWithWindowNibName: windowNibName owner: self];
|
||||||
|
@ -476,7 +484,16 @@
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder *)coder
|
- (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
|
- (void) encodeWithCoder: (NSCoder *)coder
|
||||||
|
@ -484,6 +501,8 @@
|
||||||
// What are we supposed to encode? Window nib name? Or should these
|
// 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
|
// be empty, just to conform to NSCoding, so we do an -init on
|
||||||
// unarchival. ?
|
// unarchival. ?
|
||||||
|
|
||||||
|
[super encodeWithCoder: coder];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue