diff options
author | Vlad Voicu <vladv@rosedu.org> | 2012-02-01 13:09:53 (GMT) |
---|---|---|
committer | vlad <vlad@tyrion.(none)> | 2012-10-13 13:55:44 (GMT) |
commit | 58efe2c43e54a3d868784a6968e52674309e2310 (patch) | |
tree | df6788d45659095653d70c89ea7ab894d8dc0b50 /Swift | |
parent | 3d6bc0b6181c6cdfc6c0a91960e9dac30ddfdba2 (diff) | |
download | swift-contrib-58efe2c43e54a3d868784a6968e52674309e2310.zip swift-contrib-58efe2c43e54a3d868784a6968e52674309e2310.tar.bz2 |
Context Menu improvements
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 7e7683c..60f0939 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -12,6 +12,7 @@ #include <Swift/QtUI/QtTextEdit.h> #include <Swift/QtUI/QtSwiftUtil.h> +#include <QApplication> #include <QFontMetrics> #include <QKeyEvent> #include <QDebug> @@ -122,9 +123,14 @@ QSize QtTextEdit::sizeHint() const { } void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { + QMenu *menu = createStandardContextMenu(); QTextCursor cursor = cursorForPosition(event->pos()); boost::tuple<int, int> wordPosition = getWordFromCursor(cursor.position()); if (boost::get<0>(wordPosition) < 0) { + // The click was executed outside a spellable word so no + // suggestion menu is necessary + menu->exec(event->globalPos()); + delete menu; return; } cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); @@ -132,11 +138,19 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { std::vector<std::string> wordList; checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); std::vector<QAction*> replaceWordActions; - QMenu *menu = createStandardContextMenu(); - for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { - replaceWordActions.push_back(menu->addAction(tr(it->c_str()))); + QAction *insertPoint = menu->actions().first(); + if (wordList.size() == 0) { + QAction *noSuggestions = new QAction(QApplication::translate("QtTextEdit", "No Suggestions", 0, QApplication::UnicodeUTF8), 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()); QAction* result = menu->exec(event->globalPos()); for (std::vector<QAction*>::iterator it = replaceWordActions.begin(); it != replaceWordActions.end(); ++it) { if (*it == result) { |