mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
Add KVB for menu item and popup button.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25777 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2310d97434
commit
93b0fa80e9
3 changed files with 73 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
2007-12-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSMenuItem.m: Add KVB for enable.
|
||||
* Source/NSPopUpButton.m: Add KVB for selectedIndex.
|
||||
|
||||
2007-12-22 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSView.m (-visibleRect:, -setHidden:, -hitTest:): Full
|
||||
|
|
|
@ -34,11 +34,13 @@
|
|||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <GNUstepBase/GSCategories.h>
|
||||
#include "AppKit/NSCell.h"
|
||||
#include "AppKit/NSEvent.h"
|
||||
#include "AppKit/NSImage.h"
|
||||
#include "AppKit/NSKeyValueBinding.h"
|
||||
#include "AppKit/NSMenuItem.h"
|
||||
#include "AppKit/NSMenu.h"
|
||||
#include "AppKit/NSImage.h"
|
||||
#include "AppKit/NSEvent.h"
|
||||
#include "AppKit/NSCell.h"
|
||||
#include "GSBindingHelpers.h"
|
||||
|
||||
static BOOL usesUserKeyEquivalents = NO;
|
||||
static Class imageClass;
|
||||
|
@ -76,6 +78,8 @@ static Class imageClass;
|
|||
{
|
||||
[self setVersion: 4];
|
||||
imageClass = [NSImage class];
|
||||
|
||||
[self exposeBinding: NSEnabledBinding];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,6 +107,9 @@ static Class imageClass;
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
// Remove all key value bindings for this view.
|
||||
[GSKeyValueBinding unbindAllForObject: self];
|
||||
|
||||
TEST_RELEASE(_title);
|
||||
TEST_RELEASE(_keyEquivalent);
|
||||
TEST_RELEASE(_image);
|
||||
|
@ -648,6 +655,30 @@ static Class imageClass;
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void) bind: (NSString *)binding
|
||||
toObject: (id)anObject
|
||||
withKeyPath: (NSString *)keyPath
|
||||
options: (NSDictionary *)options
|
||||
{
|
||||
if ([binding hasPrefix: NSEnabledBinding])
|
||||
{
|
||||
[self unbind: binding];
|
||||
[[GSKeyValueAndBinding alloc] initWithBinding: NSEnabledBinding
|
||||
withName: binding
|
||||
toObject: anObject
|
||||
withKeyPath: keyPath
|
||||
options: options
|
||||
fromObject: self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[super bind: binding
|
||||
toObject: anObject
|
||||
withKeyPath: keyPath
|
||||
options: options];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSMenuItem (GNUstepExtra)
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <Foundation/NSKeyValueObserving.h>
|
||||
#include "AppKit/NSApplication.h"
|
||||
#include "AppKit/NSEvent.h"
|
||||
#include "AppKit/NSKeyValueBinding.h"
|
||||
#include "AppKit/NSPopUpButton.h"
|
||||
#include "AppKit/NSPopUpButtonCell.h"
|
||||
#include "AppKit/NSMenu.h"
|
||||
|
@ -58,6 +60,8 @@ Class _nspopupbuttonCellClass = 0;
|
|||
// Initial version
|
||||
[self setVersion: 1];
|
||||
[self setCellClass: [NSPopUpButtonCell class]];
|
||||
|
||||
[self exposeBinding: NSSelectedIndexBinding];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,7 +253,9 @@ this to return nil to indicate that we have no context menu.
|
|||
|
||||
- (void) selectItem: (id <NSMenuItem>)anObject
|
||||
{
|
||||
[self willChangeValueForKey: NSSelectedIndexBinding];
|
||||
[_cell selectItem: anObject];
|
||||
[self didChangeValueForKey: NSSelectedIndexBinding];
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
}
|
||||
|
||||
|
@ -259,7 +265,9 @@ this to return nil to indicate that we have no context menu.
|
|||
*/
|
||||
- (void) selectItemAtIndex: (int)index
|
||||
{
|
||||
[self willChangeValueForKey: NSSelectedIndexBinding];
|
||||
[_cell selectItemAtIndex: index];
|
||||
[self didChangeValueForKey: NSSelectedIndexBinding];
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
}
|
||||
|
||||
|
@ -270,7 +278,9 @@ this to return nil to indicate that we have no context menu.
|
|||
*/
|
||||
- (void) selectItemWithTitle: (NSString*)title
|
||||
{
|
||||
[self willChangeValueForKey: NSSelectedIndexBinding];
|
||||
[_cell selectItemWithTitle: title];
|
||||
[self didChangeValueForKey: NSSelectedIndexBinding];
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
}
|
||||
|
||||
|
@ -517,4 +527,28 @@ this to return nil to indicate that we have no context menu.
|
|||
[super keyDown: theEvent];
|
||||
}
|
||||
|
||||
- (void) setValue: (id)anObject forKey: (NSString*)aKey
|
||||
{
|
||||
if ([aKey isEqual: NSSelectedIndexBinding])
|
||||
{
|
||||
[self selectItemAtIndex: [anObject intValue]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[super setValue: anObject forKey: aKey];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) valueForKey: (NSString*)aKey
|
||||
{
|
||||
if ([aKey isEqual: NSSelectedIndexBinding])
|
||||
{
|
||||
return [NSNumber numberWithInt: [self indexOfSelectedItem]];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [super valueForKey: aKey];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue