Vixen
02b45cc4
csharp
public sealed class MacOSDialogs

The macOS file pickers: NSOpenPanel and NSSavePanel.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The main thread, or nothing. AppKit aborts the process — SIGABRT, with a message about the main thread — when a panel is created anywhere else, and that is not a rule anything can work around. So a call from another thread returns nothing-chosen rather than crashing the application that made it. In practice the restriction costs nothing: IPlatform is owned by the thread that created it, and on macOS that thread has to be the main one for the window to exist at all.

runModal, so the frame loop stops while the panel is open. It is AppKit's own event loop that runs instead of ours, so the application is not hung — its windows redraw, the panel works, the menu bar responds — but nothing of ours advances until the user is finished. The alternative is beginSheetModalForWindow:completionHandler:, which takes an Objective-C block, and constructing a block from managed code means hand-building its layout and its descriptor to an ABI that is not part of any header. That is worth doing when a sheet is worth having; it is not worth doing to open a project.

setAllowedFileTypes: is deprecated and is used anyway. Its replacement, setAllowedContentTypes:, takes UTType objects, which have to be built from extensions through UTTypeCreateFromExtension — a second framework and a two-step conversion to say what a list of extensions already says. The deprecated call still works, and when it stops working it will stop in a way a test on a Mac notices.

Methods (6)

  • public MacOSDialogs(INativeDialogs fallback)

    The macOS file pickers: NSOpenPanel and NSSavePanel.

  • public ValueTask<string?> OpenFileAsync(FileDialogOptions options, IWindow? owner = null, CancellationToken cancellationToken = default(CancellationToken))

    Asks the user to pick one existing file.

  • public ValueTask<IReadOnlyList<string>> OpenFilesAsync(FileDialogOptions options, IWindow? owner = null, CancellationToken cancellationToken = default(CancellationToken))

    Asks the user to pick one or more existing files.

  • public ValueTask<string?> SaveFileAsync(FileDialogOptions options, IWindow? owner = null, CancellationToken cancellationToken = default(CancellationToken))

    Asks the user where to save.

  • public ValueTask<string?> OpenFolderAsync(FileDialogOptions options, IWindow? owner = null, CancellationToken cancellationToken = default(CancellationToken))

    Asks the user to pick a folder.

  • public ValueTask<MessageBoxResult> ShowMessageAsync(MessageBoxOptions options, IWindow? owner = null, CancellationToken cancellationToken = default(CancellationToken))

    Shows the message box the portable implementation shows.

Used by (2)

  • MacOSPlatformSupplementVixen.Platform.MacOS
  • MacOSSupplementTestsVixen.Platform.MacOS.Tests