A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Folders dragged to the pins go where a line shows, as in Explorer
ishiichan-dayo316b8709ff11
diff --git a/crates/rf-app/src/workspace.rs b/crates/rf-app/src/workspace.rsindex ea11070e..2c3a2de1 100644--- a/crates/rf-app/src/workspace.rs+++ b/crates/rf-app/src/workspace.rs@@ -218,6 +218,13 @@ pub struct Workspace {drag_hover_tab: Option<(usize, u64)>,/// Files are being dragged over the window: the sidebar shows its "drop here to pin" row.sidebar_ext_drag: bool,+ /// Folders dragged over a pinned place's top or bottom edge: they are pinned before (`false`) or after (`true`) it, where a+ /// line shows, as in Explorer's Quick access. Over the rest of the row they go into that folder.+ pin_insert: Option<(PathBuf, bool)>,+ /// Whether the dragged items hold a folder, by the first item's path (asked once a drag, not on every move).+ pin_drag_dirs: Option<(PathBuf, bool)>,+ /// Folders dragged over the Pinned heading: they go before the first pin (this one), where the same line shows.+ pin_header_drop: Option<PathBuf>,/// The bookmark whose name is being edited on the bookmarks bar, its text field and the field's events.bookmark_rename: Option<(usize, Entity<InputState>, Subscription)>,/// With "live" dragging on the bookmarks bar, where what is dragged over it would land (the others make room).@@ -1141,6 +1148,9 @@ impl Workspace {tab_anim_serial: 0,drag_hover_tab: None,sidebar_ext_drag: false,+ pin_insert: None,+ pin_drag_dirs: None,+ pin_header_drop: None,bookmark_rename: None,bookmark_drop: None,side_tree: Default::default(),@@ -3502,6 +3512,52 @@ impl Workspace {self.places.update(cx, |p, cx| p.refresh(cx));}+ /// Files dragged over a pinned place (`row`): at its top or bottom quarter, when they hold a folder, the folders would be pinned+ /// before or after it; the row keeps that in `pin_insert` (drawn as a line) and Windows' pointer says Link. Elsewhere on the+ /// row the drop goes into the folder, as before.+ fn pin_insert_over(&mut self, row: &Path, ev: &DragMoveEvent<ExternalPaths>, cx: &mut Context<Self>) {+ let at = ev.event.position;+ let mut want = None;+ if ev.bounds.contains(&at) && self.drag_has_dir(ev.drag(cx).paths()) {+ want = pin_insert_zone(f32::from(ev.bounds.top()), f32::from(ev.bounds.bottom()), f32::from(at.y)).map(|after| (row.to_path_buf(), after));+ if want.is_some() {+ gpui_windows::dnd_hint::set(gpui_windows::dnd_hint::LINK);+ }+ }+ // (each row changes only its own place: the row the pointer is over sets it, the one it left clears it)+ let mine = self.pin_insert.as_ref().is_some_and(|(p, _)| p == row);+ if (want.is_some() || mine) && self.pin_insert != want {+ self.pin_insert = want;+ cx.notify();+ }+ }++ /// Whether the dragged items hold a folder, asked once a drag (a share that has to wake up is not asked on every move).+ fn drag_has_dir(&mut self, paths: &[PathBuf]) -> bool {+ let Some(first) = paths.first() else { return false };+ if let Some((key, has)) = &self.pin_drag_dirs+ && key == first+ {+ return *has;+ }+ let has = paths+ .iter()+ .any(|p| !rf_win::ftp::is_ftp(p) && crate::is_dir_bounded(p.clone(), std::time::Duration::from_millis(300)).unwrap_or(false));+ self.pin_drag_dirs = Some((first.clone(), has));+ has+ }++ /// Folders dropped at a pin's edge: pinned before or after it (files are ignored, as on the pin header). A folder that is pinned+ /// already moves there.+ fn pin_dropped_at(&mut self, paths: &ExternalPaths, at: &Path, after: bool, cx: &mut Context<Self>) {+ self.sidebar_ext_drag = false;+ let dirs: Vec<PathBuf> = paths.paths().iter().filter(|p| p.is_dir()).cloned().collect();+ let list = self.current_pins(cx);+ let Some(new) = pins_with_inserted(&list, &dirs, at, after) else { return };+ crate::settings::update(cx, |s| s.pinned = Some(new));+ self.places.update(cx, |p, cx| p.refresh(cx));+ }+fn set_pinned(&mut self, path: PathBuf, pin: bool, cx: &mut Context<Self>) {let mut list = self.current_pins(cx);if !pin {@@ -4462,6 +4518,13 @@ impl Workspace {let drop_border = p.accent;// on the rail only the icon; hovering the rail opens the full sidebar over the contentlet rail = self.sidebar_rail;+ // a pinned place takes dragged folders at its top or bottom edge as new pins there (a line shows where)+ let pin_row = pin_indicator && !rail;+ let insert_here = drop_dir.as_ref().filter(|_| pin_row).and_then(|dir| {+ let at_edge = self.pin_insert.as_ref().filter(|(p, _)| p == dir).map(|(_, after)| *after);+ // (folders over the Pinned heading go before the first pin: its top line)+ at_edge.or_else(|| self.pin_header_drop.as_ref().filter(|p| *p == dir).map(|_| false))+ });let metrics = crate::settings::explorer_metrics();let icon_px = if rail { 18. } else { 16. };let req_px = crate::image_cache::ICON_PX;@@ -4727,9 +4790,30 @@ impl Workspace {}),).when_some(drop_dir, |d, dir| {- d.drag_over::<ExternalPaths>(move |s, _, _, _| s.bg(drop_bg).border_1().border_color(drop_border))+ let row = dir.clone();+ // (at a pin's edge the row is not the drop's target: no highlight, the line says where the pin goes)+ d.drag_over::<ExternalPaths>(move |s, _, _, _| if insert_here.is_some() { s } else { s.bg(drop_bg).border_1().border_color(drop_border) }).on_drag_move::<ExternalPaths>(crate::folder_view::drop_effect_over(dir.clone()))- .on_drop(move |paths: &ExternalPaths, _, cx| drop_files(paths, dir.clone(), cx))+ .when(pin_row, |d| {+ d.on_drag_move::<ExternalPaths>(cx.listener(move |this, ev: &DragMoveEvent<ExternalPaths>, _, cx| this.pin_insert_over(&row, ev, cx)))+ })+ .on_drop(cx.listener(move |this, paths: &ExternalPaths, _, cx| match this.pin_insert.take() {+ Some((at, after)) if at == dir => this.pin_dropped_at(paths, &at, after, cx),+ _ => drop_files(paths, dir.clone(), cx),+ }))+ })+ .when_some(insert_here, |d, after| {+ d.child(+ div()+ .absolute()+ .left(px(8.))+ .right(px(8.))+ .h(px(2.))+ .rounded_full()+ .bg(drop_border)+ .when(after, |d| d.bottom(px(-2.)))+ .when(!after, |d| d.top(px(-2.))),+ )})// files dropped on the Recycle Bin go into it, as on macOS' Trash and Explorer's own bin (issue 232).when(matches!(target3, Location::RecycleBin), |d| {@@ -4807,9 +4891,12 @@ impl Workspace {.child(t);if explorer_look { d.flex_shrink_0() } else { d }};- // the "drop here to pin" row lives as long as a file drag does+ // the "drop here to pin" row lives as long as a file drag does, and so does a drag's place among the pinsif !cx.has_active_drag() {self.sidebar_ext_drag = false;+ self.pin_insert = None;+ self.pin_drag_dirs = None;+ self.pin_header_drop = None;}let ext_drag = self.sidebar_ext_drag;let (drop_bg, drop_border) = (p.selection, p.accent);@@ -4870,36 +4957,36 @@ impl Workspace {if !rail && explorer_look {head = head.child(div().mx_2().mt_2().mb(below_divider).h(px(1.)).flex_shrink_0().bg(section_divider));}- // Dropping folders on the header pins them. While files are dragged the header itself says so, in its own place and at its- // own height. (It was a row of its own under the pins, which came with the drag and pushed everything below it down:- // what one was aiming at moved. Issue 301.)- let pin_header = if ext_drag && !rail {- div()- .px_2()- .pt_3()- .pb_1()- .text_xs()- .font_weight(FontWeight::SEMIBOLD)- .text_color(p.accent)- .when(explorer_look, |d| d.flex_shrink_0())- .child(- h_flex()- .gap_1()- .items_center()- .child(Icon::new(L::Pin).size(px(12.)).flex_shrink_0())- .child(div().min_w_0().overflow_hidden().text_ellipsis().whitespace_nowrap().child(t!("Sabitlemek için buraya bırakın"))),- )- } else {- header(t!("Sabitlenenler"))- };+ // Dropping folders on the header pins them at the end of the list (the way in while nothing is pinned yet); between the pins a+ // line shows where a dropped folder goes (`pin_insert`), so the header no longer turns into a "drop here to pin" row while+ // files are dragged. (That row first stood under the pins and pushed everything below it down, issue 301; then the header said+ // it itself.)+ let pin_header = header(t!("Sabitlenenler"));+ let first_pin = pinned.first().map(|f| f.path.clone());+ let none_pinned = first_pin.is_none();head = head.child(div().id("sb-pin-header").flex_shrink_0().rounded(theme::RADIUS_SM).child(pin_header)- .drag_over::<ExternalPaths>(move |s, _, _, _| s.bg(drop_bg))- .on_drop(cx.listener(|this, paths: &ExternalPaths, _, cx| this.pin_dropped(paths, cx))),+ // with pins, a line over the first one says where the folders go; with none, the heading itself lights up+ .drag_over::<ExternalPaths>(move |s, _, _, _| if none_pinned { s.bg(drop_bg) } else { s })+ .on_drag_move::<ExternalPaths>(cx.listener(move |this, ev: &DragMoveEvent<ExternalPaths>, _, cx| {+ let over = ev.bounds.contains(&ev.event.position) && this.drag_has_dir(ev.drag(cx).paths());+ if over {+ gpui_windows::dnd_hint::set(gpui_windows::dnd_hint::LINK);+ }+ let want = if over { first_pin.clone() } else { None };+ if this.pin_header_drop != want {+ this.pin_header_drop = want;+ cx.notify();+ }+ }))+ .on_drop(cx.listener(|this, paths: &ExternalPaths, _, cx| match this.pin_header_drop.take() {+ Some(first) => this.pin_dropped_at(paths, &first, false, cx),+ None => this.pin_dropped(paths, cx),+ })),);let accent = p.accent;// the open folder is already a selected row of the sidebar (a pinned folder or a drive): the tree draws no second selection@@ -5461,6 +5548,80 @@ const TAB_CHROME_W: f32 = 12. + 14. + 8. + 8. + 22. + 4. + 2.;/// The terminal button and its gap, on a tab that has one.const TAB_TERMINAL_W: f32 = 22. + 8.;const SIDEBAR_MIN: f32 = 160.;++/// Where a drag over a pinned place's row (`top`..`bottom`, pointer at `y`) would pin: before it in the top quarter (`false`),+/// after it in the bottom quarter (`true`), nowhere in between (there the drop goes into the folder).+fn pin_insert_zone(top: f32, bottom: f32, y: f32) -> Option<bool> {+ let edge = (bottom - top) / 4.;+ if y < top + edge {+ Some(false)+ } else if y >= bottom - edge {+ Some(true)+ } else {+ None+ }+}++/// `pins` with `dirs` pinned before or after `at`; a folder pinned already moves there, in the order dropped. `None` when nothing+/// changes (no folders, `at` is not pinned or is one of the dropped folders, or they are there already).+fn pins_with_inserted(pins: &[PathBuf], dirs: &[PathBuf], at: &Path, after: bool) -> Option<Vec<PathBuf>> {+ if dirs.is_empty() || dirs.iter().any(|d| d == at) {+ return None;+ }+ let mut out: Vec<PathBuf> = pins.iter().filter(|p| !dirs.contains(p)).cloned().collect();+ let ix = out.iter().position(|p| p == at)? + usize::from(after);+ let mut seen = Vec::new();+ for d in dirs {+ if !seen.contains(d) {+ seen.push(d.clone());+ }+ }+ out.splice(ix..ix, seen);+ (out != pins).then_some(out)+}++#[cfg(test)]+mod pin_insert_tests {+ use super::*;++ fn p(s: &str) -> PathBuf {+ PathBuf::from(s)+ }++ #[test]+ fn the_quarters_of_a_row_pin_before_and_after_it() {+ assert_eq!(pin_insert_zone(100., 132., 100.), Some(false));+ assert_eq!(pin_insert_zone(100., 132., 107.9), Some(false));+ assert_eq!(pin_insert_zone(100., 132., 108.), None);+ assert_eq!(pin_insert_zone(100., 132., 123.9), None);+ assert_eq!(pin_insert_zone(100., 132., 124.), Some(true));+ assert_eq!(pin_insert_zone(100., 132., 131.9), Some(true));+ }++ #[test]+ fn folders_are_pinned_where_they_are_dropped() {+ let pins = [p(r"C:\a"), p(r"C:\b"), p(r"C:\c")];+ assert_eq!(pins_with_inserted(&pins, &[p(r"D:\x")], &p(r"C:\b"), false), Some(vec![p(r"C:\a"), p(r"D:\x"), p(r"C:\b"), p(r"C:\c")]));+ assert_eq!(pins_with_inserted(&pins, &[p(r"D:\x")], &p(r"C:\b"), true), Some(vec![p(r"C:\a"), p(r"C:\b"), p(r"D:\x"), p(r"C:\c")]));+ assert_eq!(pins_with_inserted(&pins, &[p(r"D:\x")], &p(r"C:\a"), false), Some(vec![p(r"D:\x"), p(r"C:\a"), p(r"C:\b"), p(r"C:\c")]));+ assert_eq!(pins_with_inserted(&pins, &[p(r"D:\x")], &p(r"C:\c"), true), Some(vec![p(r"C:\a"), p(r"C:\b"), p(r"C:\c"), p(r"D:\x")]));+ // two at once keep their order+ assert_eq!(+ pins_with_inserted(&pins, &[p(r"D:\x"), p(r"D:\y")], &p(r"C:\a"), true),+ Some(vec![p(r"C:\a"), p(r"D:\x"), p(r"D:\y"), p(r"C:\b"), p(r"C:\c")])+ );+ }++ #[test]+ fn a_pinned_folder_moves_and_nothing_else_changes() {+ let pins = [p(r"C:\a"), p(r"C:\b"), p(r"C:\c")];+ assert_eq!(pins_with_inserted(&pins, &[p(r"C:\c")], &p(r"C:\a"), false), Some(vec![p(r"C:\c"), p(r"C:\a"), p(r"C:\b")]));+ assert_eq!(pins_with_inserted(&pins, &[p(r"C:\b")], &p(r"C:\a"), true), None, "already there");+ assert_eq!(pins_with_inserted(&pins, &[p(r"C:\b")], &p(r"C:\b"), true), None, "onto itself");+ assert_eq!(pins_with_inserted(&pins, &[], &p(r"C:\a"), true), None, "no folders");+ assert_eq!(pins_with_inserted(&pins, &[p(r"D:\x")], &p(r"D:\gone"), true), None, "not pinned");+ }+}/// The room the Explorer look's sidebar keeps at its right for the scrollbar's track.const SIDEBAR_BAR_ROOM: f32 = 20.;