Class Dialogs
- Namespace
- Ofs
- Assembly
- Ofs.Api.dll
Native file/folder/message dialogs, backed by the host's native dialog integration. Every call is
NON-BLOCKING: it queues the dialog and returns a Task that completes — on the main
thread, on a later frame — once the user answers. await it from a command or button handler;
the frame loop keeps rendering while the dialog is open. Main-thread only (call, not the await).
public sealed class Dialogs
- Inheritance
-
objectDialogs
Examples
A command that opens a file, confirms, and reports — each dialog awaited in turn:
Host.Commands.Register("import", "Import script…", async () =>
{
// ';'-separated glob list; null = all files. Returns null if the user cancelled.
string? path = await Host.Dialogs.OpenFile(
title: "Import script",
filterPatterns: "*.funscript;*.csv",
filterDesc: "Scripts");
if (path == null) return; // cancelled
if (!await Host.Dialogs.Confirm("Import", $"Import {path}?", ConfirmKind.YesNo))
return; // user chose No
Host.NotifySuccess($"Imported {path}");
});
Save-as with a default name and a single filter, and a multi-select open:
string? dest = await Host.Dialogs.SaveFile(
title: "Export axis", defaultName: "axis.funscript",
filterPatterns: "*.funscript", filterDesc: "Funscript");
if (dest != null) { /* write to dest */ }
string[]? files = await Host.Dialogs.OpenFiles("Add clips", "*.mp4;*.mkv", "Video");
foreach (string f in files ?? Array.Empty<string>())
Host.Log(f);
string? folder = await Host.Dialogs.PickFolder("Pick output folder");
Awaiting from a button handler inside OnRenderUi(Ui) — the call is fire-and-forget
(don't await in the render path); the continuation lands on a later frame, still on the main thread:
if (ui.Button("Choose file…"))
_ = PickAsync();
async Task PickAsync()
{
string? path = await Host.Dialogs.OpenFile("Choose file");
if (path != null) _selected = path; // safe: back on the main thread
}
Remarks
Because the call returns immediately and resumes later, you drive a dialog from an async
handler. The continuation runs back on the main thread, so it is safe to touch Host after the
await. A cancel/dismiss yields null (or false for Confirm(string, string, ConfirmKind, CancellationToken)); always
handle it. If the plugin unloads while a dialog is open the task is cancelled — guard the await with
the plugin's UnloadToken (or pass it) when the continuation does real work.
Methods
Confirm(string, string, ConfirmKind, CancellationToken)
Shows a message/confirmation box. The task yields true for OK/Yes, false for Cancel/No (or if the dialog was dismissed).
public Task<bool> Confirm(string title, string message, ConfirmKind kind = ConfirmKind.OkCancel, CancellationToken cancel = default)
Parameters
titlestringmessagestringkindConfirmKindcancelCancellationToken
Returns
OpenFile(string, string?, string?, CancellationToken)
Opens a file picker. filterPatterns is a ';'-separated glob list
(e.g. ".png;.jpg"), or null for all files. The task yields the chosen path, or null if cancelled.
public Task<string?> OpenFile(string title = "Open", string? filterPatterns = null, string? filterDesc = null, CancellationToken cancel = default)
Parameters
titlestringfilterPatternsstringfilterDescstringcancelCancellationToken
Returns
OpenFiles(string, string?, string?, CancellationToken)
Opens a file picker that lets the user choose several files. filterPatterns
is a ';'-separated glob list (e.g. ".png;.jpg"), or null for all files. The task yields the chosen
paths, or null if the user cancelled (selected nothing).
public Task<string[]?> OpenFiles(string title = "Open", string? filterPatterns = null, string? filterDesc = null, CancellationToken cancel = default)
Parameters
titlestringfilterPatternsstringfilterDescstringcancelCancellationToken
Returns
PickFolder(string, CancellationToken)
Opens a folder picker. The task yields the chosen folder, or null if cancelled.
public Task<string?> PickFolder(string title = "Select Folder", CancellationToken cancel = default)
Parameters
titlestringcancelCancellationToken
Returns
SaveFile(string, string, string?, string?, CancellationToken)
Opens a save-as picker. The task yields the chosen path, or null if cancelled.
public Task<string?> SaveFile(string title = "Save", string defaultName = "", string? filterPatterns = null, string? filterDesc = null, CancellationToken cancel = default)
Parameters
titlestringdefaultNamestringfilterPatternsstringfilterDescstringcancelCancellationToken