Improved the suggestion menu
This commit is contained in:
+12
-9
@@ -186,17 +186,17 @@ class GuiDocEditor(QTextEdit):
|
|||||||
theWord = theCursor.selectedText()
|
theWord = theCursor.selectedText()
|
||||||
if theWord == "":
|
if theWord == "":
|
||||||
return
|
return
|
||||||
|
if self.theDict.check(theWord):
|
||||||
|
return
|
||||||
|
|
||||||
mnuSuggest = QMenu()
|
mnuSuggest = QMenu()
|
||||||
spIcon = QIcon.fromTheme("tools-check-spelling")
|
spIcon = QIcon.fromTheme("tools-check-spelling")
|
||||||
if self.theDict.check(theWord):
|
mnuHead = QAction(spIcon,"Spelling Suggestion", mnuSuggest)
|
||||||
mnuHead = QAction(spIcon,"No Suggestion", mnuSuggest)
|
mnuSuggest.addAction(mnuHead)
|
||||||
mnuSuggest.addAction(mnuHead)
|
mnuSuggest.addSeparator()
|
||||||
else:
|
theSuggest = self.theDict.suggest(theWord)
|
||||||
mnuHead = QAction(spIcon,"Spelling Suggestion", mnuSuggest)
|
if len(theSuggest) > 0:
|
||||||
mnuSuggest.addAction(mnuHead)
|
for aWord in theSuggest:
|
||||||
mnuSuggest.addSeparator()
|
|
||||||
for aWord in self.theDict.suggest(theWord):
|
|
||||||
mnuWord = QAction(aWord, mnuSuggest)
|
mnuWord = QAction(aWord, mnuSuggest)
|
||||||
mnuWord.triggered.connect(lambda thePos, aWord=aWord : self._correctWord(theCursor, aWord))
|
mnuWord.triggered.connect(lambda thePos, aWord=aWord : self._correctWord(theCursor, aWord))
|
||||||
mnuSuggest.addAction(mnuWord)
|
mnuSuggest.addAction(mnuWord)
|
||||||
@@ -204,6 +204,9 @@ class GuiDocEditor(QTextEdit):
|
|||||||
mnuAdd = QAction("Add Word to Dictionary", mnuSuggest)
|
mnuAdd = QAction("Add Word to Dictionary", mnuSuggest)
|
||||||
mnuAdd.triggered.connect(lambda thePos : self._addWord(theCursor))
|
mnuAdd.triggered.connect(lambda thePos : self._addWord(theCursor))
|
||||||
mnuSuggest.addAction(mnuAdd)
|
mnuSuggest.addAction(mnuAdd)
|
||||||
|
else:
|
||||||
|
mnuHead = QAction("No Suggestions", mnuSuggest)
|
||||||
|
mnuSuggest.addAction(mnuHead)
|
||||||
|
|
||||||
mnuSuggest.exec_(self.viewport().mapToGlobal(thePos))
|
mnuSuggest.exec_(self.viewport().mapToGlobal(thePos))
|
||||||
|
|
||||||
@@ -220,7 +223,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _addWord(self, theCursor):
|
def _addWord(self, theCursor):
|
||||||
theWord = theCursor.selectedText()
|
theWord = theCursor.selectedText().strip()
|
||||||
logger.info("Added '%s' to project dictionary" % theWord)
|
logger.info("Added '%s' to project dictionary" % theWord)
|
||||||
self.theDict.add_to_pwl(theWord)
|
self.theDict.add_to_pwl(theWord)
|
||||||
self.hLight.setDict(self.theDict)
|
self.hLight.setDict(self.theDict)
|
||||||
|
|||||||
Reference in New Issue
Block a user