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
- Overview
- plugin.toml: Every field of plugin.toml
- Permissions: What a plugin can ask for, when notesy asks, and what changes it
- Scripts: How a script runs: its lifecycle, events, limits and errors
- Packing and installing: Making, checking, signing, packing and installing
- notesy::log: Lines for its log on the Plugins page
- notesy::events: Hearing what happens, and every event
- notesy::commands: Adding commands, and running notesy's
- notesy::store: Keeping its own data
- notesy::settings: Reading its settings
- notesy::secrets: Keys and tokens, in the system keychain
- notesy::notes: Reading and changing the vault's notes
- notesy::editor: The note in front
- notesy::files: A folder of its own
- notesy::links: Opening pages in the browser
- notesy::clipboard: Copying and pasting
- notesy::view: What panels, tabs and sections show
- notesy::panels and notesy::views: Adding side panels and tabs
- notesy::sections: Sidebar sections
- notesy::menus: Items in notesy's right-click menus
- notesy::status: Status bar items
- notesy::notices: Notices
- notesy::dialogs: Asking in a dialog, notesy's kinds or its own
- notesy::cards: Its part of the tree's hover cards
- notesy::boards: Boards' cards and arrows, and kinds of card of its own
- notesy::blocks: Drawing its fenced blocks
- notesy::icons: Drawing its own icons
- notesy::net: Requests to the sites it names
- notesy::accounts: Signing in to a service
- notesy::json: Reading and writing JSON
- notesy::toml: Reading and writing TOML
- notesy::yaml: Reading and writing YAML, and a note's front matter
- notesy::time: Now, written in the user's time zone, dates read, how long ago
- notesy::math: Trigonometry and the like, for drawing
- Names: Icon, Color, Tone, Side, Method, Command, Menu, Sidebar, Event: Notesy's names as enums
- notesy::preview: Its own screens for notesy preview
- notesy::perf: Timing its own work
- notesy::tex: Math macros for every note's formulas