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
Keep room under a full Mac folder for its menu; build with archive limits
gelenmedya33541779c687
diff --git a/crates/rf-mac/src/archive.rs b/crates/rf-mac/src/archive.rsindex 2bb89e98..72fdad0f 100644--- a/crates/rf-mac/src/archive.rs+++ b/crates/rf-mac/src/archive.rs@@ -58,7 +58,7 @@ impl Archive {#[uniffi::constructor]pub fn open(path: String, password: Option<String>) -> Result<Arc<Self>, ArchiveError> {let p = PathBuf::from(&path);- let opts = rf_archive::Options { password: password.clone(), only: Vec::new() };+ let opts = rf_archive::Options { password: password.clone(), only: Vec::new(), max_bytes: None };let entries = rf_archive::list_with(&p, &opts).map_err(ArchiveError::from_anyhow)?;let mut tree: BTreeMap<String, BTreeMap<String, Entry>> = BTreeMap::new();tree.entry(String::new()).or_default();@@ -114,11 +114,14 @@ impl Archive {/// Writes the members at `inner_paths` (a folder brings everything under it) into `dest`,/// keeping their paths inside the archive. Returns how many files were written.pub fn extract(&self, inner_paths: Vec<String>, dest: String) -> Result<u64, ArchiveError> {- let only = inner_paths.iter().map(|p| norm(p)).collect();- let opts = rf_archive::Options { password: self.password.clone(), only };- let stats = rf_archive::extract_with(&self.path, Path::new(&dest), &opts, &mut |_| {}, &|| false)- .map_err(ArchiveError::from_anyhow)?;- Ok(stats.files)+ self.extract_max(inner_paths, dest, None)+ }++ /// [`Self::extract`] for a copy nobody asked for (Quick Look of the selection): it stops+ /// with an error past 1 GiB + 64 MiB written, as Windows' automatic copies do, so a small+ /// crafted archive cannot fill the disk by being selected.+ pub fn extract_for_preview(&self, inner_paths: Vec<String>, dest: String) -> Result<u64, ArchiveError> {+ self.extract_max(inner_paths, dest, Some((1 << 30) + (64 << 20)))}/// Everything into `dest` (created if missing).@@ -162,8 +165,16 @@ impl Archive {}impl Archive {+ fn extract_max(&self, inner_paths: Vec<String>, dest: String, max_bytes: Option<u64>) -> Result<u64, ArchiveError> {+ let only = inner_paths.iter().map(|p| norm(p)).collect();+ let opts = rf_archive::Options { password: self.password.clone(), only, max_bytes };+ let stats = rf_archive::extract_with(&self.path, Path::new(&dest), &opts, &mut |_| {}, &|| false)+ .map_err(ArchiveError::from_anyhow)?;+ Ok(stats.files)+ }+fn options(&self) -> rf_archive::Options {- rf_archive::Options { password: self.password.clone(), only: Vec::new() }+ rf_archive::Options { password: self.password.clone(), only: Vec::new(), max_bytes: None }}}diff --git a/macos/Sources/RustyFiles/FileListController.swift b/macos/Sources/RustyFiles/FileListController.swiftindex 0b740b35..5ac8bc65 100644--- a/macos/Sources/RustyFiles/FileListController.swift+++ b/macos/Sources/RustyFiles/FileListController.swift@@ -201,12 +201,17 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDelescroll.hasVerticalScroller = truescroll.scrollerStyle = .overlayscroll.automaticallyAdjustsContentInsets = false- scroll.contentInsets = NSEdgeInsets(top: 4, left: 0, bottom: 4, right: 0)+ scroll.contentInsets = NSEdgeInsets(top: 4, left: 0, bottom: 4 + Self.tailRoom, right: 0)+ scroll.emptyMenu = { [weak self] in+ guard let self else { return nil }+ self.table.deselectAll(nil)+ return self.contextMenu()+ }tileLayout.itemSize = NSSize(width: TileMetrics.width, height: TileMetrics.rowHeight - TileMetrics.gap)tileLayout.minimumInteritemSpacing = TileMetrics.gaptileLayout.minimumLineSpacing = TileMetrics.gap- tileLayout.sectionInset = NSEdgeInsets(top: TileMetrics.padY, left: TileMetrics.padX, bottom: TileMetrics.padY, right: TileMetrics.padX)+ tileLayout.sectionInset = NSEdgeInsets(top: TileMetrics.padY, left: TileMetrics.padX, bottom: TileMetrics.padY + Self.tailRoom, right: TileMetrics.padX)tiles.collectionViewLayout = tileLayouttiles.register(TileItem.self, forItemWithIdentifier: TileItem.id)tiles.register(GridGroupHeader.self, forSupplementaryViewOfKind: NSCollectionView.elementKindSectionHeader, withIdentifier: GridGroupHeader.id)@@ -439,9 +444,10 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDeletileScroll.frame = NSRect(x: 0, y: barH, width: b.width, height: b.height - statusH - barH)if listByColumns {// List: filled column by column, each column as wide as its longest name- if tileLayout.scrollDirection != .horizontal || tileLayout.sectionInset.right != TileMetrics.padX {+ if tileLayout.scrollDirection != .horizontal || tileLayout.sectionInset.right != TileMetrics.padX + Self.tailRoom {tileLayout.scrollDirection = .horizontal- tileLayout.sectionInset.right = TileMetrics.padX+ tileLayout.sectionInset.right = TileMetrics.padX + Self.tailRoom+ tileLayout.sectionInset.bottom = TileMetrics.padYlistWidths = niltileLayout.invalidateLayout()}@@ -452,6 +458,7 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele} else {if tileLayout.scrollDirection != .vertical {tileLayout.scrollDirection = .vertical+ tileLayout.sectionInset.bottom = TileMetrics.padY + Self.tailRoomtileLayout.invalidateLayout()}// as many columns as fit, left-aligned with 4 between them (not spread out)@@ -1123,13 +1130,14 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele/// Writes the selected members of the archive into a scratch folder, then hands their/// new files to `done` (to open, preview or copy them).- private func extractSelected(from archive: ArchiveView, done: @escaping ([URL]) -> Void) {+ /// `preview`: a copy the user did not ask for (Quick Look), which stops at a size limit.+ private func extractSelected(from archive: ArchiveView, preview: Bool = false, done: @escaping ([URL]) -> Void) {let inner = selectedInner(archive)guard !inner.isEmpty else { return }let a = archive.archiverun {let dest = ArchiveStore.scratchFolder()- _ = try a.extract(innerPaths: inner, dest: dest.path)+ _ = try preview ? a.extractForPreview(innerPaths: inner, dest: dest.path) : a.extract(innerPaths: inner, dest: dest.path)return inner.map { dest.appendingPathComponent($0) }} done: { done($0) }}@@ -2234,7 +2242,7 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDeleguard QLPreviewPanel.sharedPreviewPanelExists(), let panel = QLPreviewPanel.shared(), panel.isVisible, panel.dataSource === selfelse { return }let wanted = selectedInner(archive)- extractSelected(from: archive) { [weak self] urls in+ extractSelected(from: archive, preview: true) { [weak self] urls inguard let self, self.archive.map({ self.selectedInner($0) }) == wanted else { return }self.previewURLs = urlspanel.reloadData()@@ -2336,6 +2344,11 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele// MARK: List, column by column (folder_view.rs `list_column_widths`)+ /// Empty room kept after the last item (below it, or right of List's last column), so a+ /// full folder still has somewhere to right-click for its own menu (Open in Terminal, New,+ /// Paste…).+ static let tailRoom: CGFloat = 56+/// List without groups fills column by column and scrolls sideways, as on Windows.var listByColumns: Bool { viewMode == .list && gridTitles.isEmpty }diff --git a/macos/Sources/RustyFiles/SelfTest.swift b/macos/Sources/RustyFiles/SelfTest.swiftindex a9be391a..a840404e 100644--- a/macos/Sources/RustyFiles/SelfTest.swift+++ b/macos/Sources/RustyFiles/SelfTest.swift@@ -70,6 +70,24 @@ enum SelfTest {scroll(sv, ended, dx: 0)check(swiped.isEmpty, "a short sideways nudge is not a swipe")+ // 0c. a full folder keeps room under its last row whose right click opens the+ // folder's own menu (Open in Terminal…): the inset below the document+ let room = SwipeScrollView(frame: NSRect(x: 0, y: 0, width: 400, height: 300))+ room.documentView = FlippedView(frame: NSRect(x: 0, y: 0, width: 400, height: 2000))+ room.automaticallyAdjustsContentInsets = false+ room.contentInsets = NSEdgeInsets(top: 4, left: 0, bottom: 4 + FileListController.tailRoom, right: 0)+ let roomWin = NSWindow(contentRect: room.frame, styleMask: [.borderless], backing: .buffered, defer: true)+ roomWin.contentView = room+ room.contentView.scroll(to: NSPoint(x: 0, y: 2000 - 300 + 4 + FileListController.tailRoom))+ room.reflectScrolledClipView(room.contentView)+ let below = room.hitTest(NSPoint(x: 200, y: 20))+ check(below != nil && below !== room.documentView, "the room under the last row is not a row (\(String(describing: below)))")+ let marker = NSMenu(title: "folder")+ room.emptyMenu = { marker }+ let click = NSEvent.mouseEvent(with: .rightMouseDown, location: NSPoint(x: 200, y: 20), modifierFlags: [], timestamp: 0,+ windowNumber: roomWin.windowNumber, context: nil, eventNumber: 0, clickCount: 1, pressure: 1)+ check(click.map { room.menu(for: $0) === marker } ?? false, "a right click there opens the folder's menu")+// 1. copy a file and a folder: both arrive wholeTransfer(.copy, [a.appendingPathComponent("big.bin"), a.appendingPathComponent("folder")], into: b).start(window: nil) { made incheck(made.count == 2, "copy reports two new items")diff --git a/macos/Sources/RustyFiles/Swipe.swift b/macos/Sources/RustyFiles/Swipe.swiftindex 154cdfa2..913f467f 100644--- a/macos/Sources/RustyFiles/Swipe.swift+++ b/macos/Sources/RustyFiles/Swipe.swift@@ -10,6 +10,9 @@ final class SwipeScrollView: NSScrollView {/// Back (true) or forward (false), and whether there is somewhere to go.var onSwipe: ((Bool) -> Void)?var canSwipe: ((Bool) -> Bool)?+ /// The folder's own menu, for a right click on the room left under the last row (the+ /// content inset below the document), which the document view does not get.+ var emptyMenu: (() -> NSMenu?)?/// The two-finger gesture under way: how far the fingers have moved, and where the list/// stood sideways when it began.@@ -59,6 +62,10 @@ final class SwipeScrollView: NSScrollView {onSwipe?(back)}+ override func menu(for event: NSEvent) -> NSMenu? {+ emptyMenu?() ?? super.menu(for: event)+ }+/// The document can still move sideways towards its start (back) or its end (forward).private func canScrollSideways(towardsStart: Bool) -> Bool {guard let doc = documentView else { return false }