From a82edd5713276d38360ef9a80bf4b8c4eab55283 Mon Sep 17 00:00:00 2001 From: 2sulraw <2sulraw@gmail.com> Date: Mon, 30 Nov 2026 16:14:07 +0330 Subject: [PATCH] rust-explorer: Open cmd here in the folder and item context menus --- plugins/rust-explorer/src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/rust-explorer/src/main.rs b/plugins/rust-explorer/src/main.rs index 235f6047..c96eaf81 100644 --- a/plugins/rust-explorer/src/main.rs +++ b/plugins/rust-explorer/src/main.rs @@ -368,6 +368,7 @@ const MENU_ZIP: u32 = 0x9001; const MENU_EXTRACT: u32 = 0x9002; const MENU_PIN: u32 = 0x9003; const MENU_RENAME: u32 = 0x9004; +const MENU_CMD: u32 = 0x9005; /// True while the window shows the inside of a .zip: read-only, its rows are no files on disk. fn in_zip() -> bool { zipx::split_zip(&cur_dir()).is_some() } @@ -474,10 +475,19 @@ fn zip_menu(h: HWND, paths: &[PathBuf]) { } } +/// Opens a command prompt in `dir`. +fn open_cmd(dir: &Path) { + let comspec = env::var_os("COMSPEC").unwrap_or_else(|| "cmd.exe".into()); + let _ = std::process::Command::new(comspec).current_dir(dir).spawn(); +} + /// The shell menu for the selection, with our "Compress to ZIP" / "Extract here" on top. fn item_menu(h: HWND, dir: &Path, paths: &[PathBuf]) { if zipx::split_zip(dir).is_some() { return zip_menu(h, paths); } - let mut extra = vec![(MENU_ZIP, t!("Сжать в ZIP", "Compress to ZIP", ja: "ZIP に圧縮", pt: "Compactar em ZIP", zh: "压缩为 ZIP"))]; + let mut extra = vec![ + (MENU_CMD, t!("Открыть командную строку здесь", "Open cmd here", ja: "ここでコマンド プロンプトを開く", pt: "Abrir cmd aqui", zh: "在此处打开命令提示符")), + (MENU_ZIP, t!("Сжать в ZIP", "Compress to ZIP", ja: "ZIP に圧縮", pt: "Compactar em ZIP", zh: "压缩为 ZIP")), + ]; if paths.iter().all(|p| p.is_file() && jobs::is_archive(p)) { extra.insert(0, (MENU_EXTRACT, t!("Извлечь сюда", "Extract here", ja: "ここに展開", pt: "Extrair aqui", zh: "解压到此处"))); } @@ -486,6 +496,7 @@ fn item_menu(h: HWND, dir: &Path, paths: &[PathBuf]) { if let [p] = paths { if p.is_dir() { extra.push((MENU_PIN, if ui::pins().contains(p) { t!("Открепить от быстрого доступа", "Unpin from Quick access", ja: "クイック アクセスからピン留めを解除", pt: "Desafixar do Acesso rápido", zh: "从快速访问取消固定") } else { t!("Закрепить в быстром доступе", "Pin to Quick access", ja: "クイック アクセスにピン留め", pt: "Fixar no Acesso rápido", zh: "固定到快速访问") })); } } let picked = sh::show(h, paths, if jobs::busy() { &[] } else { &extra }).ok().flatten(); match picked { + Some(MENU_CMD) => open_cmd(match paths { [p] if p.is_dir() => p.as_path(), _ => dir }), Some(MENU_PIN) => ui::toggle_pin(&paths[0]), Some(MENU_RENAME) => unsafe { let (list, ..) = selected(); @@ -586,6 +597,7 @@ unsafe fn bg_menu(h: HWND) { menu::item(m, 1, "\u{E8F4}", t!("Новая папка", "New folder", ja: "新しいフォルダー", pt: "Nova pasta", zh: "新建文件夹"), false); menu::item(m, 2, "\u{E8A5}", t!("Новый текстовый файл", "New text file", ja: "新しいテキスト ドキュメント", pt: "Novo arquivo de texto", zh: "新建文本文件"), false); menu::item(m, 3, "\u{E77F}", t!("Вставить", "Paste", ja: "貼り付け", pt: "Colar", zh: "粘贴"), false); + menu::item(m, 17, "\u{E756}", t!("Открыть командную строку здесь", "Open cmd here", ja: "ここでコマンド プロンプトを開く", pt: "Abrir cmd aqui", zh: "在此处打开命令提示符"), false); menu::sep(m); if !desk() { let sort = CreatePopupMenu(); @@ -633,6 +645,7 @@ unsafe fn bg_menu(h: HWND) { match id { 7 => set_icons_hidden(!icons_hidden()), 16 => { SHOW_HIDDEN.fetch_xor(true, Relaxed); } // the reload below lists them + 17 => open_cmd(&dir), 20..=23 => SORT_COL.store(id as usize - 20, Relaxed), // the reload below sorts again 30 | 31 => SORT_ASC.store(id == 30, Relaxed), 13 => {