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: up to four lines of a name in the grid, and a play mark on videos

gelenmedyadca3de65f8f0
diff --git a/macos/Sources/RustyFiles/FileListController.swift b/macos/Sources/RustyFiles/FileListController.swift
index d53a5544..cd4dbba4 100644
--- a/macos/Sources/RustyFiles/FileListController.swift
+++ b/macos/Sources/RustyFiles/FileListController.swift
@@ -1,5 +1,6 @@
import AppKit
import Quartz
+import UniformTypeIdentifiers
/// Details (the table), or the grid in one of its styles (folder_view.rs `GridStyle`): Tiles,
/// Cards (wide, with type, size and date beside the picture) and List (a small icon and the
@@ -783,6 +784,8 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
showHidden = AppSettings.showHidden
case "hoverDetails", "alternatingRows":
if folder != nil { reloadItems() }
+ case "tileNameLines", "videoBadge":
+ tileSizeChanged()
case "showSystemFiles":
setShowSystemFiles(show: AppSettings.showSystemFiles)
rearrange()
@@ -2481,6 +2484,7 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDele
tile.facts.textColor = Palette.of(collectionView).textSecondary
}
tile.label.textColor = Palette.of(collectionView).text
+ tile.isVideo = !entry.isDir && (UTType(filenameExtension: (entry.name as NSString).pathExtension)?.conforms(to: .movie) ?? false)
tile.alphaValue = entry.hidden || Clipboard.isCut(path) ? 0.6 : 1
tile.isSelected = item.isSelected
tile.detailTip = AppSettings.hoverDetails ? { [weak self] in self?.hoverDetails(row: row) } : nil
diff --git a/macos/Sources/RustyFiles/Settings.swift b/macos/Sources/RustyFiles/Settings.swift
index 67a38f3a..dff0e282 100644
--- a/macos/Sources/RustyFiles/Settings.swift
+++ b/macos/Sources/RustyFiles/Settings.swift
@@ -194,6 +194,18 @@ enum AppSettings {
set { set(newValue, "showThumbnails") }
}
+ /// A play mark on videos' pictures in the grid.
+ static var videoBadge: Bool {
+ get { bool("videoBadge", true) }
+ set { set(newValue, "videoBadge") }
+ }
+
+ /// Lines of a name under a tile in the grid, 2 to 4.
+ static var tileNameLines: Int {
+ get { TileMetrics.nameLines }
+ set { set(newValue, "tileNameLines") }
+ }
+
static var decimalSizes: Bool {
get { bool("decimalSizes", false) }
set { set(newValue, "decimalSizes") }
diff --git a/macos/Sources/RustyFiles/SettingsView.swift b/macos/Sources/RustyFiles/SettingsView.swift
index f7e254e9..fce979d0 100644
--- a/macos/Sources/RustyFiles/SettingsView.swift
+++ b/macos/Sources/RustyFiles/SettingsView.swift
@@ -158,6 +158,14 @@ enum SettingsContent {
.card(
title: String(localized: "Show thumbnails"), detail: String(localized: "Pictures of the files themselves in the Tiles layout."), icon: "image",
control: .toggle(get: { AppSettings.showThumbnails }, set: { AppSettings.showThumbnails = $0 })),
+ .card(
+ title: String(localized: "Mark videos"), detail: String(localized: "A small play mark on a video's picture in the grid, so it is told from a photo."), icon: "circle-play",
+ control: .toggle(get: { AppSettings.videoBadge }, set: { AppSettings.videoBadge = $0 })),
+ .card(
+ title: String(localized: "Name lines in the grid"), detail: String(localized: "How many lines of a long name show under a tile."), icon: "text",
+ control: .choice(
+ options: [("2", "2"), ("3", "3"), ("4", "4")],
+ get: { String(AppSettings.tileNameLines) }, set: { AppSettings.tileNameLines = Int($0) ?? 2 })),
.section(String(localized: "Behaviours")),
.card(
title: String(localized: "Size format"), detail: String(localized: "Binary: 1 KB = 1024 bytes. Decimal: 1 KB = 1000 bytes, as macOS counts."),
diff --git a/macos/Sources/RustyFiles/Tiles.swift b/macos/Sources/RustyFiles/Tiles.swift
index ebf8cf8a..5e7587d0 100644
--- a/macos/Sources/RustyFiles/Tiles.swift
+++ b/macos/Sources/RustyFiles/Tiles.swift
@@ -14,7 +14,12 @@ enum TileMetrics {
return min(max(v, 0), sizes.count - 1)
}
static var width: CGFloat { sizes[size].0 }
- static var rowHeight: CGFloat { sizes[size].1 }
+ /// Lines of a name under a tile (2 to 4; Windows' tile_name_lines, issue 452): the row grows
+ /// by a line for each one past two.
+ static var nameLines: Int { min(max(UserDefaults.standard.object(forKey: "tileNameLines") as? Int ?? 2, 2), 4) }
+ static var rowHeight: CGFloat { sizes[size].1 + CGFloat(nameLines - 2) * lineHeight }
+ /// One line of `text_xs` (12 pt).
+ static let lineHeight: CGFloat = 15
static let gap: CGFloat = 4
/// The picture drawn: three quarters of the one asked for.
static var visual: CGFloat { sizes[size].2 * 0.75 }
@@ -110,6 +115,9 @@ final class TileView: HoverView, NSViewToolTipOwner {
/// (a tile moved by the layout may now be on the other kind of line)
override var frame: NSRect { didSet { if style == .list && frame.origin != oldValue.origin { needsDisplay = true } } }
var isThumbnail = false { didSet { picture.layer?.cornerRadius = isThumbnail ? 4 : 0 } }
+ /// A small play mark on a video's picture, so it is told from a photo (Windows' video_badge).
+ let badge = NSImageView()
+ var isVideo = false { didSet { if isVideo != oldValue { applyStyle(); needsLayout = true } } }
override init(frame: NSRect) {
super.init(frame: frame)
@@ -118,8 +126,8 @@ final class TileView: HoverView, NSViewToolTipOwner {
picture.layer?.masksToBounds = true
label.font = Metrics.textXs
label.alignment = .center
- // two lines at most, the second ending in "…" (a name cut at both ends reads as broken)
- label.maximumNumberOfLines = 2
+ // two lines at most (Settings › Name lines in the grid), the last ending in "…"
+ label.maximumNumberOfLines = TileMetrics.nameLines
label.lineBreakMode = .byWordWrapping
label.cell?.truncatesLastVisibleLine = true
label.cell?.lineBreakMode = .byWordWrapping
@@ -129,6 +137,11 @@ final class TileView: HoverView, NSViewToolTipOwner {
addSubview(picture)
addSubview(label)
addSubview(facts)
+ badge.image = NSImage(systemSymbolName: "play.circle.fill", accessibilityDescription: nil)?
+ .withSymbolConfiguration(.init(paletteColors: [.white, NSColor.black.withAlphaComponent(0.55)]))
+ badge.imageScaling = .scaleProportionallyUpOrDown
+ badge.isHidden = true
+ addSubview(badge)
}
private func applyStyle() {
@@ -148,10 +161,11 @@ final class TileView: HoverView, NSViewToolTipOwner {
default:
label.font = Metrics.textXs
label.alignment = .center
- label.maximumNumberOfLines = 2
+ label.maximumNumberOfLines = TileMetrics.nameLines
label.cell?.lineBreakMode = .byWordWrapping
facts.isHidden = true
}
+ badge.isHidden = !(isVideo && style == .tiles && AppSettings.videoBadge)
}
@available(*, unavailable)
@@ -184,6 +198,8 @@ final class TileView: HoverView, NSViewToolTipOwner {
let box = TileMetrics.visual + 4
let boxX = (bounds.width - box) / 2
picture.frame = NSRect(x: boxX + 2, y: 4 + 2, width: TileMetrics.visual, height: TileMetrics.visual)
+ let b = max(16, min(28, TileMetrics.visual / 4))
+ badge.frame = NSRect(x: picture.frame.minX + 4, y: picture.frame.maxY - b - 4, width: b, height: b)
label.frame = NSRect(x: 4, y: 4 + box + 4, width: bounds.width - 8, height: bounds.height - (4 + box + 4) - 4)
}