[Adium-commits] adium 1964:7c54b52a482a: Fix many problems with the contact list...

adium-commits at adiumx.com adium-commits at adiumx.com
Fri Apr 24 20:49:17 UTC 2009


details:	http://hg.adiumx.com/adium/rev/7c54b52a482a
revision:	1964:7c54b52a482a
author:		Colin Barrett <colin at springsandstruts.com>
date:		Fri Apr 24 13:48:27 2009 -0700

Fix many problems with the contact list filtering not properly restoring group expanding, and not properly expanding groups.

Instead of trying to twiddle the view proxies directly, we set a special display property on each expanded group's model object. The list controller checks this property when deciding if an item is expanded or not.

diffstat:

 Frameworks/Adium Framework/Source/AIAbstractListController.m |   2 +-
 Source/AIListWindowController.m                              |  76 +++++---------
 2 files changed, 29 insertions(+), 49 deletions(-)

diffs (98 lines):

diff -r c39b835b9400 -r 7c54b52a482a Frameworks/Adium Framework/Source/AIAbstractListController.m
--- a/Frameworks/Adium Framework/Source/AIAbstractListController.m	Fri Apr 24 16:36:44 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIAbstractListController.m	Fri Apr 24 13:48:27 2009 -0700
@@ -673,7 +673,7 @@
 //
 - (BOOL)outlineView:(NSOutlineView *)outlineView expandStateOfItem:(AIProxyListObject *)item
 {
-    return !item || ((id<AIContainingObject>)(item.listObject)).expanded;
+    return !item || ((id<AIContainingObject>)(item.listObject)).expanded || [item.listObject boolValueForProperty:@"ExpandedByFiltering"];
 }
 
 /*!
diff -r c39b835b9400 -r 7c54b52a482a Source/AIListWindowController.m
--- a/Source/AIListWindowController.m	Fri Apr 24 16:36:44 2009 -0400
+++ b/Source/AIListWindowController.m	Fri Apr 24 13:48:27 2009 -0700
@@ -1666,54 +1666,34 @@
 		return;
 	
 	if (!filterBarExpandedGroups && ![[sender stringValue] isEqualToString:@""]) {
-		// Temporarily expand all groups when performing a search.
-		NSMutableArray *groupsToExpand = [NSMutableArray array];
-		NSUInteger rows = [contactListView numberOfRows];
-		for (int i = 0; i < rows; i++) {
-			AIProxyListObject *proxyObject = [contactListView itemAtRow:i];
-			if ([proxyObject isKindOfClass:[AIListGroup class]] && ((AIListGroup *)proxyObject).expanded == NO)
-				[groupsToExpand addObject:proxyObject];
-		}
-		
-		if (groupsToExpand.count) {
-			for (AIProxyListObject *proxyObject in groupsToExpand) {
-				// Force the listgroup to save its expanded status
-				AIListGroup *proxiedObject = (AIListGroup *)proxyObject;
-				
-				[proxiedObject setPreference:[NSNumber numberWithBool:proxiedObject.expanded]
-									  forKey:@"IsExpanded"
-									   group:@"Contact List"];
-				
-				// Set the group as expanded
-				[contactListView expandItem:proxyObject];
-			}			
-		}
-		
-		filterBarExpandedGroups = YES;
-		
-	} else if (filterBarExpandedGroups && [[sender stringValue] isEqualToString:@""]) {
-		// Restore saved expansion status when returning to no search.
-		
-		// Temporarily expand all groups when performing a search.
-		NSMutableArray *groupsToCollapse = [NSMutableArray array];
-		NSUInteger rows = [contactListView numberOfRows];
-		for (int i = 0; i < rows; i++) {
-			AIProxyListObject *proxyObject = [contactListView itemAtRow:i];
-			
-			if ([proxyObject isKindOfClass:[AIListGroup class]] &&
-				![[(AIListGroup *)proxyObject preferenceForKey:@"IsExpanded" group:@"Contact List"] boolValue]) {
-				[groupsToCollapse addObject:proxyObject];
-			}
-		}
-		
-		if (groupsToCollapse.count) {
-			for (AIProxyListObject *proxyObject in groupsToCollapse) {
-				[contactListView collapseItem:proxyObject];
-			}			
-		}
-		
-		filterBarExpandedGroups = NO;
-	}
+        BOOL modified = NO;
+        for (AIListObject *listObject in [self.contactList containedObjects]) {
+            if ([listObject isKindOfClass:[AIListGroup class]] && [(AIListGroup *)listObject isExpanded] == NO) {
+                [listObject setValue:[NSNumber numberWithBool:YES] forProperty:@"ExpandedByFiltering" notify:NotifyNever];
+                modified = YES;
+            }
+        }
+        
+        filterBarExpandedGroups = YES;
+        
+        if (modified) {
+            [contactListView reloadData];
+        }
+    } else if (filterBarExpandedGroups && [[sender stringValue] isEqualToString:@""]) {
+        BOOL modified = NO;
+        for (AIListObject *listObject in [self.contactList containedObjects]) {
+            if ([listObject isKindOfClass:[AIListGroup class]] && [listObject boolValueForProperty:@"ExpandedByFiltering"]) {
+                [listObject setValue:[NSNumber numberWithBool:NO] forProperty:@"ExpandedByFiltering" notify:NotifyNever];
+                modified = YES;
+            }
+        }
+        
+        filterBarExpandedGroups = NO;
+        
+        if (modified) {
+            [contactListView reloadData];
+        }
+    }
 	
 	if ([[AIContactHidingController sharedController] filterContacts:[sender stringValue]]) {
 		// Select the first contact; we're guaranteed at least one visible contact.




More information about the commits mailing list