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>
This commit is contained in:
parent
14fbbc8335
commit
b577bff1ae
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue