From 6c575a3986cbe6494e52e74f8b6fd88bee9ad016 Mon Sep 17 00:00:00 2001 From: 2sulraw <2sulraw@gmail.com> Date: Wed, 25 Nov 2026 22:11:14 +0330 Subject: [PATCH] rust-explorer: middle click a folder opens it in a background tab --- plugins/rust-explorer/src/main.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/plugins/rust-explorer/src/main.rs b/plugins/rust-explorer/src/main.rs index 6fedc67..3f3ea12 100644 --- a/plugins/rust-explorer/src/main.rs +++ b/plugins/rust-explorer/src/main.rs @@ -5,7 +5,8 @@ // Ctrl+T/W/Tab tabs, Ctrl+M thumbnails, Ctrl+L/F4 address bar, Ctrl+F or "? terms" in the bar = instant search through the rs service, right click / Menu key = shell context menu. // Look: topbar's palette, painted tabs / toolbar / address pill and status line (src/ui.rs), dark title bar and list. // Clipboard is the system one (Ctrl+C/X/V interoperate with Explorer). Also: Alt+Left/Right back/forward, Alt+Up up, -// Alt+Enter properties, F5 refresh, Ctrl+H hidden files, click a column header to sort, right click on empty space = folder menu. +// Alt+Enter properties, F5 refresh, Ctrl+H hidden files, click a column header to sort, right click on empty space = folder menu, +// middle click on a folder = open it in a new tab. // shortcuts: std::fs listing (not FindFirstFileEx large fetch), icons are extension-based (exe/lnk/ico/url/scr // per file) and synchronous (thumbnails: one background thread, 96px, no disk cache), internal copy/cut clipboard, silent rename errors, // search blocks the UI while it waits for the service (no async), the service pipe is admin-only so run as admin, @@ -19,7 +20,7 @@ #![windows_subsystem = "windows"] use std::{cell::RefCell, env, fs, os::windows::fs::MetadataExt, path::{Path, PathBuf}, ptr, sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed}}; use winrust_common::{t, tf}; -use windows_sys::Win32::{Foundation::*, Graphics::Gdi::{GetStockObject, InvalidateRect}, System::LibraryLoader::GetModuleHandleW, UI::{Controls::*, Input::KeyboardAndMouse::{GetKeyState, SetFocus, VK_CONTROL}, Shell::*, WindowsAndMessaging::*}}; +use windows_sys::Win32::{Foundation::*, Graphics::Gdi::{GetStockObject, InvalidateRect, ScreenToClient}, System::LibraryLoader::GetModuleHandleW, UI::{Controls::*, Input::KeyboardAndMouse::{GetKeyState, SetFocus, VK_CONTROL}, Shell::*, WindowsAndMessaging::*}}; mod zipx; // our own ZIP engine (deflate, inflate, container) mod jobs; // our own copier, ZIP packer, ZIP/7z unpacker (background, progress in the status line) @@ -757,6 +758,12 @@ fn tab_new() { tab_text(tab, 0, "", true); } +/// Opens `dir` in a new tab, staying on the current one (middle click on a folder row). +fn tab_open(dir: PathBuf) { + let tab = ST.with_borrow_mut(|st| { st.tabs.push(dir); st.tab }); + tab_text(tab, 0, "", true); // insert: the bar repaints with the new tab, the listing stays +} + fn tab_select(h: HWND, i: usize) { let dir = ST.with_borrow_mut(|st| { st.active = i; st.tabs[i].clone() }); load(h, dir); @@ -1614,6 +1621,21 @@ unsafe extern "system" fn proc(h: HWND, m: u32, wp: WPARAM, lp: LPARAM) -> LRESU } // mouse buttons 4 / 5 (and keyboard media keys) arrive as APPCOMMAND_BROWSER_BACKWARD / _FORWARD 0x0319 if !desk() && matches!((lp >> 16) & 0x7FF, 1 | 2) => { nav(h, (lp >> 16) & 0x7FF == 1); 1 } + // the list reports its button downs here: middle click on a folder row opens it in a new tab + WM_PARENTNOTIFY if !desk() && (wp & 0xFFFF) as u32 == WM_MBUTTONDOWN => { + let list = ST.with_borrow(|st| st.list); + let mut pt: POINT = std::mem::zeroed(); + GetCursorPos(&mut pt); + if WindowFromPoint(pt) == list { + ScreenToClient(list, &mut pt); + let mut ht: LVHITTESTINFO = std::mem::zeroed(); + ht.pt = pt; + let i = put(list, LVM_SUBITEMHITTEST, 0, &mut ht as *mut _ as isize); + let dir = ST.with_borrow(|st| usize::try_from(i).ok().and_then(|i| st.rows.get(i)).filter(|r| r.dir && !r.hdr).map(|r| st.dir.join(&r.name))); + if let Some(d) = dir { tab_open(d); } + } + 0 + } WM_SIZE => { let list = ST.with_borrow(|st| st.list); let (cw, ch) = ((lp & 0xFFFF) as i32, ((lp >> 16) & 0xFFFF) as i32);