diff options
| -rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index fed8819..79a9474 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp | |||
| @@ -150,35 +150,37 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { | |||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) | 152 | void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) |
| 153 | { | 153 | { |
| 154 | replaceWordActions_.clear(); | 154 | replaceWordActions_.clear(); |
| 155 | QAction* insertPoint = menu->actions().first(); | 155 | if (checker_ && highlighter_) { |
| 156 | QTextCursor cursor = cursorForPosition(event->pos()); | 156 | QAction* insertPoint = menu->actions().first(); |
| 157 | PositionPair wordPosition = getWordFromCursor(cursor.position()); | 157 | QTextCursor cursor = cursorForPosition(event->pos()); |
| 158 | if (boost::get<0>(wordPosition) < 0) { | 158 | PositionPair wordPosition = getWordFromCursor(cursor.position()); |
| 159 | // The click was executed outside a spellable word so no | 159 | if (boost::get<0>(wordPosition) < 0) { |
| 160 | // suggestions are necessary | 160 | // The click was executed outside a spellable word so no |
| 161 | return; | 161 | // suggestions are necessary |
| 162 | } | 162 | return; |
| 163 | cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); | 163 | } |
| 164 | cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); | 164 | cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); |
| 165 | std::vector<std::string> wordList; | 165 | cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); |
| 166 | checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); | 166 | std::vector<std::string> wordList; |
| 167 | if (wordList.size() == 0) { | 167 | checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); |
| 168 | QAction* noSuggestions = new QAction(tr("No Suggestions"), menu); | 168 | if (wordList.size() == 0) { |
| 169 | noSuggestions->setDisabled(true); | 169 | QAction* noSuggestions = new QAction(tr("No Suggestions"), menu); |
| 170 | menu->insertAction(insertPoint, noSuggestions); | 170 | noSuggestions->setDisabled(true); |
| 171 | } | 171 | menu->insertAction(insertPoint, noSuggestions); |
| 172 | else { | ||
| 173 | for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { | ||
| 174 | QAction* wordAction = new QAction(it->c_str(), menu); | ||
| 175 | menu->insertAction(insertPoint, wordAction); | ||
| 176 | replaceWordActions_.push_back(wordAction); | ||
| 177 | } | 172 | } |
| 173 | else { | ||
| 174 | for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { | ||
| 175 | QAction* wordAction = new QAction(it->c_str(), menu); | ||
| 176 | menu->insertAction(insertPoint, wordAction); | ||
| 177 | replaceWordActions_.push_back(wordAction); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | menu->insertAction(insertPoint, menu->addSeparator()); | ||
| 178 | } | 181 | } |
| 179 | menu->insertAction(insertPoint, menu->addSeparator()); | ||
| 180 | } | 182 | } |
| 181 | 183 | ||
| 182 | 184 | ||
| 183 | #ifdef HAVE_SPELLCHECKER | 185 | #ifdef HAVE_SPELLCHECKER |
| 184 | void QtTextEdit::setUpSpellChecker() | 186 | void QtTextEdit::setUpSpellChecker() |
Swift