Dialogs

sw.dialog opens the operating system's own dialogs — message boxes, file pickers, and so on. They are native (not drawn by your app) and modal: the call blocks until the user responds, then returns the result.

Message boxes

sw.dialog.alert('File saved.');

if (sw.dialog.confirm('Delete this item?')) {
  // the user clicked Yes
}

Both accept an options object: title, icon ('info', 'question', 'warning', 'error'), and detail (secondary text).

sw.dialog.alert('Could not open the file.', {
  title: 'Error',
  icon: 'error',
  detail: String(err),
});

File and directory pickers

Each returns the chosen path as a string, or an empty string if the user cancels.

const path = sw.dialog.openFile({ title: 'Open note' });
if (path) text.setText(sw.fs.readFile(path));

const dest = sw.dialog.saveFile({ initialFile: 'untitled.txt' });
const dir = sw.dialog.chooseDirectory();

Common options: title, initialDir, initialFile (open / save), and defaultExtension (save).

Colour picker

const colour = sw.dialog.chooseColor({ initial: '#3366ff' });
if (colour) shape.fill = colour; // '#rrggbb', or '' if cancelled

A note on blocking

Because these dialogs are modal, the call waits for the user and your code resumes on the next line with the result in hand. The window stays responsive underneath; your script simply pauses at that point — usually exactly what you want for a prompt.

Next