adium-1.4 2678:4f51d10a2af5: Clean up the per-contact spelling a...
commits at adium.im
commits at adium.im
Thu Oct 29 16:43:44 UTC 2009
details: http://hg.adium.im/adium-1.4/rev/4f51d10a2af5
revision: 2678:4f51d10a2af5
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 (78 lines):
diff -r 62a90e20d6cc -r 4f51d10a2af5 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 62a90e20d6cc -r 4f51d10a2af5 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