adium 2914:def06ccb99eb: When cycling chats (using "Next Chat" a...

commits at adium.im commits at adium.im
Sat Nov 21 22:08:32 UTC 2009


details:	http://hg.adium.im/adium/rev/def06ccb99eb
revision:	2914:def06ccb99eb
author:		Zachary West <zacw at adium.im>
date:		Sat Nov 21 16:57:52 2009 -0500

When cycling chats (using "Next Chat" and "Previous Chat") stay in the current window. Do nothing if outside of a chat window.
(transplanted from 790da92cabb614bb336dc7f73a32e6e5bee9e4fd)
Subject: adium 2915:4ff6b0bfa42e: This complex fast enumeration was throwing *two* warnings.

details:	http://hg.adium.im/adium/rev/4ff6b0bfa42e
revision:	2915:4ff6b0bfa42e
author:		Zachary West <zacw at adium.im>
date:		Sat Nov 21 16:58:09 2009 -0500

This complex fast enumeration was throwing *two* warnings.
(transplanted from b00f7de2a5c96ab1c0600ddb9b321e39fa3e6fdf)

diffs (151 lines):

diff -r 0c5b69d24ed3 -r 4ff6b0bfa42e Frameworks/Adium Framework/Source/AIAddressBookController.m
--- a/Frameworks/Adium Framework/Source/AIAddressBookController.m	Sat Nov 21 13:22:15 2009 -0500
+++ b/Frameworks/Adium Framework/Source/AIAddressBookController.m	Sat Nov 21 16:58:09 2009 -0500
@@ -1280,8 +1280,10 @@
 			[person setValue:[contact phoneticName] forKey:kABFirstNamePhoneticProperty];
 
 		NSString				*UID = contact.formattedUID;
-			
-		for (AIListObject *c in [contact isKindOfClass:[AIMetaContact class]] ? [(AIMetaContact *)contact uniqueContainedObjects] : [NSArray arrayWithObject:contact])	{
+		
+		NSArray *contacts = [contact isKindOfClass:[AIMetaContact class]] ? [(AIMetaContact *)contact uniqueContainedObjects] : [NSArray arrayWithObject:contact];
+		
+		for (AIListObject *c in contacts) {
 			ABMutableMultiValue *multiValue = [[ABMutableMultiValue alloc] init];
 			UID = c.formattedUID;
 			serviceProperty = [AIAddressBookController propertyFromService:c.service];
diff -r 0c5b69d24ed3 -r 4ff6b0bfa42e Frameworks/Adium Framework/Source/AIInterfaceControllerProtocol.h
--- a/Frameworks/Adium Framework/Source/AIInterfaceControllerProtocol.h	Sat Nov 21 13:22:15 2009 -0500
+++ b/Frameworks/Adium Framework/Source/AIInterfaceControllerProtocol.h	Sat Nov 21 16:58:09 2009 -0500
@@ -165,7 +165,7 @@
  * @brief Active Chat property
  *
  * Setter brings the tab/window for a chat to the front and sets it as active
- * If no chat is active (a non-chat window is focued, or Adium is not focused), getter returns nil.
+ * If no chat is active (a non-chat window is focused, or Adium is not focused), getter returns nil.
  */
 @property (nonatomic, retain) AIChat *activeChat;
 
@@ -192,6 +192,14 @@
 - (NSArray *)openChatsInContainerWithID:(NSString *)containerID;
 
 /*!
+ * @brief The container ID for a chat
+ *
+ * @param chat The chat to look up
+ * @returns The container ID for the container the chat is in.
+ */
+- (NSString *)containerIDForChat:(AIChat *)chat;
+
+/*!
  * @brief Get an array of the containerIDs of all open containers
  */
 @property (nonatomic, readonly) NSArray *openContainerIDs;
@@ -209,14 +217,14 @@
 /*!
  * @brief Cycles to the next open chat, making it active
  *
- * This crosses container boundaries.
+ * This does not cross container boundaries. If there is no currently active chat, this has no effect.
  */
 - (void)nextChat:(id)sender;
 
 /*!
  * @brief Cycles to the previous open chat, making it active
  *
- * This crosses container boundaries.
+ * This does not cross container boundaries. If there is no currently active chat, this has no effect.
  */
 - (void)previousChat:(id)sender;
 
diff -r 0c5b69d24ed3 -r 4ff6b0bfa42e Source/AIChatCyclingPlugin.m
--- a/Source/AIChatCyclingPlugin.m	Sat Nov 21 13:22:15 2009 -0500
+++ b/Source/AIChatCyclingPlugin.m	Sat Nov 21 16:58:09 2009 -0500
@@ -116,7 +116,11 @@
  */
 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
 {
-	return [[adium.interfaceController openChats] count] != 0;
+	if (!adium.interfaceController.activeChat) return NO;
+	
+	NSString *containerID = [adium.interfaceController containerIDForChat:adium.interfaceController.activeChat];
+	
+	return ([adium.interfaceController openChatsInContainerWithID:containerID].count > 0);
 }
 
 /*!
diff -r 0c5b69d24ed3 -r 4ff6b0bfa42e Source/AIInterfaceController.m
--- a/Source/AIInterfaceController.m	Sat Nov 21 13:22:15 2009 -0500
+++ b/Source/AIInterfaceController.m	Sat Nov 21 16:58:09 2009 -0500
@@ -750,6 +750,17 @@
 }
 
 /*!
+ * @brief The container ID for a chat
+ *
+ * @param chat The chat to look up
+ * @returns The container ID for the container the chat is in.
+ */
+- (NSString *)containerIDForChat:(AIChat *)chat
+{
+	return [interfacePlugin containerIDForChat:chat];
+}
+
+/*!
  * @brief Resets the cache of open chats
  */
 - (void)_resetOpenChatsCache
@@ -1085,16 +1096,17 @@
  */
 - (void)nextChat:(id)sender
 {
-	NSArray	*openChats = [self openChats];
+	if (!activeChat) return;
+	
+	NSString *containerID = [self containerIDForChat:activeChat];
+	NSArray *chats = [self openChatsInContainerWithID:containerID];
 
-	if ([openChats count]) {
-		if (activeChat) {
-			NSInteger chatIndex = [openChats indexOfObject:activeChat]+1;
-			[self setActiveChat:[openChats objectAtIndex:(chatIndex < [openChats count] ? chatIndex : 0)]];
-		} else {
-			[self setActiveChat:[openChats objectAtIndex:0]];
-		}
-	}
+	NSInteger nextChat = [chats indexOfObject:activeChat] + 1;
+	
+	if (nextChat >= chats.count)
+		nextChat = 0;
+	
+	[self setActiveChat:[chats objectAtIndex:nextChat]];
 }
 
 /*!
@@ -1102,16 +1114,17 @@
  */
 - (void)previousChat:(id)sender
 {
-	NSArray	*openChats = [self openChats];
+	if (!activeChat) return;
 	
-	if ([openChats count]) {
-		if (activeChat) {
-			NSInteger chatIndex = [openChats indexOfObject:activeChat]-1;
-			[self setActiveChat:[openChats objectAtIndex:(chatIndex >= 0 ? chatIndex : [openChats count]-1)]];
-		} else {
-			[self setActiveChat:[openChats lastObject]];
-		}
-	}
+	NSString *containerID = [self containerIDForChat:activeChat];
+	NSArray *chats = [self openChatsInContainerWithID:containerID];
+	
+	NSInteger nextChat = [chats indexOfObject:activeChat] - 1;
+	
+	if (nextChat < 0)
+		nextChat = chats.count - 1;
+	
+	[self setActiveChat:[chats objectAtIndex:nextChat]];
 }
 
 //Selected contact ------------------------------------------------




More information about the commits mailing list