Posted On: Wednesday, October 10th, 2007 (ResExcellence, User Interface)
Posted by: Paul Lefebvre

by Seth Willits

The MessageDialog class is an important user interface element that if not done correctly, sticks out like a sore thumb on Mac OS X. Users expect a consistent message interface between applications, so it is critical that developers adopt and embrace the MessageDialog class as a part of becoming a good Mac OS X citizen.

It’s a Sheet!

This tutorial isn’t exactly the most indepth of them all. In the code below, you simply have a chunk which sets up a MessageDialog in the CancelClose event of a Window and displays it using ShowModalWithin.

MessageDialog Sheet

Function CancelClose(appQuitting As Boolean) As Boolean
Dim dlog As MessageDialog
 
// Create Dialog
dlog = New MessageDialog
dlog.Message = "Do you want to save the changes you made in the document """ + self.Title + """?"
dlog.Explanation = "Your changes will be lost if you don't save them."
dlog.ActionButton.Caption = "&Save..."
dlog.CancelButton.Caption = "Cancel"
dlog.AlternateActionButton.Caption = "&Don't Save"
dlog.ActionButton.Visible = True
dlog.CancelButton.Visible = True
dlog.AlternateActionButton.Visible = True
 
// Show Dialog
Select Case dlog.ShowModalWithin(self).Caption
Case "&Save..."
MsgBox "Pretend this is a save dialog..."
Return False
Case "&Don't Save"
Return False
Case "Cancel"
Return True
End Select
End Function

Finished

What’s really nice about this class is that any cross-platform issues are already taken care of for you. If the ShowModalWithin method is used to create a sheet window in Mac OS X, the same code compiled for Windows and Linux has the dialos appear as a standalone window. In addition, the placement of the Save, Don’t Save, and Cancel buttons is different in Mac OS X than it is in Windows and Linux, but the MessageDialog class takes care of button placement as well.

Download MessageDialogSheet REALbasic project

Originally published by ResExcellence
Reprinted with permission

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

This entry was posted on Wednesday, October 10th, 2007 at 10:32 am and is filed under ResExcellence, User Interface. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “MessageDialog Sheet”

  1. RBtv on November 25th, 2007 at 2:59 pm

    We cover MessageDialogs and SaveDialogs in RBtv Episode 5. Check it out. http://www.realbasic.tv

Leave a Reply