Merged [15040]: Trying some magic: 5 seconds after the last unreachable host is repor...
[adiumx.git] / Source / AISpellCheckingPlugin.m
blob851628f17893c3b5f81bdba4c60e04a7a0acbdb7
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
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;
26 @end
28 /*!
29  * @class AISpellCheckingPlugin
30  * @brief Component to save continuous spell checking preferences and apply them to text entry views
31  */
32 @implementation AISpellCheckingPlugin
34 /*!
35  * @brief Install
36  */
37 - (void)installPlugin
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];
53 /*!
54  * @brief Uninstall
55  */
56 - (void)uninstallPlugin
58     [[adium    contentController] unregisterTextEntryFilter:self];
59         [[adium preferenceController] unregisterPreferenceObserver:self];
62 /*!
63  * @brief A text entry view was opened
64  *
65  * Set the continuous spell checking setting as per our preference
66  */
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];
75 /*!
76  * @brief A text entry view will close
77  *
78  * Save its continuous spell checking setting as our preference
79  */
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];
91         }
92     }
95 /*!
96  * @brief Preferences changed
97  *
98  * Update all open views to match the new spell checking preference
99  */
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;
105         id                              entryView;
106         
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];
111         }
115  * @brief Set the continuous spell checking for an object
117  * @param enabled Is continuous spell checking enabled?
118  */
119 - (void)_setSpellCheckingForObject:(id)inObject enabled:(BOOL)enabled
121     if([inObject respondsToSelector:@selector(setContinuousSpellCheckingEnabled:)]){
122         [(NSTextView *)inObject setContinuousSpellCheckingEnabled:enabled];
123     }
126 @end