From 2f5b1a4b92a4e7b120dc3358500c3b76c63575fe Mon Sep 17 00:00:00 2001 From: Tobi Lutke Date: Wed, 25 Nov 2026 10:31:40 -0500 Subject: [PATCH] app: scan home directly, default depth 4, and clean up location chooser --- AGENTS.md | 13 +- Makefile | 2 +- README.md | 2 +- crates/disktree-app/src/main.rs | 21 +- crates/disktree-app/src/state.rs | 169 ++++++++-- crates/disktree-app/src/tests.rs | 12 +- crates/disktree-app/src/ui.rs | 6 +- crates/disktree-app/src/views.rs | 489 ++++++++++++++++++++++------ crates/disktree-core/src/space.rs | 3 + crates/disktree-core/src/treemap.rs | 2 +- 10 files changed, 554 insertions(+), 165 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4c48a09..4b6ae25 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,7 +15,7 @@ the removal mode, the confirmation). Marking is never destructive. ```sh make build # release build -make run # build and open the source/root chooser +make run # build and scan your home directory make install # ~/.local: binary, desktop entry, icon make install PREFIX=/usr/local # system-wide (needs root) make uninstall @@ -117,11 +117,12 @@ and `cargo build --release` directly; CI runs the gate on both systems. added to this volume's free space; see `space::attribution`. The final number comes from `statvfs` before and after. -10. **Discovery is not a scan.** No implicit home walk at startup. List - mounts in the selected machine's namespace without probing them; scans - stop at nested mounts, including bind mounts and same-device subvolumes. - Switching machines clears marks and identity. The Unix SSH helper streams - records and never retains the tree. SSH hosts are Unix, so remote paths +10. **Discovery is not a scan.** Local launch scans `$HOME` directly, while + bare `disktree ssh HOST` and the location dialog list mounts in the + selected machine's namespace without probing them; scans stop at nested + mounts, including bind mounts and same-device subvolumes. Switching + machines clears marks and identity. The Unix SSH helper streams records + and never retains the tree. SSH hosts are Unix, so remote paths are POSIX on every client: join, split and compare them through `PathStyle`, never `std::path`, which uses `\` on Windows. diff --git a/Makefile b/Makefile index 75fc361..0a7865d 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ help: @echo "disktree" @echo @echo " make build release build" - @echo " make run build and open the source/root chooser" + @echo " make run build and scan your home directory" @echo " make install-scan build/install the headless SSH helper only" @echo " make install install to $(PREFIX): binary, desktop entry, icon" @echo " (macOS: disktree.app into $(APPS))" diff --git a/README.md b/README.md index 1c5f6b6..98747c2 100644 --- a/README.md +++ b/README.md @@ -565,7 +565,7 @@ windowrule = size 1400 900, class:^(disktree)$ ## Develop ```sh -make run # release build, opening the source/root chooser +make run # release build, scanning your home directory make lint # rustfmt --check, then clippy with every warning an error make test # scanner, layout and removal tests, plus window-harness tests make test-ssh # real localhost SSH scans/errors; Linux, bun + openssh required diff --git a/crates/disktree-app/src/main.rs b/crates/disktree-app/src/main.rs index d88e685..1831469 100644 --- a/crates/disktree-app/src/main.rs +++ b/crates/disktree-app/src/main.rs @@ -66,12 +66,13 @@ Remote sessions are read-only: mark, export list/prompt/delete script. Use --check with ssh to deploy and scan without opening a window. arguments: - PATH explicit directory to scan; omitted opens root selection + PATH directory to scan (default: your home directory) -Without PATH, choose this computer or SSH, then a mount or directory. -No scan starts before explicit acceptance. Nested mounts are excluded. -With PATH the window scans it directly, largest first. Space marks the -selected tile, Enter opens it, c reviews the marked list, ? lists every key. +Without PATH, disktree scans your home directory directly, largest first. +Press v (or click the source button) to switch folders, disks, or an SSH host. +With `disktree ssh HOST` and no PATH, root selection opens for that host. +Space marks the selected tile, Enter opens it, c reviews the marked list, +? lists every key. options: -a, --apparent-size measure apparent length instead of allocated blocks @@ -81,7 +82,7 @@ options: -X, --cross-filesystems also measure other disks, network shares and pseudo filesystems mounted below PATH (local only; off by default) - -d, --depth N how many levels to draw at once (1-6, default 3) + -d, --depth N how many levels to draw at once (1-6, default 4) --power-efficiency PRESET miser, balanced (default), aggressive, drain-my-battery --scan-threads N fixed scan workers, capped by available CPU count @@ -314,7 +315,7 @@ fn parse_args_with_power( ..ScanOptions::default() }; let mut power = Some(preset); - let mut depth = 3_u32; + let mut depth = 4_u32; let mut disk = false; // `std::env::args` panics on a name that is not Unicode, and a path is // any name: a restart as administrator hands the root back exactly as @@ -440,7 +441,7 @@ fn parse_args_with_power( !(disk && root.is_some()), "--disk and a PATH cannot be combined" ); - let choose_root = root.is_none() && !disk && !check; + let choose_root = remote.is_some() && root.is_none() && !disk && !check; if remote.is_some() { // SSH hosts are Unix: a root such as `C:\x` names nothing there, and // a relative one would be resolved against an unknown directory. @@ -573,11 +574,11 @@ mod argument_tests { } #[test] - fn no_implicit_root_requires_selection_but_explicit_scans_do_not() { + fn local_defaults_to_home_while_bare_ssh_asks_for_a_root() { let parse = |args: &[&str]| { parse_args(args.iter().map(std::ffi::OsString::from)).unwrap() }; - assert!(parse(&[]).choose_root); + assert!(!parse(&[]).choose_root); assert!(parse(&["ssh", "dev"]).choose_root); assert!(!parse(&["."]).choose_root); assert!(!parse(&["--disk"]).choose_root); diff --git a/crates/disktree-app/src/state.rs b/crates/disktree-app/src/state.rs index be099d3..8690da5 100644 --- a/crates/disktree-app/src/state.rs +++ b/crates/disktree-app/src/state.rs @@ -28,9 +28,10 @@ use disktree_core::treemap::{ }; use gpui_kit::base::input::{InputEvent, InputState}; use gpui_kit::{ - AppContext as _, Context, Entity, FocusHandle, KeyDownEvent, MouseButton, - MouseDownEvent, MouseMoveEvent, NavigationDirection, Pixels, Point, Render, - ScrollDelta, ScrollWheelEvent, Size, Window, px, size, + AppContext as _, Context, Entity, FocusHandle, Focusable as _, + KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, + NavigationDirection, Pixels, Point, Render, ScrollDelta, ScrollWheelEvent, + Size, Window, px, size, }; use gpui_omarchy::Status; use rustc_hash::{FxHashMap, FxHashSet}; @@ -467,6 +468,7 @@ pub struct Disktree { pub volumes_open: bool, pub volumes_loading: bool, pub awaiting_root: bool, + pub picker_remote_tab: bool, pub volumes_source: Option, pub volumes_error: Option, pub picker_error: Option, @@ -623,6 +625,7 @@ impl Disktree { volumes_open: false, volumes_loading: false, awaiting_root: !start, + picker_remote_tab: false, volumes_source: None, volumes_error: None, picker_error: None, @@ -761,6 +764,7 @@ impl Disktree { return; } self.volumes_open = true; + self.picker_remote_tab = self.remote.is_some(); self.picker_host = None; self.picker_path = None; self.focus_request = Some(FocusTarget::Dialog); @@ -778,6 +782,7 @@ impl Disktree { self.volume_epoch += 1; let epoch = self.volume_epoch; self.roots_job = None; + self.picker_remote_tab = host.is_some(); self.volumes_source.clone_from(&host); self.volumes.clear(); self.volume_highlight = 0; @@ -901,12 +906,13 @@ impl Disktree { } if self.picker_path.is_none() { let path = cx.new(|cx| { - InputState::new(window, cx).placeholder("/absolute/path") + InputState::new(window, cx).placeholder("/path/to/folder") }); cx.subscribe(&path, |this, _, event, cx| { if matches!(event, InputEvent::PressEnter { .. }) { this.choose_picker_path(cx); } + cx.notify(); }) .detach(); self.picker_path = Some(path); @@ -914,12 +920,64 @@ impl Disktree { } pub fn picker_source_matches(&self, cx: &Context<'_, Self>) -> bool { + if self.picker_remote_tab && self.volumes_source.is_none() { + return false; + } self.picker_host.as_ref().is_none_or(|input| { input.read(cx).value().trim() == self.volumes_source.as_deref().unwrap_or_default() }) } + pub fn picker_path_value(&self, cx: &Context<'_, Self>) -> String { + self.picker_path + .as_ref() + .map(|input| input.read(cx).value().trim().to_owned()) + .unwrap_or_default() + } + + pub fn picker_has_path(&self, cx: &Context<'_, Self>) -> bool { + !self.picker_path_value(cx).is_empty() + } + + pub fn set_picker_tab( + &mut self, + remote: bool, + window: &mut Window, + cx: &mut Context<'_, Self>, + ) { + if self.picker_remote_tab == remote { + return; + } + if !remote { + self.choose_local_source(window, cx); + return; + } + self.picker_remote_tab = true; + self.picker_error = None; + self.volumes_error = None; + if let Some(current_remote) = self.remote.clone() { + if let Some(host) = self.picker_host.clone() { + host.update(cx, |host, cx| { + host.set_value(current_remote.clone(), window, cx); + }); + } + self.load_volume_source(Some(current_remote), cx); + } else { + self.volume_epoch += 1; + self.roots_job = None; + self.volumes_loading = false; + self.volumes_source = None; + self.volumes.clear(); + self.volume_highlight = 0; + if let Some(host) = self.picker_host.as_ref() { + let focus = host.read(cx).focus_handle(cx); + window.focus(&focus, cx); + } + cx.notify(); + } + } + pub fn choose_local_source( &mut self, window: &mut Window, @@ -932,6 +990,7 @@ impl Disktree { } pub fn connect_picker(&mut self, cx: &mut Context<'_, Self>) { + self.picker_remote_tab = true; let host = self .picker_host .as_ref() @@ -940,16 +999,50 @@ impl Disktree { self.load_volume_source(Some(host), cx); } - pub fn choose_picker_path(&mut self, cx: &mut Context<'_, Self>) { - let path = self - .picker_path - .as_ref() - .map(|input| PathBuf::from(input.read(cx).value().as_str())); - if let Some(path) = path { - self.choose_source_root(path, cx); + pub fn accept_picker(&mut self, cx: &mut Context<'_, Self>) { + if self.picker_has_path(cx) { + self.choose_picker_path(cx); + } else { + self.choose_volume(cx); } } + pub fn browse_local_folder(&mut self, cx: &mut Context<'_, Self>) { + self.close_volumes(cx); + self.open_folder(cx); + } + + pub fn choose_picker_path(&mut self, cx: &mut Context<'_, Self>) { + let raw = self.picker_path_value(cx); + if raw.is_empty() { + self.choose_source_root(PathBuf::new(), cx); + return; + } + let path = if self.volumes_source.is_none() { + expand_tilde(&raw) + } else { + PathBuf::from(raw) + }; + self.choose_source_root(path, cx); + } + + fn clear_machine_state(&mut self, local: bool) { + // Absolute paths only identify marks within one machine. + self.marks.clear(); + self.history = History::default(); + self.remote_identity = None; + self.remote_platform.clear(); + self.git.clear(); + self.git_pending.clear(); + self.space = None; + self.space_baseline = None; + self.disk_root = None; + self.device = None; + self.full_disk_access = None; + self.file_table = false; + self.home = if local { std::env::home_dir() } else { None }; + } + pub fn choose_source_root( &mut self, mut path: PathBuf, @@ -962,9 +1055,8 @@ impl Disktree { return; } if !self.picker_source_matches(cx) { - self.picker_error = Some( - "Connect SSH or choose This computer before scanning.".into(), - ); + self.picker_error = + Some("Connect to the SSH host before scanning.".into()); cx.notify(); return; } @@ -992,24 +1084,7 @@ impl Disktree { } self.picker_error = None; if self.remote != self.volumes_source { - // Absolute paths only identify marks within one machine. - self.marks.clear(); - self.history = History::default(); - self.remote_identity = None; - self.remote_platform.clear(); - self.git.clear(); - self.git_pending.clear(); - self.space = None; - self.space_baseline = None; - self.disk_root = None; - self.device = None; - self.full_disk_access = None; - self.file_table = false; - self.home = if self.volumes_source.is_none() { - std::env::home_dir() - } else { - None - }; + self.clear_machine_state(self.volumes_source.is_none()); } self.remote.clone_from(&self.volumes_source); if self.remote.is_some() { @@ -2983,10 +3058,11 @@ impl Disktree { && !self.volumes_open } - /// Ask for a directory and scan it: an app opened from the Dock has no - /// command line to name one. + /// Ask for a local directory and scan it: an app opened from the launcher + /// or Dock has no command line to name one, and this also switches back + /// from an SSH session cleanly. pub fn open_folder(&self, cx: &Context<'_, Self>) { - if self.remote.is_some() { + if !self.can_start_over() { return; } let chosen = cx.prompt_for_paths(gpui_kit::PathPromptOptions { @@ -3004,11 +3080,16 @@ impl Disktree { }; // Canonical, like a root from the command line, so a later // widening recognises this tree in the wider walk. - let path = path.canonicalize().unwrap_or(path); + let path = dunce::canonicalize(&path).unwrap_or(path); // The panel does not block the window: the review list or a // removal may have started while it was open. let _ = this.update(cx, |this, cx| { if this.can_start_over() { + if this.remote.is_some() { + this.clear_machine_state(true); + this.remote = None; + } + this.awaiting_root = false; this.set_root(path, cx); } }); @@ -3824,6 +3905,22 @@ pub fn now_seconds() -> i64 { }) } +/// Expand a leading `~` or `~/` against the local home directory. +fn expand_tilde(raw: &str) -> PathBuf { + if raw == "~" + && let Some(home) = std::env::home_dir() + { + return home; + } + if let Some(rest) = + raw.strip_prefix("~/").or_else(|| raw.strip_prefix("~\\")) + && let Some(home) = std::env::home_dir() + { + return home.join(rest); + } + PathBuf::from(raw) +} + /// Let go of a tree off the UI thread: freeing a disk's millions of nodes /// takes a good part of a second, and nothing waits on it. fn discard(tree: Option>) { diff --git a/crates/disktree-app/src/tests.rs b/crates/disktree-app/src/tests.rs index 19f5cd4..cea6796 100644 --- a/crates/disktree-app/src/tests.rs +++ b/crates/disktree-app/src/tests.rs @@ -247,7 +247,9 @@ fn startup_chooser_never_scans_before_explicit_acceptance( cx.run_until_parked(); draw(cx); assert!(cx.debug_bounds("choose-root-idle").is_some()); - assert!(cx.debug_bounds("source-host").is_some()); + assert!(cx.debug_bounds("source-tabs").is_some()); + assert!(cx.debug_bounds("source-path").is_some()); + assert!(cx.debug_bounds("source-browse").is_some()); read(&view, cx, |app| { assert!(app.awaiting_root); assert_eq!(app.scan_epoch, 0); @@ -308,6 +310,10 @@ fn invalid_ssh_input_does_not_start_a_scan_or_change_the_source( let (view, cx) = cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx)); cx.run_until_parked(); + update(&view, cx, |app, cx| { + app.picker_remote_tab = true; + cx.notify(); + }); draw(cx); let input = cx.debug_bounds("source-host").expect("host editor"); cx.simulate_click(input.center(), gpui_kit::Modifiers::none()); @@ -386,6 +392,10 @@ fn editing_a_host_never_retargets_an_existing_scan(cx: &mut TestAppContext) { let (view, cx) = view_over(temp.path(), cx); update(&view, cx, Disktree::open_volumes); cx.run_until_parked(); + update(&view, cx, |app, cx| { + app.picker_remote_tab = true; + cx.notify(); + }); draw(cx); let before = read(&view, cx, |app| app.scan_epoch); let input = cx.debug_bounds("source-host").unwrap(); diff --git a/crates/disktree-app/src/ui.rs b/crates/disktree-app/src/ui.rs index c21d026..d8b76e8 100644 --- a/crates/disktree-app/src/ui.rs +++ b/crates/disktree-app/src/ui.rs @@ -96,9 +96,9 @@ pub mod size { pub const SIZE_LANE: Rems = Rems(5.0); /// The cursor tooltip. pub const TOOLTIP: Rems = Rems(16.75); - /// Source/root chooser, with room for host, path and mount labels. - pub const SOURCE_PICKER: Rems = Rems(40.0); - pub const SOURCE_LIST_HEIGHT: Rems = Rems(18.0); + /// Location/source chooser, sized for paths and mount device names. + pub const SOURCE_PICKER: Rems = Rems(36.0); + pub const SOURCE_LIST_HEIGHT: Rems = Rems(15.0); /// Leave a visible backdrop even at large interface zoom. pub const SOURCE_VIEWPORT_FRACTION: f32 = 0.92; /// The keyboard overlay. diff --git a/crates/disktree-app/src/views.rs b/crates/disktree-app/src/views.rs index 3e9006c..5f1dccc 100644 --- a/crates/disktree-app/src/views.rs +++ b/crates/disktree-app/src/views.rs @@ -134,66 +134,45 @@ pub fn root( /// Discovery is lightweight; a separate, explicit action starts the walk. fn volumes_dialog( app: &Disktree, - window: &Window, + window: &mut Window, cx: &mut Context<'_, Disktree>, ) -> impl IntoElement { let theme = cx.omarchy().clone(); - let cancel = cx.entity().downgrade(); + let entity = cx.entity().downgrade(); + let cancel = entity.clone(); let source_ready = app.picker_source_matches(cx); - let source = app.volumes_source.as_ref().map_or_else( - || "This computer".to_owned(), - |host| format!("{host} · SSH · read-only"), - ); - let mut rows = div() - .id("volume-rows") - .debug_selector(|| "volume-rows".into()) - .flex() - .flex_col() - .gap(space::XS) - .max_h(size::SOURCE_LIST_HEIGHT) - .overflow_y_scroll(); - if app.volumes_loading { - rows = rows.child(dialog_description( - "Listing mounts, not scanning files…", + let has_path = app.picker_has_path(cx); + let can_scan = source_ready + && !app.volumes_loading + && app.volumes_error.is_none() + && (has_path || !app.volumes.is_empty()); + let show_locations = !app.picker_remote_tab + || app.volumes_source.is_some() + || app.volumes_loading + || app.volumes_error.is_some(); + + let source_tabs = { + let entity = entity.clone(); + button_group( + "source-tabs", + vec![ + ChoiceItem::new("source-local", "This computer"), + ChoiceItem::new("source-remote", "SSH remote"), + ], + Some(usize::from(app.picker_remote_tab)), + move |index, window, cx| { + let _ = entity.update(cx, |this, cx| { + this.set_picker_tab(index == 1, window, cx); + }); + }, + window, cx, - )); - } else if let Some(error) = &app.volumes_error { - rows = rows.child(div().text_color(theme.danger).child(error.clone())); - } else if app.volumes.is_empty() { - rows = rows.child(dialog_description( - "No mounts listed. Enter a directory below.", - cx, - )); - } - for (index, volume) in app.volumes.iter().enumerate() { - let highlighted = index == app.volume_highlight; - let label = format!( - "{} · {}", - volume.point.display(), - volume.device.as_deref().unwrap_or("Mounted volume") - ); - rows = rows.child( - div() - .id(ElementId::Name(format!("volume-{index}").into())) - .debug_selector(move || format!("volume-{index}")) - .px(space::MD) - .py(space::SM) - .text_size(text::BODY) - .text_color(if highlighted { - theme.bright - } else { - theme.foreground - }) - .when(highlighted, |row| row.bg(theme.accent.opacity(0.18))) - .hover(|row| row.bg(theme.accent.opacity(0.1))) - .child(label) - .on_click(cx.listener(move |this, _, window, cx| { - this.volume_highlight = index; - window.focus(&this.confirm_focus, cx); - cx.notify(); - })), - ); - } + ) + .debug_selector(|| "source-tabs".into()) + .w_full() + .p(space::XXS) + }; + let host = app .picker_host .as_ref() @@ -202,39 +181,290 @@ fn volumes_dialog( .picker_path .as_ref() .expect("picker prepared before rendering"); - let popup = dialog_popup(cx).w_full() - .child(dialog_title("Choose what to scan", cx)) - .child(dialog_description( - "Connect, then select a mount or directory. No new scan starts until you choose Scan.", - cx)) - .child(div().flex().flex_row().gap(space::SM) - .child(button("source-local", "This computer", ButtonVariant::Secondary, cx) - .on_click(cx.listener(|this, _, window, cx| this.choose_local_source(window, cx)))) - .child(gpui_omarchy::input("source-host", host, window, cx) - .debug_selector(|| "source-host".into()).flex_1()) - .child(button("source-connect", "Connect SSH", ButtonVariant::Secondary, cx) - .on_click(cx.listener(|this, _, _, cx| this.connect_picker(cx))))) - .child(div().text_color(theme.bright).child(source)) - .child(rows) - .child(dialog_description( - "Nested mounts and symlinks are not traversed. Space is measured only after selection.", cx)) - .child(div().flex().flex_row().gap(space::SM) - .child(gpui_omarchy::input("source-path", path, window, cx) - .debug_selector(|| "source-path".into()).flex_1()) - .child(button("source-scan-path", "Scan directory", ButtonVariant::Secondary, cx) - .disabled(!source_ready || app.volumes_loading || app.volumes_error.is_some()) - .on_click(cx.listener(|this, _, _, cx| this.choose_picker_path(cx))))) - .children(app.picker_error.as_ref().map(|error| div().text_color(theme.danger).child(error.clone()))) - .child(div().flex().flex_row().justify_end().gap(space::SM) - .child(dialog_button("source-cancel", "Cancel", ButtonVariant::Secondary, cx) - .on_click(cx.listener(|this, _, window, cx| { - this.close_volumes(cx); this.apply_focus(window, cx); - }))) - .child(dialog_button("source-scan", "Scan selected root", ButtonVariant::Primary, cx) - .disabled(!source_ready || app.volumes_loading || app.volumes_error.is_some() || app.volumes.is_empty()) - .on_click(cx.listener(|this, _, window, cx| { - this.choose_volume(cx); this.apply_focus(window, cx); - })))); + + let mut rows = div() + .id("volume-rows") + .debug_selector(|| "volume-rows".into()) + .flex() + .flex_col() + .max_h(size::SOURCE_LIST_HEIGHT) + .overflow_y_scroll() + .bg(theme.inset) + .border_1() + .border_color(theme.divider()); + if app.volumes_loading { + rows = rows.child( + div() + .p(space::MD) + .child(dialog_description("Listing mounts…", cx)), + ); + } else if let Some(error) = &app.volumes_error { + rows = rows.child( + div() + .p(space::MD) + .text_color(theme.danger) + .child(error.clone()), + ); + } else if app.volumes.is_empty() { + rows = rows.child(div().p(space::MD).child(dialog_description( + "No mounts listed. Enter a folder path below.", + cx, + ))); + } else { + let count = app.volumes.len(); + for (index, volume) in app.volumes.iter().enumerate() { + let highlighted = index == app.volume_highlight; + let is_home = volume.device.as_deref() == Some("Home directory"); + let primary = if is_home { + "Home".to_owned() + } else { + volume.point.display().to_string() + }; + let secondary = if is_home { + volume.point.display().to_string() + } else { + volume.device.clone().unwrap_or_default() + }; + let glyph = if is_home { + gpui_omarchy::IconName::FolderOpen + } else { + gpui_omarchy::IconName::HardDrive + }; + rows = rows.child( + div() + .id(ElementId::Name(format!("volume-{index}").into())) + .debug_selector(move || format!("volume-{index}")) + .flex() + .flex_row() + .items_center() + .gap(space::SM) + .px(space::MD) + .py(space::SM) + .cursor_pointer() + .when(index + 1 < count, |row| { + row.border_b_1() + .border_color(theme.divider().opacity(0.45)) + }) + .when(highlighted, |row| row.bg(theme.accent.opacity(0.16))) + .hover(|row| row.bg(theme.accent.opacity(0.1))) + .child( + gpui_omarchy::icon(glyph) + .size(icon::SM) + .text_color(if highlighted { + theme.accent + } else { + theme.secondary + }) + .flex_shrink_0(), + ) + .child( + div() + .flex_1() + .min_w_0() + .truncate() + .text_size(text::BODY) + .font_weight(if highlighted { + FontWeight::SEMIBOLD + } else { + FontWeight::NORMAL + }) + .text_color(if highlighted { + theme.bright + } else { + theme.foreground + }) + .child(primary), + ) + .when(!secondary.is_empty(), |row| { + row.child( + div() + .flex_shrink_0() + .text_size(text::CAPTION) + .text_color(theme.secondary) + .child(secondary), + ) + }) + .on_click(cx.listener( + move |this, event: &ClickEvent, window, cx| { + this.volume_highlight = index; + if event.click_count() >= 2 { + this.choose_volume(cx); + this.apply_focus(window, cx); + } else { + window.focus(&this.confirm_focus, cx); + cx.notify(); + } + }, + )), + ); + } + } + + let mut popup = dialog_popup(cx) + .w_full() + .gap(space::MD) + .child(dialog_title("Open location", cx)) + .child(source_tabs); + + if app.picker_remote_tab { + let connect_variant = if source_ready { + ButtonVariant::Outline + } else { + ButtonVariant::Primary + }; + popup = popup.child( + div() + .flex() + .flex_row() + .items_center() + .gap(space::SM) + .child( + gpui_omarchy::input("source-host", host, window, cx) + .debug_selector(|| "source-host".into()) + .flex_1(), + ) + .child( + button("source-connect", "Connect", connect_variant, cx) + .debug_selector(|| "source-connect".into()) + .on_click(cx.listener(|this, _, _, cx| { + this.connect_picker(cx); + })), + ), + ); + } + + if show_locations { + let list_header = div() + .flex() + .flex_row() + .items_center() + .justify_between() + .child(widgets::eyebrow( + if app.picker_remote_tab { + "Remote mounts" + } else { + "Locations" + }, + cx, + )) + .when_some( + app.volumes_source.as_ref().filter(|_| { + app.picker_remote_tab + && !app.volumes_loading + && app.volumes_error.is_none() + }), + |header, connected_host| { + header.child( + div() + .text_size(text::CAPTION) + .text_color(theme.secondary) + .child(format!("{connected_host} · read-only")), + ) + }, + ); + popup = popup.child( + div() + .flex() + .flex_col() + .gap(space::XS) + .child(list_header) + .child(rows), + ); + } else { + popup = popup.child(dialog_description( + "Enter an SSH alias or user@host and connect to list its mounts. Remote scans are read-only.", + cx, + )); + } + + if !app.picker_remote_tab || source_ready { + popup = + popup.child( + div() + .flex() + .flex_col() + .gap(space::XS) + .child(widgets::eyebrow("Folder path", cx)) + .child( + div() + .flex() + .flex_row() + .items_center() + .gap(space::SM) + .child( + gpui_omarchy::input( + "source-path", + path, + window, + cx, + ) + .debug_selector(|| "source-path".into()) + .flex_1(), + ) + .when(!app.picker_remote_tab, |row| { + row.child( + button( + "source-browse", + "Browse…", + ButtonVariant::Outline, + cx, + ) + .debug_selector(|| "source-browse".into()) + .on_click(cx.listener(|this, _, _, cx| { + this.browse_local_folder(cx); + })), + ) + }), + ), + ); + } + + popup = popup + .children(app.picker_error.as_ref().map(|error| { + div() + .text_size(text::CAPTION) + .text_color(theme.danger) + .child(error.clone()) + })) + .child( + div() + .flex() + .flex_row() + .items_center() + .justify_end() + .gap(space::SM) + .pt(space::XS) + .child( + dialog_button( + "source-cancel", + "Cancel", + ButtonVariant::Secondary, + cx, + ) + .on_click(cx.listener( + |this, _, window, cx| { + this.close_volumes(cx); + this.apply_focus(window, cx); + }, + )), + ) + .child( + dialog_button( + "source-scan", + "Scan", + ButtonVariant::Primary, + cx, + ) + .disabled(!can_scan) + .on_click(cx.listener( + |this, _, window, cx| { + this.accept_picker(cx); + this.apply_focus(window, cx); + }, + )), + ), + ); + let popup = div() .id("source-picker-scroll") .debug_selector(|| "source-picker".into()) @@ -258,7 +488,7 @@ fn volumes_dialog( }); } }); - let accept = cx.entity().downgrade(); + let accept = entity; alert_dialog(&app.confirm_focus, cx) .open(true) .on_ok(move |_, window, cx| { @@ -277,7 +507,7 @@ fn volumes_dialog( } else if path_focused { this.choose_picker_path(cx); } else { - this.choose_volume(cx); + this.accept_picker(cx); } } this.apply_focus(window, cx); @@ -657,26 +887,73 @@ fn top_bar( window: &mut Window, cx: &mut Context<'_, Disktree>, ) -> Div { - div() - .flex() - .flex_row() - .items_center() - .gap(space::LG) - .px(space::LG) - .py(space::MD) - .border_b_1() - .border_color(theme.divider()) - .child(with_tooltip( - logo(theme).id("choose-source").cursor_pointer() + let source_button = { + let (glyph, label, variant, icon_color) = + if let Some(host) = &app.remote { + ( + gpui_omarchy::IconName::Globe, + Some(host.clone()), + ButtonVariant::Primary, + theme.accent, + ) + } else { + ( + gpui_omarchy::IconName::FolderOpen, + None, + ButtonVariant::Outline, + theme.secondary, + ) + }; + with_tooltip( + button("choose-source", "", variant, cx) + .debug_selector(|| "choose-source".into()) + .tab_stop(false) + .flex_shrink_0() + .px(space::XS) + .py(space::XS) + .gap(space::XS) + .child( + gpui_omarchy::icon(glyph) + .size(icon::SM) + .text_color(icon_color), + ) + .when_some(label, |btn, host| { + btn.child( + div().max_w(size::KEY_LANE).truncate().child(host), + ) + }) + .child( + gpui_omarchy::icon(gpui_omarchy::IconName::ChevronsUpDown) + .size(icon::SM) + .text_color(theme.secondary), + ) .on_click(cx.listener(|this, _, window, cx| { this.open_volumes(cx); this.apply_focus(window, cx); })), - "Choose local or SSH source · v", - )) + "Open folder, disk or SSH remote · v", + ) + }; + div() + .flex() + .flex_row() + .items_center() + .gap(space::SM) + .px(space::LG) + .py(space::MD) + .border_b_1() + .border_color(theme.divider()) + .child(logo(theme)) + .child(source_button) // Where you are is navigation, and it belongs to the whole window. - .child(trail(app, theme, cx)) - .child(div().flex_1()) + .child( + div() + .flex() + .flex_1() + .min_w_0() + .overflow_hidden() + .child(trail(app, theme, cx)), + ) .child(view_settings(app, window, cx)) } @@ -2251,7 +2528,7 @@ fn disk_section( ) .child(div().flex_1()) .child( - button("volumes", "Source…", ButtonVariant::Secondary, cx) + button("volumes", "Switch…", ButtonVariant::Outline, cx) .tab_stop(false) .on_click(cx.listener(|this, _, window, cx| { this.open_volumes(cx); diff --git a/crates/disktree-core/src/space.rs b/crates/disktree-core/src/space.rs index c12ce4c..31c50af 100644 --- a/crates/disktree-core/src/space.rs +++ b/crates/disktree-core/src/space.rs @@ -885,8 +885,10 @@ fn is_volume_candidate(mount: &Mount) -> bool { | "devpts" | "devtmpfs" | "efivarfs" + | "fuse.gvfsd-fuse" | "fuse.portal" | "fusectl" + | "gvfsd-fuse" | "hugetlbfs" | "mqueue" | "nsfs" @@ -1200,6 +1202,7 @@ bpf /sys/fs/bpf bpf rw 0 0 efivarfs /sys/firmware/efi/efivars efivarfs rw 0 0 devtmpfs /dev devtmpfs rw 0 0 devpts /dev/pts devpts rw 0 0 +gvfsd-fuse /run/user/1000/gvfs fuse.gvfsd-fuse rw 0 0 none /mnt/ramdisk ramfs rw 0 0 "; let points: Vec = volumes_in(&parse_mounts(table)) diff --git a/crates/disktree-core/src/treemap.rs b/crates/disktree-core/src/treemap.rs index 3bd572b..993a5db 100644 --- a/crates/disktree-core/src/treemap.rs +++ b/crates/disktree-core/src/treemap.rs @@ -127,7 +127,7 @@ pub struct LayoutOptions { impl Default for LayoutOptions { fn default() -> Self { Self { - max_depth: 3, + max_depth: 4, padding: 1.0, min_tile: 5.0, max_children: 96,