Skip to content

A treemap for finding and removing what fills your disk, for Omarchy. Rust + GPUI.

Rust

app: choose a local or SSH source and root before scanning

Tobi Lutkefb6a7f63b369
diff --git a/crates/disktree-app/src/main.rs b/crates/disktree-app/src/main.rs
index cd9fe66..22111b0 100644
--- a/crates/disktree-app/src/main.rs
+++ b/crates/disktree-app/src/main.rs
@@ -45,6 +45,7 @@ struct Args {
remote: Option<String>,
remote_disk: bool,
check: bool,
+ choose_root: bool,
options: ScanOptions,
depth: u32,
power: Option<power::PowerEfficiency>,
@@ -225,14 +226,23 @@ fn run() -> Result<()> {
appearance::follow(window);
}
cx.new(|cx| {
- let mut app = Disktree::open(
- root_for_app.clone(),
- options.clone(),
- depth,
- args.remote.clone(),
- args.remote_disk,
- cx,
- );
+ let mut app = if args.choose_root {
+ Disktree::choose(
+ options.clone(),
+ depth,
+ args.remote.clone(),
+ cx,
+ )
+ } else {
+ Disktree::open(
+ root_for_app.clone(),
+ options.clone(),
+ depth,
+ args.remote.clone(),
+ args.remote_disk,
+ cx,
+ )
+ };
app.power_choice = args.power;
app
})
@@ -424,12 +434,14 @@ fn parse_args_with_power(
!(disk && root.is_some()),
"--disk and a PATH cannot be combined"
);
+ let choose_root = root.is_none() && !disk && !check;
if remote.is_some() {
return Ok(Args {
root: root.unwrap_or_default(),
remote,
remote_disk: disk,
check,
+ choose_root,
power,
options,
depth,
@@ -442,23 +454,33 @@ fn parse_args_with_power(
.and_then(disktree_core::space::volume_root_for)
.unwrap_or_else(|| PathBuf::from("/")),
Some(root) => root,
- None => home.context("no path given and no home directory")?,
+ None => home.unwrap_or_default(),
};
// Store the depth as the initial view setting rather than a scan option: it
// is a display choice the run-time `[` and `]` keys also change.
// Canonical, so a later widening recognises this tree in the wider walk;
// through dunce, so Windows gets `C:\Users\…` rather than the `\\?\C:\…`
// form nothing else is written in.
- let root = dunce::canonicalize(&root).unwrap_or(root);
- let metadata = std::fs::metadata(&root)
- .with_context(|| format!("cannot read {}", root.display()))?;
- anyhow::ensure!(metadata.is_dir(), "{} is not a directory", root.display());
+ let root = if choose_root {
+ root
+ } else {
+ let root = dunce::canonicalize(&root).unwrap_or(root);
+ let metadata = std::fs::metadata(&root)
+ .with_context(|| format!("cannot read {}", root.display()))?;
+ anyhow::ensure!(
+ metadata.is_dir(),
+ "{} is not a directory",
+ root.display()
+ );
+ root
+ };
Ok(Args {
root,
remote: None,
remote_disk: false,
check,
+ choose_root,
options,
depth: depth.clamp(1, 6),
power,
@@ -536,6 +558,19 @@ mod argument_tests {
assert_eq!(args.options.threads.system_cpu_limit, None);
}
+ #[test]
+ fn no_implicit_root_requires_selection_but_explicit_scans_do_not() {
+ let parse = |args: &[&str]| {
+ parse_args(args.iter().map(std::ffi::OsString::from)).unwrap()
+ };
+ assert!(parse(&[]).choose_root);
+ assert!(parse(&["ssh", "dev"]).choose_root);
+ assert!(!parse(&["."]).choose_root);
+ assert!(!parse(&["--disk"]).choose_root);
+ assert!(!parse(&["ssh", "dev", "/only-on-server"]).choose_root);
+ assert!(!parse(&["ssh", "dev", "--check"]).choose_root);
+ }
+
#[test]
fn ssh_keeps_worker_options_without_inspecting_the_remote_root() {
let args = parse_args(
diff --git a/crates/disktree-app/src/state.rs b/crates/disktree-app/src/state.rs
index 966d79b..4dc8809 100644
--- a/crates/disktree-app/src/state.rs
+++ b/crates/disktree-app/src/state.rs
@@ -25,10 +25,11 @@ use disktree_core::tree::{Metric, Node, path_of};
use disktree_core::treemap::{
LayoutOptions, Rect, Tile, TileKind, hit, layout_filtered,
};
+use gpui_kit::base::input::{InputEvent, InputState};
use gpui_kit::{
- Context, FocusHandle, KeyDownEvent, MouseButton, MouseDownEvent,
- MouseMoveEvent, NavigationDirection, Pixels, Point, Render, ScrollDelta,
- ScrollWheelEvent, Size, Window, px, size,
+ AppContext as _, Context, Entity, FocusHandle, KeyDownEvent, MouseButton,
+ MouseDownEvent, MouseMoveEvent, NavigationDirection, Pixels, Point, Render,
+ ScrollDelta, ScrollWheelEvent, Size, Window, px, size,
};
use gpui_omarchy::Status;
use rustc_hash::{FxHashMap, FxHashSet};
@@ -448,6 +449,13 @@ pub struct Disktree {
/// could be read.
pub volumes_open: bool,
pub volumes_loading: bool,
+ pub awaiting_root: bool,
+ pub volumes_source: Option<String>,
+ pub volumes_error: Option<String>,
+ pub picker_error: Option<String>,
+ pub picker_host: Option<Entity<InputState>>,
+ pub picker_path: Option<Entity<InputState>>,
+ roots_job: Option<disktree_core::remote::RemoteRoots>,
volume_epoch: u64,
pub volumes: Vec<disktree_core::space::Volume>,
pub volume_highlight: usize,
@@ -480,10 +488,32 @@ impl Disktree {
remote: Option<String>,
remote_disk: bool,
cx: &mut Context<'_, Self>,
+ ) -> Self {
+ Self::build(root_path, options, depth, remote, remote_disk, true, cx)
+ }
+
+ /// Startup without a scan: discovering roots is not consent to walk one.
+ pub fn choose(
+ options: ScanOptions,
+ depth: u32,
+ remote: Option<String>,
+ cx: &mut Context<'_, Self>,
+ ) -> Self {
+ Self::build(PathBuf::new(), options, depth, remote, false, false, cx)
+ }
+
+ fn build(
+ root_path: PathBuf,
+ options: ScanOptions,
+ depth: u32,
+ remote: Option<String>,
+ remote_disk: bool,
+ start: bool,
+ cx: &mut Context<'_, Self>,
) -> Self {
let local = remote.is_none();
let home = if local { std::env::home_dir() } else { None };
- let space = if local {
+ let space = if local && start {
space_info(&root_path).ok()
} else {
None
@@ -570,6 +600,13 @@ impl Disktree {
disk_root: None,
volumes_open: false,
volumes_loading: false,
+ awaiting_root: !start,
+ volumes_source: None,
+ volumes_error: None,
+ picker_error: None,
+ picker_host: None,
+ picker_path: None,
+ roots_job: None,
volume_epoch: 0,
volumes: Vec::new(),
volume_highlight: 0,
@@ -579,7 +616,7 @@ impl Disktree {
scan_elapsed: None,
scanned_at: now_seconds(),
};
- if local {
+ if local && start {
tree.device = device_for(&tree.root_path);
tree.full_disk_access = tree
.home
@@ -591,10 +628,12 @@ impl Disktree {
tree.file_table = file_table_readable(&tree.root_path);
disktree_core::removal::prime_mount_points();
}
- tree.start_scan(cx);
- if local {
- Self::start_space_ticker(cx);
+ if start {
+ tree.start_scan(cx);
+ } else {
+ tree.open_volumes(cx);
}
+ Self::start_space_ticker(cx);
tree
}
@@ -691,73 +730,253 @@ 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>) {
- if self.remote.is_some() {
+ if self.run.is_some() || self.screen != Screen::Explore {
+ return;
+ }
+ self.volumes_open = true;
+ self.picker_host = None;
+ self.picker_path = None;
+ self.focus_request = Some(FocusTarget::Dialog);
+ self.load_volume_source(self.remote.clone(), cx);
+ }
+
+ pub fn load_volume_source(
+ &mut self,
+ host: Option<String>,
+ cx: &mut Context<'_, Self>,
+ ) {
+ if !self.volumes_open {
return;
}
self.volume_epoch += 1;
let epoch = self.volume_epoch;
- let root_path = self.root_path.clone();
+ self.roots_job = None;
+ self.volumes_source.clone_from(&host);
self.volumes.clear();
self.volume_highlight = 0;
+ self.volumes_error = None;
+ self.picker_error = None;
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 {
- let mut volumes = disktree_core::space::volumes();
- if let Some(root) = volume_root_for(&root_path)
- && !volumes.iter().any(|volume| volume.point == root)
- {
- volumes.push(disktree_core::space::Volume {
- point: root.clone(),
- device: device_for(&root),
- space: space_info(&root).ok(),
+ if let Some(host) = host {
+ match disktree_core::remote::RemoteRoots::discover(&host) {
+ Ok(job) => {
+ self.roots_job = Some(job);
+ cx.spawn(async move |this, cx| {
+ loop {
+ cx.background_executor()
+ .timer(Duration::from_millis(110))
+ .await;
+ let keep = this
+ .update(cx, |this, cx| {
+ this.poll_roots_once(epoch, cx)
+ })
+ .unwrap_or(false);
+ if !keep {
+ break;
+ }
+ }
+ })
+ .detach();
+ }
+ Err(error) => self.finish_volume_listing(Err(error), cx),
+ }
+ } else {
+ let task = cx.background_executor().spawn(async {
+ disktree_core::space::volume_roots()
+ .map(|volumes| (volumes, std::env::home_dir()))
+ });
+ cx.spawn(async move |this, cx| {
+ let result = task.await;
+ let _ = this.update(cx, |this, cx| {
+ if this.volumes_open && this.volume_epoch == epoch {
+ this.finish_volume_listing(result, cx);
+ }
});
+ })
+ .detach();
+ }
+ cx.notify();
+ }
+
+ pub(crate) fn poll_roots_once(
+ &mut self,
+ epoch: u64,
+ cx: &mut Context<'_, Self>,
+ ) -> bool {
+ if !self.volumes_open || self.volume_epoch != epoch {
+ return false;
+ }
+ let Some(result) = self
+ .roots_job
+ .as_ref()
+ .and_then(disktree_core::remote::RemoteJob::poll)
+ else {
+ return self.roots_job.is_some();
+ };
+ self.roots_job = None;
+ self.finish_volume_listing(
+ result.map(|roots| (roots.volumes, roots.home)),
+ cx,
+ );
+ false
+ }
+
+ fn finish_volume_listing(
+ &mut self,
+ result: std::io::Result<(
+ Vec<disktree_core::space::Volume>,
+ Option<PathBuf>,
+ )>,
+ cx: &mut Context<'_, Self>,
+ ) {
+ self.volumes_loading = false;
+ match result {
+ Ok((mut volumes, home)) => {
+ if let Some(home) = home
+ && !volumes.iter().any(|volume| volume.point == home)
+ {
+ volumes.insert(
+ 0,
+ disktree_core::space::Volume {
+ point: home,
+ device: Some("Home directory".into()),
+ space: None,
+ },
+ );
+ }
+ self.volumes = volumes;
}
- 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 {
- this.volumes = volumes;
- this.volumes_loading = false;
- cx.notify();
+ Err(error) => self.volumes_error = Some(error.to_string()),
+ }
+ cx.notify();
+ }
+
+ pub fn prepare_picker_inputs(
+ &mut self,
+ window: &mut Window,
+ cx: &mut Context<'_, Self>,
+ ) {
+ if self.picker_host.is_none() {
+ let value = self.volumes_source.clone().unwrap_or_default();
+ let host = cx.new(|cx| {
+ InputState::new(window, cx)
+ .placeholder("SSH alias or user@host")
+ .default_value(value)
+ });
+ cx.subscribe(&host, |this, _, event, cx| {
+ if matches!(event, InputEvent::PressEnter { .. }) {
+ this.connect_picker(cx);
}
+ })
+ .detach();
+ self.picker_host = Some(host);
+ }
+ if self.picker_path.is_none() {
+ let path = cx.new(|cx| {
+ InputState::new(window, cx).placeholder("/absolute/path")
});
- })
- .detach();
- cx.notify();
+ cx.subscribe(&path, |this, _, event, cx| {
+ if matches!(event, InputEvent::PressEnter { .. }) {
+ this.choose_picker_path(cx);
+ }
+ })
+ .detach();
+ self.picker_path = Some(path);
+ }
+ }
+
+ pub fn connect_picker(&mut self, cx: &mut Context<'_, Self>) {
+ let host = self
+ .picker_host
+ .as_ref()
+ .map(|input| input.read(cx).value().trim().to_owned())
+ .unwrap_or_default();
+ 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);
+ }
}
- /// Close the picker and return the keyboard to the treemap.
+ pub fn choose_source_root(
+ &mut self,
+ mut path: PathBuf,
+ cx: &mut Context<'_, Self>,
+ ) {
+ if !self.volumes_open
+ || self.volumes_loading
+ || self.volumes_error.is_some()
+ {
+ return;
+ }
+ if !path.is_absolute() {
+ self.picker_error =
+ Some("Enter an absolute directory path.".into());
+ cx.notify();
+ return;
+ }
+ if self.volumes_source.is_none() {
+ match dunce::canonicalize(&path) {
+ Ok(root) if root.is_dir() => path = root,
+ _ => {
+ self.picker_error =
+ Some("Cannot open that local directory.".into());
+ cx.notify();
+ return;
+ }
+ }
+ }
+ 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.remote.clone_from(&self.volumes_source);
+ self.awaiting_root = false;
+ self.close_volumes(cx);
+ self.set_root(path, cx);
+ }
+
+ /// Closing cancels discovery, not the scan already on screen.
pub fn close_volumes(&mut self, cx: &mut Context<'_, Self>) {
+ self.volume_epoch += 1;
+ self.roots_job = None;
+ self.volumes_loading = false;
self.volumes_open = false;
self.focus_request = Some(FocusTarget::Root);
cx.notify();
}
- /// Scan the highlighted volume from scratch; closes the picker when there
- /// is nothing to pick.
pub fn choose_volume(&mut self, cx: &mut Context<'_, Self>) {
- if self.volumes_loading {
- return;
- }
- self.focus_request = Some(FocusTarget::Root);
- let Some(point) = self
+ if let Some(point) = self
.volumes
.get(self.volume_highlight)
.map(|volume| volume.point.clone())
- else {
- self.volumes_open = false;
- cx.notify();
- return;
- };
- self.volumes_open = false;
- self.volumes.clear();
- self.set_root(point, cx);
+ {
+ self.choose_source_root(point, cx);
+ }
}
/// Move the highlight in the open picker, wrapping at the ends.
@@ -813,6 +1032,7 @@ impl Disktree {
}
let path = path.to_path_buf();
self.git_pending.insert(path.clone());
+ let epoch = self.scan_epoch;
let task = cx.background_executor().spawn({
let path = path.clone();
async move { crate::git::state(&path) }
@@ -820,6 +1040,9 @@ impl Disktree {
cx.spawn(async move |this, cx| {
let state = task.await;
let _ = this.update(cx, |this, cx| {
+ if this.scan_epoch != epoch || this.remote.is_some() {
+ return;
+ }
this.git_pending.remove(&path);
this.git.insert(path, state);
cx.notify();
@@ -972,7 +1195,11 @@ impl Disktree {
/// Start a fresh scan, abandoning any walk still in progress.
pub fn start_scan(&mut self, cx: &mut Context<'_, Self>) {
- if let Some(scan) = &self.scan {
+ if self.awaiting_root {
+ self.open_volumes(cx);
+ return;
+ }
+ if let Some(scan) = self.scan.take() {
scan.cancel();
}
self.scan_epoch += 1;
@@ -991,6 +1218,7 @@ impl Disktree {
self.cache = None;
self.insights.clear();
self.git.clear();
+ self.git_pending.clear();
self.clear_filter();
self.scan_started = Some(Instant::now());
self.scan_elapsed = None;
@@ -1166,6 +1394,12 @@ impl Disktree {
cx.background_executor().timer(interval).await;
let ok = this
.update(cx, |this, cx| {
+ if this.remote.is_some()
+ || this.awaiting_root
+ || this.tree.is_none()
+ {
+ return;
+ }
let path = this.root_path.clone();
let fresh = space_info(&path).ok();
if fresh != this.space {
diff --git a/crates/disktree-app/src/tests.rs b/crates/disktree-app/src/tests.rs
index 6700c5d..7571a74 100644
--- a/crates/disktree-app/src/tests.rs
+++ b/crates/disktree-app/src/tests.rs
@@ -92,6 +92,120 @@ fn read<R>(
view.read_with(cx, |app, _| f(app))
}
+#[gpui_kit::test]
+fn startup_chooser_never_scans_before_explicit_acceptance(
+ cx: &mut TestAppContext,
+) {
+ cx.update(gpui_omarchy::init);
+ let (view, cx) =
+ cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
+ cx.run_until_parked();
+ draw(cx);
+ assert!(cx.debug_bounds("choose-root-idle").is_some());
+ assert!(cx.debug_bounds("source-host").is_some());
+ read(&view, cx, |app| {
+ assert!(app.awaiting_root);
+ assert_eq!(app.scan_epoch, 0);
+ assert!(app.scan.is_none() && app.remote_scan.is_none());
+ });
+ press(cx, "escape");
+ assert!(!read(&view, cx, |app| app.volumes_open));
+ press(cx, "r");
+ assert!(read(&view, cx, |app| app.volumes_open
+ && app.awaiting_root
+ && app.scan.is_none()));
+}
+
+#[gpui_kit::test]
+fn entering_a_directory_scans_only_that_explicit_root(cx: &mut TestAppContext) {
+ cx.update(gpui_omarchy::init);
+ let selected = fixture();
+ let other = fixture();
+ let (view, cx) =
+ cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
+ cx.run_until_parked();
+ update(&view, cx, |app, _| {
+ app.volumes = vec![Volume {
+ point: other.path().into(),
+ device: None,
+ space: None,
+ }];
+ app.volumes_loading = false;
+ });
+ draw(cx);
+ let input = cx.debug_bounds("source-path").expect("path editor");
+ cx.simulate_click(input.center(), gpui_kit::Modifiers::none());
+ cx.simulate_input(selected.path().to_str().unwrap());
+ assert_eq!(
+ update(&view, cx, |app, cx| app
+ .picker_path
+ .as_ref()
+ .unwrap()
+ .read(cx)
+ .value()
+ .to_string()),
+ selected.path().to_str().unwrap()
+ );
+ press(cx, "enter");
+ assert_eq!(
+ read(&view, cx, |app| app.root_path.clone()),
+ dunce::canonicalize(selected.path()).unwrap()
+ );
+ assert!(!read(&view, cx, |app| app.awaiting_root || app.volumes_open));
+ finish_scan(&view, cx);
+}
+
+#[gpui_kit::test]
+fn invalid_ssh_input_does_not_start_a_scan_or_change_the_source(
+ cx: &mut TestAppContext,
+) {
+ cx.update(gpui_omarchy::init);
+ let (view, cx) =
+ cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
+ cx.run_until_parked();
+ draw(cx);
+ let input = cx.debug_bounds("source-host").expect("host editor");
+ cx.simulate_click(input.center(), gpui_kit::Modifiers::none());
+ cx.simulate_input("invalid host");
+ press(cx, "enter");
+ read(&view, cx, |app| {
+ assert!(app.volumes_error.is_some());
+ assert!(app.remote.is_none());
+ assert!(app.scan.is_none() && app.remote_scan.is_none());
+ assert_eq!(app.scan_epoch, 0);
+ });
+ press(cx, "escape");
+ assert!(!read(&view, cx, |app| app.volumes_open));
+}
+
+#[gpui_kit::test]
+fn switching_from_remote_to_local_clears_machine_specific_marks(
+ cx: &mut TestAppContext,
+) {
+ cx.update(gpui_omarchy::init);
+ let temp = fixture();
+ let target = fixture();
+ let (view, cx) = view_over(temp.path(), cx);
+ update(&view, cx, |app, cx| {
+ app.remote = Some("old-source".into());
+ app.remote_identity = Some(disktree_core::identity::HostIdentity {
+ hostname: "old-source".into(),
+ machine_id: None,
+ });
+ let crumbs = app.crumbs_for_path(&temp.path().join("junk")).unwrap();
+ app.select(Some(crumbs), cx);
+ app.toggle_mark_selected(cx);
+ assert!(!app.marks.is_empty());
+ app.volumes_open = true;
+ app.volumes_source = None;
+ app.choose_source_root(target.path().to_path_buf(), cx);
+ assert!(app.remote.is_none() && app.remote_identity.is_none());
+ assert!(app.marks.is_empty());
+ assert!(app.tree.is_none());
+ });
+ finish_scan(&view, cx);
+}
+
#[gpui_kit::test]
fn remote_review_never_deletes_even_through_direct_actions(
cx: &mut TestAppContext,
diff --git a/crates/disktree-app/src/ui.rs b/crates/disktree-app/src/ui.rs
index ea715d2..1cebdd7 100644
--- a/crates/disktree-app/src/ui.rs
+++ b/crates/disktree-app/src/ui.rs
@@ -96,6 +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);
/// The keyboard overlay.
pub const HELP: Rems = Rems(32.5);
/// The key column of the keyboard overlay.
diff --git a/crates/disktree-app/src/views.rs b/crates/disktree-app/src/views.rs
index db7214a..06b314e 100644
--- a/crates/disktree-app/src/views.rs
+++ b/crates/disktree-app/src/views.rs
@@ -12,8 +12,8 @@ use disktree_core::tree::Metric;
use gpui_kit::base::CheckboxState;
use gpui_kit::{
App, AppContext as _, ClickEvent, Context, Div, DragMoveEvent, ElementId,
- FontWeight, InteractiveElement as _, IntoElement, KeyDownEvent,
- MouseDownEvent, ParentElement, Rems, SharedString, Stateful,
+ Focusable as _, FontWeight, InteractiveElement as _, IntoElement,
+ KeyDownEvent, MouseDownEvent, ParentElement, Rems, SharedString, Stateful,
StatefulInteractiveElement as _, Styled, Window, anchored, deferred, div,
pattern_slash, px, relative,
};
@@ -43,6 +43,10 @@ pub fn root(
window: &mut Window,
cx: &mut Context<'_, Disktree>,
) -> Stateful<Div> {
+ if app.volumes_open {
+ app.prepare_picker_inputs(window, cx);
+ }
+ app.apply_focus(window, cx);
let theme = cx.omarchy().clone();
let body = match app.screen {
Screen::Explore => explore(app, window, cx),
@@ -93,6 +97,11 @@ pub fn root(
cx.notify();
return;
}
+ if this.volumes_open {
+ let editing = [&this.picker_host, &this.picker_path].into_iter()
+ .flatten().any(|input| input.read(cx).focus_handle(cx).is_focused(window));
+ if editing && event.keystroke.key != "escape" { return; }
+ }
this.on_key_down(event, cx);
this.apply_focus(window, cx);
}))
@@ -112,7 +121,7 @@ pub fn root(
root = root.child(help_overlay(app, cx));
}
if app.volumes_open {
- root = root.child(volumes_dialog(app, cx));
+ root = root.child(volumes_dialog(app, window, cx));
}
if app.confirm_open {
root = root.child(delete_dialog(app, cx));
@@ -124,38 +133,47 @@ pub fn root(
/// volume with its free space, and the choice is the new root.
fn volumes_dialog(
app: &Disktree,
+ window: &Window,
cx: &mut Context<'_, Disktree>,
) -> impl IntoElement {
let theme = cx.omarchy().clone();
let cancel = cx.entity().downgrade();
+ 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);
+ .gap(space::XS)
+ .max_h(size::SOURCE_LIST_HEIGHT)
+ .overflow_y_scroll();
if app.volumes_loading {
- rows = rows.child(dialog_description("Looking for volumes…", cx));
+ rows = rows.child(dialog_description(
+ "Listing mounts, not scanning files…",
+ 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 other volume could be read.", cx));
+ 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 free = volume.space.map_or_else(
- || "unknown free".to_string(),
- |space| format!("{} free", human_bytes(space.available)),
+ let label = format!(
+ "{} · {}",
+ volume.point.display(),
+ volume.device.as_deref().unwrap_or("Mounted volume")
);
- let label = match &volume.device {
- Some(device) => format!(
- "{} \u{00b7} {device} \u{00b7} {free}",
- volume.point.display()
- ),
- None => format!("{} \u{00b7} {free}", volume.point.display()),
- };
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)
@@ -164,25 +182,57 @@ fn volumes_dialog(
} else {
theme.foreground
})
- // Only the row the keys are on is tinted: a second highlight
- // would read as a second selection.
.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;
- this.choose_volume(cx);
- window.focus(&this.focus, cx);
+ window.focus(&this.confirm_focus, cx);
+ cx.notify();
})),
);
}
- let popup = dialog_popup(cx)
- .child(dialog_title("Scan a volume", cx))
+ let host = app
+ .picker_host
+ .as_ref()
+ .expect("picker prepared before rendering");
+ let path = app
+ .picker_path
+ .as_ref()
+ .expect("picker prepared before rendering");
+ let popup = dialog_popup(cx).w(size::SOURCE_PICKER)
+ .child(dialog_title("Choose what to scan", cx))
.child(dialog_description(
- "Up and down moves, Enter scans it, Escape stays here.",
- cx,
- ))
- .child(rows);
+ "Connect, then select a mount or directory. Nothing is scanned 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, _, _, cx| this.load_volume_source(None, 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(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 mount", ButtonVariant::Primary, cx)
+ .disabled(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 centred = centred_popup(popup, {
let close = cancel.clone();
move |_, window, cx| {
@@ -197,7 +247,23 @@ fn volumes_dialog(
.open(true)
.on_ok(move |_, window, cx| {
let _ = accept.update(cx, |this, cx| {
- this.choose_volume(cx);
+ let host_focused =
+ this.picker_host.as_ref().is_some_and(|input| {
+ input.read(cx).focus_handle(cx).is_focused(window)
+ });
+ let path_focused =
+ this.picker_path.as_ref().is_some_and(|input| {
+ input.read(cx).focus_handle(cx).is_focused(window)
+ });
+ if this.volumes_open {
+ if host_focused {
+ this.connect_picker(cx);
+ } else if path_focused {
+ this.choose_picker_path(cx);
+ } else {
+ this.choose_volume(cx);
+ }
+ }
this.apply_focus(window, cx);
});
false
@@ -342,6 +408,39 @@ fn explore(
cx: &mut Context<'_, Disktree>,
) -> Div {
let theme = cx.omarchy().clone();
+ if app.awaiting_root {
+ return div()
+ .debug_selector(|| "choose-root-idle".into())
+ .flex()
+ .flex_col()
+ .flex_1()
+ .items_center()
+ .justify_center()
+ .gap(space::LG)
+ .p(space::XXL)
+ .child(
+ div()
+ .text_size(text::HEADING)
+ .child("Choose a source. Then choose a root."),
+ )
+ .child(div().text_color(theme.secondary).child(
+ "Local or SSH · one mount at a time · no background scan",
+ ))
+ .child(
+ button(
+ "choose-source",
+ "Choose source…",
+ ButtonVariant::Primary,
+ cx,
+ )
+ .on_click(cx.listener(
+ |this, _, window, cx| {
+ this.open_volumes(cx);
+ this.apply_focus(window, cx);
+ },
+ )),
+ );
+ }
let mosaic: Mosaic = app.prepare();
let width_rems = window.viewport_size().width.as_f32() / app.rem;
// The panel is where the selection, the marks and the disk live; it
@@ -460,7 +559,14 @@ fn top_bar(
.py(space::MD)
.border_b_1()
.border_color(theme.divider())
- .child(logo(theme))
+ .child(with_tooltip(
+ logo(theme).id("choose-source").cursor_pointer()
+ .on_click(cx.listener(|this, _, window, cx| {
+ this.open_volumes(cx);
+ this.apply_focus(window, cx);
+ })),
+ "Choose local or SSH source · v",
+ ))
// Where you are is navigation, and it belongs to the whole window.
.child(trail(app, theme, cx))
.child(div().flex_1())
@@ -2031,7 +2137,7 @@ fn disk_section(
)
.child(div().flex_1())
.child(
- button("volumes", "Volumes", ButtonVariant::Secondary, cx)
+ button("volumes", "Source…", ButtonVariant::Secondary, cx)
.tab_stop(false)
.on_click(cx.listener(|this, _, window, cx| {
this.open_volumes(cx);