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.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Text menu: keep popups and inline rename open, avoid panel jump, and forward grown Start right-click
Ruchir3173bc91ee2f64a
diff --git a/crates/rf-app/src/dock/left.rs b/crates/rf-app/src/dock/left.rsindex b4e279f8..1279658f 100644--- a/crates/rf-app/src/dock/left.rs+++ b/crates/rf-app/src/dock/left.rs@@ -462,7 +462,16 @@ impl Render for LeftIsland {// (away: the panel's field stands in its place, same size, same look, with the keyboard; this one keeps its room, so the// weather does not move, and takes the press for the panel's field, which lies under this window: the text cursor over it,// and a press gives the keyboard to the panel's field and does not close the panel)- .when(field_hidden, |d| d.opacity(0.0).cursor_text().on_mouse_down(MouseButton::Left, |_, _, cx| super::panel::focus_start_field(cx)))+ .when(field_hidden, |d| {+ d.opacity(0.0)+ .cursor_text()+ .on_mouse_down(MouseButton::Left, |_, _, cx| super::panel::focus_start_field(cx))+ .on_mouse_down(MouseButton::Right, |ev, window, cx| {+ cx.stop_propagation();+ let pos = window.bounds().origin + ev.position;+ cx.defer(move |cx| super::panel::start_field_context_menu(pos, cx));+ })+ }).when(!field_hidden, |d| d.cursor_pointer().hover(move |s| s.bg(pressed)).active(move |s| s.bg(plate))).child(Icon::new(L::Search).size(px(plan::FIELD_ICON * k)).flex_shrink_0().text_color(secondary))// what is being typed in the panel above is shown here too; the panel's own field takes the keys (this window is never@@ -506,7 +515,15 @@ impl Render for LeftIsland {.items_center().opacity(weather_alpha)// (the panel's widened field lies under this part of the island's window: a press here is a press on that field)- .when(field_hidden, |d| d.cursor_text().on_mouse_down(MouseButton::Left, |_, _, cx| super::panel::focus_start_field(cx)))+ .when(field_hidden, |d| {+ d.cursor_text()+ .on_mouse_down(MouseButton::Left, |_, _, cx| super::panel::focus_start_field(cx))+ .on_mouse_down(MouseButton::Right, |ev, window, cx| {+ cx.stop_propagation();+ let pos = window.bounds().origin + ev.position;+ cx.defer(move |cx| super::panel::start_field_context_menu(pos, cx));+ })+ }).child(Icon::new(picture_icon(plan::weather_picture(o.code, o.is_day))).size(px(plan::WEATHER_ICON * k)).flex_shrink_0().text_color(pal.text().hsla())).child(text)});diff --git a/crates/rf-app/src/dock/panel.rs b/crates/rf-app/src/dock/panel.rsindex c452e486..3e7e39ad 100644--- a/crates/rf-app/src/dock/panel.rs+++ b/crates/rf-app/src/dock/panel.rs@@ -90,6 +90,8 @@ trait Hooks {fn redraw(&self, _cx: &mut App) {}/// The keyboard goes to the view's text field (only the Start panel has one).fn focus_field(&self, _cx: &mut App) {}+ /// Opens the text right-click menu on the view's text field at `screen_pos` (logical screen coords).+ fn field_context_menu(&self, _screen_pos: Point<Pixels>, _cx: &mut App) {}/// The dock ends: the window goes with it.fn remove(&self, cx: &mut App);}@@ -244,6 +246,9 @@ impl Hooks for StartHooks {fn focus_field(&self, cx: &mut App) {let _ = self.handle.update(cx, |v, window, cx| v.focus_search(window, cx));}+ fn field_context_menu(&self, screen_pos: Point<Pixels>, cx: &mut App) {+ let _ = self.handle.update(cx, |v, window, cx| v.open_field_menu(screen_pos, window, cx));+ }fn remove(&self, cx: &mut App) {let _ = self.handle.update(cx, |v, window, cx| {v.on_hidden(window, cx);@@ -390,6 +395,13 @@ pub fn focus_start_field(cx: &mut App) {hooks.focus_field(cx);}+/// A right click on the left island's search field while the panel's glass has grown out of it:+/// forwards the text-box context menu to the Start panel's own search field.+pub fn start_field_context_menu(screen_pos: Point<Pixels>, cx: &mut App) {+ let Some(hooks) = panel(cx).and_then(|p| p.slot(PanelId::START)).map(|s| s.hooks.clone()) else { return };+ hooks.field_context_menu(screen_pos, cx);+}+/// A right click on the island's Start button: the Start panel with the button's own menu (`sys_menu.rs`) open in it. The panel is/// opened on this monitor's dock when it is not the open one there; a panel that is open gets the menu at once.pub fn start_system_menu_on(mon: MonId, cx: &mut App) {@@ -766,7 +778,7 @@ fn watch_once(serial: u64, cx: &mut App) -> bool {let Some(p) = cx.try_global::<PanelHost>() else { return false };let Some(open) = p.open.filter(|_| p.serial == serial) else { return false };let Some(slot) = p.slot(open) else { return false };- let (hwnd, kind) = (slot.hwnd, slot.kind);+ let (hwnd, kind, slot_window) = (slot.hwnd, slot.kind, slot.window);let (rect, opened_at, been_front, was_down) = (p.rect, p.opened_at, p.been_front, p.mouse_was_down);// (a panel that grows is "on" where its glass is now, not where it will be: a click on the desktop above the half-grown glass is outside)let rect = grow_host::visible_rect(cx).unwrap_or(rect);@@ -776,6 +788,16 @@ fn watch_once(serial: u64, cx: &mut App) -> bool {let fg = rf_win::dock::foreground_root();let front = fg == hwnd;let down = geo::any_button_down();+ // Keep the panel up while its own text-box right-click menu (text_menu.rs) has the foreground.+ if crate::fluent_menu::is_open_for(slot_window, cx) {+ let p = cx.global_mut::<PanelHost>();+ p.mouse_was_down = down;+ p.opened_at = Instant::now()+ .checked_sub(Duration::from_millis(geo::FOREGROUND_GRACE_MS.saturating_sub(300)))+ .unwrap_or_else(Instant::now);+ p.been_front = false;+ return true;+ }// (the Start corner of its monitor is the open left panel's own button too: closing on its press would open it again on the// release, issue 313)let at = geo::cursor();diff --git a/crates/rf-app/src/dock/start.rs b/crates/rf-app/src/dock/start.rsindex 3df1c46b..07463e08 100644--- a/crates/rf-app/src/dock/start.rs+++ b/crates/rf-app/src/dock/start.rs@@ -552,6 +552,15 @@ impl StartView {}}+ /// Opens the text-box right-click menu for the search field at `screen_pos` (logical screen coords).+ pub fn open_field_menu(&mut self, screen_pos: Point<Pixels>, window: &mut Window, cx: &mut Context<Self>) {+ if self.open() {+ self.focus_field(window, cx);+ let at = screen_pos - window.bounds().origin;+ crate::text_menu::show_at(&self.input, at, window, cx);+ }+ }+/// The window is on the screen: the glass goes on, the keyboard goes to the field.pub fn on_shown(&mut self, dark: bool, window: &mut Window, cx: &mut Context<Self>) {if self.popup.is_none() && self.shown {diff --git a/crates/rf-app/src/dock/start_folder.rs b/crates/rf-app/src/dock/start_folder.rsindex 0ba855e2..16170512 100644--- a/crates/rf-app/src/dock/start_folder.rs+++ b/crates/rf-app/src/dock/start_folder.rs@@ -114,10 +114,10 @@ impl StartView {}let name = f.name.clone();let input = cx.new(|cx| InputState::new(window, cx).default_value(name));- let sub = cx.subscribe_in(&input, window, |this: &mut Self, _, ev: &InputEvent, _, cx| {- if matches!(ev, InputEvent::PressEnter { .. } | InputEvent::Blur) {- this.commit_folder_name(cx);- }+ let sub = cx.subscribe_in(&input, window, |this: &mut Self, _, ev: &InputEvent, _, cx| match ev {+ InputEvent::PressEnter { .. } => this.commit_folder_name(cx),+ InputEvent::Blur if !crate::fluent_menu::is_open(cx) => this.commit_folder_name(cx),+ _ => {}});f.input = Some(input);f._sub = Some(sub);diff --git a/crates/rf-app/src/fluent_menu.rs b/crates/rf-app/src/fluent_menu.rsindex 5c82b396..ea2e2448 100644--- a/crates/rf-app/src/fluent_menu.rs+++ b/crates/rf-app/src/fluent_menu.rs@@ -283,6 +283,7 @@ struct HostState {restore: Option<FocusHandle>,popup: bool,wins: Wins,+ on_dismiss: Rc<RefCell<Option<Box<dyn FnOnce(&mut App)>>>>,}struct Host(Option<HostState>);@@ -374,7 +375,7 @@ fn show_ex(let display = crate::theme::popup_display(window, cx);let wins: Wins = Default::default();view.update(cx, |m, _| m.popup = Some(PopupState { anchor, area, display, wins: wins.clone() }));- cx.set_global(Host(Some(HostState { main, view: view.clone(), restore: restore.clone(), popup: true, wins })));+ cx.set_global(Host(Some(HostState { main, view: view.clone(), restore: restore.clone(), popup: true, wins, on_dismiss: Default::default() })));gpui_windows::KEEP_ACTIVE_LOOK.store(true, std::sync::atomic::Ordering::Relaxed);if sync_popups(&view, cx) {// follow level changes (submenus opening, shell items arriving)@@ -391,8 +392,8 @@ fn show_ex(gpui_windows::KEEP_ACTIVE_LOOK.store(false, std::sync::atomic::Ordering::Relaxed);view.update(cx, |m, _| m.popup = None);}+ cx.set_global(Host(Some(HostState { main, view: view.clone(), restore, popup: false, wins: Default::default(), on_dismiss: Default::default() })));window.focus(&view.read(cx).focus.clone(), cx);- cx.set_global(Host(Some(HostState { main, view: view.clone(), restore, popup: false, wins: Default::default() })));window.refresh();view}@@ -402,6 +403,19 @@ pub fn is_open(cx: &App) -> bool {host(cx).is_some()}+/// Whether an open menu belongs to `window`.+pub fn is_open_for(window: WindowId, cx: &App) -> bool {+ host(cx).is_some_and(|h| h.main.window_id() == window)+}++/// Runs `f` if the open menu for `window` closes without giving focus back to `window`+/// (e.g. the user clicked outside into another window).+pub fn on_dismiss_for(window: WindowId, f: impl FnOnce(&mut App) + 'static, cx: &mut App) {+ if let Some(h) = host(cx).filter(|h| h.main.window_id() == window) {+ *h.on_dismiss.borrow_mut() = Some(Box::new(f));+ }+}+/// The open in-window menu, if it belongs to `window` (the workspace paints it as its top layer).pub fn current(window: &Window, cx: &App) -> Option<Entity<MenuView>> {let h = host(cx)?;@@ -457,7 +471,7 @@ fn watch_orphan(view: Entity<MenuView>, cx: &mut App) {});if geo::menu_orphaned(outside, front_is_ours(), opened.elapsed().as_millis() as u64) {log::info!("menu: put away by its watch (it was not the window in front)");- let _ = h.main.update(cx, |_, window, cx| close(window, cx));+ let _ = h.main.update(cx, |_, window, cx| close_inner(false, window, cx));return false;}true@@ -470,9 +484,30 @@ fn watch_orphan(view: Entity<MenuView>, cx: &mut App) {.detach();}+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+enum AfterClose {+ Restore,+ RefreshMain,+ DismissOwner,+}++fn after_close(restore_window: bool, main_is_active: bool) -> AfterClose {+ if restore_window {+ AfterClose::Restore+ } else if main_is_active {+ AfterClose::RefreshMain+ } else {+ AfterClose::DismissOwner+ }+}+/// Closes the open menu (if any) and gives focus back. `window` is the window whose handler/// asks (the app window, or one of the menu's own popups).pub fn close(window: &mut Window, cx: &mut App) {+ close_inner(true, window, cx);+}++fn close_inner(restore_window: bool, window: &mut Window, cx: &mut App) {let Some(h) = host(cx) else { return };cx.set_global(Host(None));if !h.popup {@@ -495,13 +530,30 @@ pub fn close(window: &mut Window, cx: &mut App) {if host(cx).is_some() {return;}- let _ = h.main.update(cx, |_, window, cx| {- window.activate_window();- if let Some(f) = &h.restore {- window.focus(f, cx);+ match after_close(restore_window, cx.active_window() == Some(h.main)) {+ AfterClose::Restore => {+ let hwnd = h.main+ .update(cx, |_, window, cx| {+ if let Some(f) = &h.restore {+ window.focus(f, cx);+ }+ window.refresh();+ crate::look::window::hwnd_of(window)+ })+ .unwrap_or(0);+ if hwnd != 0 {+ cx.spawn(async move |_| rf_win::window::bring_to_front_quietly(hwnd)).detach();+ }}- window.refresh();- });+ AfterClose::RefreshMain => {+ let _ = h.main.update(cx, |_, window, _| window.refresh());+ }+ AfterClose::DismissOwner => {+ if let Some(cb) = h.on_dismiss.borrow_mut().take() {+ cb(cx);+ }+ }+ }});}@@ -547,7 +599,10 @@ fn run_in_main(run: Run, window: &mut Window, cx: &mut App) {cx.defer(move |cx| {let now: Vec<WindowId> = cx.windows().into_iter().map(|w| w.window_id()).collect();if should_reactivate_menu_owner(host(cx).is_some(), &before, &now) {- let _ = main.update(cx, |_, window, _| window.activate_window());+ let hwnd = main.update(cx, |_, window, _| crate::look::window::hwnd_of(window)).unwrap_or(0);+ if hwnd != 0 {+ cx.spawn(async move |_| rf_win::window::bring_to_front_quietly(hwnd)).detach();+ }}});});@@ -701,7 +756,7 @@ impl LevelView {let ours: Vec<AnyWindowHandle> = h.wins.borrow().iter().map(|w| w.0).collect();let active = cx.active_window();if active.is_none_or(|a| !ours.contains(&a)) {- let _ = h.main.update(cx, |_, window, cx| close(window, cx));+ let _ = h.main.update(cx, |_, window, cx| close_inner(false, window, cx));}});}),@@ -1751,7 +1806,15 @@ fn mnemonic_match(items: &[Item], current_hl: Option<usize>, ch: char) -> Mnemon#[cfg(test)]mod tests {- use super::{Capsule, Item, MenuIcon, MnemonicMatch, capsule_target, level_height, mnemonic_candidates, mnemonic_match, should_reactivate_menu_owner, without_stray_separators};+ use super::{AfterClose, Capsule, Item, MenuIcon, MnemonicMatch, after_close, capsule_target, level_height, mnemonic_candidates, mnemonic_match, should_reactivate_menu_owner, without_stray_separators};++ #[test]+ fn after_close_restores_refreshes_or_dismisses() {+ assert_eq!(after_close(true, true), AfterClose::Restore);+ assert_eq!(after_close(true, false), AfterClose::Restore);+ assert_eq!(after_close(false, true), AfterClose::RefreshMain);+ assert_eq!(after_close(false, false), AfterClose::DismissOwner);+ }/// Issue 368: when an empty "Show more options" row goes, the separators around it do not pile up.#[test]diff --git a/crates/rf-app/src/ops.rs b/crates/rf-app/src/ops.rsindex b49d675b..a574ef4c 100644--- a/crates/rf-app/src/ops.rs+++ b/crates/rf-app/src/ops.rs@@ -977,7 +977,7 @@ impl FolderView {}return;}- if self.renaming.is_some() {+ if self.renaming.is_some() && !crate::fluent_menu::is_open(cx) {self.commit_rename(window, cx);}}diff --git a/crates/rf-app/src/quick_search.rs b/crates/rf-app/src/quick_search.rsindex 1f28e35e..18586651 100644--- a/crates/rf-app/src/quick_search.rs+++ b/crates/rf-app/src/quick_search.rs@@ -1072,6 +1072,11 @@ impl QuickSearch {})];subs.push(cx.observe_window_activation(window, |_, window, cx| {if !window.is_window_active() {+ let wid = window.window_handle().window_id();+ if crate::fluent_menu::is_open_for(wid, cx) {+ crate::fluent_menu::on_dismiss_for(wid, close, cx);+ return;+ }log::info!("quick search: the window lost the foreground and closes");cx.defer(close);}diff --git a/crates/rf-app/src/select_box.rs b/crates/rf-app/src/select_box.rsindex 848349a8..e13df0e6 100644--- a/crates/rf-app/src/select_box.rs+++ b/crates/rf-app/src/select_box.rs@@ -255,6 +255,18 @@ impl SelectView {let focus = cx.focus_handle();let mut subs = vec![cx.observe_window_activation(window, |this: &mut Self, window, cx| {if !window.is_window_active() {+ let wid = window.window_handle().window_id();+ if crate::fluent_menu::is_open_for(wid, cx) {+ let weak = cx.entity().downgrade();+ crate::fluent_menu::on_dismiss_for(+ wid,+ move |cx| {+ let _ = weak.update(cx, |this, cx| this.dismiss(cx));+ },+ cx,+ );+ return;+ }this.dismiss(cx);}})];diff --git a/crates/rf-app/src/shell/desktop/operations.rs b/crates/rf-app/src/shell/desktop/operations.rsindex b05c540b..f68e4cce 100644--- a/crates/rf-app/src/shell/desktop/operations.rs+++ b/crates/rf-app/src/shell/desktop/operations.rs@@ -380,10 +380,10 @@ impl DesktopView {let (text, select_to) = rename_check::edit_text(&it.name, it.is_dir, shown);let hidden_ext = rename_check::hidden_extension(&it.name, it.is_dir, shown);let input = cx.new(|cx| InputState::new(window, cx).default_value(text));- let sub = cx.subscribe_in(&input, window, |this, _, ev: &InputEvent, window, cx| {- if matches!(ev, InputEvent::PressEnter { .. } | InputEvent::Blur) {- this.commit_rename(window, cx);- }+ let sub = cx.subscribe_in(&input, window, |this, _, ev: &InputEvent, window, cx| match ev {+ InputEvent::PressEnter { .. } => this.commit_rename(window, cx),+ InputEvent::Blur if !crate::fluent_menu::is_open(cx) => this.commit_rename(window, cx),+ _ => {}});input.update(cx, |s, cx| {s.focus(window, cx);diff --git a/crates/rf-app/src/shell/desktop/view.rs b/crates/rf-app/src/shell/desktop/view.rsindex 1f5b4960..1bd28cc8 100644--- a/crates/rf-app/src/shell/desktop/view.rs+++ b/crates/rf-app/src/shell/desktop/view.rs@@ -877,6 +877,7 @@ impl DesktopView {.border_1().border_color(p.accent).on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())+ .on_mouse_down(MouseButton::Right, |_, _, cx| cx.stop_propagation()).child(crate::text_menu::input(inp).appearance(false).small().px_1().text_xs().text_center()).into_any_element(),(None, Some(l)) => {diff --git a/crates/rf-app/src/text_menu.rs b/crates/rf-app/src/text_menu.rsindex 81845b66..6029d1c7 100644--- a/crates/rf-app/src/text_menu.rs+++ b/crates/rf-app/src/text_menu.rs@@ -26,6 +26,10 @@ fn offers(editable: bool, masked: bool, selected: bool) -> (bool, bool, bool) {}fn show(state: &Entity<InputState>, window: &mut Window, cx: &mut App) {+ show_at(state, window.mouse_position(), window, cx);+}++pub(crate) fn show_at(state: &Entity<InputState>, at: Point<Pixels>, window: &mut Window, cx: &mut App) {let (editable, masked, selected) = {let s = state.read(cx);let p = s.presentation();@@ -47,7 +51,6 @@ fn show(state: &Entity<InputState>, window: &mut Window, cx: &mut App) {Item::Separator,Item::action(t!("Tümünü seç"), MenuIcon::None, act(|| Box::new(SelectAll))).hint("Ctrl+A"),];- let at = window.mouse_position();crate::fluent_menu::show(Menu { quick: Vec::new(), items }, at, window, cx);}