notesy::dialogs

A plugin's script can ask the user something in a dialog, drawn as notesy draws its own: one of notesy's kinds (a question to confirm, a line to type), or one of its own made of the parts of a view. It takes the ui permission.

rustuse notesy::{dialogs, notices};

pub fn ready() {
    dialogs::confirm(#{ title: "Reset the pad?", message: "Its lines go.", confirm: "Reset", danger: true }, |ok| {
        if ok {
            notices::success("Reset it");
        }
    });
    dialogs::prompt(#{ title: "Rename it", value: "Scratch", confirm: "Rename" }, |name| {
        if let Some(typed) = name {
            notices::info(`Renamed it ${typed}`);
        }
    });
}

The script doesn't wait for the answer: the user may take a while, so it goes to the function it gave, later, as a click in a panel does.

#notesy's kinds

Function What it does
dialogs::confirm(options, answer) Asks, with two buttons: answer(true) for the first, answer(false) for the other, Esc or a click outside it.
dialogs::prompt(options, answer) Asks for a line of text: answer(Some(text)) for the first button or Enter, answer(None) for the rest.
Option What it is
title What it asks. It needs one.
message A line or two under it.
icon Its icon, by name (notesy::view): the plugin's own unless it says.
confirm, cancel Its buttons: OK and Cancel unless it says.
danger A confirm's: true when its first button loses something, so it's red and Enter doesn't pick it.
lines A confirm's: lines on a card under the message, like ["Its 3 lines", "Its note"].
note A confirm's: something worth a second look, in a soft red block.
value, placeholder A prompt's: what's in its field to start with, and the hint while it's empty.

#One of its own

rustuse notesy::{dialogs, notices, store, view};

pub fn export() {
    let dialog = dialogs::open("export", #{ title: "Export", buttons: ["Export", "Cancel"] }, || {
        let format = view::segmented(["PDF", "HTML"], store::get("format").unwrap_or("PDF"));
        format.target = "format";
        let tags = view::switch("Include tags", store::get("tags").unwrap_or(true));
        tags.target = "tags";
        view::column([format, tags])
    });
    dialog.on_change(|target, value| store::set(target, value));
    dialog.on_button(|button| {
        if button == "Export" {
            notices::info("Exporting");
        }
    });
}
Function What it does
dialogs::open(key, options, build) Opens a dialog of its own, and returns it. build() makes what shows under its message: a view (notesy::view), its inputs heard as a panel's are. options are a confirm's, with buttons (a list of labels, up to 4: the first the one it suggests, the last what Esc picks; ["OK"] unless it says) in place of confirm and cancel.
Method What it does
on_button(handler) handler(button) when a button's picked, by its label. Any button puts it away; Esc and a click outside pick the last.
on_click(handler) handler(target) when something in it with a target is clicked.
on_change(handler) handler(target, value) when a switch, box, field or choice in it with a target changes; it's built again after.
refresh() Builds it again: after what it shows changed.
close() Puts it away, unanswered.

#How they show

One at a time, in the middle of the window, over everything, as notesy's own are: never over one of notesy's (it waits until that's answered), and in the order they were asked. Each says under it which plugin it's from, with the plugin's icon, so a plugin's can't pass for one of notesy's. A plugin may have 3 waiting at once: asking for a fourth is an error. What a script asked goes, unanswered, when it stops.

Every page