Skip to content

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

Rust

Reveal a tile in the file manager on right-click

David Aronchick010df88bc352
diff --git a/README.md b/README.md
index 0ca0d18..02a53ba 100644
--- a/README.md
+++ b/README.md
@@ -229,6 +229,7 @@ and shows how much free space was actually gained.
| `g` | the whole disk |
| `p` | show or hide the selection line |
| `o` | show it in Finder, File Explorer or the file manager |
+| right-click | show that tile in Finder, File Explorer or the file manager |
| `?` | every key |
| `q` | quit |
diff --git a/crates/disktree-app/src/state.rs b/crates/disktree-app/src/state.rs
index 46195f2..0b22da5 100644
--- a/crates/disktree-app/src/state.rs
+++ b/crates/disktree-app/src/state.rs
@@ -2756,6 +2756,14 @@ impl Disktree {
self.toggle_mark(&crumbs, cx);
}
}
+ // What `o` does, for the tile under the pointer: select it, then
+ // show it in Finder, File Explorer or the file manager.
+ MouseButton::Right => {
+ if let Some(crumbs) = crumbs {
+ self.select(Some(crumbs), cx);
+ self.reveal_target(cx);
+ }
+ }
// Buttons 8 and 9. gpui-pre maps them on X11, Wayland and
// Windows; a mouse with no side buttons never sends them, and
// then the header `<` / `>` and alt-arrows are the whole story.
@@ -2769,7 +2777,8 @@ impl Disktree {
{
self.go_forward(cx);
}
- _ => {}
+ // Side buttons off the explore screen.
+ MouseButton::Navigate(_) => {}
}
}
diff --git a/crates/disktree-app/src/tests.rs b/crates/disktree-app/src/tests.rs
index 2eb15d2..fea30a4 100644
--- a/crates/disktree-app/src/tests.rs
+++ b/crates/disktree-app/src/tests.rs
@@ -383,6 +383,68 @@ fn hovering_reports_the_tile_under_the_pointer(cx: &mut TestAppContext) {
assert_eq!(hovered.as_deref(), Some(biggest.as_slice()));
}
+#[gpui_kit::test]
+fn right_click_selects_the_tile_and_reveals_it(cx: &mut TestAppContext) {
+ cx.update(gpui_omarchy::init);
+ let temp = fixture();
+ let (view, cx) = view_over(temp.path(), cx);
+ draw(cx);
+
+ let (at, target, path) = update(&view, cx, |app, _| {
+ let biggest = app
+ .layout()
+ .and_then(|tiles| {
+ tiles
+ .iter()
+ .max_by(|left, right| {
+ left.rect.area().total_cmp(&right.rect.area())
+ })
+ .map(|tile| tile.crumbs().to_vec())
+ })
+ .expect("a tile");
+ let rect = app.tile_rect(&biggest).expect("a rectangle");
+ let screen = app.view.project(rect);
+ let (x, y) = (screen.x + screen.w / 2.0, screen.y + screen.h / 2.0);
+ // The deepest tile there, which is what a click resolves to.
+ let target = app.tile_at(x, y).expect("a tile under the pointer");
+ let path = app.path_at(&target).expect("a path");
+ let origin = app.treemap_origin.get();
+ (Point::new(origin.x + px(x), origin.y + px(y)), target, path)
+ });
+
+ // The test platform cannot open a file manager, so take the path away
+ // first: the reveal then reports it instead of reaching the platform.
+ if path.is_dir() {
+ std::fs::remove_dir_all(&path).expect("remove");
+ } else {
+ std::fs::remove_file(&path).expect("remove");
+ }
+
+ cx.simulate_mouse_down(
+ at,
+ gpui_kit::MouseButton::Right,
+ gpui_kit::Modifiers::none(),
+ );
+ cx.simulate_mouse_up(
+ at,
+ gpui_kit::MouseButton::Right,
+ gpui_kit::Modifiers::none(),
+ );
+ draw(cx);
+
+ let (selected, notice) = read(&view, cx, |app| {
+ (
+ app.selected.clone(),
+ app.notice.as_ref().map(|(text, _)| text.clone()),
+ )
+ });
+ assert_eq!(selected, Some(target), "the clicked tile is selected");
+ assert!(
+ notice.is_some_and(|text| text.contains("no longer on disk")),
+ "the reveal ran for it"
+ );
+}
+
#[gpui_kit::test]
fn typing_filters_live_and_enter_shows_only_the_matches(
cx: &mut TestAppContext,