From 01c824df6a867049cfb8f52a81dba43202418c3c Mon Sep 17 00:00:00 2001 From: "Nicholas H.Tollervey" Date: Mon, 6 Jan 2020 15:40:06 +0000 Subject: [PATCH] Add shortcuts for sending replies. Fixes # 606. --- securedrop_client/gui/widgets.py | 9 ++++++++- tests/gui/test_widgets.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index 302a5666d..a19ddffdd 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -26,7 +26,7 @@ from uuid import uuid4 from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QEvent, QTimer, QSize, pyqtBoundSignal, \ QObject, QPoint -from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor, QFont, QLinearGradient +from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor, QFont, QLinearGradient, QKeySequence from PyQt5.QtWidgets import QListWidget, QLabel, QWidget, QListWidgetItem, QHBoxLayout, \ QPushButton, QVBoxLayout, QLineEdit, QScrollArea, QDialog, QAction, QMenu, QMessageBox, \ QToolButton, QSizePolicy, QPlainTextEdit, QStatusBar, QGraphicsDropShadowEffect @@ -2561,6 +2561,11 @@ def __init__(self, source: Source, controller: Controller) -> None: button_icon = QIcon(button_pixmap) self.send_button.setIcon(button_icon) self.send_button.setIconSize(QSize(56.5, 47)) + self.send_button.setShortcut(QKeySequence("Ctrl+Return")) + self.send_button.setDefault(True) + + # Ensure TAB order from text edit -> send button + self.setTabOrder(self.text_edit, self.send_button) # Add widgets to replybox replybox_layout.addWidget(self.text_edit) @@ -2641,6 +2646,8 @@ def __init__(self, source, controller): self.setObjectName('reply_textedit') self.setStyleSheet(self.CSS) + self.setTabChangesFocus(True) # Needed so we can TAB to send button. + self.placeholder = QLabel() self.placeholder.setObjectName("reply_placeholder") self.placeholder.setParent(self) diff --git a/tests/gui/test_widgets.py b/tests/gui/test_widgets.py index 3daa3a7b4..b9553c856 100644 --- a/tests/gui/test_widgets.py +++ b/tests/gui/test_widgets.py @@ -2367,6 +2367,8 @@ def test_ReplyBoxWidget_init(mocker): rb = ReplyBoxWidget(mocker.MagicMock(), mocker.MagicMock()) assert rb.text_edit.isEnabled() assert not rb.send_button.isHidden() + assert rb.send_button.isDefault() is True # Needed for "Enter" to work. + assert rb.send_button.shortcut().toString() == "Ctrl+Return" def test_ReplyBoxWidget_init_no_auth(mocker):