Added selection functions to the context menu
This commit is contained in:
@@ -245,6 +245,7 @@ class nwUnicode:
|
|||||||
## Symbols
|
## Symbols
|
||||||
U_CHECK = "\u2714" # Heavy check mark
|
U_CHECK = "\u2714" # Heavy check mark
|
||||||
U_MULT = "\u2715" # Multiplication x
|
U_MULT = "\u2715" # Multiplication x
|
||||||
|
U_BULL = "\u2022" # List bullet
|
||||||
|
|
||||||
## Arrows
|
## Arrows
|
||||||
U_UTRI = "\u25b2" # Up-pointing triangle
|
U_UTRI = "\u25b2" # Up-pointing triangle
|
||||||
@@ -294,6 +295,7 @@ class nwUnicode:
|
|||||||
## Symbols
|
## Symbols
|
||||||
H_CHECK = "✔"
|
H_CHECK = "✔"
|
||||||
H_MULT = "✕"
|
H_MULT = "✕"
|
||||||
|
H_BULL = "•"
|
||||||
|
|
||||||
## Arrows
|
## Arrows
|
||||||
H_UTRI = "▲"
|
H_UTRI = "▲"
|
||||||
|
|||||||
+46
-10
@@ -732,14 +732,14 @@ class GuiDocEditor(QTextEdit):
|
|||||||
"""Triggered by right click to open the context menu. Also
|
"""Triggered by right click to open the context menu. Also
|
||||||
triggered by the Ctrl+. shortcut.
|
triggered by the Ctrl+. shortcut.
|
||||||
"""
|
"""
|
||||||
if not self.spellCheck:
|
|
||||||
return
|
|
||||||
|
|
||||||
userCursor = self.textCursor()
|
userCursor = self.textCursor()
|
||||||
userSelection = userCursor.hasSelection()
|
userSelection = userCursor.hasSelection()
|
||||||
|
|
||||||
mnuContext = QMenu()
|
mnuContext = QMenu()
|
||||||
|
|
||||||
|
# Cut, Copy and Paste
|
||||||
|
# ===================
|
||||||
|
|
||||||
if userSelection:
|
if userSelection:
|
||||||
mnuCut = QAction("Cut", mnuContext)
|
mnuCut = QAction("Cut", mnuContext)
|
||||||
mnuCut.triggered.connect(lambda: self.docAction(nwDocAction.CUT))
|
mnuCut.triggered.connect(lambda: self.docAction(nwDocAction.CUT))
|
||||||
@@ -753,11 +753,37 @@ class GuiDocEditor(QTextEdit):
|
|||||||
mnuPaste.triggered.connect(lambda: self.docAction(nwDocAction.PASTE))
|
mnuPaste.triggered.connect(lambda: self.docAction(nwDocAction.PASTE))
|
||||||
mnuContext.addAction(mnuPaste)
|
mnuContext.addAction(mnuPaste)
|
||||||
|
|
||||||
# Check if we should look up the spelling
|
mnuContext.addSeparator()
|
||||||
posCursor = self.cursorForPosition(thePos)
|
|
||||||
posCursor.select(QTextCursor.WordUnderCursor)
|
# Selections
|
||||||
theWord = posCursor.selectedText().strip().strip(self.nonWord)
|
# ==========
|
||||||
spellCheck = theWord != ""
|
|
||||||
|
mnuSelAll = QAction("Select All", mnuContext)
|
||||||
|
mnuSelAll.triggered.connect(lambda: self.docAction(nwDocAction.SEL_ALL))
|
||||||
|
mnuContext.addAction(mnuSelAll)
|
||||||
|
|
||||||
|
mnuSelWord = QAction("Select Word", mnuContext)
|
||||||
|
mnuSelWord.triggered.connect(
|
||||||
|
lambda: self._makePosSelection(QTextCursor.WordUnderCursor, thePos)
|
||||||
|
)
|
||||||
|
mnuContext.addAction(mnuSelWord)
|
||||||
|
|
||||||
|
mnuSelPara = QAction("Select Paragraph", mnuContext)
|
||||||
|
mnuSelPara.triggered.connect(
|
||||||
|
lambda: self._makePosSelection(QTextCursor.BlockUnderCursor, thePos)
|
||||||
|
)
|
||||||
|
mnuContext.addAction(mnuSelPara)
|
||||||
|
|
||||||
|
# Spell Checking
|
||||||
|
# ==============
|
||||||
|
|
||||||
|
spellCheck = self.spellCheck
|
||||||
|
|
||||||
|
if spellCheck:
|
||||||
|
posCursor = self.cursorForPosition(thePos)
|
||||||
|
posCursor.select(QTextCursor.WordUnderCursor)
|
||||||
|
theWord = posCursor.selectedText().strip().strip(self.nonWord)
|
||||||
|
spellCheck &= theWord != ""
|
||||||
|
|
||||||
if spellCheck:
|
if spellCheck:
|
||||||
logger.verbose("Looking up '%s' in the dictionary" % theWord)
|
logger.verbose("Looking up '%s' in the dictionary" % theWord)
|
||||||
@@ -771,7 +797,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
theSuggest = self.theDict.suggestWords(theWord)
|
theSuggest = self.theDict.suggestWords(theWord)
|
||||||
if len(theSuggest) > 0:
|
if len(theSuggest) > 0:
|
||||||
for aWord in theSuggest:
|
for aWord in theSuggest:
|
||||||
mnuWord = QAction(aWord, mnuContext)
|
mnuWord = QAction("%s %s" % (nwUnicode.U_ENDASH, aWord), mnuContext)
|
||||||
mnuWord.triggered.connect(
|
mnuWord.triggered.connect(
|
||||||
lambda thePos, aWord=aWord : self._correctWord(posCursor, aWord)
|
lambda thePos, aWord=aWord : self._correctWord(posCursor, aWord)
|
||||||
)
|
)
|
||||||
@@ -785,6 +811,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
mnuHead = QAction("No Suggestions", mnuContext)
|
mnuHead = QAction("No Suggestions", mnuContext)
|
||||||
mnuContext.addAction(mnuHead)
|
mnuContext.addAction(mnuHead)
|
||||||
|
|
||||||
|
# Open the context menu
|
||||||
mnuContext.exec_(self.viewport().mapToGlobal(thePos))
|
mnuContext.exec_(self.viewport().mapToGlobal(thePos))
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -1215,7 +1242,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _makeSelection(self, selMode):
|
def _makeSelection(self, selMode):
|
||||||
"""Wrapper function to select a word based on a selection mode.
|
"""Wrapper function to select text based on a selection mode.
|
||||||
"""
|
"""
|
||||||
theCursor = self.textCursor()
|
theCursor = self.textCursor()
|
||||||
theCursor.clearSelection()
|
theCursor.clearSelection()
|
||||||
@@ -1235,6 +1262,15 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _makePosSelection(self, selMode, thePos):
|
||||||
|
"""Wrapper function to select text based on selection mode, but
|
||||||
|
first move cursor to given position.
|
||||||
|
"""
|
||||||
|
theCursor = self.cursorForPosition(thePos)
|
||||||
|
self.setTextCursor(theCursor)
|
||||||
|
self._makeSelection(selMode)
|
||||||
|
return
|
||||||
|
|
||||||
def _beginSearch(self):
|
def _beginSearch(self):
|
||||||
"""Sets the selected text as the search text for the search bar.
|
"""Sets the selected text as the search text for the search bar.
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user