diff options
author | Vlad Voicu <vladv@rosedu.org> | 2012-03-08 13:10:15 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-03-09 15:04:11 (GMT) |
commit | 02f7f0d98e937d8ec2d527ac701daf783bb37f27 (patch) | |
tree | 90555f4fd78725042cddb0abac32fca403a94be9 /Swift | |
parent | dbc27f2f163c33366fc9ca31088f0c255963168b (diff) | |
download | swift-contrib-02f7f0d98e937d8ec2d527ac701daf783bb37f27.zip swift-contrib-02f7f0d98e937d8ec2d527ac701daf783bb37f27.tar.bz2 |
Gracefully degrade when hunspell is not present
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 24 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 2 |
2 files changed, 16 insertions, 10 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 75bc292..513e6fd 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -27,7 +27,9 @@ QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit( connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged())); checker_ = NULL; settings_ = settings; +#ifdef HAVE_SPELLCHECKER setUpSpellChecker(); +#endif handleTextChanged(); }; @@ -60,9 +62,11 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) { } else { QTextEdit::keyPressEvent(event); - if(settings_->getSetting(SettingConstants::SPELL_CHECKER)) { +#ifdef HAVE_SPELLCHECKER + if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) { underlineMisspells(); } +#endif } } @@ -82,12 +86,10 @@ void QtTextEdit::underlineMisspells() { std::string fragment = Q2PSTRING(cursor.selectedText()); checker_->checkFragment(fragment, misspelledPositions_); for (PositionPairList::iterator it = misspelledPositions_.begin(); it != misspelledPositions_.end(); ++it) { - if (textCursor().position() > boost::get<1>(*it)) { - cursor.setPosition(boost::get<0>(*it), QTextCursor::MoveAnchor); - cursor.setPosition(boost::get<1>(*it), QTextCursor::KeepAnchor); - cursor.setCharFormat(spellingErrorFormat); - cursor.clearSelection(); - } + cursor.setPosition(boost::get<0>(*it), QTextCursor::MoveAnchor); + cursor.setPosition(boost::get<1>(*it), QTextCursor::KeepAnchor); + cursor.setCharFormat(spellingErrorFormat); + cursor.clearSelection(); cursor.setCharFormat(normalFormat); } } @@ -134,8 +136,8 @@ QSize QtTextEdit::sizeHint() const { void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { QMenu *menu = createStandardContextMenu(); QTextCursor cursor = cursorForPosition(event->pos()); +#ifdef HAVE_SPELLCHECKER QAction *insertPoint = menu->actions().first(); - QAction *settingsAction = new QAction(QApplication::translate("QtTextEdit", "Spell Checker Options", 0, QApplication::UnicodeUTF8), menu); menu->insertAction(insertPoint, settingsAction); menu->insertAction(insertPoint, menu->addSeparator()); @@ -149,6 +151,9 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { replaceMisspelledWord((*it)->text(), cursor.position()); } } +#else + menu->exec(event->globalPos()); +#endif delete menu; } @@ -193,6 +198,7 @@ void QtTextEdit::setUpSpellChecker() std::string affixFile(dictFile); boost::replace_all(affixFile, ".dic", ".aff"); if ((boost::filesystem::exists(dictPath + dictFile)) && (boost::filesystem::exists(dictPath + affixFile))) { + std::cout << dictPath + dictFile << std::endl; checker_ = checkerFactory->createSpellChecker((dictPath + affixFile).c_str(), (dictPath + dictFile).c_str()); } else { @@ -220,8 +226,6 @@ void QtTextEdit::spellCheckerSettingsWindow() { } void QtTextEdit::handleModifiedSettings() { - delete checker_; - checker_ = NULL; setUpSpellChecker(); underlineMisspells(); } diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 2c0b28b..3b49f4b 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -39,6 +39,8 @@ if myenv["swift_mobile"] : if myenv.get("HAVE_SNARL", False) : myenv.UseFlags(myenv["SNARL_FLAGS"]) myenv.Append(CPPDEFINES = ["HAVE_SNARL"]) +if myenv.get("HAVE_HUNSPELL", True): + myenv.Append(CPPDEFINES = ["HAVE_HUNSPELL"]) if env["PLATFORM"] == "win32" : myenv.Append(LIBS = ["cryptui"]) myenv.UseFlags(myenv["PLATFORM_FLAGS"]) |