notesy::menus
A plugin's script can add items to notesy's own right-click menus. Each
menu is named with a Menu, and each hands its items what it was opened
on. It takes the ui permission.
rustuse notesy::{menus, notes, notices, Menu};
pub fn ready() {
menus::add(Menu::Note, "count", #{ title: "Count its words", icon: "number" }, |path| {
if let Some(note) = notes::read(path) {
notices::info(`${note.title()}: ${note.words()} words`);
}
});
menus::add(Menu::Editor, "line", "Which line is this?", |at| notices::info(`Line ${at.line}`));
}
#The menus
| Menu | Where it opens | What run gets |
|---|---|---|
Menu::Note |
On a note in the tree | Its path within the vault: "Projects/Plan.md" |
Menu::File |
On any other file in the tree (an image, a PDF …) | Its path |
Menu::Folder |
On a folder in the tree | Its path |
Menu::Tab |
On a tab | #{ title, path }: path only on a note's tab, not a plugin's tab or a plugin's own file |
Menu::Editor |
In the note's text | #{ path, line, start, end }: the caret's line, counted from 1 (a right-click puts the caret there, unless it's in the selection), and the selection's start and end in characters. No path on a plugin's own file |
Menu::Board |
On a board's empty canvas | #{ path, x, y }: the board's path, and where on it, in the board's units (notesy::boards) |
Menu::BoardCard |
On a card on a board | #{ path, id, type, selected }: the card's id and type, and the ids of every card and arrow picked |
Menu::BoardArrow |
On an arrow on a board | #{ path, id } |
A plugin's own sidebar section has a menu for its items too:
section.menu(key, options, run) (notesy::sections), whose run
gets the item's id.
#Adding one
| Function | What it does |
|---|---|
menus::add(menu, key, options, run) |
Adds an item to menu, and returns it. run(target) runs when it's picked. |
key names it in that menu: lowercase letters, digits, -, _ and .,
starting with a letter. The same key can name an item in each menu, and
adding one with a key it has in that menu already changes it. options is
its title, or #{ title, icon } (an icon by name, notesy::view).
What run gets is the plugin's because the user picked its item on it;
reading what's in a note still takes notes.read (notesy::notes),
and changing the text takes editor (notesy::editor).
#An item
| Method | What it does |
|---|---|
remove() |
Takes it out of its menu. |
#Where they show
Plugins' items come after notesy's own: above "Move to Trash" in the tree's menus, at the bottom of a tab's and the editor's. A plugin's one item in a menu is a row of its own; two or more go in a submenu under the plugin's name, which opens as the pointer comes to it. Whatever a script added goes 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