diff options
| -rw-r--r-- | SwifTools/HunspellChecker.cpp | 2 | ||||
| -rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 8 |
2 files changed, 3 insertions, 7 deletions
diff --git a/SwifTools/HunspellChecker.cpp b/SwifTools/HunspellChecker.cpp index ecd352e..e9bc558 100644 --- a/SwifTools/HunspellChecker.cpp +++ b/SwifTools/HunspellChecker.cpp @@ -1,55 +1,55 @@ /* * Copyright (c) 2011 Vlad Voicu * Licensed under the Simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include <SwifTools/HunspellChecker.h> #include <algorithm> #include <hunspell/hunspell.hxx> #include <boost/algorithm/string.hpp> namespace Swift { HunspellChecker::HunspellChecker(const char* affix_path, const char* dictionary_path) { speller_ = new Hunspell(affix_path, dictionary_path); } HunspellChecker::~HunspellChecker() { delete speller_; } bool HunspellChecker::isCorrect(const std::string& word) { return speller_->spell(word.c_str()); } void HunspellChecker::getSuggestions(const std::string& word, std::vector<std::string>& list) { - char **suggestList; + char **suggestList = NULL; int words_returned; if (!word.empty()) { words_returned = speller_->suggest(&suggestList, word.c_str()); } for (int i = 0; i < words_returned; ++i) { list.push_back(suggestList[i]); free(suggestList[i]); } free(suggestList); } void HunspellChecker::checkFragment(const std::string& fragment, PositionPairList& misspelledPositions) { if (!fragment.empty()) { parser_->check(fragment, misspelledPositions); for (PositionPairList::iterator it = misspelledPositions.begin(); it != misspelledPositions.end();) { if (isCorrect(fragment.substr(boost::get<0>(*it), boost::get<1>(*it) - boost::get<0>(*it)))) { it = misspelledPositions.erase(it); } else { ++it; } } } } } diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index cac8bb4..8551f3d 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -170,74 +170,70 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) { replaceWordActions_.clear(); QAction* insertPoint = menu->actions().first(); QTextCursor cursor = cursorForPosition(event->pos()); PositionPair wordPosition = getWordFromCursor(cursor.position()); if (boost::get<0>(wordPosition) < 0) { // The click was executed outside a spellable word so no // suggestions are necessary return; } cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); std::vector<std::string> wordList; checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); if (wordList.size() == 0) { QAction* noSuggestions = new QAction(tr("No Suggestions"), menu); noSuggestions->setDisabled(true); menu->insertAction(insertPoint, noSuggestions); } else { for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { QAction* wordAction = new QAction(it->c_str(), menu); menu->insertAction(insertPoint, wordAction); replaceWordActions_.push_back(wordAction); } } menu->insertAction(insertPoint, menu->addSeparator()); } #ifdef HAVE_SPELLCHECKER void QtTextEdit::setUpSpellChecker() { - SpellCheckerFactory* checkerFactory = new SpellCheckerFactory(); delete checker_; + checker_ = NULL; if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) { std::string dictPath = settings_->getSetting(SettingConstants::DICT_PATH); std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE); - checker_ = checkerFactory->createSpellChecker(dictPath + dictFile); - delete checkerFactory; - } - else { - checker_ = NULL; + checker_ = SpellCheckerFactory().createSpellChecker(dictPath + dictFile); } } #endif void QtTextEdit::spellCheckerSettingsWindow() { if (!spellCheckerWindow_) { spellCheckerWindow_ = new QtSpellCheckerWindow(settings_); settings_->onSettingChanged.connect(boost::bind(&QtTextEdit::handleSettingChanged, this, _1)); spellCheckerWindow_->show(); } else { spellCheckerWindow_->show(); spellCheckerWindow_->raise(); spellCheckerWindow_->activateWindow(); } } void QtTextEdit::handleSettingChanged(const std::string& settings) { if (settings == SettingConstants::SPELL_CHECKER.getKey() || settings == SettingConstants::DICT_PATH.getKey() || settings == SettingConstants::DICT_FILE.getKey()) { #ifdef HAVE_SPELLCHECKER setUpSpellChecker(); underlineMisspells(); #endif } } } |
Swift