Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-app/src/menu.rs

//! **NavModel → facett-menu bridge.** Now that `facett_menu::Command` takes owned
//! ids, the *same* [`NavModel`](crate::NavModel) that drives the sidebar and
//! breadcrumb can also drive facett-menu's palette, menubar and context-menu —
//! "one model → many surfaces" all the way through. Each navigable leaf becomes a
//! [`Command`](facett_menu::Command) whose `id` is the route and whose `group` is
//! the parent section's label.

use crate::nav::{NavItem, NavModel};
use facett_menu::Command;

/// Build a facett-menu command set from a nav model: one command per enabled leaf
/// (`id` = route, `group` = parent section label, else `"Go"`), icons preserved.
pub fn nav_commands(model: &NavModel) -> Vec<Command> {
    let mut out = Vec::new();
    fn walk(items: &[NavItem], parent: &str, out: &mut Vec<Command>) {
        for it in items {
            if it.is_section() {
                walk(&it.children, &it.label, out);
            } else if it.enabled {
                let group = if parent.is_empty() { "Go" } else { parent };
                let mut c = Command::new(it.route_or_id().to_string(), it.label.clone(), group.to_string());
                if let Some(icon) = &it.icon {
                    c = c.icon(icon.clone());
                }
                out.push(c);
            }
        }
    }
    walk(&model.items, "", &mut out);
    out
}