MessageDialog keyboard TAB - default button always fires

https://documentation.xojo.com/api/language/me.htmlssageDialog
Am I doing something wrong? The other buttons hi-lite upon pressing TAB but never fire on pressing the Enter key. Works via mouse click.

Var d As New MessageDialog                     // declare the MessageDialog object
Var b As MessageDialogButton                   // for handling the result
d.IconType = MessageDialog.IconTypes.Caution   // display warning icon
d.ActionButton.Caption = "Save"
d.CancelButton.Visible = True                  // show the Cancel button
d.AlternateActionButton.Visible = True         // show the "Don't Save" button
d.AlternateActionButton.Caption = "Don't Save"
d.Message = "Use TAB to navigated to the button and press enter."
d.Explanation = "Though the correct button is highlited " + Chr(13) + Chr(10) + _
"The default button is the one that fires. "

b = d.ShowModal                               // display the dialog
Select Case b                                 // determine which button was pressed.
Case d.ActionButton
  // user pressed Save
  MessageBox("user pressed save")
  
Case d.AlternateActionButton
  // user pressed Don't Save
  MessageBox("user pressed Don't save")
  
Case d.CancelButton
  // user pressed Cancel
  MessageBox("user pressed cancel")
  
End Select

Use the Space Bar to activate highlighted buttons, while enter always activates the default button, like escape always activates the Cancel button.

Hmmm… ok. BUT the rest of the gui already responds to the TAB and ENTER keys. So I’m wondering if there is a way to make the dialog box accept the ENTER key for the button that is high-lighted?

Yes if it is the default button, no otherwise… IMHO

Did you try to press keys (Esc, Tab, Enter, fn+, etc…) ?

That’s not how dialogs work. You could build your own dialog-like window, though, and make it work however you want it to.

1 Like

Ah yes. I did that years ago and forgot that’s how I solved the issue before.
Thanks
Ben

Many applications have dialogbox when we quit asking if we want to save or not the modified documents.
In the example below (Xojo), which key should I hit in order to not save?


Enter=Return is the “Save” button, Esc the “Cancel” button, but “Don’t save”?
I hit spacebar, Tab or arrows keys but I only get a beep.
It is a Off-topic question as it apply to all Mac applications but as this thread was about the same subject….

Traditionally, it’s command-D (for “Don’t save”). It still works for these vertical dialogs.

1 Like

That’s because you have ‘Keyboard navigation’ turned off (OS setting). If you turn that on then you can use other keys to move between buttons and activate the buttons (will add a focus ring to the corresponding button).

1 Like

Thank you, Command-D works, I have to remember it.

Cmd-D only works on apps that use this “Don’t Save” phrasing. Apps that use the new Save / Delete dialog, the shortcut was changed to Cmd-Backspace to annoy every long time Mac user who’s been hitting Cmd-D for 20+ years.

3 Likes

Thank you Tim, effectively when I create a new TextEdit document just to paste some temporary text and close the window, the button was not “Don’t save” but “Delete” and I was searching too the short-key, but I need it less often then I didn’t ask for that. You gave me the answer, I will try to remember it too.

That’s because TextEdit supports automatic save and versioning. These are saved each time they are changed. Thus “Don’t save” doesn’t make sense as it is already saved. The choice becomes update it or delete what has been saved already.

And even worse: in those “new” dialogs, ⌘D moves to the desktop instead.