adium 2807:e0421b510067: Add %incomingColor% and %outgoingColor%...

commits at adium.im commits at adium.im
Thu Oct 29 16:58:29 UTC 2009


details:	http://hg.adium.im/adium/rev/e0421b510067
revision:	2807:e0421b510067
author:		Zachary West <zacw at adium.im>
date:		Thu Oct 29 12:57:14 2009 -0400

Add %incomingColor% and %outgoingColor%, remove %senderColor% in headers. Fixes #12666.

This also should speed up significantly message display for styles that don't specify a custom set of colors, since we won't be querying the file for every message any longer.
Subject: adium 2808:6a41be7632e5: Clean up the per-contact spelling a little. I think this fixes #12359.

details:	http://hg.adium.im/adium/rev/6a41be7632e5
revision:	2808:6a41be7632e5
author:		Zachary West <zacw at adium.im>
date:		Thu Oct 29 12:43:40 2009 -0400

Clean up the per-contact spelling a little. I think this fixes #12359.

This uses new, proper "language-grabbing" methods from the spell checker, as well as properly saves the spelling if the spelling was changed and the window was immediately closed. In this case, it would end up saving the wrong value.

diffs (168 lines):

diff -r 5585035f872b -r 6a41be7632e5 Frameworks/AIUtilities Framework/Source/AILeopardCompatibility.h
--- a/Frameworks/AIUtilities Framework/Source/AILeopardCompatibility.h	Thu Oct 29 11:44:17 2009 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AILeopardCompatibility.h	Thu Oct 29 12:43:40 2009 -0400
@@ -36,6 +36,10 @@
 - (BOOL)isAutomaticSpellingCorrectionEnabled;
 - (void)toggleAutomaticSpellingCorrection:(id)sender;
 @end
+
+ at interface NSSpellChecker(NSSpellCheckerLeopardMethods)
+- (NSArray *)userPreferredLanguages;
+ at end
 #endif
 
 #else //Not compiling for 10.6
diff -r 5585035f872b -r 6a41be7632e5 Plugins/WebKit Message View/AIWebkitMessageViewStyle.h
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h	Thu Oct 29 11:44:17 2009 -0400
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h	Thu Oct 29 12:43:40 2009 -0400
@@ -103,6 +103,9 @@
 	BOOL				transparentDefaultBackground;
 	BOOL				allowsUserIcons;
 	BOOL				usingCustomTemplateHTML;
+	
+	BOOL				checkedSenderColors;
+	NSArray				*validSenderColors;
 
 	//Behavior
 	NSDateFormatter		*timeStampFormatter;
@@ -236,6 +239,11 @@
  */
 @property (readonly, nonatomic) BOOL allowsColors;
 
+/*!
+ * @brief The style's sender colors
+ */
+ at property (readonly, nonatomic) NSArray *validSenderColors;
+
 //Behavior
 /*!
  *	@brief Set the format of dates/time stamps
diff -r 5585035f872b -r 6a41be7632e5 Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Thu Oct 29 11:44:17 2009 -0400
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Thu Oct 29 12:43:40 2009 -0400
@@ -55,8 +55,6 @@
 // We set back, when the user finishes editing, the correct topic, which wipes out the existance of the span before. We don't need to undo the dbl click action.
 #define TOPIC_INDIVIDUAL_WRAPPER		@"<span id=\"topicEdit\" ondblclick=\"this.setAttribute('contentEditable', true); this.focus();\">%@</span>"
 
-static NSArray *validSenderColors;
-
 @interface NSMutableString (AIKeywordReplacementAdditions)
 - (void) replaceKeyword:(NSString *)word withString:(NSString *)newWord;
 - (void) safeReplaceCharactersInRange:(NSRange)range withString:(NSString *)newWord;
@@ -247,6 +245,21 @@
 
 @synthesize allowsCustomBackground, allowsUserIcons, allowsColors, userIconMask;
 
+- (NSArray *)validSenderColors
+{
+	if(!checkedSenderColors) {
+		NSURL *url = [NSURL fileURLWithPath:[stylePath stringByAppendingPathComponent:@"Incoming/SenderColors.txt"]];
+		NSString *senderColorsFile = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL];
+		
+		if(senderColorsFile)
+			validSenderColors = [[senderColorsFile componentsSeparatedByString:@":"] retain];
+		
+		checkedSenderColors = YES;
+	}
+	
+	return validSenderColors;
+}
+
 - (BOOL)isBackgroundTransparent
 {
 	//Our custom background is only transparent if the user has set a custom color with an alpha component less than 1.0
@@ -776,15 +789,8 @@
 	[inString replaceKeyword:@"%messageClasses%"
 				  withString:[(contentIsSimilar ? @"consecutive " : @"") stringByAppendingString:[[content displayClasses] componentsJoinedByString:@" "]]];
 	
-	if(!validSenderColors) {
-		NSURL *url = [NSURL fileURLWithPath:[stylePath stringByAppendingPathComponent:@"Incoming/SenderColors.txt"]];
-		NSString *senderColorsFile = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL];
-		
-		if(senderColorsFile)
-			validSenderColors = [[senderColorsFile componentsSeparatedByString:@":"] retain];
-	}
 	[inString replaceKeyword:@"%senderColor%"
-				  withString:[NSColor representedColorForObject:contentSource.UID withValidColors:validSenderColors]];
+				  withString:[NSColor representedColorForObject:contentSource.UID withValidColors:self.validSenderColors]];
 	
 	//HAX. The odd conditional here detects the rtl html that our html parser spits out.
 	[inString replaceKeyword:@"%messageDirection%"
@@ -1149,8 +1155,11 @@
 	AIListContact	*listObject = chat.listObject;
 	NSString		*iconPath = nil;
 	
-	[inString replaceKeyword:@"%senderColor%"
-				  withString:[NSColor representedColorForObject:listObject.UID withValidColors:validSenderColors]];
+	[inString replaceKeyword:@"%incomingColor%"
+				  withString:[NSColor representedColorForObject:listObject.UID withValidColors:self.validSenderColors]];
+	
+	[inString replaceKeyword:@"%outgoingColor%"
+				  withString:[NSColor representedColorForObject:chat.account.UID withValidColors:self.validSenderColors]];
 	
 	if (listObject) {
 		iconPath = [listObject valueForProperty:KEY_WEBKIT_USER_ICON];
diff -r 5585035f872b -r 6a41be7632e5 Source/OWSpellingPerContactPlugin.m
--- a/Source/OWSpellingPerContactPlugin.m	Thu Oct 29 11:44:17 2009 -0400
+++ b/Source/OWSpellingPerContactPlugin.m	Thu Oct 29 12:43:40 2009 -0400
@@ -18,6 +18,9 @@
 #import <Adium/AIChat.h>
 #import <Adium/AIListContact.h>
 
+#import <AIUtilities/AIApplicationAdditions.h>
+#import <AIUtilities/AILeopardCompatibility.h>
+
 #define GROUP_LAST_USED_SPELLING	@"Last Used Spelling"
 #define KEY_LAST_USED_SPELLING		@"Last Used Spelling Languge"
 
@@ -49,13 +52,15 @@
 	languageDict = [[NSMutableDictionary alloc] init];
 	
 	//Find the first language the user prefers which the spellchecker knows about, then keep it around for future reference
-	NSEnumerator *enumerator = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectEnumerator];
-	NSString	 *language;
-	while ((language = [enumerator nextObject])) {
-		if ([[NSSpellChecker sharedSpellChecker] setLanguage:language]) {
-			preferredLanguage = [language retain];
-			break;
-		}
+	NSArray *preferredLanguages = nil;
+	if ([NSApp isOnSnowLeopardOrBetter]) {
+		preferredLanguages = [[NSSpellChecker sharedSpellChecker] userPreferredLanguages];
+	} else {
+		preferredLanguages = [[NSSpellChecker sharedSpellChecker] availableLanguages];
+	}
+		
+	if (preferredLanguages.count) {
+		preferredLanguage = [preferredLanguages objectAtIndex:0];
 	}
 }
 
@@ -135,8 +140,9 @@
 		NSString	 *chatID = chat.uniqueChatID;
 		NSString	 *chatLanguage = [languageDict objectForKey:chatID];
 
-		//If we didn't cache a language for this chat, we might just never have made it inactive; use the spell checker's current language
-		if (!chatLanguage) chatLanguage = [[NSSpellChecker sharedSpellChecker] language];
+		//If we didn't cache a language for this chat, or the chat is currently the active chat, use the spell checker's value.
+		if (!chatLanguage || adium.interfaceController.activeChat == chat)
+			chatLanguage = [[NSSpellChecker sharedSpellChecker] language];
 
 		//Now, if we end up at the user's default language, we don't want to store anything
 		if ([preferredLanguage isEqualToString:chatLanguage])
@@ -147,14 +153,7 @@
 			 (!previousLanguage && chatLanguage)) {
 			[listObject setPreference:chatLanguage
 							   forKey:KEY_LAST_USED_SPELLING
-								group:GROUP_LAST_USED_SPELLING];			
-			
-			/* Set this as a global preference such that it will be the default choice for future new chats.
-			 * If a listObject doesn't have its own preference set, this will be inherited.
-			 */
-			[[adium preferenceController] setPreference:chatLanguage
-												 forKey:KEY_LAST_USED_SPELLING
-												  group:GROUP_LAST_USED_SPELLING];
+								group:GROUP_LAST_USED_SPELLING];
 		}
 		
 		[languageDict removeObjectForKey:chatID];




More information about the commits mailing list