Skip to main content

CustomAction

Trait CustomAction 

Source
pub trait CustomAction: Send + Sync {
    // Required method
    fn label(&self) -> String;

    // Provided methods
    fn key(&self) -> Option<String> { ... }
    fn applies(&self, kind: &str, value: &str) -> bool { ... }
    fn run(
        &self,
        kind: &str,
        value: &str,
    ) -> Result<Option<String>, PluginError> { ... }
}
Expand description

A custom action on interactive views (#491): list items, table rows, tree nodes and file entries. A host shows it in a view’s action menu, and on its key if it has one; when the user picks it, the view reports the action’s name and target, and the host may call run.

Required Methods§

Source

fn label(&self) -> String

The label a menu shows.

Provided Methods§

Source

fn key(&self) -> Option<String>

A key that picks it directly, as a key name (ctrl+o, f5), or None (the default): from the menu only.

Source

fn applies(&self, kind: &str, value: &str) -> bool

Whether it applies to a target: its kind (item, row, node or file) and its value (an item’s text, a row’s cells joined by tabs, a node’s path of labels joined by /, a file’s path). All, by default.

Source

fn run(&self, kind: &str, value: &str) -> Result<Option<String>, PluginError>

Do it to a target. Ok(Some(text)) is output for the host to show; the default does nothing, leaving the host to act on the name. The value comes from what the user browsed, so treat it as untrusted.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§