From b44c774c07551964db0e3aa7321b2fba679605ad Mon Sep 17 00:00:00 2001 From: armada45-pixel Date: Tue, 13 Oct 2026 12:04:09 +0700 Subject: [PATCH 1/2] Close the key list by a button and by a press outside it The list `?` opens could only be closed from the keyboard, so a hand on the mouse had to go back to it. Its heading now ends in a Close button, and a press outside the card closes it as Escape does. A press on the card is the card's own, and neither reaches the screen behind. The dimmed page and its heading are `modal` and `page_header`, which take the function that closes them, so another page can be built on them. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 + crates/disktree-app/src/tests.rs | 45 +++++++++ crates/disktree-app/src/views.rs | 158 +++++++++++++++++++++---------- 3 files changed, 156 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 80442695..cfd7c799 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,8 @@ rescan, ⌘[ and ⌘] for back and forward, and ⌘Q, ⌘H and ⌘W (closing the window quits); other ⌘ chords are left to the system. On Linux and Windows the same work with ctrl, with F5 to rescan too. +The key list closes with `esc`, its Close button, or a click outside it. + On the review screen: `m` trash, `p` permanent, `!` unmark all, `enter` commits, `esc` goes back. Or hand the list on instead of acting on it: `s` saves it as a text file, one path per line, and `a` copies a prompt for a diff --git a/crates/disktree-app/src/tests.rs b/crates/disktree-app/src/tests.rs index 3d7f151b..1e7675cd 100644 --- a/crates/disktree-app/src/tests.rs +++ b/crates/disktree-app/src/tests.rs @@ -517,6 +517,51 @@ fn the_help_overlay_opens_and_closes(cx: &mut TestAppContext) { assert!(!read(&view, cx, |app| app.show_help)); } +#[gpui_kit::test] +fn the_help_overlay_closes_by_button_and_from_outside_it( + cx: &mut TestAppContext, +) { + cx.update(gpui_omarchy::init); + let temp = fixture(); + let (view, cx) = view_over(temp.path(), cx); + draw(cx); + let drawn = + read(&view, cx, |app| (app.crumbs.clone(), app.selected.clone())); + + press(cx, "?"); + draw(cx); + assert!(read(&view, cx, |app| app.show_help)); + // A press on the card is the card's own. + let card = cx.debug_bounds("help-card").expect("the key list"); + cx.simulate_click(card.center(), gpui_kit::Modifiers::none()); + draw(cx); + assert!(read(&view, cx, |app| app.show_help)); + // One beside it closes the page, and the keys are the treemap's again. + let page = cx.debug_bounds("help").expect("the page"); + let outside = Point::new(page.origin.x + px(4.), page.origin.y + px(4.)); + cx.simulate_click(outside, gpui_kit::Modifiers::none()); + draw(cx); + assert!(!read(&view, cx, |app| app.show_help)); + // Neither press reached the screen behind: the same directory is drawn. + assert_eq!( + read(&view, cx, |app| (app.crumbs.clone(), app.selected.clone())), + drawn + ); + + // The way out is a button as well as a key. + press(cx, "?"); + draw(cx); + assert!(read(&view, cx, |app| app.show_help)); + let close = cx.debug_bounds("help-close").expect("Close"); + cx.simulate_click(close.center(), gpui_kit::Modifiers::none()); + draw(cx); + assert!(!read(&view, cx, |app| app.show_help)); + press(cx, "?"); + assert!(read(&view, cx, |app| app.show_help)); + press(cx, "escape"); + assert!(!read(&view, cx, |app| app.show_help)); +} + #[gpui_kit::test] fn the_volume_picker_opens_moves_and_closes(cx: &mut TestAppContext) { cx.update(gpui_omarchy::init); diff --git a/crates/disktree-app/src/views.rs b/crates/disktree-app/src/views.rs index c23e91b3..a9907d72 100644 --- a/crates/disktree-app/src/views.rs +++ b/crates/disktree-app/src/views.rs @@ -250,6 +250,84 @@ fn centred_popup( ) } +/// A page over the dimmed window: the keys, for one. A press outside the +/// card closes it, as Escape does; one on the card is the card's own, and +/// nothing reaches the screen behind either way. +fn modal( + id: &'static str, + theme: &Theme, + card: impl IntoElement, + close: fn(&mut Disktree, &mut Context<'_, Disktree>), + cx: &Context<'_, Disktree>, +) -> Stateful
{ + div() + .id(id) + .debug_selector(move || id.into()) + .absolute() + .inset_0() + .flex() + .items_center() + .justify_center() + .bg(theme.background.opacity(0.86)) + .on_any_mouse_down(cx.listener( + move |this, _: &MouseDownEvent, window, cx| { + cx.stop_propagation(); + close(this, cx); + window.focus(&this.focus, cx); + }, + )) + .child( + div() + .id(ElementId::Name(format!("{id}-card").into())) + .debug_selector(move || format!("{id}-card")) + .on_any_mouse_down( + |_: &MouseDownEvent, _: &mut Window, cx: &mut App| { + cx.stop_propagation(); + }, + ) + .child(card), + ) +} + +/// A page's heading with the way out of it at the far end, for a hand on +/// the mouse; Escape and a press outside do the same. +fn page_header( + id: &'static str, + glyph: gpui_omarchy::IconName, + title: &'static str, + close: fn(&mut Disktree, &mut Context<'_, Disktree>), + cx: &Context<'_, Disktree>, +) -> Div { + let theme = cx.omarchy(); + div() + .flex() + .flex_row() + .items_center() + .gap(space::SM) + .child( + gpui_omarchy::icon(glyph) + .size(icon::MD) + .text_color(theme.accent), + ) + .child( + div() + .text_size(text::TITLE) + .font_weight(FontWeight::BOLD) + .text_color(theme.bright) + .child(title), + ) + .child(div().flex_1()) + .child( + button(id, "Close", ButtonVariant::Secondary, cx) + .debug_selector(move || id.into()) + .tab_stop(false) + .on_click(cx.listener(move |this, _, window, cx| { + close(this, cx); + window.focus(&this.focus, cx); + })), + ) +} + /// The one question disktree asks: a permanent deletion cannot be undone, so /// it is an alert dialog that names what goes and what comes back. The trash is /// reversible and needs no dialog. @@ -3495,8 +3573,12 @@ const MODIFIER_OPEN: &str = if cfg!(target_os = "macos") { "ctrl-o" }; -fn help_overlay(app: &Disktree, cx: &gpui_kit::App) -> Div { - let theme = cx.omarchy(); +fn help_overlay(app: &Disktree, cx: &Context<'_, Disktree>) -> Stateful
{ + let theme = cx.omarchy().clone(); + let close: fn(&mut Disktree, &mut Context<'_, Disktree>) = |this, cx| { + this.show_help = false; + cx.notify(); + }; // Sentence case, and the tile a key acts on is always the one under the // pointer if the pointer moved last, else the keyboard selection. let rows = [ @@ -3580,54 +3662,32 @@ fn help_overlay(app: &Disktree, cx: &gpui_kit::App) -> Div { ); } - div() - .absolute() - .inset_0() + let card = div() .flex() - .items_center() - .justify_center() - .bg(theme.background.opacity(0.86)) + .flex_col() + .gap(space::MD) + .w(size::HELP) + .p(space::XL) + .border_1() + .border_color(theme.border) + .bg(theme.surface) + .child(page_header( + "help-close", + gpui_omarchy::IconName::Keyboard, + "Keyboard and mouse", + close, + cx, + )) + .child(keys) .child( div() - .flex() - .flex_col() - .gap(space::MD) - .w(size::HELP) - .p(space::XL) - .border_1() - .border_color(theme.border) - .bg(theme.surface) - .child( - div() - .flex() - .flex_row() - .items_center() - .gap(space::SM) - .child( - gpui_omarchy::icon( - gpui_omarchy::IconName::Keyboard, - ) - .size(icon::MD) - .text_color(theme.accent), - ) - .child( - div() - .text_size(text::TITLE) - .font_weight(FontWeight::BOLD) - .text_color(theme.bright) - .child("Keyboard and mouse"), - ), - ) - .child(keys) - .child( - div() - .text_size(text::CAPTION) - .text_color(theme.secondary) - .child(format!( - "? or esc closes \u{00b7} {} \u{00b7} {}", - app.root_path.display(), - app.options.metric.label() - )), - ), - ) + .text_size(text::CAPTION) + .text_color(theme.secondary) + .child(format!( + "?, esc or a click outside closes \u{00b7} {} \u{00b7} {}", + app.root_path.display(), + app.options.metric.label() + )), + ); + modal("help", &theme, card, close, cx) } From 0f630ae140940c2521c67c8129c34febfc553349 Mon Sep 17 00:00:00 2001 From: armada45-pixel Date: Tue, 13 Oct 2026 12:11:28 +0700 Subject: [PATCH 2/2] Add a page of every disk, opened from the title bar Scanning another disk meant knowing the v key, and the picker it opens names a disk by its mount point alone and leaves out the one on screen. A disk button beside the name now opens a page of cards, as a file manager's first page has them: the label and mount point, the room left of the total, a meter that turns to the danger colour when nearly full, and the device on a line of its own where the system keeps no label. The scanned disk is among them and says so. A click scans a disk; up, down and Enter work too; Escape, Close or a press outside leaves. On Windows the label is read with GetVolumeInformationW. The picker's loader is shared, told whether to keep the scanned volume. Co-Authored-By: Claude Opus 5.5 --- README.md | 7 +- crates/disktree-app/src/state.rs | 54 ++++++- crates/disktree-app/src/tests.rs | 98 +++++++++++++ crates/disktree-app/src/ui.rs | 4 + crates/disktree-app/src/views.rs | 213 +++++++++++++++++++++++++++- crates/disktree-core/src/space.rs | 21 +++ crates/disktree-core/src/windows.rs | 25 ++++ 7 files changed, 415 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cfd7c799..93b76e83 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,9 @@ disktree --help # options: apparent size, follow links, skip hidden, … ### The screen - **Top:** the trail from `/`, then what is measured — **Size**, **Files** or - **Age**, **Hidden files**, **Apparent size**, and the depth drawn. In the + **Age**, **Hidden files**, **Apparent size**, and the depth drawn. The disk + button beside the name opens a page of every disk, with its name, size + and room; click one to scan it. In the tree a crumb goes there, and its ▾ lists its siblings, largest first with their share and size, to jump sideways (arrows and Enter work too). Above the scanned root a crumb is dimmer, and clicking it widens the scan to @@ -238,7 +240,8 @@ rescan, ⌘[ and ⌘] for back and forward, and ⌘Q, ⌘H and ⌘W (closing the window quits); other ⌘ chords are left to the system. On Linux and Windows the same work with ctrl, with F5 to rescan too. -The key list closes with `esc`, its Close button, or a click outside it. +The key list and the page of disks close with `esc`, their Close button, +or a click outside them. On the review screen: `m` trash, `p` permanent, `!` unmark all, `enter` commits, `esc` goes back. Or hand the list on instead of acting on it: `s` diff --git a/crates/disktree-app/src/state.rs b/crates/disktree-app/src/state.rs index ee351f3a..1e49d32b 100644 --- a/crates/disktree-app/src/state.rs +++ b/crates/disktree-app/src/state.rs @@ -446,6 +446,9 @@ pub struct Disktree { volume_epoch: u64, pub volumes: Vec, pub volume_highlight: usize, + /// The page of disks is up. It lists `volumes` as the picker does, the + /// scanned one among them. + pub home_open: bool, /// The side panel's width, in rem; dragged from its left edge. pub panel_rems: f32, pub scan_started: Option, @@ -545,6 +548,7 @@ impl Disktree { volumes_loading: false, volume_epoch: 0, volumes: Vec::new(), + home_open: false, volume_highlight: 0, panel_rems: PANEL_REMS, scan_started: None, @@ -650,14 +654,37 @@ impl Disktree { /// is left alone until a volume is picked; picking calls [`set_root`], /// which cancels it. pub fn open_volumes(&mut self, cx: &mut Context<'_, Self>) { + self.volumes_open = true; + self.focus_request = Some(FocusTarget::Dialog); + self.load_volumes(false, cx); + } + + /// The home page: every disk with its name, size and room, as a file + /// manager's own first page shows them, the one being scanned too. + pub fn open_home(&mut self, cx: &mut Context<'_, Self>) { + if !self.can_start_over() { + return; + } + self.home_open = true; + self.load_volumes(true, cx); + } + + /// Leave the page of disks without choosing one. + pub fn close_home(&mut self, cx: &mut Context<'_, Self>) { + self.home_open = false; + self.focus_request = Some(FocusTarget::Root); + cx.notify(); + } + + /// Read the volumes for the picker, or with `with_current` for the + /// page of disks, which shows the scanned one among the others. + fn load_volumes(&mut self, with_current: bool, cx: &mut Context<'_, Self>) { self.volume_epoch += 1; let epoch = self.volume_epoch; let root_path = self.root_path.clone(); self.volumes.clear(); self.volume_highlight = 0; self.volumes_loading = true; - self.volumes_open = true; - self.focus_request = Some(FocusTarget::Dialog); // Removable media and network volumes can take seconds to answer. // Keep Escape and the window responsive while probing them. let task = cx.background_executor().spawn(async move { @@ -669,15 +696,19 @@ impl Disktree { point: root.clone(), device: device_for(&root), space: space_info(&root).ok(), + label: disktree_core::space::volume_label(&root), }); } - volumes.retain(|volume| volume.point != root_path); + if !with_current { + volumes.retain(|volume| volume.point != root_path); + } volumes }); cx.spawn(async move |this, cx| { let volumes = task.await; let _ = this.update(cx, |this, cx| { - if this.volumes_open && this.volume_epoch == epoch { + let wanted = this.volumes_open || this.home_open; + if wanted && this.volume_epoch == epoch { this.volumes = volumes; this.volumes_loading = false; cx.notify(); @@ -708,10 +739,12 @@ impl Disktree { .map(|volume| volume.point.clone()) else { self.volumes_open = false; + self.home_open = false; cx.notify(); return; }; self.volumes_open = false; + self.home_open = false; self.volumes.clear(); self.set_root(point, cx); } @@ -2397,6 +2430,7 @@ impl Disktree { self.screen == Screen::Explore && !self.confirm_open && !self.volumes_open + && !self.home_open } /// Ask for a directory and scan it: an app opened from the Dock has no @@ -2537,6 +2571,18 @@ impl Disktree { return; } + // The page of disks takes the picker's keys. + if self.home_open { + match key { + "escape" => self.close_home(cx), + "enter" => self.choose_volume(cx), + "up" if !control => self.move_volume_highlight(-1, cx), + "down" if !control => self.move_volume_highlight(1, cx), + _ => {} + } + return; + } + // The volume picker owns its keys while open: arrows move, Enter // picks, Escape closes, and nothing behind it acts. if self.volumes_open { diff --git a/crates/disktree-app/src/tests.rs b/crates/disktree-app/src/tests.rs index 1e7675cd..ab66507e 100644 --- a/crates/disktree-app/src/tests.rs +++ b/crates/disktree-app/src/tests.rs @@ -597,6 +597,7 @@ fn enter_in_the_focused_volume_picker_scans_the_selected_root( point: target.clone(), device: None, space: None, + label: None, }]; app.volume_highlight = 0; app.volumes_open = true; @@ -631,11 +632,13 @@ fn the_volume_picker_is_centred_and_still_dismisses_from_outside( free: 500, available: 400, }), + label: None, }, Volume { point: PathBuf::from("/two"), device: None, space: None, + label: None, }, ]; app.volumes_open = true; @@ -668,6 +671,101 @@ fn the_volume_picker_is_centred_and_still_dismisses_from_outside( ); } +#[gpui_kit::test] +fn the_page_of_disks_scans_the_one_clicked(cx: &mut TestAppContext) { + cx.update(gpui_omarchy::init); + let temp = fixture(); + let target = temp.path().join("junk"); + let (view, cx) = view_over(temp.path(), cx); + draw(cx); + + let home = cx.debug_bounds("home").expect("the home button"); + cx.simulate_click(home.center(), gpui_kit::Modifiers::none()); + assert!(read(&view, cx, |app| app.home_open)); + // Fixed disks, so this is not about the machine running the test. + update(&view, cx, |app, cx| { + app.volumes = vec![ + Volume { + point: PathBuf::from("/elsewhere"), + device: Some("/dev/elsewhere".into()), + space: Some(SpaceInfo { + total: 1_000, + free: 50, + available: 40, + }), + label: Some("Nearly full".into()), + }, + Volume { + point: target.clone(), + device: None, + space: None, + label: None, + }, + ]; + app.volumes_loading = false; + cx.notify(); + }); + draw(cx); + // The treemap's keys are the page's while it is up. + press(cx, "c"); + assert_eq!(read(&view, cx, |app| app.screen), Screen::Explore); + press(cx, "down"); + assert_eq!(read(&view, cx, |app| app.volume_highlight), 1); + + let drive = cx.debug_bounds("drive-1").expect("the second disk"); + cx.simulate_click(drive.center(), gpui_kit::Modifiers::none()); + draw(cx); + read(&view, cx, |app| { + assert!(!app.home_open); + assert_eq!(app.root_path, target); + }); + finish_scan(&view, cx); +} + +#[gpui_kit::test] +fn the_page_of_disks_closes_without_moving_the_scan(cx: &mut TestAppContext) { + cx.update(gpui_omarchy::init); + let temp = fixture(); + let (view, cx) = view_over(temp.path(), cx); + draw(cx); + let before = read(&view, cx, |app| app.root_path.clone()); + let open = |cx: &mut VisualTestContext| { + let home = cx.debug_bounds("home").expect("the home button"); + cx.simulate_click(home.center(), gpui_kit::Modifiers::none()); + draw(cx); + }; + + // The page lists this machine's disks and draws them without + // panicking; nothing behind it may start over while it is up. + open(cx); + read(&view, cx, |app| { + assert!(app.home_open); + assert!(!app.can_start_over()); + }); + press(cx, "escape"); + assert!(!read(&view, cx, |app| app.home_open)); + + // A press on the card is the card's own; one beside it closes the page. + open(cx); + let card = cx.debug_bounds("home-card").expect("the page's card"); + cx.simulate_click(card.center(), gpui_kit::Modifiers::none()); + draw(cx); + assert!(read(&view, cx, |app| app.home_open)); + let page = cx.debug_bounds("home").expect("the page"); + let outside = Point::new(page.origin.x + px(4.), page.origin.y + px(4.)); + cx.simulate_click(outside, gpui_kit::Modifiers::none()); + draw(cx); + assert!(!read(&view, cx, |app| app.home_open)); + + // The way out is a button as well as a key. + open(cx); + let close = cx.debug_bounds("home-close").expect("Close"); + cx.simulate_click(close.center(), gpui_kit::Modifiers::none()); + draw(cx); + assert!(!read(&view, cx, |app| app.home_open)); + assert_eq!(read(&view, cx, |app| app.root_path.clone()), before); +} + #[gpui_kit::test] fn showing_a_tile_that_is_gone_says_so_instead(cx: &mut TestAppContext) { cx.update(gpui_omarchy::init); diff --git a/crates/disktree-app/src/ui.rs b/crates/disktree-app/src/ui.rs index ea715d25..9a264b22 100644 --- a/crates/disktree-app/src/ui.rs +++ b/crates/disktree-app/src/ui.rs @@ -98,6 +98,10 @@ pub mod size { pub const TOOLTIP: Rems = Rems(16.75); /// The keyboard overlay. pub const HELP: Rems = Rems(32.5); + /// The page of disks: three cards across at the default rem. + pub const HOME: Rems = Rems(58.0); + /// One disk on that page: wide enough for a label and its letter. + pub const DRIVE_CARD: Rems = Rems(16.0); /// The key column of the keyboard overlay. pub const KEY_LANE: Rems = Rems(7.0); } diff --git a/crates/disktree-app/src/views.rs b/crates/disktree-app/src/views.rs index a9907d72..67fd556a 100644 --- a/crates/disktree-app/src/views.rs +++ b/crates/disktree-app/src/views.rs @@ -111,6 +111,9 @@ pub fn root( if app.show_help { root = root.child(help_overlay(app, cx)); } + if app.home_open { + root = root.child(home_page(app, cx)); + } if app.volumes_open { root = root.child(volumes_dialog(app, cx)); } @@ -250,7 +253,7 @@ fn centred_popup( ) } -/// A page over the dimmed window: the keys, for one. A press outside the +/// A page over the dimmed window: the keys, the disks. A press outside the /// card closes it, as Escape does; one on the card is the card's own, and /// nothing reaches the screen behind either way. fn modal( @@ -328,6 +331,191 @@ fn page_header( ) } +/// A volume as a file manager names it: its label, then where it is +/// mounted, `Data (D:)`; or the mount point alone when it has no label. +fn volume_name(volume: &disktree_core::space::Volume) -> String { + let point = volume.point.display().to_string(); + match &volume.label { + Some(label) => { + let short = point.trim_end_matches(['\\', '/']); + let short = if short.is_empty() { &point } else { short }; + format!("{label} ({short})") + } + None => point, + } +} + +/// How much room a volume has, of how much: `23 GiB free of 317 GiB`. +fn volume_room(volume: &disktree_core::space::Volume) -> String { + volume.space.map_or_else( + || "size unknown".to_string(), + |space| { + format!( + "{} free of {}", + human_bytes(space.available), + human_bytes(space.total) + ) + }, + ) +} + +/// How full a volume has to be before its bar turns to the danger colour, +/// the way a file manager warns that a drive is nearly out of room. +const NEARLY_FULL: f32 = 0.9; + +/// Every disk, as the first page of a file manager shows them: name, a bar +/// of what is used, and the room left. A click scans that one. +fn home_page(app: &Disktree, cx: &Context<'_, Disktree>) -> Stateful
{ + let theme = cx.omarchy().clone(); + let close: fn(&mut Disktree, &mut Context<'_, Disktree>) = + Disktree::close_home; + let mut drives = div() + .id("home-drives") + .flex() + .flex_row() + .flex_wrap() + .gap(space::LG); + if app.volumes_loading { + drives = drives.child( + div() + .text_color(theme.secondary) + .child("Looking for disks\u{2026}"), + ); + } else if app.volumes.is_empty() { + drives = drives.child( + div() + .text_color(theme.secondary) + .child("No disk could be read."), + ); + } + for (index, volume) in app.volumes.iter().enumerate() { + let highlighted = index == app.volume_highlight; + let scanned = app.root_path.starts_with(&volume.point); + let used = volume.space.map_or(0.0, |space| { + (space.used() as f32 / space.total.max(1) as f32).clamp(0.0, 1.0) + }); + let fill = if used >= NEARLY_FULL { + theme.danger + } else { + theme.accent + }; + drives = drives.child( + div() + .id(ElementId::Name(format!("drive-{index}").into())) + .debug_selector(move || format!("drive-{index}")) + .flex() + .flex_row() + .items_center() + .gap(space::MD) + .w(size::DRIVE_CARD) + .p(space::MD) + .border_1() + .border_color(if highlighted { + theme.accent + } else { + theme.control_border() + }) + .when(highlighted, |card| card.bg(theme.accent.opacity(0.12))) + .hover(|card| card.bg(theme.hover_fill())) + .cursor_pointer() + .on_click(cx.listener(move |this, _, window, cx| { + this.volume_highlight = index; + this.choose_volume(cx); + window.focus(&this.focus, cx); + })) + .child( + gpui_omarchy::icon(gpui_omarchy::IconName::HardDrive) + .size(icon::LG) + .text_color(theme.secondary), + ) + .child( + div() + .flex() + .flex_col() + .flex_1() + .min_w_0() + .gap(space::XS) + .child( + div() + .flex() + .flex_row() + .items_center() + .gap(space::SM) + .child( + div() + .flex_1() + .min_w_0() + .text_size(text::BODY) + .text_color(theme.bright) + .whitespace_nowrap() + .overflow_hidden() + .text_ellipsis() + .child(volume_name(volume)), + ) + .when(scanned, |row| { + row.child(widgets::chip( + "scanned", + theme.accent, + cx, + )) + }), + ) + .child(widgets::bar(used, fill, cx)) + .child( + div() + .text_size(text::CAPTION) + .text_color(theme.secondary) + .whitespace_nowrap() + .overflow_hidden() + .text_ellipsis() + .child(volume_room(volume)), + ) + // Where a volume has no label, as on Linux, its + // device is what tells two apart. On a line of its + // own: beside the room it pushed the total out of + // the card. + .children(volume.device.clone().map(|device| { + div() + .text_size(text::CAPTION) + .text_color(theme.secondary.opacity(0.7)) + .whitespace_nowrap() + .overflow_hidden() + .text_ellipsis() + .child(device) + })), + ), + ); + } + let card = div() + .flex() + .flex_col() + .gap(space::LG) + .w(size::HOME) + .max_w(relative(0.94)) + .p(space::XL) + .border_1() + .border_color(theme.border) + .bg(theme.surface) + .child(page_header( + "home-close", + gpui_omarchy::IconName::HardDrive, + "Disks", + close, + cx, + )) + .child(drives) + .child( + div() + .text_size(text::CAPTION) + .text_color(theme.secondary) + .child( + "Click a disk to scan it \u{00b7} up, down and enter work \ + too \u{00b7} esc stays here", + ), + ); + modal("home", &theme, card, close, cx) +} + /// The one question disktree asks: a permanent deletion cannot be undone, so /// it is an alert dialog that names what goes and what comes back. The trash is /// reversible and needs no dialog. @@ -536,12 +724,35 @@ fn top_bar( .border_b_1() .border_color(theme.divider()) .child(logo(theme)) + .child(with_tooltip( + bar_icon("home", gpui_omarchy::IconName::HardDrive, theme) + .on_click(cx.listener(|this, _, window, cx| { + this.open_home(cx); + window.focus(&this.focus, cx); + })), + "Every disk, to scan another", + )) // Where you are is navigation, and it belongs to the whole window. .child(trail(app, theme, cx)) .child(div().flex_1()) .child(view_settings(app, window, cx)) } +/// A glyph on the bar that does one thing when clicked. +fn bar_icon( + id: &'static str, + name: gpui_omarchy::IconName, + theme: &Theme, +) -> Stateful
{ + div() + .id(id) + .debug_selector(move || id.into()) + .p(space::XS) + .text_color(theme.secondary) + .hover(|style| style.bg(theme.hover_fill()).text_color(theme.bright)) + .child(gpui_omarchy::icon(name).size(icon::MD)) +} + /// The trail, from `/`. Above the scanned root, a crumb widens the scan; /// in the tree, it goes there, and its ▾ lists its siblings to jump to. /// A deep trail keeps its first two steps and its last four. diff --git a/crates/disktree-core/src/space.rs b/crates/disktree-core/src/space.rs index 8a2bc4ee..a2a04214 100644 --- a/crates/disktree-core/src/space.rs +++ b/crates/disktree-core/src/space.rs @@ -689,6 +689,20 @@ pub const fn foreign_mounts_for(_root: &Path) -> Option> { Some(Vec::new()) } +/// The name of the volume `path` is on, where the system keeps one. +#[cfg(windows)] +pub fn volume_label(path: &Path) -> Option { + crate::windows::volume_root(path) + .and_then(|root| crate::windows::volume_label(&root)) +} + +/// The name of the volume `path` is on, where the system keeps one: only +/// Windows is asked, the mount point being the name elsewhere. +#[cfg(not(windows))] +pub const fn volume_label(_path: &Path) -> Option { + None +} + /// A mounted volume the picker can switch the scan to: where it is mounted /// and how much room it has. Listed by [`volumes`]. #[derive(Clone, Debug, PartialEq, Eq)] @@ -701,6 +715,9 @@ pub struct Volume { pub device: Option, /// Free space on the volume now; `None` when it cannot be read. pub space: Option, + /// The name its owner gave it, such as `Data` for `D:\`; `None` when + /// it has none or the system does not say. + pub label: Option, } /// Every volume worth offering as a scan root, fullest first. @@ -742,6 +759,7 @@ pub fn volumes_in(mounts: &[Mount]) -> Vec { let mut volumes: Vec = seen .iter() .map(|mount| Volume { + label: None, point: mount.point.clone(), device: Some(mount.source.clone()), space: space_info(&mount.point).ok(), @@ -824,6 +842,7 @@ pub fn volumes() -> Vec { let mut volumes: Vec = points .iter() .map(|point| Volume { + label: None, point: point.clone(), device: device_for(point), space: space_info(point).ok(), @@ -844,6 +863,7 @@ pub fn volumes() -> Vec { .into_iter() .filter_map(|point| { space_info(&point).ok().map(|space| Volume { + label: crate::windows::volume_label(&point), point, device: None, space: Some(space), @@ -999,6 +1019,7 @@ portal /run/user/1000/doc fuse.portal rw 0 0 #[test] fn volumes_with_least_space_come_first_and_unknowns_last() { let volume = |name: &str, available: Option| Volume { + label: None, point: PathBuf::from(name), device: None, space: available.map(|available| SpaceInfo { diff --git a/crates/disktree-core/src/windows.rs b/crates/disktree-core/src/windows.rs index 53b8564c..9a4f0d5c 100644 --- a/crates/disktree-core/src/windows.rs +++ b/crates/disktree-core/src/windows.rs @@ -639,6 +639,31 @@ pub fn file_table_readable(root: &Path) -> bool { ok != 0 && String::from_utf16_lossy(&name[..end]) == "NTFS" } +/// The label of the volume mounted at `root`, as File Explorer shows it +/// before the drive letter. `None` for an unlabelled or unreadable volume. +pub fn volume_label(root: &Path) -> Option { + let volume = wide(root, true).ok()?; + let mut label = [0_u16; MAX_PATH as usize + 1]; + let length = u32::try_from(label.len()).unwrap_or(u32::MAX); + // SAFETY: `volume` is NUL-terminated and outlives the call, `label` is + // writable for the length passed, and the other outputs may be null. + let ok = unsafe { + GetVolumeInformationW( + volume.as_ptr(), + label.as_mut_ptr(), + length, + std::ptr::null_mut(), + std::ptr::null_mut(), + std::ptr::null_mut(), + std::ptr::null_mut(), + 0, + ) + }; + let end = label.iter().position(|&unit| unit == 0).unwrap_or(0); + let label = String::from_utf16_lossy(&label[..end]); + (ok != 0 && !label.is_empty()).then_some(label) +} + /// Start `program` with `args` as an administrator, through the UAC /// prompt. Returns once the prompt is answered; declining it is an error /// (`ERROR_CANCELLED`).