[Adium-commits] adium 1957:fc02b9eb998b: Contact Controller: Sort the group menu...
adium-commits at adiumx.com
adium-commits at adiumx.com
Fri Apr 24 01:03:45 UTC 2009
details: http://hg.adiumx.com/adium/rev/fc02b9eb998b
revision: 1957:fc02b9eb998b
author: Colin Barrett <colin at springsandstruts.com>
date: Thu Apr 23 17:59:46 2009 -0700
Contact Controller: Sort the group menu using the active sort controller. Also separate groups by contact list (main or detatched) that they're on.
diffstat:
Source/AIContactController.m | 47 ++++++++++++++++++++++++++++++++++++-----------
1 files changed, 36 insertions(+), 11 deletions(-)
diffs (61 lines):
diff -r fe470f38b994 -r fc02b9eb998b Source/AIContactController.m
--- a/Source/AIContactController.m Thu Apr 23 16:35:17 2009 -0400
+++ b/Source/AIContactController.m Thu Apr 23 17:59:46 2009 -0700
@@ -1048,21 +1048,46 @@
//- The menu items represented object is the group it represents
- (NSMenu *)groupMenuWithTarget:(id)target
{
- NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
-
+ NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
[menu setAutoenablesItems:NO];
-
- for(AIListGroup *group in self.allGroups) {
+
+ // Separate groups by the contact list they're on.
+ NSMutableDictionary *groupsByList = [NSMutableDictionary dictionaryWithCapacity:contactLists.count];
+ for (AIListGroup *group in self.allGroups) {
if (group != self.offlineGroup) {
- NSMenuItem *menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:group.displayName
- target:target
- action:@selector(selectGroup:)
- keyEquivalent:@""];
- [menuItem setRepresentedObject:group];
- [menu addItem:menuItem];
- [menuItem release];
+ NSMutableArray *groups = [groupsByList objectForKey:group.contactList.UID];
+ if (!groups) {
+ groups = [NSMutableArray array];
+ [groupsByList setObject:groups forKey:group.contactList.UID];
+ }
+ [groups addObject:group];
}
}
+
+ // Now traverse the contactLists array in order and build a menu showing the groups in each list with separators in between.
+ NSInteger i = 0;
+ for (AIContactList *list in contactLists) {
+ NSMutableArray *groups = [groupsByList objectForKey:list.UID];
+ [groups sortUsingActiveSortControllerInContainer:list];
+ for (AIListGroup *group in groups) {
+ NSMenuItem *menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:group.displayName
+ target:target
+ action:@selector(selectGroup:)
+ keyEquivalent:@""];
+ [menuItem setRepresentedObject:group];
+ [menu addItem:menuItem];
+ [menuItem release];
+ }
+
+ i++;
+
+ // Add the separator unless this is the last list.
+ if (i < contactLists.count) {
+ [menu addItem:[NSMenuItem separatorItem]];
+ }
+
+ }
+
return [menu autorelease];
}
More information about the commits
mailing list