Using a New Feature From REALbasic 2005!
In this tutorial, we're going to use a new feature of the MessageDialog class, the ShowModalWithin method, to show the dialog as a sheet within a parent window. This is something that was sorely lacking in REALbasic 5.5. Without this feature, developers (such as myself) had to resort to using declares to implement a standard message alert that could be shown as a sheet.
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. See the tutorial "Using MessageDialogs" to learn about the other features of this class.
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.
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
The important thing here isn't so much of how to do it, but rather that you now can! Over the next several weeks we'll be exploring features new to REALbasic 2005 like this, some more indepth than others. As always, you can download the project here.