aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-03-24 19:15:14 -0700
committerGuy Harris <guy@alum.mit.edu>2018-03-25 02:15:50 +0000
commitb577bff1ae1187471e0df2e4477b75ff548f1510 (patch)
tree74c2c388efdbbaef38e96755eefccf50f2e358c1 /ui
parent14fbbc83356333b660b5c18f3b2e97f5ed9c06ca (diff)
In some dialogs, have *no* auto-default buttons on macOS.
In macOS dialogs, there's a default button, which is the button that Enter/Return activates, and that Enter/Return *always* activates, *regardless* of what button has the input focus. To activate the button that has the input focus, you use the space bar. To implement that, we need to disable auto-default on all buttons, including the Cancel button. Put in a comment explaining all this. We may want to do this in all alert boxes, and possibly all dialogs with buttons. Change-Id: I214dd2870a9720ea705d8db39adc5b6af2003fb1 Reviewed-on: https://code.wireshark.org/review/26629 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/capture_file_dialog.cpp26
-rw-r--r--ui/qt/main_window.cpp29
2 files changed, 53 insertions, 2 deletions
diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp
index 56e157a3e7..957aca23ca 100644
--- a/ui/qt/capture_file_dialog.cpp
+++ b/ui/qt/capture_file_dialog.cpp
@@ -155,7 +155,31 @@ check_savability_t CaptureFileDialog::checkSaveAsWithComments(QWidget *
}
#if defined(Q_OS_MAC)
- discard_button->setAutoDefault(false);
+ /*
+ * In macOS, the "default button" is not necessarily the button that
+ * has the input focus; Enter/Return activates the default button, and
+ * the spacebar activates the button that has the input focus, and
+ * they might be different buttons.
+ *
+ * In a "do you want to save" dialog, for example, the "save" button
+ * is the default button, and the "don't save" button has the input
+ * focus, so you can press Enter/Return to save or space not to save
+ * (or Escape to dismiss the dialog).
+ *
+ * In Qt terms, this means "no auto-default", as auto-default makes the
+ * button with the input focus the default button, so that Enter/Return
+ * will activate it.
+ */
+ QList<QAbstractButton *> buttons = msg_dialog.buttons();
+ for (int i = 0; i < buttons.size(); ++i) {
+ QPushButton *button = static_cast<QPushButton *>(buttons.at(i));;
+ button->setAutoDefault(false);
+ }
+
+ /*
+ * It also means that the "don't save" button should be the one
+ * initially given the focus.
+ */
discard_button->setFocus();
#endif
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 875d768595..89231ce39f 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -78,6 +78,7 @@ DIAG_ON(frame-larger-than=)
#include <QActionGroup>
#include <QDesktopWidget>
#include <QKeyEvent>
+#include <QList>
#include <QMessageBox>
#include <QMetaObject>
#include <QMimeData>
@@ -1804,7 +1805,33 @@ bool MainWindow::testCaptureFileClose(QString before_what, FileCloseContext cont
discard_button = msg_dialog.addButton(discard_button_text, QMessageBox::DestructiveRole);
#if defined(Q_OS_MAC)
- discard_button->setAutoDefault(false);
+ /*
+ * In macOS, the "default button" is not necessarily the
+ * button that has the input focus; Enter/Return activates
+ * the default button, and the spacebar activates the button
+ * that has the input focus, and they might be different
+ * buttons.
+ *
+ * In a "do you want to save" dialog, for example, the
+ * "save" button is the default button, and the "don't
+ * save" button has the input focus, so you can press
+ * Enter/Return to save or space not to save (or Escape
+ * to dismiss the dialog).
+ *
+ * In Qt terms, this means "no auto-default", as auto-default
+ * makes the button with the input focus the default button,
+ * so that Enter/Return will activate it.
+ */
+ QList<QAbstractButton *> buttons = msg_dialog.buttons();
+ for (int i = 0; i < buttons.size(); ++i) {
+ QPushButton *button = static_cast<QPushButton *>(buttons.at(i));;
+ button->setAutoDefault(false);
+ }
+
+ /*
+ * It also means that the "don't save" button should be the one
+ * initially given the focus.
+ */
discard_button->setFocus();
#endif