notesy::sections
A section of the sidebar, under notesy's notes and tags: a tree of the
plugin's own (bookmarks, tasks, a list from somewhere), drawn like the
vault's and folded the same way. Its script adds it; takes the ui
permission.
rustuse notesy::{events, sections, Event};
pub fn ready() {
let pinned = sections::add("pinned", "Pinned");
pinned.set([
#{ id: "plan", name: "Launch plan", icon: "pin", note: "Projects/Launch plan.md" },
#{ id: "reading", name: "Reading", children: [
#{ id: "book", name: "The book", note: "Reading/The book.md", detail: "p. 120" },
] },
]);
events::on(Event::SidebarItem, |event| { /* event.section, event.item */ });
// Right-click an item: "Unpin". `item` is the id of the one it was opened on.
pinned.menu("unpin", #{ title: "Unpin", icon: "pin" }, |item| { /* unpin it */ });
}
| Function | What it does |
|---|---|
sections::add(key, options) |
Adds a section, empty until it's set, and returns it. options is its title, or #{ title }. |
section.set(items) |
Replaces what it shows. |
section.action(key, options, run) |
Adds a button to its heading, and returns it: options as a menu item's (#{ title, icon }, notesy::zones), the title its tip; run() when it's clicked. |
section.heading_menu(key, options, run) |
Adds an item to its heading's right-click menu, and returns it: options as a menu item's, and run() when it's picked. |
button.menu(key, options, run) |
On a button action returned: adds an item to the button's own right-click menu, and returns it; run() when it's picked. A button with none opens no menu. |
section.menu(key, options, run) |
Adds an item to its items' right-click menu, and returns it: options as a menu item's (notesy::zones), and run(item) gets the id of the item the menu was opened on. |
section.on_drop(accept, run) |
Says what can be dropped on it, and run(drop) gets each drop (below). accept names what it takes, or lists them: "items" (its own, moved about), "notes", "folders", "files", "images", or files by extension, like ".pdf". |
section.remove() |
Takes it away. |
key names it for good (lowercase letters, digits, -, _ and .,
starting with a letter): notesy remembers which of its folders are open
by it.
An item is #{ id, name } and any of:
| Field | What it is |
|---|---|
icon |
Its icon, by name (notesy::view). |
detail |
Faint text at its right, like a count. |
note |
A note (relative to the vault) a click opens. |
command |
A command a click runs, instead: a command's id(), or notesy's own. |
children |
Items inside it: it's a folder. |
menu |
Which of its section's menu items its right-click menu has, by key (["unpin"]); every one unless it says, and none for []. |
drag |
Whether it can be dragged: true or false. Unless it says, it can when its section takes "items", or it opens a note (dragged into a note or onto a board, it drops a link to the note). |
drop |
What can be dropped into it, named as on_drop names them. Unless it says, a folder takes what its section does, and anything else nothing. |
Ids are unique within the section: they say which item was clicked, and
which folders stay open. The plugin hears every click as the
sidebar.item event, whatever the item opens (notesy::events).
A heading's buttons show at its right while the pointer's on it: notesy's
own first (Notes has New note, New canvas, New folder and Close every
folder), then plugins', at most 4 of a plugin's on one heading. A
right-click on a heading opens its menu: Notes' has New note, New canvas and
New folder, then plugins' items for the heading; with nothing in it, none
opens. remove() on what action or heading_menu returned takes it away.
An item that opens a note has "Open in new tab" in its menu too, before the section's own items. At most 500 items at the top, nested 8 deep. Whatever a script added goes when it stops.
#Dragging and dropping
What a section takes can be dropped on it: on its heading or the room it
takes (into the section itself), before or after one of its items (a line
shows where), or into an item that takes it (lit). Closed folders open
when something's held over them, and the sidebar scrolls near its edges.
run(drop) gets #{ kind, item, path, onto, place }:
| Field | What it is |
|---|---|
kind |
"item": one of its own. "note", "folder" or "file": from the vault's tree. |
item |
The id of its item that was dragged, for "item". |
path |
Where the note, folder or file is in the vault, for the rest. |
onto |
The id of the item it was dropped against; left out when it was dropped on the section itself, so ask with drop.get("onto"). |
place |
"before" or "after" that item, or "into" it (or into the section). |
notesy moves nothing itself: the plugin puts what's dropped where it
likes, and sets its items again. A drop from the tree hands over a path,
so notes, folders and files are dropped only on sections of plugins with
notes.read; without it, a section takes only its own items.
rustuse notesy::sections;
pub fn ready() {
let pinned = sections::add("pinned", "Pinned");
pinned.on_drop(["items", "notes"], |drop| {
if drop.kind == "note" {
// pin drop.path
} else {
// move drop.item drop.place drop.get("onto")
}
pinned.set([]); // its items, as they are now
});
}
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::templates: What templates fill in, and functions of its own for them
- notesy::files: A folder of its own
- notesy::links: Opening pages in the browser, naming links after their pages
- notesy::clipboard: Copying and pasting
- notesy::view: What panels, tabs and sections show
- notesy::sections: Sidebar sections
- notesy::hidden: Hiding notes, files and folders from the tree
- notesy::status: Status bar items
- notesy::tools: Buttons in the formatting bar
- notesy::notices: Notices
- notesy::dialogs: Asking in a dialog, notesy's kinds or its own
- notesy::wizards: Pages one after another, like a setup
- 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::ipc: Talking to a program on this computer
- 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, Zone, Event: Notesy's names as enums
- notesy::preview: Its own screens for notesy preview
- notesy::perf: Timing its own work
- notesy::drawings: Drawings' shapes, and buttons in their tool strip
- notesy::sound: Playing sounds, and making them as it runs
- notesy::tex: Math macros for every note's formulas
- notesy::views: Side panels, tabs of its own, and its part of the tree's hover cards
- notesy::zones: Notesy's own places — its menus, its bars and its headings