mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-07 11:17:12 +00:00
Allow binding to CPPopUpButton's selectedTag.
This commit is contained in:
@@ -49,6 +49,11 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
||||
return "popup-button";
|
||||
}
|
||||
|
||||
+ (CPSet)keyPathsForValuesAffectingSelectedTag
|
||||
{
|
||||
return [CPSet setWithObject:CPValueBinding];
|
||||
}
|
||||
|
||||
/*!
|
||||
Initializes the pop-up button to the specified size.
|
||||
@param aFrame the size for the button
|
||||
@@ -233,6 +238,32 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
||||
return _selectedIndex;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (int)selectedTag
|
||||
{
|
||||
return [[self selectedItem] tag];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)setSelectedTag:(int)aTag
|
||||
{
|
||||
[self selectItemWithTag:aTag];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_reverseSetBinding
|
||||
{
|
||||
var theBinding = [CPKeyValueBinding getBinding:@"selectedTag" forObject:self];
|
||||
[theBinding reverseSetValueFor:@"selectedTag"];
|
||||
[super _reverseSetBinding];
|
||||
}
|
||||
|
||||
// Setting the Current Selection
|
||||
/*!
|
||||
Selects the specified menu item.
|
||||
@@ -252,6 +283,8 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
||||
if (_selectedIndex == anIndex)
|
||||
return;
|
||||
|
||||
[self willChangeValueForKey:CPValueBinding];
|
||||
|
||||
if (_selectedIndex >= 0 && ![self pullsDown])
|
||||
[[self selectedItem] setState:CPOffState];
|
||||
|
||||
@@ -261,6 +294,8 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
||||
[[self selectedItem] setState:CPOnState];
|
||||
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
|
||||
[self didChangeValueForKey:CPValueBinding];
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -20,4 +20,33 @@
|
||||
[self assert:["Option A", "Option B"] equals:[button itemTitles]];
|
||||
}
|
||||
|
||||
- (void)testBindingSelectedTag
|
||||
{
|
||||
var dict = [CPDictionary dictionary],
|
||||
item = nil;
|
||||
|
||||
item = [[CPMenuItem alloc] initWithTitle:@"Mouse" action:nil keyEquivalent:nil];
|
||||
[item setTag:20];
|
||||
[button addItem:item];
|
||||
|
||||
item = [[CPMenuItem alloc] initWithTitle:@"Elephant" action:nil keyEquivalent:nil];
|
||||
[item setTag:4990000];
|
||||
[button addItem:item];
|
||||
|
||||
[dict setObject:20 forKey:@"weight"];
|
||||
|
||||
[button bind:@"selectedTag"
|
||||
toObject:dict
|
||||
withKeyPath:@"weight"
|
||||
options:nil];
|
||||
|
||||
[self assert:20 equals:[button selectedTag]];
|
||||
|
||||
[button selectItemAtIndex:1];
|
||||
// simulate selection by the user
|
||||
[button sendAction:[button action] to:[button target]];
|
||||
|
||||
[self assert:4990000 equals:[dict objectForKey:@"weight"]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user