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
Mac: drag with the right button, and a choice for plain drops
gelenmedya294ca8e7e591
diff --git a/macos/Sources/RustyFiles/ContextMenus.swift b/macos/Sources/RustyFiles/ContextMenus.swiftindex 986e3d76..cadf1c8b 100644--- a/macos/Sources/RustyFiles/ContextMenus.swift+++ b/macos/Sources/RustyFiles/ContextMenus.swift@@ -194,10 +194,11 @@ enum MenuActions {extension FileOps {/// "name alias" next to the item, as Finder's Make Alias; " 2", " 3"… when taken.- static func makeAlias(_ url: URL) throws -> URL {+ /// `dir`: where the alias goes (a right-button drop's "Make alias here"); else next to the item.+ static func makeAlias(_ url: URL, in dir: URL? = nil) throws -> URL {let data = try url.bookmarkData(options: .suitableForBookmarkFile, includingResourceValuesForKeys: nil, relativeTo: nil)let base = url.lastPathComponent + " " + String(localized: "alias")- let dest = unique(base, ext: "", in: url.deletingLastPathComponent())+ let dest = unique(base, ext: "", in: dir ?? url.deletingLastPathComponent())try URL.writeBookmarkData(data, to: dest)return dest}diff --git a/macos/Sources/RustyFiles/FileList.swift b/macos/Sources/RustyFiles/FileList.swiftindex 252e903d..deef3d68 100644--- a/macos/Sources/RustyFiles/FileList.swift+++ b/macos/Sources/RustyFiles/FileList.swift@@ -640,6 +640,15 @@ final class FileTableView: NSTableView, NSServicesMenuRequestor {return super.validateProposedFirstResponder(responder, for: event)}+ /// Right button on an item: a drag with it asks Move / Copy / Alias on the drop (RightDrag).+ override func rightMouseDown(with event: NSEvent) {+ let r = row(at: convert(event.locationInWindow, from: nil))+ guard r >= 0, let list, list.archiveIsNil else { return super.rightMouseDown(with: event) }+ if !selectedRowIndexes.contains(r) { selectRowIndexes([r], byExtendingSelection: false) }+ if RightDrag.track(event, in: self, urls: { list.selectedURLs }) { return }+ super.rightMouseDown(with: event)+ }+override func menu(for event: NSEvent) -> NSMenu? {let r = row(at: convert(event.locationInWindow, from: nil))if r >= 0 && !selectedRowIndexes.contains(r) { selectRowIndexes([r], byExtendingSelection: false) }diff --git a/macos/Sources/RustyFiles/FileListController.swift b/macos/Sources/RustyFiles/FileListController.swiftindex 7e165325..d53a5544 100644--- a/macos/Sources/RustyFiles/FileListController.swift+++ b/macos/Sources/RustyFiles/FileListController.swift@@ -2568,7 +2568,45 @@ extension FileListController {let mods = NSEvent.modifierFlagsif mods.contains(.option) { return .copy }if mods.contains(.command) { return .move }- return Transfer.defaultKind(urls, into: dest)+ switch AppSettings.plainDrag {+ case "move": return .move+ case "copy": return .copy+ default: return Transfer.defaultKind(urls, into: dest)+ }+ }++ /// A drop that asks what to do: one made with the right button, or any plain one when+ /// Settings › Dragging and dropping says "Ask with a menu".+ static func dropAsks() -> Bool {+ if RightDrag.active { return true }+ return AppSettings.plainDrag == "ask" && NSEvent.modifierFlags.intersection([.option, .command]).isEmpty+ }++ /// The right-button drop's menu at the pointer: Move here, Copy here, Make alias here.+ func askDrop(_ urls: [URL], into dest: URL, in view: NSView) {+ let b = MenuBuilder()+ let auto = Transfer.defaultKind(urls, into: dest)+ b.add(String(localized: "Move here"), "move") { [weak self] in+ self?.transfer(urls, into: dest, kind: .move, selectHere: dest == self?.url)+ }+ b.add(String(localized: "Copy here"), "copy") { [weak self] in+ self?.transfer(urls, into: dest, kind: .copy, selectHere: dest == self?.url)+ }+ b.add(String(localized: "Make alias here"), "link") { [weak self] in+ self?.run { try urls.map { try FileOps.makeAlias($0, in: dest) } } done: { made in+ FileUndo.shared.record(.trash(made), title: String(localized: "Make Alias"))+ if dest == self?.url { self?.reloadSelecting(made.map(\.lastPathComponent)) }+ }+ }+ b.separator()+ b.add(String(localized: "Cancel")) {}+ let menu = b.done()+ // the item the drop would do by itself comes first in bold, as Windows shows it+ if let first = menu.items.first(where: { $0.title == (auto == .copy ? String(localized: "Copy here") : String(localized: "Move here")) }) {+ first.attributedTitle = NSAttributedString(string: first.title, attributes: [.font: NSFont.boldSystemFont(ofSize: NSFont.systemFontSize)])+ }+ let at = view.convert(view.window?.mouseLocationOutsideOfEventStream ?? .zero, from: nil)+ DispatchQueue.main.async { menu.popUp(positioning: nil, at: at, in: view) }}/// The folder a drop lands in: the folder row under the pointer, else the folder shown.@@ -2615,6 +2653,10 @@ extension FileListController {return true}let urls = Self.droppedURLs(info)+ if Self.dropAsks() {+ askDrop(urls, into: dest, in: viewMode == .details ? table : tiles)+ return true+ }transfer(urls, into: dest, kind: Self.dropKind(info, urls, into: dest), selectHere: dest == url)return true}diff --git a/macos/Sources/RustyFiles/RightDrag.swift b/macos/Sources/RustyFiles/RightDrag.swiftnew file mode 100644index 00000000..ea97c035--- /dev/null+++ b/macos/Sources/RustyFiles/RightDrag.swift@@ -0,0 +1,48 @@+import AppKit++/// Dragging with the right button, as on Windows: pressing it on an item and moving starts a+/// drag of the selection; letting go over a folder asks Move here / Copy here / Make alias here+/// (FileListController.askDrop). A right click that doesn't move opens the menu as before.+@MainActor+enum RightDrag {+ /// A right-button drag is under way (the drop shows the menu).+ static var active = false++ /// Called from a list's rightMouseDown with the item under the pointer selected. Waits for+ /// the button to move or come up: true when a drag started, false for a plain right click.+ static func track(_ event: NSEvent, in view: NSView, urls: () -> [URL]) -> Bool {+ guard AppSettings.rightDrag, let window = view.window else { return false }+ let start = event.locationInWindow+ while let e = window.nextEvent(matching: [.rightMouseDragged, .rightMouseUp], until: .distantFuture, inMode: .eventTracking, dequeue: true) {+ if e.type == .rightMouseUp { return false }+ let p = e.locationInWindow+ guard hypot(p.x - start.x, p.y - start.y) > 5 else { continue }+ let files = urls()+ guard !files.isEmpty else { return false }+ let at = view.convert(start, from: nil)+ let items = files.enumerated().map { i, u -> NSDraggingItem in+ let item = NSDraggingItem(pasteboardWriter: u as NSURL)+ let icon = NSWorkspace.shared.icon(forFile: u.path)+ let size: CGFloat = 32+ item.setDraggingFrame(NSRect(x: at.x - size / 2 + CGFloat(i) * 3, y: at.y - size / 2 - CGFloat(i) * 3, width: size, height: size), contents: icon)+ return item+ }+ active = true+ let session = view.beginDraggingSession(with: items, event: e, source: Source.shared)+ session.animatesToStartingPositionsOnCancelOrFail = true+ return true+ }+ return false+ }++ final class Source: NSObject, NSDraggingSource {+ static let shared = Source()+ func draggingSession(_ session: NSDraggingSession, sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {+ context == .withinApplication ? [.move, .copy, .link, .generic] : [.copy, .link, .generic]+ }+ func draggingSession(_ session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) {+ // the drop's menu (if any) was already put up asynchronously; it reads nothing from here+ DispatchQueue.main.async { MainActor.assumeIsolated { RightDrag.active = false } }+ }+ }+}diff --git a/macos/Sources/RustyFiles/SettingsAdvanced.swift b/macos/Sources/RustyFiles/SettingsAdvanced.swiftindex e101a937..d752bff0 100644--- a/macos/Sources/RustyFiles/SettingsAdvanced.swift+++ b/macos/Sources/RustyFiles/SettingsAdvanced.swift@@ -54,6 +54,20 @@ extension AppSettings {set { store(newValue, "statusClearHours") }}+ /// What a drop without ⌥ or ⌘ does: "auto" (move on the same disk, copy to another, as+ /// Finder), "move", "copy", or "ask" (a menu, as a right-button drop gives). Windows' plain_drag.+ static var plainDrag: String {+ get { d.string(forKey: "plainDrag") ?? "auto" }+ set { store(newValue, "plainDrag") }+ }++ /// Dragging with the right button (or a two-finger press) and letting go shows Move here /+ /// Copy here / Make alias here, as on Windows.+ static var rightDrag: Bool {+ get { d.object(forKey: "rightDrag") as? Bool ?? true }+ set { store(newValue, "rightDrag") }+ }+/// Check copies: "off", "fast" (size and date), "full" (content).static var verifyCopies: String {get { d.string(forKey: "verifyCopies") ?? "off" }@@ -310,6 +324,16 @@ extension SettingsContent {control: .choice(options: [("status", String(localized: "In the status bar")), ("card", String(localized: "On a floating card")), ("center", String(localized: "Only in the Status Center"))],get: { AppSettings.progressPlace }, set: { AppSettings.progressPlace = $0 })),+ .card(+ title: String(localized: "Dragging and dropping"),+ detail: String(localized: "What a drop does without ⌥ (copy) or ⌘ (move)."), icon: "move",+ control: .choice(+ options: [("auto", String(localized: "Move on the same disk, copy to another")), ("move", String(localized: "Always move")), ("copy", String(localized: "Always copy")), ("ask", String(localized: "Ask with a menu"))],+ get: { AppSettings.plainDrag }, set: { AppSettings.plainDrag = $0 })),+ .card(+ title: String(localized: "Drag with the right button"),+ detail: String(localized: "Letting go asks: move here, copy here or make an alias here."), icon: "mouse-pointer-click",+ control: .toggle(get: { AppSettings.rightDrag }, set: { AppSettings.rightDrag = $0 })),.card(title: String(localized: "Clear finished operations"),detail: String(localized: "Finished operations leave the Status Center by themselves after this long."), icon: "eraser",diff --git a/macos/Sources/RustyFiles/Tiles.swift b/macos/Sources/RustyFiles/Tiles.swiftindex 4d3a467d..ebf8cf8a 100644--- a/macos/Sources/RustyFiles/Tiles.swift+++ b/macos/Sources/RustyFiles/Tiles.swift@@ -318,6 +318,19 @@ final class TileCollectionView: NSCollectionView, NSServicesMenuRequestor {selectionIndexPaths = selection}+ /// Right button on a tile: a drag with it asks Move / Copy / Alias on the drop (RightDrag).+ override func rightMouseDown(with event: NSEvent) {+ guard let at = indexPathForItem(at: convert(event.locationInWindow, from: nil)), let list, list.archiveIsNil else {+ return super.rightMouseDown(with: event)+ }+ if !selectionIndexPaths.contains(at) {+ selectionIndexPaths = [at]+ delegate?.collectionView?(self, didSelectItemsAt: [at])+ }+ if RightDrag.track(event, in: self, urls: { list.selectedURLs }) { return }+ super.rightMouseDown(with: event)+ }+override func menu(for event: NSEvent) -> NSMenu? {let at = indexPathForItem(at: convert(event.locationInWindow, from: nil))if let at, !selectionIndexPaths.contains(at) {