2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AIContentController.h"
18 #import "AIInterfaceController.h"
19 #import "AIPreferenceController.h"
20 #import "AISpellCheckingPlugin.h"
21 #import <AIUtilities/AIDictionaryAdditions.h>
23 @interface AISpellCheckingPlugin (PRIVATE)
24 - (void)preferencesChanged:(NSNotification *)notification;
25 - (void)_setSpellCheckingForObject:(id)inObject enabled:(BOOL)enabled;
29 * @class AISpellCheckingPlugin
30 * @brief Component to save continuous spell checking preferences and apply them to text entry views
32 @implementation AISpellCheckingPlugin
39 AIPreferenceController *preferenceController = [adium preferenceController];
41 //Setup our preferences
42 [preferenceController registerDefaults:[NSDictionary dictionaryNamed:SPELL_CHECKING_DEFAULT_PREFS
43 forClass:[self class]]
44 forGroup:PREF_GROUP_SPELLING];
46 //Register as a text entry filter
47 [[adium contentController] registerTextEntryFilter:self];
49 //Observe preference changes
50 [preferenceController registerPreferenceObserver:self forGroup:PREF_GROUP_SPELLING];
56 - (void)uninstallPlugin
58 [[adium contentController] unregisterTextEntryFilter:self];
59 [[adium preferenceController] unregisterPreferenceObserver:self];
63 * @brief A text entry view was opened
65 * Set the continuous spell checking setting as per our preference
67 - (void)didOpenTextEntryView:(NSText<AITextEntryView> *)inTextEntryView
69 BOOL spellEnabled = [[[[adium preferenceController] preferencesForGroup:PREF_GROUP_SPELLING] objectForKey:KEY_SPELL_CHECKING] boolValue];
71 //Set spellcheck state
72 [self _setSpellCheckingForObject:inTextEntryView enabled:spellEnabled];
76 * @brief A text entry view will close
78 * Save its continuous spell checking setting as our preference
80 - (void)willCloseTextEntryView:(NSText<AITextEntryView> *)inTextEntryView
82 //Save spellcheck state
83 if([inTextEntryView respondsToSelector:@selector(isContinuousSpellCheckingEnabled)]){
84 BOOL spellEnabled = [[[[adium preferenceController] preferencesForGroup:PREF_GROUP_SPELLING] objectForKey:KEY_SPELL_CHECKING] boolValue];
85 BOOL currentEnabled = [(NSTextView *)inTextEntryView isContinuousSpellCheckingEnabled];
87 if(currentEnabled != spellEnabled){
88 [[adium preferenceController] setPreference:[NSNumber numberWithBool:currentEnabled]
89 forKey:KEY_SPELL_CHECKING
90 group:PREF_GROUP_SPELLING];
96 * @brief Preferences changed
98 * Update all open views to match the new spell checking preference
100 - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
101 object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
103 BOOL spellEnabled = [[prefDict objectForKey:KEY_SPELL_CHECKING] boolValue];
104 NSEnumerator *enumerator;
107 //Set spellcheck state of all open views
108 enumerator = [[[adium contentController] openTextEntryViews] objectEnumerator];
109 while(entryView = [enumerator nextObject]){
110 [self _setSpellCheckingForObject:entryView enabled:spellEnabled];
115 * @brief Set the continuous spell checking for an object
117 * @param enabled Is continuous spell checking enabled?
119 - (void)_setSpellCheckingForObject:(id)inObject enabled:(BOOL)enabled
121 if([inObject respondsToSelector:@selector(setContinuousSpellCheckingEnabled:)]){
122 [(NSTextView *)inObject setContinuousSpellCheckingEnabled:enabled];