8#include "nsspellcheckerdict.h"
9#include "nsspellcheckerdebug.h"
11#import <AppKit/AppKit.h>
15NSSpellCheckerDict::NSSpellCheckerDict(
const QString &lang)
17 , m_langCode([lang.toNSString() retain])
19 NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
20 if ([checker setLanguage:m_langCode]) {
21 qCDebug(SONNET_NSSPELLCHECKER) <<
"Loading dictionary for" << lang;
22 [checker updatePanels];
24 qCWarning(SONNET_NSSPELLCHECKER) <<
"Loading dictionary for unsupported language" << lang;
28NSSpellCheckerDict::~NSSpellCheckerDict()
33bool NSSpellCheckerDict::isCorrect(
const QString &word)
const
36 NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
37 NSRange range = [checker checkSpellingOfString:nsWord
38 startingAt:0 language:m_langCode
39 wrap:NO inSpellDocumentWithTag:0 wordCount:
nullptr];
40 if (range.length == 0) {
44 if (NSDictionary *replacements = [checker userReplacementsDictionary]) {
45 return [replacements objectForKey:nsWord] == nil;
56 NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
57 NSArray *suggestions = [checker guessesForWordRange:NSMakeRange(0, word.
length())
58 inString:nsWord language:m_langCode inSpellDocumentWithTag:0];
60 NSDictionary *replacements = [checker userReplacementsDictionary];
62 if ([replacements objectForKey:nsWord]) {
67 for (NSString *suggestion in suggestions) {
71 if (str != replacement) {
78bool NSSpellCheckerDict::storeReplacement(
const QString &bad,
81 qCDebug(SONNET_NSSPELLCHECKER) <<
"Not storing replacement" << good <<
"for" << bad;
85bool NSSpellCheckerDict::addToPersonal(
const QString &word)
88 NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
89 if (![checker hasLearnedWord:nsWord]) {
90 [checker learnWord:nsWord];
91 [checker updatePanels];
96bool NSSpellCheckerDict::addToSession(
const QString &word)
98 qCDebug(SONNET_NSSPELLCHECKER) <<
"Not storing" << word <<
"in the session dictionary";
QString fromNSString(const NSString *string)
qsizetype length() const const
NSString * toNSString() const const