Native-only message dialogs for MoonBit on Windows, macOS, and Linux.
let dialog = @dialog.MessageDialog::new(
"Build finished successfully.",
title="moonbit-dialog",
level=Info,
)let confirm = @dialog.ConfirmDialog::new(
"Overwrite the generated files?",
)let choice = @dialog.ChoiceDialog::new(
"Save changes before closing?",
buttons=YesNoCancel,
level=Question,
)let relabeled = @dialog.MessageDialog::new(
"Build finished successfully.",
).with_labels(@dialog.DialogLabels::ok("Open report"))match @dialog.open_file(directory="C:/Projects") {
Ok(outcome) => ignore(outcome)
Err(error) => ignore(error)
}let filters = [
@dialog.FileFilter::new("Text Files", ["*.txt", "*.md"]),
@dialog.FileFilter::new("All Files", ["*"]),
]
let save_dialog = @dialog.SaveFileDialog::new(file_name="report")
.with_filters(filters)
.with_default_extension("txt")let open_many = @dialog.OpenFilesDialog::new(directory="C:/Projects")
.with_filters([
@dialog.FileFilter::new("Sources", ["*.mbt", "*.c", "*.h"]),
])pub struct ChoiceDialog {
title : String
message : String
level : DialogLevel
buttons : DialogButtons
labels : DialogLabels
} derive(Eq, Debug)fn ChoiceDialog::new(message : StringView, title? : StringView, buttons? : DialogButtons, level? : DialogLevel) -> ChoiceDialogpub struct ConfirmDialog {
title : String
message : String
level : DialogLevel
labels : DialogLabels
} derive(Eq, Debug)fn ConfirmDialog::new(message : StringView, title? : StringView, level? : DialogLevel) -> ConfirmDialogpub(all) enum DialogError {
UnsupportedPlatform(Platform)
BackendUnavailable(Platform)
BackendFailed(DialogBackend, Int)
} derive(Eq, Debug)fn DialogLabels::yes_no_cancel(yes_label : StringView, no_label : StringView, cancel_label : StringView) -> DialogLabelspub struct MessageDialog {
title : String
message : String
level : DialogLevel
labels : DialogLabels
} derive(Eq, Debug)fn MessageDialog::new(message : StringView, title? : StringView, level? : DialogLevel) -> MessageDialogpub struct MultiPathDialogOutcome {
backend : DialogBackend
selection : MultiPathSelection
} derive(Eq, Debug)pub struct OpenFileDialog {
title : String
directory : String
filters : Array[FileFilter]
} derive(Eq, Debug)fn OpenFileDialog::with_filters(self : OpenFileDialog, filters : Array[FileFilter]) -> OpenFileDialogpub struct OpenFilesDialog {
title : String
directory : String
filters : Array[FileFilter]
} derive(Eq, Debug)fn OpenFilesDialog::with_filters(self : OpenFilesDialog, filters : Array[FileFilter]) -> OpenFilesDialogpub struct PathDialogOutcome {
backend : DialogBackend
selection : PathDialogSelection
} derive(Eq, Debug)pub struct SaveFileDialog {
title : String
directory : String
file_name : String
filters : Array[FileFilter]
default_extension : String
} derive(Eq, Debug)fn SaveFileDialog::new(title? : StringView, directory? : StringView, file_name? : StringView) -> SaveFileDialogfn SaveFileDialog::with_default_extension(self : SaveFileDialog, extension : StringView) -> SaveFileDialogfn SaveFileDialog::with_filters(self : SaveFileDialog, filters : Array[FileFilter]) -> SaveFileDialogfn ask_yes_no(message : StringView, title? : StringView, level? : DialogLevel) -> Result[DialogOutcome, DialogError]fn ask_yes_no_cancel(message : StringView, title? : StringView, level? : DialogLevel) -> Result[DialogOutcome, DialogError]fn open_file(title? : StringView, directory? : StringView) -> Result[PathDialogOutcome, DialogError]fn open_files(title? : StringView, directory? : StringView) -> Result[MultiPathDialogOutcome, DialogError]fn save_file(title? : StringView, directory? : StringView, file_name? : StringView) -> Result[PathDialogOutcome, DialogError]fn select_folder(title? : StringView, directory? : StringView) -> Result[PathDialogOutcome, DialogError]fn show_dialog(message : StringView, title? : StringView, buttons? : DialogButtons, level? : DialogLevel) -> Result[DialogOutcome, DialogError]fn show_message(message : StringView, title? : StringView, level? : DialogLevel) -> Result[DialogBackend, DialogError]fn show_ok_cancel(message : StringView, title? : StringView, level? : DialogLevel) -> Result[DialogOutcome, DialogError]Native-only message dialogs for MoonBit on Windows, macOS, and Linux.