adium 2147:018482e6c290: Reuse the same AIContactMenu, avoiding ...

commits at adium.im commits at adium.im
Mon May 11 05:10:47 UTC 2009


details:	http://hg.adium.im/adium/rev/018482e6c290
revision:	2147:018482e6c290
author:		Zachary West <zacw at adium.im>
date:		Mon May 11 01:10:29 2009 -0400

Reuse the same AIContactMenu, avoiding an annoying race conditiony-crash, and improving the speed it creates stuff.

diffstat:

 Frameworks/Adium Framework/Source/AIContactMenu.h |   1 +
 Frameworks/Adium Framework/Source/AIContactMenu.m |  12 ++++++++++++
 Source/AIAdvancedInspectorPane.m                  |  13 ++++++++-----
 3 files changed, 21 insertions(+), 5 deletions(-)

diffs (63 lines):

diff -r 2caf01fe27de -r 018482e6c290 Frameworks/Adium Framework/Source/AIContactMenu.h
--- a/Frameworks/Adium Framework/Source/AIContactMenu.h	Mon May 11 00:46:25 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIContactMenu.h	Mon May 11 01:10:29 2009 -0400
@@ -27,6 +27,7 @@
 }
 
 + (id)contactMenuWithDelegate:(id<AIContactMenuDelegate>)inDelegate forContactsInObject:(AIListObject *)inContainingObject;
+- (void)setContainingObject:(AIListObject *)inContainingObject;
 
 @property (readwrite, nonatomic, assign) id<AIContactMenuDelegate> delegate;
 
diff -r 2caf01fe27de -r 018482e6c290 Frameworks/Adium Framework/Source/AIContactMenu.m
--- a/Frameworks/Adium Framework/Source/AIContactMenu.m	Mon May 11 00:46:25 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIContactMenu.m	Mon May 11 01:10:29 2009 -0400
@@ -72,6 +72,18 @@
 }
 
 /*!
+ * @brief Set the containing object
+ *
+ * Updates the containing object, and rebuilds the menu items.
+ */
+- (void)setContainingObject:(AIListObject *)inContainingObject
+{
+	containingObject = [inContainingObject retain];
+	
+	[self rebuildMenu];
+}
+
+/*!
  * @brief Returns the existing menu item for a specific contact
  *
  * @param contact AIListContact whose menu item to return
diff -r 2caf01fe27de -r 018482e6c290 Source/AIAdvancedInspectorPane.m
--- a/Source/AIAdvancedInspectorPane.m	Mon May 11 00:46:25 2009 -0400
+++ b/Source/AIAdvancedInspectorPane.m	Mon May 11 01:10:29 2009 -0400
@@ -144,10 +144,7 @@
 
 #pragma mark Menus
 -(void)reloadPopup
-{
-	[contactMenu release]; contactMenu = nil;
-	contactMenu = [[AIContactMenu contactMenuWithDelegate:self forContactsInObject:displayedObject] retain];
-	
+{	
 	[accountMenu rebuildMenu];
 	
 	[button_addGroup setMenu:[adium.contactController groupMenuWithTarget:self]];
@@ -159,7 +156,13 @@
 {
 	currentSelectedAccount = inAccount;
 	
-	[contactMenu rebuildMenu];
+	if (!contactMenu) {
+		// Instantiate here so we don't end up creating a massive menu for all contacts.
+		contactMenu = [[AIContactMenu contactMenuWithDelegate:self
+										  forContactsInObject:displayedObject] retain];	
+	} else {
+		[contactMenu setContainingObject:displayedObject];
+	}
 }
 
 - (BOOL)accountMenu:(AIAccountMenu *)inAccountMenu shouldIncludeAccount:(AIAccount *)inAccount




More information about the commits mailing list