mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-07 17:38:02 +00:00
CPTokenField menu per token support.
This change implements support for the CPTokenField delegate method `tokenField:menuForRepresentedObject:` (and the associated `tokenField:hasMenuForRepresentedObject:`).
This commit is contained in:
1 parent
55ec70cbd6
commit
18d77ca9f7
2 files changed
+60
-1
No files matched your search
@@ -1241,6 +1241,20 @@ var CPScrollDestinationNone = 0,
|
||||
return aString;
|
||||
}
|
||||
|
||||
- (CPMenu)_menuForRepresentedObject:(id)aRepresentedObject
|
||||
{
|
||||
var delegate = [self delegate];
|
||||
if ([delegate respondsToSelector:@selector(tokenField:hasMenuForRepresentedObject:)] &&
|
||||
[delegate respondsToSelector:@selector(tokenField:menuForRepresentedObject:)])
|
||||
{
|
||||
var hasMenu = [delegate tokenField:self hasMenuForRepresentedObject:aRepresentedObject];
|
||||
if (hasMenu)
|
||||
return [delegate tokenField:self menuForRepresentedObject:aRepresentedObject];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
// We put the string on the pasteboard before calling this delegate method.
|
||||
// By default, we write the NSStringPboardType as well as an array of NSStrings.
|
||||
// - (BOOL)tokenField:(NSTokenField *)tokenField writeRepresentedObjects:(NSArray *)objects toPasteboard:(NSPasteboard *)pboard;
|
||||
@@ -1398,6 +1412,11 @@ var CPScrollDestinationNone = 0,
|
||||
[_tokenField _deleteToken:self];
|
||||
}
|
||||
|
||||
- (CPMenu)menu
|
||||
{
|
||||
return [_tokenField _menuForRepresentedObject:_representedObject];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
|
||||
@@ -88,10 +88,17 @@ var STATES = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorad
|
||||
[tokenFieldD setDelegate:self];
|
||||
|
||||
var tokenFieldDEditable = [CPCheckBox checkBoxWithTitle:"Editable"];
|
||||
[tokenFieldDEditable setFrame:CGRectMake(525, CGRectGetMinY([tokenFieldD frame]), 200, 30)];
|
||||
[tokenFieldDEditable sizeToFit];
|
||||
[tokenFieldDEditable setFrameOrigin:CGPointMake(525, 5 + CGRectGetMinY([tokenFieldD frame]))];
|
||||
[tokenFieldDEditable bind:CPValueBinding toObject:tokenFieldD withKeyPath:@"editable" options:nil];
|
||||
[contentView addSubview:tokenFieldDEditable];
|
||||
|
||||
var tokenFieldDMenus = [CPCheckBox checkBoxWithTitle:"Menus"];
|
||||
[tokenFieldDMenus sizeToFit];
|
||||
[tokenFieldDMenus setFrameOrigin:CGPointMake(CGRectGetMaxX([tokenFieldDEditable frame]), 5 + CGRectGetMinY([tokenFieldD frame]))];
|
||||
[tokenFieldDMenus bind:CPValueBinding toObject:self withKeyPath:@"tokenFieldDHasMenus" options:nil];
|
||||
[contentView addSubview:tokenFieldDMenus];
|
||||
|
||||
allPersons = [
|
||||
[Person personWithFirstName:@"Luc" lastName:@"Vauvillier"],
|
||||
[Person personWithFirstName:@"John" lastName:@"Doe"],
|
||||
@@ -113,6 +120,27 @@ var STATES = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorad
|
||||
|
||||
}
|
||||
|
||||
- (void)setTokenFieldDHasMenus:(BOOL)shouldHaveMenus
|
||||
{
|
||||
if (shouldHaveMenus)
|
||||
{
|
||||
[[tokenFieldD objectValue] enumerateObjectsUsingBlock:function(aPerson)
|
||||
{
|
||||
var menu = [CPMenu new];
|
||||
for (var i = 0; i < 3; i++)
|
||||
[menu addItem:[[CPMenuItem alloc] initWithTitle:[CPString stringWithFormat:@"%@ Item %i", aPerson, i] action:nil keyEquivalent:nil]];
|
||||
aPerson.menu = menu;
|
||||
}];
|
||||
}
|
||||
else
|
||||
[[tokenFieldD objectValue] makeObjectsPerformSelector:@selector(setMenu:) withObject:nil];
|
||||
}
|
||||
|
||||
- (BOOL)tokenFieldDHasMenus
|
||||
{
|
||||
return !![[[tokenFieldD objectValue] firstObject] menu];
|
||||
}
|
||||
|
||||
- (void)getObjectValues:(id)sender
|
||||
{
|
||||
alert([tokenFieldD objectValue]);
|
||||
@@ -177,6 +205,16 @@ var STATES = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorad
|
||||
return tokens;
|
||||
}
|
||||
|
||||
- (BOOL)tokenField:(CPTokenField)aTokenField hasMenuForRepresentedObject:(id)aRepresentedObject
|
||||
{
|
||||
return !!aRepresentedObject.menu;
|
||||
}
|
||||
|
||||
- (CPMenu)tokenField:(CPTokenField)aTokenField menuForRepresentedObject:(id)aRepresentedObject
|
||||
{
|
||||
return aRepresentedObject.menu;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// A sample of a custom Object
|
||||
@@ -185,6 +223,8 @@ var STATES = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorad
|
||||
{
|
||||
CPString _firstName;
|
||||
CPString _lastName;
|
||||
|
||||
CPMenu menu @accessors;
|
||||
}
|
||||
|
||||
+ (id)personWithFirstName:(CPString)aFirstName lastName:(CPString)aLastName
|
||||
|
||||
Reference in new issue
Block a user