Skip to content

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.

Mac: tab numbers, more menu choices, Status Center clearing, sizes

gelenmedyae2c70c00084b
diff --git a/macos/Sources/RustyFiles/BrowserWindowController.swift b/macos/Sources/RustyFiles/BrowserWindowController.swift
index 273bb70a..79162aff 100644
--- a/macos/Sources/RustyFiles/BrowserWindowController.swift
+++ b/macos/Sources/RustyFiles/BrowserWindowController.swift
@@ -456,6 +456,7 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMen
l.onFocus = { [weak self] in self?.focusPane(right: right) }
l.onOpenFolder = { url in pane { $0.navigate(to: url) }() }
l.onOpenInNewTab = { [weak self] url in self?.openTab(url) }
+ l.onOpenInBackgroundTab = { [weak self] url in self?.openTab(url, activate: false) }
l.onReveal = { url in pane { $0.navigate(to: url.deletingLastPathComponent(), selecting: url.lastPathComponent) }() }
l.onShowInFolder = { [weak self] url in self?.openTab(url.deletingLastPathComponent(), activate: true, selecting: url.lastPathComponent) }
l.onOpenInNewWindow = { url in AppDelegate.shared.openWindow(at: url) }
@@ -833,6 +834,12 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMen
@objc func selectNextTab(_ sender: Any?) { activate((active + 1) % tabs.count) }
@objc func selectPreviousTab(_ sender: Any?) { activate((active - 1 + tabs.count) % tabs.count) }
+ /// ⌃1…⌃8: that tab, if there is one; ⌃9: the last tab.
+ @objc func selectTabByNumber(_ sender: Any?) {
+ guard let n = (sender as? NSMenuItem)?.tag, n >= 1 else { return }
+ let i = n == 9 ? tabs.count - 1 : n - 1
+ if tabs.indices.contains(i), i != active { activate(i) }
+ }
// MARK: navigation
diff --git a/macos/Sources/RustyFiles/ContextMenus.swift b/macos/Sources/RustyFiles/ContextMenus.swift
index 460438c0..986e3d76 100644
--- a/macos/Sources/RustyFiles/ContextMenus.swift
+++ b/macos/Sources/RustyFiles/ContextMenus.swift
@@ -17,7 +17,9 @@ struct MenuBuilder {
/// The row of icon buttons at the top (Cut, Copy, Paste, Rename, Share, Delete…); the
/// shortcut is in each button's tooltip.
- func quick(_ buttons: [(icon: String, tip: String, enabled: Bool, action: () -> Void)]) {
+ func quick(_ all: [(icon: String, tip: String, enabled: Bool, action: () -> Void)]) {
+ // Settings › Right-click menu › Properties off: its button leaves the row
+ let buttons = AppSettings.shows(.properties) ? all : all.filter { $0.icon != "wrench" }
guard !buttons.isEmpty else { return }
let item = NSMenuItem()
item.view = QuickRowView(buttons)
diff --git a/macos/Sources/RustyFiles/FileListController.swift b/macos/Sources/RustyFiles/FileListController.swift
index 9999359e..7e165325 100644
--- a/macos/Sources/RustyFiles/FileListController.swift
+++ b/macos/Sources/RustyFiles/FileListController.swift
@@ -274,6 +274,7 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
card.onLayout = { [weak self] in self?.layoutCard() }
NotificationCenter.default.addObserver(self, selector: #selector(statusCenterChanged), name: .rfStatusCenterChanged, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(cutChanged), name: .rfCutChanged, object: nil)
+ NotificationCenter.default.addObserver(self, selector: #selector(folderSized), name: .rfFolderSized, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(updateChanged), name: .rfUpdateChanged, object: nil)
status.onUpdate = { Updater.restart() }
applyScrollBars()
@@ -1636,6 +1637,8 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
/// new things in.
var isGathered: Bool { url.map { !$0.isFileURL } ?? false }
var onOpenInNewTab: ((URL) -> Void)?
+ /// Opens a tab without switching to it ("Open in new tab in background").
+ var onOpenInBackgroundTab: ((URL) -> Void)?
/// A middle click on an item: a folder (or an archive or smart folder shown as one) opens in
/// a new tab, as Cmd-click's "Open in new tab" does (issue 325).
@@ -1745,6 +1748,9 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
private static func pruned(_ menu: NSMenu) -> NSMenu {
typealias C = AppSettings.MenuCommand
let titles: [C: [String]] = [
+ .open: [String(localized: "Open")], .refresh: [String(localized: "Refresh")], .select: [String(localized: "Select")],
+ .properties: [String(localized: "Properties")],
+ .backgroundTab: [String(localized: "Open in new tab in background")],
.newTab: [String(localized: "Open in new tab")], .newWindow: [String(localized: "Open in new window")],
.copyPath: [String(localized: "Copy item path")], .alias: [String(localized: "Make alias")],
.pin: [String(localized: "Pin to sidebar"), String(localized: "Unpin from sidebar")],
@@ -1787,6 +1793,7 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
let singleArchive = archive == nil && items.count == 1 && !items[0].isDir && AppSettings.archivesAsFolders && urls.first.map { isArchive(path: $0.path) } == true
if singleDir || singleArchive, let u = urls.first {
b.add(String(localized: "Open in new tab"), "square-plus") { [weak self] in self?.onOpenInNewTab?(u) }
+ b.add(String(localized: "Open in new tab in background"), "square-plus") { [weak self] in self?.onOpenInBackgroundTab?(u) }
b.add(String(localized: "Open in new window"), "app-window") { [weak self] in self?.onOpenInNewWindow?(u) }
}
if hasFiles { b.sub(String(localized: "Open with"), "layout-grid") { MenuActions.openWithMenu(urls, $0) } }
@@ -1860,6 +1867,7 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
b.add(String(localized: "Download with HyperDownload"), "download") { HyperDownload.download(.torrentFile(urls[0]), into: here) }
}
b.sub(String(localized: "Tags"), "tag") { MenuActions.tagsMenu(urls, $0) }
+ selectMenu(b)
b.menu.addItem(FerryMenu.make(for: urls))
if singleDir, let u = urls.first {
b.separator()
@@ -1931,6 +1939,15 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
}
}
+ /// "Select": all, none, invert, as the command bar's buttons do (Windows' `select` menu part).
+ private func selectMenu(_ b: MenuBuilder) {
+ b.sub(String(localized: "Select"), "list-checks") { m in
+ m.add(String(localized: "Select all"), "check-check") { [weak self] in self?.selectAllItems() }
+ m.add(String(localized: "Select none"), "x") { [weak self] in self?.selectNoItems() }
+ m.add(String(localized: "Invert selection"), "arrow-left-right") { [weak self] in self?.invertSelection() }
+ }
+ }
+
/// Right-click on empty space (`background_menu`): paste, layout, sort, refresh, new, the
/// folder's own commands, Terminal.
private func backgroundMenu() -> NSMenu {
@@ -1972,6 +1989,7 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
let g = b.sub(String(localized: "Group by"), "list-tree") { _ in }
g.submenu = groups.menu
b.add(String(localized: "Refresh"), "rotate-cw", key: "r") { [weak self] in self?.onRefresh?() }
+ if folder.map({ $0.count() > 0 }) ?? false { selectMenu(b) }
b.separator()
let um = FileUndo.shared.manager
if um.canUndo { b.add(um.undoMenuItemTitle, "undo-2", key: "z") { um.undo() } }
@@ -2006,7 +2024,7 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
// Developer tools › “Open in editor”
if Editors.offered(for: dir) { b.add(String(localized: "Open in \(Editors.name)"), "code") { Editors.open([dir]) } }
}
- return b.done()
+ return Self.pruned(b.done())
}
/// Inside an archive: open, copy and extract (it is read only here).
@@ -2160,10 +2178,11 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
Self.sizeQueue.addOperation {
let size = onDisk ? Self.sizeOnDisk(path) : folderSize(path: path)
DispatchQueue.main.async {
- MainActor.assumeIsolated { [weak self] in
+ MainActor.assumeIsolated {
Self.sizing.remove(key)
Self.remember(key, path: path, size: size)
- self?.reloadSize(of: path)
+ // every list showing the folder (another tab, the other pane, a search)
+ NotificationCenter.default.post(name: .rfFolderSized, object: path)
}
}
}
@@ -2184,16 +2203,24 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
return (try? url.resourceValues(forKeys: [.isVolumeKey]).isVolume) ?? false
}
+ /// Redraws the size cell of `path` wherever it is shown here. Search results and
+ /// subfolder views list items of other folders, so the row is found by its path, not
+ /// by its name in this folder (issue 963: such a row stayed at "Calculating…").
private func reloadSize(of path: String) {
- guard let folder, let url else { return }
- let name = URL(fileURLWithPath: path).lastPathComponent
- guard URL(fileURLWithPath: path).deletingLastPathComponent().standardizedFileURL == url.standardizedFileURL,
- let row = folder.rowOf(name: name)
- else { return }
+ guard let folder, viewMode == .details else { return }
let col = table.column(withIdentifier: .init(ListColumn.size.rawValue))
- if viewMode == .details, col >= 0 {
- table.reloadData(forRowIndexes: [Int(row)], columnIndexes: [col])
+ guard col >= 0 else { return }
+ let visible = table.rows(in: table.visibleRect)
+ guard visible.length > 0 else { return }
+ var rows = IndexSet()
+ for row in visible.location..<(visible.location + visible.length) where folder.childPath(row: UInt32(row)) == path {
+ rows.insert(row)
}
+ if !rows.isEmpty { table.reloadData(forRowIndexes: rows, columnIndexes: [col]) }
+ }
+
+ @objc private func folderSized(_ note: Notification) {
+ if let path = note.object as? String { reloadSize(of: path) }
}
func tableViewSelectionDidChange(_ notification: Notification) { selectionChanged() }
diff --git a/macos/Sources/RustyFiles/FileOps.swift b/macos/Sources/RustyFiles/FileOps.swift
index ba2f9f5f..1d7ed433 100644
--- a/macos/Sources/RustyFiles/FileOps.swift
+++ b/macos/Sources/RustyFiles/FileOps.swift
@@ -111,6 +111,8 @@ enum FileOps {
/// with the pasteboard's change count: a paste moves only while that copy is still on it.
extension Notification.Name {
static let rfCutChanged = Notification.Name("rustyfiles.cutChanged")
+ /// A folder's size was worked out; the object is its path.
+ static let rfFolderSized = Notification.Name("rustyfiles.folderSized")
}
@MainActor
diff --git a/macos/Sources/RustyFiles/MainMenu.swift b/macos/Sources/RustyFiles/MainMenu.swift
index 814283ce..b0414cff 100644
--- a/macos/Sources/RustyFiles/MainMenu.swift
+++ b/macos/Sources/RustyFiles/MainMenu.swift
@@ -157,6 +157,17 @@ enum MainMenu {
m.addItem(item(String(localized: "Next Tab"), #selector(W.selectNextTab(_:)), "\t", .control))
m.addItem(item(String(localized: "Previous Tab"), #selector(W.selectPreviousTab(_:)), "\t", [.control, .shift]))
m.addItem(item(String(localized: "Search Tabs…"), #selector(W.searchTabs(_:)), "\\", [.command, .shift]))
+ // ⌃1…⌃8 go to that tab, ⌃9 to the last one (Windows' Ctrl+1…9; ⌘1…4 are the views here)
+ let go = NSMenu(title: String(localized: "Go to Tab"))
+ for n in 1...9 {
+ let title = n == 9 ? String(localized: "Last Tab") : String(format: String(localized: "Tab %d"), n)
+ let i = item(title, #selector(W.selectTabByNumber(_:)), "\(n)", .control)
+ i.tag = n
+ go.addItem(i)
+ }
+ let goItem = NSMenuItem(title: go.title, action: nil, keyEquivalent: "")
+ goItem.submenu = go
+ m.addItem(goItem)
return m
}
}
diff --git a/macos/Sources/RustyFiles/SettingsAdvanced.swift b/macos/Sources/RustyFiles/SettingsAdvanced.swift
index 21a4b725..e101a937 100644
--- a/macos/Sources/RustyFiles/SettingsAdvanced.swift
+++ b/macos/Sources/RustyFiles/SettingsAdvanced.swift
@@ -47,6 +47,13 @@ extension AppSettings {
set { store(newValue, "progressPlace") }
}
+ /// Finished operations leave the Status Center this many hours after they ended; 0: never
+ /// (Windows' status_clear_hours, discussion 700).
+ static var statusClearHours: Int {
+ get { d.object(forKey: "statusClearHours") as? Int ?? 0 }
+ set { store(newValue, "statusClearHours") }
+ }
+
/// Check copies: "off", "fast" (size and date), "full" (content).
static var verifyCopies: String {
get { d.string(forKey: "verifyCopies") ?? "off" }
@@ -303,6 +310,12 @@ 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: "Clear finished operations"),
+ detail: String(localized: "Finished operations leave the Status Center by themselves after this long."), icon: "eraser",
+ control: .choice(
+ options: [("0", String(localized: "Never")), ("1", String(localized: "After 1 hour")), ("24", String(localized: "After 1 day")), ("168", String(localized: "After 1 week"))],
+ get: { String(AppSettings.statusClearHours) }, set: { AppSettings.statusClearHours = Int($0) ?? 0 })),
.card(
title: String(localized: "Notify when long operations finish"),
detail: String(localized: "Copies, moves and archives that took more than 10 seconds while rustyfiles was in the background."), icon: "bell",
diff --git a/macos/Sources/RustyFiles/SettingsBehaviour.swift b/macos/Sources/RustyFiles/SettingsBehaviour.swift
index 8bf4b2f9..1b200a93 100644
--- a/macos/Sources/RustyFiles/SettingsBehaviour.swift
+++ b/macos/Sources/RustyFiles/SettingsBehaviour.swift
@@ -65,11 +65,13 @@ extension AppSettings {
/// The item menu's optional commands (settings.rs `ctx_*`), each on unless turned off.
enum MenuCommand: String, CaseIterable {
- case newTab, newWindow, copyPath, alias, pin, archive, tags, ferry, terminal
+ case open, newTab, backgroundTab, newWindow, copyPath, alias, pin, archive, tags, select, ferry, terminal, refresh, properties
var title: String {
switch self {
+ case .open: String(localized: "Open")
case .newTab: String(localized: "Open in new tab")
+ case .backgroundTab: String(localized: "Open in new tab in background")
case .newWindow: String(localized: "Open in new window")
case .copyPath: String(localized: "Copy item path")
case .alias: String(localized: "Make alias")
@@ -78,13 +80,28 @@ extension AppSettings {
case .tags: String(localized: "Tags")
case .ferry: String(localized: "Send with Ferry")
case .terminal: String(localized: "Open in Terminal")
+ case .select: String(localized: "Select")
+ case .refresh: String(localized: "Refresh")
+ case .properties: String(localized: "Properties")
}
}
}
- static func shows(_ c: MenuCommand) -> Bool { !(d.stringArray(forKey: "menuHidden") ?? []).contains(c.rawValue) }
+ /// Commands a menu leaves out until they are turned on (Windows' defaults).
+ static let menuOffByDefault: Set<MenuCommand> = [.backgroundTab]
+
+ static func shows(_ c: MenuCommand) -> Bool {
+ if menuOffByDefault.contains(c) { return (d.stringArray(forKey: "menuShown") ?? []).contains(c.rawValue) }
+ return !(d.stringArray(forKey: "menuHidden") ?? []).contains(c.rawValue)
+ }
static func setShows(_ c: MenuCommand, _ on: Bool) {
+ if menuOffByDefault.contains(c) {
+ var shown = Set(d.stringArray(forKey: "menuShown") ?? [])
+ if on { shown.insert(c.rawValue) } else { shown.remove(c.rawValue) }
+ store(Array(shown).sorted(), "menuShown")
+ return
+ }
var hidden = Set(d.stringArray(forKey: "menuHidden") ?? [])
if on { hidden.remove(c.rawValue) } else { hidden.insert(c.rawValue) }
store(Array(hidden).sorted(), "menuHidden")
diff --git a/macos/Sources/RustyFiles/StatusCenter.swift b/macos/Sources/RustyFiles/StatusCenter.swift
index 9e2fff3b..9d6c87ea 100644
--- a/macos/Sources/RustyFiles/StatusCenter.swift
+++ b/macos/Sources/RustyFiles/StatusCenter.swift
@@ -122,6 +122,8 @@ final class StatusCenter {
func add(title: String, folder: URL?, cancel: (() -> Void)?) -> Card {
let c = Card(title: title, folder: folder, cancel: cancel)
cards.insert(c, at: 0)
+ _ = sweeper
+ dropOld()
changed()
return c
}
@@ -146,6 +148,19 @@ final class StatusCenter {
}
}
+ /// Settings › Advanced › Clear finished operations: cards that ended longer ago than that go.
+ func dropOld() {
+ let hours = AppSettings.statusClearHours
+ guard hours > 0 else { return }
+ let before = cards.count
+ cards.removeAll { $0.state != .running && ($0.ended.map { -$0.timeIntervalSinceNow > Double(hours) * 3600 } ?? false) }
+ if cards.count != before { changed() }
+ }
+
+ private lazy var sweeper: Timer = Timer.scheduledTimer(withTimeInterval: 300, repeats: true) { _ in
+ MainActor.assumeIsolated { StatusCenter.shared.dropOld() }
+ }
+
func clearFinished() {
cards.removeAll { $0.state != .running }
changed()