Allow Ctrl+Del to be propagated to the document editor

This commit is contained in:
Veronica K. B. Olsen
2021-02-11 19:11:41 +01:00
parent 3a60abaeee
commit 08651685d4
3 changed files with 17 additions and 3 deletions
+1
View File
@@ -94,6 +94,7 @@ class nwDocAction(Enum):
BLOCK_TXT = 23 BLOCK_TXT = 23
REPL_SNG = 24 REPL_SNG = 24
REPL_DBL = 25 REPL_DBL = 25
DEL_WORD = 26
# END Enum nwDocAction # END Enum nwDocAction
+5 -2
View File
@@ -37,11 +37,11 @@ from time import time
from PyQt5.QtCore import ( from PyQt5.QtCore import (
Qt, QSize, QTimer, pyqtSlot, pyqtSignal, QRegExp, QRegularExpression, Qt, QSize, QTimer, pyqtSlot, pyqtSignal, QRegExp, QRegularExpression,
QPointF, QObject, QRunnable, QPropertyAnimation QPointF, QObject, QRunnable, QPropertyAnimation, QEvent
) )
from PyQt5.QtGui import ( from PyQt5.QtGui import (
QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette, QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette,
QTextDocument, QCursor, QPixmap QTextDocument, QCursor, QPixmap, QKeyEvent
) )
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
qApp, QTextEdit, QAction, QMenu, QShortcut, QMessageBox, QWidget, QLabel, qApp, QTextEdit, QAction, QMenu, QShortcut, QMessageBox, QWidget, QLabel,
@@ -719,6 +719,8 @@ class GuiDocEditor(QTextEdit):
self._replaceQuotes("'", self.typSQOpen, self.typSQClose) self._replaceQuotes("'", self.typSQOpen, self.typSQClose)
elif theAction == nwDocAction.REPL_DBL: elif theAction == nwDocAction.REPL_DBL:
self._replaceQuotes("\"", self.typDQOpen, self.typDQClose) self._replaceQuotes("\"", self.typDQOpen, self.typDQClose)
elif theAction == nwDocAction.DEL_WORD:
self.keyPressEvent(QKeyEvent(QEvent.KeyPress, Qt.Key_Delete, Qt.ControlModifier))
else: else:
logger.debug("Unknown or unsupported document action %s" % str(theAction)) logger.debug("Unknown or unsupported document action %s" % str(theAction))
self._allowAutoReplace(True) self._allowAutoReplace(True)
@@ -843,6 +845,7 @@ class GuiDocEditor(QTextEdit):
* The undo/redo/select all sequences bypasses the docAction * The undo/redo/select all sequences bypasses the docAction
pathway from the menu, so we redirect them back from here. pathway from the menu, so we redirect them back from here.
""" """
print(keyEvent.type())
self.lastActive = time() self.lastActive = time()
isReturn = keyEvent.key() == Qt.Key_Return isReturn = keyEvent.key() == Qt.Key_Return
isReturn |= keyEvent.key() == Qt.Key_Enter isReturn |= keyEvent.key() == Qt.Key_Enter
+11 -1
View File
@@ -172,6 +172,16 @@ class GuiMainMenu(QMenuBar):
QDesktopServices.openUrl(QUrl(theUrl)) QDesktopServices.openUrl(QUrl(theUrl))
return True return True
def _handleCtrlDel(self):
"""Direct the Ctrl+Del key press to the correct widget.
"""
if self.theParent.treeView.hasFocus():
self.theParent.treeView.deleteItem(None)
elif self.theParent.docEditor.hasFocus():
self.theParent.docEditor.docAction(nwDocAction.DEL_WORD)
return
## ##
# Menu Builders # Menu Builders
## ##
@@ -270,7 +280,7 @@ class GuiMainMenu(QMenuBar):
self.aDeleteItem = QAction("Delete Item", self) self.aDeleteItem = QAction("Delete Item", self)
self.aDeleteItem.setStatusTip("Delete selected project item") self.aDeleteItem.setStatusTip("Delete selected project item")
self.aDeleteItem.setShortcut("Ctrl+Del") self.aDeleteItem.setShortcut("Ctrl+Del")
self.aDeleteItem.triggered.connect(lambda: self.theParent.treeView.deleteItem(None)) self.aDeleteItem.triggered.connect(self._handleCtrlDel)
self.projMenu.addAction(self.aDeleteItem) self.projMenu.addAction(self.aDeleteItem)
# Project > Move Up # Project > Move Up