Dialogs

Dialogs are modal windows that are handled in the same way as in Objective-C, so the code writing is pretty direct. For more informations on dialogs, refer toDialogs and Special Panels.

// Use a standard alert to display the message
AppKitFramework.NSRunAlertPanel("Message, Hello", "Hello, Cocoa!", "OK", null, null);

Sheets

A sheet is simply a dialog attached to a specific window, ensuring that a user never loses track of which window the dialog belongs to. A sheet is document modal—that is while it is open the user is prevented from doing anything else in the window, or document, until the dialog is dismissed. In contrast, a dialog that is application modal prevents the user from doing anything else within the application. For more informations on sheets, refer to Sheet Programming Topics for Cocoa.

Some classes can be used with delegates as their completion callback (for more classes, see the API Reference). Here a list of some class that support completion callback:

  • NSAlert
  • NSApplication
  • NSOpenPanel
  • NSSavePanel

The callback methods must conform to the following signature:

public void Callback(SheetClass sheet, int returnCode, IntPtr contextInfo);

Examples

The asynchronous API can be used either with the Objective-C syntax or the .NET syntax.

The Objective-C syntax is very straightfoward. The callback must be exposed as an Objective-C message and both the instance and the selector are passed when calling the sheet method.

[ObjectiveCMessage("saveDocumentAs:")]
public void SaveDocumentAs(Id sender)
{
    NSSavePanel panel = NSSavePanel.SavePanel;
    ...
    panel.BeginSheetForDirectoryFileModalForWindowModalDelegateDidEndSelectorContextInfo(null, (NSString) "Untitled", this.imageView.Window, this, ObjectiveCRuntime.Selector("saveImageDidEnd:returnCode:contextInfo:"), IntPtr.Zero);
}

[ObjectiveCMessage("saveImageDidEnd:returnCode:contextInfo:")]
public void SaveImageDidEnd(NSSavePanel panel, NSInteger returnCode, IntPtr contextInfo)
{
    if (returnCode == NSPanel.NSOKButton)
    {
        ...
    }
}

The .NET syntax is very also straightfoward. The callback does not need to be exposed and an implicit delegate is passed when calling the sheet method.

[ObjectiveCMessage("saveDocumentAs:")]
public void SaveDocumentAs(Id sender)
{
    NSSavePanel panel = NSSavePanel.SavePanel;
    ...
    panel.BeginSheetForDirectoryFileModalForWindowModalDelegateDidEndSelectorContextInfo(null, (NSString) "Untitled", this.imageView.Window, this.SaveImageDidEnd, IntPtr.Zero);
}

public void SaveImageDidEnd(NSSavePanel panel, NSInteger returnCode, IntPtr contextInfo)
{
    if (returnCode == NSPanel.NSOKButton)
    {
        ...
    }
}