free-launch 0.2.9

A simple fuzzy launcher written in Rust.
Documentation
use crate::launch_entries::action_name::ActionName;
use egui::Ui;
use std::path::Path;

use crate::launch_entries::action_result::ActionResult;

/// Trait for items that can be launched and have an identifier
// TODO rename to LaunchInfo
pub(crate) trait LaunchId {
    /// An identifier to match launch items against invocations
    fn id(&self) -> String;

    /// Whether this item is actually launchable
    ///
    /// Currently just a check if the item at the given `file_path` actually exists on disk
    fn launchable(&self) -> bool;

    /// The path on disk at which this item resides
    fn file_path(&self) -> &Path;

    /// The name of the icon representing this item
    fn icon_name(&self) -> Option<&str>;

    /// A comment describing this item
    fn comment(&self) -> Option<&str>;

    /// A function to render the debug version of this item
    fn debug_ui(&self, ui: &mut Ui, count: usize);
}

pub(crate) trait LaunchAction {
    /// Returns the list of available action names for this item
    fn actions(&self) -> Vec<&'static str>;

    // TODO find out if we can define required, associated constants for the default and secondary actions

    /// Returns the name of the default action for this type
    ///
    /// This is the action that should happen on Return or Click without any modifiers
    fn default_action(&self) -> &'static str;

    /// Returns the name of the secondary action
    ///
    /// This is the action that should happen on Return or Click without Shift held
    fn secondary_action(&self) -> &'static str;

    /// Invoke the specified action
    fn invoke(&self, action: &ActionName) -> ActionResult;

    /// Invoke the default action
    fn invoke_default(&self) -> ActionResult;
}

pub(crate) trait Launchable: LaunchId + LaunchAction + Send + Sync {}