Clean up the per-contact spelling a little. I think this fixes #12359.
authorZachary West <zacw@adium.im>
Thu Oct 29 12:43:40 2009 -0400 (2009-10-29)
changeset 28086a41be7632e5
parent 2807 e0421b510067
child 2809 db7418b3e2f9
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.
Frameworks/AIUtilities Framework/Source/AILeopardCompatibility.h
Source/OWSpellingPerContactPlugin.m
     1.1 --- a/Frameworks/AIUtilities Framework/Source/AILeopardCompatibility.h	Thu Oct 29 12:57:14 2009 -0400
     1.2 +++ b/Frameworks/AIUtilities Framework/Source/AILeopardCompatibility.h	Thu Oct 29 12:43:40 2009 -0400
     1.3 @@ -36,6 +36,10 @@
     1.4  - (BOOL)isAutomaticSpellingCorrectionEnabled;
     1.5  - (void)toggleAutomaticSpellingCorrection:(id)sender;
     1.6  @end
     1.7 +
     1.8 +@interface NSSpellChecker(NSSpellCheckerLeopardMethods)
     1.9 +- (NSArray *)userPreferredLanguages;
    1.10 +@end
    1.11  #endif
    1.12  
    1.13  #else //Not compiling for 10.6
     2.1 --- a/Source/OWSpellingPerContactPlugin.m	Thu Oct 29 12:57:14 2009 -0400
     2.2 +++ b/Source/OWSpellingPerContactPlugin.m	Thu Oct 29 12:43:40 2009 -0400
     2.3 @@ -18,6 +18,9 @@
     2.4  #import <Adium/AIChat.h>
     2.5  #import <Adium/AIListContact.h>
     2.6  
     2.7 +#import <AIUtilities/AIApplicationAdditions.h>
     2.8 +#import <AIUtilities/AILeopardCompatibility.h>
     2.9 +
    2.10  #define GROUP_LAST_USED_SPELLING	@"Last Used Spelling"
    2.11  #define KEY_LAST_USED_SPELLING		@"Last Used Spelling Languge"
    2.12  
    2.13 @@ -49,13 +52,15 @@
    2.14  	languageDict = [[NSMutableDictionary alloc] init];
    2.15  	
    2.16  	//Find the first language the user prefers which the spellchecker knows about, then keep it around for future reference
    2.17 -	NSEnumerator *enumerator = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectEnumerator];
    2.18 -	NSString	 *language;
    2.19 -	while ((language = [enumerator nextObject])) {
    2.20 -		if ([[NSSpellChecker sharedSpellChecker] setLanguage:language]) {
    2.21 -			preferredLanguage = [language retain];
    2.22 -			break;
    2.23 -		}
    2.24 +	NSArray *preferredLanguages = nil;
    2.25 +	if ([NSApp isOnSnowLeopardOrBetter]) {
    2.26 +		preferredLanguages = [[NSSpellChecker sharedSpellChecker] userPreferredLanguages];
    2.27 +	} else {
    2.28 +		preferredLanguages = [[NSSpellChecker sharedSpellChecker] availableLanguages];
    2.29 +	}
    2.30 +		
    2.31 +	if (preferredLanguages.count) {
    2.32 +		preferredLanguage = [preferredLanguages objectAtIndex:0];
    2.33  	}
    2.34  }
    2.35  
    2.36 @@ -135,8 +140,9 @@
    2.37  		NSString	 *chatID = chat.uniqueChatID;
    2.38  		NSString	 *chatLanguage = [languageDict objectForKey:chatID];
    2.39  
    2.40 -		//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
    2.41 -		if (!chatLanguage) chatLanguage = [[NSSpellChecker sharedSpellChecker] language];
    2.42 +		//If we didn't cache a language for this chat, or the chat is currently the active chat, use the spell checker's value.
    2.43 +		if (!chatLanguage || adium.interfaceController.activeChat == chat)
    2.44 +			chatLanguage = [[NSSpellChecker sharedSpellChecker] language];
    2.45  
    2.46  		//Now, if we end up at the user's default language, we don't want to store anything
    2.47  		if ([preferredLanguage isEqualToString:chatLanguage])
    2.48 @@ -147,14 +153,7 @@
    2.49  			 (!previousLanguage && chatLanguage)) {
    2.50  			[listObject setPreference:chatLanguage
    2.51  							   forKey:KEY_LAST_USED_SPELLING
    2.52 -								group:GROUP_LAST_USED_SPELLING];			
    2.53 -			
    2.54 -			/* Set this as a global preference such that it will be the default choice for future new chats.
    2.55 -			 * If a listObject doesn't have its own preference set, this will be inherited.
    2.56 -			 */
    2.57 -			[[adium preferenceController] setPreference:chatLanguage
    2.58 -												 forKey:KEY_LAST_USED_SPELLING
    2.59 -												  group:GROUP_LAST_USED_SPELLING];
    2.60 +								group:GROUP_LAST_USED_SPELLING];
    2.61  		}
    2.62  		
    2.63  		[languageDict removeObjectForKey:chatID];