Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

1.1 KB
Raw Blame
//! Prints the rows of the shell's context menu for the files given, as the file list builds it (issue 743: items of two folders
//! lost the rows their file type adds, such as WPS's "PDF merge" or an image's "Rotate").
//!
//!   cargo run -p rf-win --example menu_rows -- <file> [<file> ...]
//!
//! Read-only: the menu is built and released, nothing is invoked.

use std::path::PathBuf;
use std::time::Duration;

use rf_win::ctxmenu::{self, ShellTarget};

fn main() {
    let items: Vec<PathBuf> = std::env::args().skip(1).map(PathBuf::from).collect();
    let (tx, rx) = std::sync::mpsc::channel();
    rf_win::sta::run(move |owner| {
        let out = match ctxmenu::build(owner, &ShellTarget::Items(items), false) {
            Ok((session, rows)) => {
                ctxmenu::release(session);
                rows.iter().filter(|r| !r.label.is_empty()).map(|r| format!("{} [{}]", r.label, r.verb)).collect()
            }
            Err(e) => vec![format!("error: {e}")],
        };
        let _ = tx.send(out);
    });
    for row in rx.recv_timeout(Duration::from_secs(20)).unwrap_or_else(|_| vec!["(no answer)".into()]) {
        println!("{row}");
    }
}