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: a bookmarks bar under the address bar, as on Windows
gelenmedya0e4dc0939cb2
diff --git a/macos/Sources/RustyFiles/Bookmarks.swift b/macos/Sources/RustyFiles/Bookmarks.swiftnew file mode 100644index 00000000..ea81d1ab--- /dev/null+++ b/macos/Sources/RustyFiles/Bookmarks.swift@@ -0,0 +1,243 @@+import AppKit+import UniformTypeIdentifiers++extension Notification.Name {+ static let rfBookmarksChanged = Notification.Name("rustyfiles.bookmarksChanged")+}++/// A bookmarks bar as browsers have one, under the address bar (Windows' bookmarks.rs, issue+/// 694): a bookmark is a folder or file of this Mac, or a web address; bookmarks can be grouped+/// in folders, which open as menus. Kept in Application Support/rustyfiles/bookmarks.json (the+/// Windows app's format), imported from and exported to the bookmark file browsers write.+enum Bookmark: Codable, Equatable {+ case link(name: String, target: String)+ case folder(name: String, children: [Bookmark])++ var name: String {+ switch self {+ case .link(let n, _), .folder(let n, _): n+ }+ }++ func renamed(_ name: String) -> Bookmark {+ switch self {+ case .link(_, let t): .link(name: name, target: t)+ case .folder(_, let c): .folder(name: name, children: c)+ }+ }++ static func forPath(_ url: URL) -> Bookmark {+ .link(name: url.lastPathComponent.isEmpty ? url.path : url.lastPathComponent, target: url.path)+ }++ /// Where a link leads: a path of this Mac, or nil for a web address.+ static func localPath(_ target: String) -> URL? {+ let t = target.trimmingCharacters(in: .whitespaces)+ return t.hasPrefix("/") || t.hasPrefix("~") ? URL(fileURLWithPath: (t as NSString).expandingTildeInPath) : nil+ }++ // the Windows app's JSON: {"kind":"link","name":…,"target":…} / {"kind":"folder","name":…,"children":[…]}+ private enum Keys: String, CodingKey { case kind, name, target, children }++ init(from decoder: Decoder) throws {+ let c = try decoder.container(keyedBy: Keys.self)+ let name = try c.decode(String.self, forKey: .name)+ if try c.decode(String.self, forKey: .kind) == "folder" {+ self = .folder(name: name, children: try c.decodeIfPresent([Bookmark].self, forKey: .children) ?? [])+ } else {+ self = .link(name: name, target: try c.decode(String.self, forKey: .target))+ }+ }++ func encode(to encoder: Encoder) throws {+ var c = encoder.container(keyedBy: Keys.self)+ switch self {+ case .link(let n, let t):+ try c.encode("link", forKey: .kind)+ try c.encode(n, forKey: .name)+ try c.encode(t, forKey: .target)+ case .folder(let n, let ch):+ try c.encode("folder", forKey: .kind)+ try c.encode(n, forKey: .name)+ try c.encode(ch, forKey: .children)+ }+ }+}++@MainActor+enum Bookmarks {+ private static var file: URL {+ let dir = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0].appendingPathComponent("rustyfiles", isDirectory: true)+ try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)+ return dir.appendingPathComponent("bookmarks.json")+ }++ private static var loaded: [Bookmark]?++ static var items: [Bookmark] {+ if let loaded { return loaded }+ let read = (try? Data(contentsOf: file)).flatMap { try? JSONDecoder().decode([Bookmark].self, from: $0) } ?? []+ loaded = read+ return read+ }++ static func update(_ change: (inout [Bookmark]) -> Void) {+ var list = items+ change(&list)+ loaded = list+ let enc = JSONEncoder()+ enc.outputFormatting = .prettyPrinted+ if let data = try? enc.encode(list) { try? data.write(to: file, options: .atomic) }+ NotificationCenter.default.post(name: .rfBookmarksChanged, object: nil)+ }++ static func add(_ urls: [URL]) {+ update { list in+ for u in urls where !list.contains(where: { if case .link(_, let t) = $0 { return t == u.path } else { return false } }) {+ list.append(.forPath(u))+ }+ }+ }++ static func contains(_ url: URL) -> Bool {+ items.contains { if case .link(_, let t) = $0 { return t == url.path } else { return false } }+ }++ // MARK: the Netscape bookmark file ("bookmarks.html")++ private static func unescape(_ s: String) -> String {+ s.trimmingCharacters(in: .whitespacesAndNewlines)+ .replacingOccurrences(of: "<", with: "<").replacingOccurrences(of: ">", with: ">")+ .replacingOccurrences(of: """, with: "\"").replacingOccurrences(of: "'", with: "'")+ .replacingOccurrences(of: "&", with: "&")+ }++ private static func escape(_ s: String) -> String {+ s.replacingOccurrences(of: "&", with: "&").replacingOccurrences(of: "<", with: "<")+ .replacingOccurrences(of: ">", with: ">").replacingOccurrences(of: "\"", with: """)+ }++ private static func attr(_ tag: String, _ name: String) -> String? {+ guard let r = tag.range(of: name + "=\"", options: .caseInsensitive) else { return nil }+ let rest = tag[r.upperBound...]+ guard let end = rest.firstIndex(of: "\"") else { return nil }+ return String(rest[..<end])+ }++ /// A file's address as a link's target: `file:///Users/a/My%20Folder` is that path; a+ /// Windows path (`file:///D:/…`) stays an address, since it means nothing here.+ private static func target(of href: String) -> String {+ if let u = URL(string: href), u.isFileURL, !u.path.isEmpty, !(u.path.dropFirst().first?.isLetter == true && u.path.dropFirst(2).first == ":") {+ return u.path+ }+ return href+ }++ private static func href(of target: String) -> String {+ Bookmark.localPath(target).map { $0.absoluteString } ?? target+ }++ /// The bookmarks of a bookmark file: the folder it marks as the toolbar's first, as browsers+ /// read it, then whatever else it has, its folders as folders.+ static func parse(_ text: String) -> [Bookmark] {+ let s = Array(text.unicodeScalars)+ // (tags and attributes are ASCII: only those letters are lowered, so both have one length)+ let lower = s.map { $0.value >= 65 && $0.value <= 90 ? Unicode.Scalar($0.value + 32)! : $0 }+ func find(_ needle: String, from: Int) -> Int? {+ let n = Array(needle.unicodeScalars)+ guard !n.isEmpty, from <= lower.count - n.count else { return nil }+ var i = from+ while i <= lower.count - n.count {+ if lower[i] == n[0] && Array(lower[i..<(i + n.count)]) == n { return i }+ i += 1+ }+ return nil+ }+ func str(_ a: [Unicode.Scalar], _ r: Range<Int>) -> String { String(String.UnicodeScalarView(a[r])) }+ var stack: [(name: String, children: [Bookmark], toolbar: Bool)] = [("", [], false)]+ var header: (String, Bool)?+ var toolbar: [Bookmark]?+ var i = 0+ func close() {+ let top = stack.removeLast()+ if top.toolbar && toolbar == nil {+ toolbar = top.children+ } else if top.name.isEmpty {+ stack[stack.count - 1].children += top.children+ } else {+ stack[stack.count - 1].children.append(.folder(name: top.name, children: top.children))+ }+ }+ while let start = find("<", from: i) {+ guard let end = find(">", from: start) else { break }+ let tag = str(lower, (start + 1)..<end)+ let raw = str(s, (start + 1)..<end)+ i = end + 1+ if tag.hasPrefix("h3") {+ let c = find("</h3>", from: i) ?? i+ header = (unescape(str(s, i..<c)), tag.contains("personal_toolbar_folder=\"true\""))+ i = c+ } else if tag == "a" || tag.hasPrefix("a ") {+ let c = find("</a>", from: i) ?? i+ let name = unescape(str(s, i..<c))+ if let h = attr(raw, "href") {+ let t = target(of: unescape(h))+ stack[stack.count - 1].children.append(.link(name: name.isEmpty ? t : name, target: t))+ }+ i = c+ } else if tag.hasPrefix("dl") {+ let (name, isToolbar) = header ?? ("", false)+ header = nil+ stack.append((name, [], isToolbar))+ } else if tag.hasPrefix("/dl"), stack.count > 1 {+ close()+ }+ }+ while stack.count > 1 { close() }+ return (toolbar ?? []) + stack[0].children+ }++ /// The bar as a bookmark file, its bookmarks in the toolbar's folder (browsers read it back as their bar).+ static func toHTML(_ items: [Bookmark]) -> String {+ func write(_ out: inout String, _ items: [Bookmark], _ depth: Int) {+ let pad = String(repeating: " ", count: depth)+ for b in items {+ switch b {+ case .link(let n, let t):+ out += "\(pad)<DT><A HREF=\"\(escape(href(of: t)))\">\(escape(n))</A>\n"+ case .folder(let n, let c):+ out += "\(pad)<DT><H3>\(escape(n))</H3>\n\(pad)<DL><p>\n"+ write(&out, c, depth + 1)+ out += "\(pad)</DL><p>\n"+ }+ }+ }+ let now = Int(Date().timeIntervalSince1970)+ var out = "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<!-- This is an automatically generated file.\n It will be read and overwritten.\n DO NOT EDIT! -->\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n<TITLE>Bookmarks</TITLE>\n<H1>Bookmarks</H1>\n<DL><p>\n"+ out += " <DT><H3 ADD_DATE=\"\(now)\" LAST_MODIFIED=\"\(now)\" PERSONAL_TOOLBAR_FOLDER=\"true\">Bookmarks</H3>\n <DL><p>\n"+ write(&out, items, 2)+ out += " </DL><p>\n</DL><p>\n"+ return out+ }++ static func importFile(from window: NSWindow?) {+ let panel = NSOpenPanel()+ panel.allowedContentTypes = [.html]+ panel.message = String(localized: "Choose a bookmark file exported from a browser.")+ guard panel.runModal() == .OK, let u = panel.url, let text = try? String(contentsOf: u, encoding: .utf8) else { return }+ let read = parse(text)+ guard !read.isEmpty else {+ NSSound.beep()+ return+ }+ update { $0 += read }+ }++ static func exportFile(from window: NSWindow?) {+ let panel = NSSavePanel()+ panel.allowedContentTypes = [.html]+ panel.nameFieldStringValue = "bookmarks.html"+ guard panel.runModal() == .OK, let u = panel.url else { return }+ try? toHTML(items).write(to: u, atomically: true, encoding: .utf8)+ }+}diff --git a/macos/Sources/RustyFiles/BookmarksBar.swift b/macos/Sources/RustyFiles/BookmarksBar.swiftnew file mode 100644index 00000000..ab0f4fac--- /dev/null+++ b/macos/Sources/RustyFiles/BookmarksBar.swift@@ -0,0 +1,252 @@+import AppKit++/// The bookmarks bar under the address bar (Windows' bookmarks_bar.rs): a button per bookmark,+/// a folder of bookmarks opens as a menu, folders dropped on it become bookmarks, and its+/// right-click menu opens, renames, moves and removes them, adds the current folder, and+/// imports or exports the bar as a browser's bookmark file. Settings › Appearance turns it on.+@MainActor+final class BookmarksBar: FlippedView {+ static let height: CGFloat = 30++ /// Opens a path: in this tab, or (`newTab`) in a new one.+ var onOpen: ((URL, _ newTab: Bool) -> Void)?+ /// The folder shown, for "Add this folder".+ var current: (() -> URL?)?++ private var rects: [NSRect] = []+ private var hovered: Int?+ private var dropHighlight = false++ override init(frame: NSRect) {+ super.init(frame: frame)+ registerForDraggedTypes([.fileURL])+ NotificationCenter.default.addObserver(self, selector: #selector(changed), name: .rfBookmarksChanged, object: nil)+ }++ @available(*, unavailable)+ required init?(coder: NSCoder) { fatalError() }++ @objc private func changed() {+ needsLayout = true+ needsDisplay = true+ }++ override var mouseDownCanMoveWindow: Bool { false }++ override func updateTrackingAreas() {+ super.updateTrackingAreas()+ trackingAreas.forEach(removeTrackingArea)+ addTrackingArea(NSTrackingArea(rect: .zero, options: [.mouseMoved, .mouseEnteredAndExited, .activeInKeyWindow, .inVisibleRect], owner: self))+ }++ private static let font = Metrics.textXs++ private func icon(_ b: Bookmark) -> String {+ switch b {+ case .folder: "folder-open"+ case .link(_, let t):+ if let u = Bookmark.localPath(t) {+ (try? u.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) == true ? "folder" : "file"+ } else {+ "globe"+ }+ }+ }++ override func layout() {+ super.layout()+ var x: CGFloat = 8+ rects = Bookmarks.items.map { b in+ let w = min(ceil((b.name as NSString).size(withAttributes: [.font: Self.font]).width), 180) + 16 + 6 + 16+ defer { x += w + 2 }+ return NSRect(x: x, y: 3, width: w, height: bounds.height - 6)+ }+ toolTip = Bookmarks.items.isEmpty ? String(localized: "Drop folders here to bookmark them") : nil+ }++ override func draw(_ dirtyRect: NSRect) {+ let p = Palette.of(self)+ if dropHighlight {+ p.hover.setFill()+ NSBezierPath(roundedRect: bounds.insetBy(dx: 4, dy: 2), xRadius: Metrics.radius, yRadius: Metrics.radius).fill()+ }+ let items = Bookmarks.items+ if items.isEmpty {+ let attrs: [NSAttributedString.Key: Any] = [.font: Self.font, .foregroundColor: p.textSecondary]+ let t = String(localized: "Drop folders here to bookmark them") as NSString+ t.draw(at: NSPoint(x: 12, y: (bounds.height - t.size(withAttributes: attrs).height) / 2), withAttributes: attrs)+ return+ }+ let style = NSMutableParagraphStyle()+ style.lineBreakMode = .byTruncatingTail+ for (i, b) in items.enumerated() where rects.indices.contains(i) {+ let r = rects[i]+ if hovered == i {+ p.hover.setFill()+ NSBezierPath(roundedRect: r, xRadius: Metrics.radius, yRadius: Metrics.radius).fill()+ }+ Draw.icon(icon(b), in: NSRect(x: r.minX + 8, y: r.minY, width: 16, height: r.height), size: 14, color: p.textSecondary)+ let attrs: [NSAttributedString.Key: Any] = [.font: Self.font, .foregroundColor: p.text, .paragraphStyle: style]+ let h = (b.name as NSString).size(withAttributes: attrs).height+ (b.name as NSString).draw(in: NSRect(x: r.minX + 8 + 16 + 6, y: r.midY - h / 2, width: r.width - 8 - 16 - 6 - 8, height: h), withAttributes: attrs)+ }+ }++ private func index(at event: NSEvent) -> Int? {+ let pt = convert(event.locationInWindow, from: nil)+ return rects.firstIndex { $0.contains(pt) }+ }++ override func mouseMoved(with event: NSEvent) {+ let i = index(at: event)+ if i != hovered { hovered = i; needsDisplay = true }+ }++ override func mouseExited(with event: NSEvent) {+ hovered = nil+ needsDisplay = true+ }++ override func mouseDown(with event: NSEvent) {+ guard let i = index(at: event) else { return }+ open(i, newTab: event.modifierFlags.contains(.command))+ }++ override func otherMouseUp(with event: NSEvent) {+ guard event.buttonNumber == 2, let i = index(at: event) else { return }+ open(i, newTab: true)+ }++ private func open(_ i: Int, newTab: Bool) {+ let items = Bookmarks.items+ guard items.indices.contains(i) else { return }+ switch items[i] {+ case .link(_, let t):+ follow(t, newTab: newTab)+ case .folder(_, let children):+ let menu = NSMenu()+ fill(menu, children)+ menu.popUp(positioning: nil, at: NSPoint(x: rects[i].minX, y: rects[i].maxY + 2), in: self)+ }+ }++ private func follow(_ target: String, newTab: Bool) {+ if let u = Bookmark.localPath(target) {+ var dir: ObjCBool = false+ if FileManager.default.fileExists(atPath: u.path, isDirectory: &dir), !dir.boolValue {+ NSWorkspace.shared.open(u)+ } else {+ onOpen?(u, newTab)+ }+ } else if let u = URL(string: target) {+ NSWorkspace.shared.open(u)+ }+ }++ private func fill(_ menu: NSMenu, _ items: [Bookmark]) {+ for b in items {+ switch b {+ case .link(let n, let t):+ let item = ClosureMenuItem(title: n) { [weak self] in self?.follow(t, newTab: false) }+ item.image = Icons.menu(icon(b))+ menu.addItem(item)+ case .folder(let n, let c):+ let item = NSMenuItem(title: n, action: nil, keyEquivalent: "")+ item.image = Icons.menu("folder-open")+ let sub = NSMenu()+ fill(sub, c)+ item.submenu = sub+ menu.addItem(item)+ }+ }+ }++ override func menu(for event: NSEvent) -> NSMenu? {+ let b = MenuBuilder()+ let i = index(at: event)+ let items = Bookmarks.items+ if let i, items.indices.contains(i) {+ let bm = items[i]+ if case .link(_, let t) = bm {+ b.add(String(localized: "Open"), "square-arrow-out-up-right") { [weak self] in self?.follow(t, newTab: false) }+ if Bookmark.localPath(t) != nil {+ b.add(String(localized: "Open in new tab"), "square-plus") { [weak self] in self?.follow(t, newTab: true) }+ }+ }+ b.add(String(localized: "Rename…"), "text-cursor-input") { [weak self] in self?.rename(i) }+ if i > 0 { b.add(String(localized: "Move left"), "arrow-left") { Bookmarks.update { $0.swapAt(i, i - 1) } } }+ if i < items.count - 1 { b.add(String(localized: "Move right"), "arrow-right") { Bookmarks.update { $0.swapAt(i, i + 1) } } }+ b.add(String(localized: "Remove"), "trash") { Bookmarks.update { $0.remove(at: i) } }+ b.separator()+ }+ if let here = current?(), here.isFileURL, !Bookmarks.contains(here) {+ b.add(String(localized: "Add this folder"), "bookmark-plus") { Bookmarks.add([here]) }+ }+ b.add(String(localized: "New bookmark folder…"), "folder-plus") { [weak self] in self?.newFolder() }+ b.separator()+ b.add(String(localized: "Import bookmarks…"), "import") { [weak self] in Bookmarks.importFile(from: self?.window) }+ b.add(String(localized: "Export bookmarks…"), "share") { [weak self] in Bookmarks.exportFile(from: self?.window) }+ b.add(String(localized: "Hide bookmarks bar"), "eye-off") { AppSettings.bookmarksBar = false }+ return b.done()+ }++ private func ask(_ title: String, _ value: String) -> String? {+ let a = NSAlert()+ a.messageText = title+ let f = NSTextField(frame: NSRect(x: 0, y: 0, width: 260, height: 24))+ f.stringValue = value+ a.accessoryView = f+ a.addButton(withTitle: String(localized: "OK"))+ a.addButton(withTitle: String(localized: "Cancel"))+ a.window.initialFirstResponder = f+ guard a.runModal() == .alertFirstButtonReturn else { return nil }+ let t = f.stringValue.trimmingCharacters(in: .whitespaces)+ return t.isEmpty ? nil : t+ }++ private func rename(_ i: Int) {+ let items = Bookmarks.items+ guard items.indices.contains(i), let name = ask(String(localized: "Rename bookmark"), items[i].name) else { return }+ Bookmarks.update { if $0.indices.contains(i) { $0[i] = $0[i].renamed(name) } }+ }++ /// A folder of bookmarks: a menu on the bar; folders dropped on it go into it.+ private func newFolder() {+ guard let name = ask(String(localized: "New bookmark folder"), String(localized: "Folder")) else { return }+ Bookmarks.update { $0.append(.folder(name: name, children: [])) }+ }++ // MARK: drops: folders and files become bookmarks; on a bookmark folder, they go into it++ private func dropped(_ info: NSDraggingInfo) -> [URL] {+ (info.draggingPasteboard.readObjects(forClasses: [NSURL.self], options: [.urlReadingFileURLsOnly: true]) as? [URL]) ?? []+ }++ override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {+ guard !dropped(sender).isEmpty else { return [] }+ dropHighlight = true+ needsDisplay = true+ return .link+ }++ override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation { dropped(sender).isEmpty ? [] : .link }++ override func draggingExited(_ sender: NSDraggingInfo?) {+ dropHighlight = false+ needsDisplay = true+ }++ override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {+ dropHighlight = false+ needsDisplay = true+ let urls = dropped(sender)+ guard !urls.isEmpty else { return false }+ let pt = convert(sender.draggingLocation, from: nil)+ if let i = rects.firstIndex(where: { $0.contains(pt) }), case .folder(let n, let c) = Bookmarks.items[i] {+ Bookmarks.update { $0[i] = .folder(name: n, children: c + urls.map(Bookmark.forPath)) }+ } else {+ Bookmarks.add(urls)+ }+ return true+ }+}diff --git a/macos/Sources/RustyFiles/BrowserWindowController.swift b/macos/Sources/RustyFiles/BrowserWindowController.swiftindex 7d59bd88..9235fca4 100644--- a/macos/Sources/RustyFiles/BrowserWindowController.swift+++ b/macos/Sources/RustyFiles/BrowserWindowController.swift@@ -159,6 +159,7 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMenprivate let sidebar = SidebarView()private let handle = SidebarResizeHandle()private let paneDivider = PaneDivider()+ private let bookmarksBar = BookmarksBar()private let leftPath = PanePathStrip(), rightPath = PanePathStrip()private var lastPaneArea: NSRect = .zero/// The left pane's share of a dual pane's width, kept across starts (0.5: half each).@@ -228,7 +229,11 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMenwindow.contentView = frameapplyMaterial()applyScale()- [sidebar, handle, leftList.card, rightList.card, leftPath, rightPath, paneDivider, navBar, titleBar].forEach(root.addSubview)+ [sidebar, handle, leftList.card, rightList.card, leftPath, rightPath, paneDivider, navBar, bookmarksBar, titleBar].forEach(root.addSubview)+ bookmarksBar.onOpen = { [weak self] url, newTab in+ if newTab { self?.openTab(url) } else { self?.navigate(to: url) }+ }+ bookmarksBar.current = { [weak self] in self.map { $0.tab.isPage ? nil : $0.tab.url } ?? nil }leftPath.onClick = { [weak self] in self?.focusPane(right: false) }rightPath.onClick = { [weak self] in self?.focusPane(right: true) }paneDivider.onDrag = { [weak self] x in@@ -270,7 +275,11 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMenlet b = root.boundstitleBar.frame = NSRect(x: 0, y: 0, width: b.width, height: Metrics.titleBarHeight)navBar.frame = NSRect(x: 0, y: Metrics.titleBarHeight, width: b.width, height: Metrics.navRowHeight)- let top = Metrics.titleBarHeight + Metrics.navRowHeight+ // Settings › Appearance › Bookmarks bar: under the address bar, across the window+ let bar = AppSettings.bookmarksBar ? BookmarksBar.height : 0+ bookmarksBar.isHidden = bar == 0+ bookmarksBar.frame = NSRect(x: 0, y: Metrics.titleBarHeight + Metrics.navRowHeight, width: b.width, height: bar)+ let top = Metrics.titleBarHeight + Metrics.navRowHeight + barlet sw = sidebarShown ? sidebarWidth : 0sidebar.isHidden = !sidebarShownhandle.isHidden = !sidebarShown@@ -334,7 +343,7 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMenif key == "material" || key == "theme" { applyMaterial() }if key == "interfacePercent" { applyScale() }if key == "tabPath" { refreshTabs() }- if key == "dualPanePaths" { root.needsLayout = true }+ if key == "dualPanePaths" || key == "bookmarksBar" { root.needsLayout = true }if key == "compactWindow" {[leftList, rightList].forEach { $0.card.applyCompact(); $0.card.needsLayout = true }root.needsLayout = true@@ -677,6 +686,13 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMen// MARK: command palette (command_palette.rs)@objc func toggleShelf(_ sender: Any?) { list.shelfShown.toggle() }+ @objc func toggleBookmarksBar(_ sender: Any?) { AppSettings.bookmarksBar.toggle() }+ /// Bookmarks › Bookmark This Folder: the folder shown goes on the bar (which shows itself).+ @objc func bookmarkThisFolder(_ sender: Any?) {+ guard !tab.isPage, tab.url.isFileURL else { return }+ Bookmarks.add([tab.url])+ if !AppSettings.bookmarksBar { AppSettings.bookmarksBar = true }+ }@objc func addToShelf(_ sender: Any?) { list.addToShelf() }/// Go › Disk Usage: where the space under the open folder goes (or the home folder's).@@ -1393,6 +1409,11 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMencase #selector(toggleDualPane(_:)):item.state = dual ? .on : .offreturn true+ case #selector(toggleBookmarksBar(_:)):+ item.title = AppSettings.bookmarksBar ? String(localized: "Hide Bookmarks Bar") : String(localized: "Show Bookmarks Bar")+ return true+ case #selector(bookmarkThisFolder(_:)):+ return !tab.isPage && tab.url.isFileURL && !Bookmarks.contains(tab.url)case #selector(toggleShelf(_:)):item.title = list.shelfShown ? String(localized: "Hide Shelf") : String(localized: "Show Shelf")return truediff --git a/macos/Sources/RustyFiles/MainMenu.swift b/macos/Sources/RustyFiles/MainMenu.swiftindex b0414cff..f1952a58 100644--- a/macos/Sources/RustyFiles/MainMenu.swift+++ b/macos/Sources/RustyFiles/MainMenu.swift@@ -123,6 +123,8 @@ enum MainMenu {m.addItem(item(String(localized: "Hide Sidebar"), #selector(W.toggleSidebar(_:)), "s", [.command, .control]))m.addItem(item(String(localized: "Show Preview"), #selector(W.togglePreviewPane(_:)), "p", [.command, .shift]))m.addItem(item(String(localized: "Show Shelf"), #selector(W.toggleShelf(_:)), "s", [.command, .option]))+ m.addItem(item(String(localized: "Show Bookmarks Bar"), #selector(W.toggleBookmarksBar(_:)), "b", [.command, .shift]))+ m.addItem(item(String(localized: "Bookmark This Folder"), #selector(W.bookmarkThisFolder(_:)), "b", [.command, .control]))m.addItem(item(String(localized: "Dual Pane"), #selector(W.toggleDualPane(_:)), "d", [.command, .option]))m.addItem(item(String(localized: "Switch Pane"), #selector(W.switchPane(_:)), key(NSF6FunctionKey), []))m.addItem(item(String(localized: "Copy to Other Pane"), #selector(W.copyToOtherPane(_:)), key(NSF5FunctionKey), .shift))diff --git a/macos/Sources/RustyFiles/SelfTest.swift b/macos/Sources/RustyFiles/SelfTest.swiftindex 57ce54bd..609f4481 100644--- a/macos/Sources/RustyFiles/SelfTest.swift+++ b/macos/Sources/RustyFiles/SelfTest.swift@@ -37,6 +37,27 @@ enum SelfTest {crc.update(Data("123456789".utf8))check(crc.value == 0xCBF4_3926, "CRC32 gives the standard check value")check(PropertiesWindow.normalizedHash(" 0xAB-CD:ef 12 ") == "abcdef12", "a pasted hash is compared without spaces, dashes and 0x")+ let sample = """+ <!DOCTYPE NETSCAPE-Bookmark-file-1>+ <DL><p>+ <DT><H3 ADD_DATE="1" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks bar</H3>+ <DL><p>+ <DT><A HREF="file:///Users/me/My%20Folder" ICON="data:x">My Folder</A>+ <DT><H3>More</H3>+ <DL><p>+ <DT><A HREF="https://example.com/a?b=1&c=2">Web & more</A>+ </DL><p>+ </DL><p>+ <DT><A HREF="file:///Applications">Apps</A>+ </DL><p>+ """+ let marks = Bookmarks.parse(sample)+ check(marks == [+ .link(name: "My Folder", target: "/Users/me/My Folder"),+ .folder(name: "More", children: [.link(name: "Web & more", target: "https://example.com/a?b=1&c=2")]),+ .link(name: "Apps", target: "/Applications"),+ ], "a browser's bookmark file is read, its toolbar folder first")+ check(Bookmarks.parse(Bookmarks.toHTML(marks)) == marks, "the bookmarks bar is written as a bookmark file that reads back the same")// 0. the Git look-up ends at the disk's root and finds a repository from inside it (issue 429)check(GitRepo.repoRoot(URL(fileURLWithPath: "/")) == nil, "no repository above the root")diff --git a/macos/Sources/RustyFiles/SettingsAppearance.swift b/macos/Sources/RustyFiles/SettingsAppearance.swiftindex 5d28dc55..028e32c5 100644--- a/macos/Sources/RustyFiles/SettingsAppearance.swift+++ b/macos/Sources/RustyFiles/SettingsAppearance.swift@@ -96,6 +96,12 @@ extension AppSettings {}}+ /// Settings › Appearance › Bookmarks bar: a row of bookmarks under the address bar.+ static var bookmarksBar: Bool {+ get { flag("bookmarksBar", false) }+ set { store(newValue, "bookmarksBar") }+ }+/// Settings › Appearance › Alternating row colors: every other row of Details and Columns, and every/// other line of List, lightly shaded (settings.rs `alternating_rows`).static var alternatingRows: Bool {@@ -268,6 +274,11 @@ extension SettingsContent {detail: String(localized: "The tabs, the address bar and the command bar are thinner, and the content reaches the window's right and bottom edges. Icons and text keep their size."),icon: "minimize-2",control: .toggle(get: { AppSettings.compactWindow }, set: { AppSettings.compactWindow = $0 })),+ .card(+ title: String(localized: "Bookmarks bar"),+ detail: String(localized: "A row of bookmarks under the address bar, as browsers have. Drop folders on it; its menu imports a browser's bookmarks."),+ icon: "bookmark",+ control: .toggle(get: { AppSettings.bookmarksBar }, set: { AppSettings.bookmarksBar = $0 })),.card(title: String(localized: "Alternating row colors"),detail: String(localized: "In Details, List and Columns, every other row is lightly shaded, so that rows next to each other are easier to tell apart."),