Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -238,6 +240,9 @@ 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 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`
saves it as a text file, one path per line, and `a` copies a prompt for a
Expand Down
54 changes: 50 additions & 4 deletions crates/disktree-app/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ pub struct Disktree {
volume_epoch: u64,
pub volumes: Vec<disktree_core::space::Volume>,
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<Instant>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
143 changes: 143 additions & 0 deletions crates/disktree-app/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -552,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;
Expand Down Expand Up @@ -586,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;
Expand Down Expand Up @@ -623,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);
Expand Down
4 changes: 4 additions & 0 deletions crates/disktree-app/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading