Fixes ##1977496
This commit is contained in:
Kovid Goyal 2022-06-03 19:00:25 +05:30
commit 303380ba37
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,7 +7,7 @@ __license__ = 'GPL v3'
from qt.core import (
QApplication, QDialog, QDialogButtonBox, QPlainTextEdit, QSize, Qt,
QVBoxLayout
QVBoxLayout, QLabel, QHBoxLayout, pyqtSignal
)
from calibre.gui2 import Application, gprefs
@ -66,6 +66,17 @@ class CommentsDialog(QDialog):
return QDialog.closeEvent(self, ev)
class PlainTextEdit(QPlainTextEdit):
ctrl_enter_pushed = pyqtSignal()
def keyPressEvent(self, event):
if event.modifiers() & Qt.KeyboardModifier.ControlModifier and event.key() == Qt.Key.Key_Return:
event.accept()
self.ctrl_enter_pushed.emit()
else:
super().keyPressEvent(event)
class PlainTextDialog(Dialog):
def __init__(self, parent, text, column_name=None):
@ -75,9 +86,16 @@ class PlainTextDialog(Dialog):
def setup_ui(self):
self.l = l = QVBoxLayout(self)
self._text = QPlainTextEdit(self)
self._text = PlainTextEdit(self)
self._text.ctrl_enter_pushed.connect(self.ctrl_enter_pushed)
l.addWidget(self._text)
l.addWidget(self.bb)
hl = QHBoxLayout()
hl.addWidget(QLabel(_('Press Ctrl+Enter to accept or Esc to cancel')))
hl.addWidget(self.bb)
l.addLayout(hl)
def ctrl_enter_pushed(self):
self.accept()
@property
def text(self):