PM-Oberfläche: Favoriten/Navigator/Aufgaben, Tabs, PM-Filter, PM-Kacheln, IPTC-Layout wie PM, ⌘I Mass-Edit, ⌘U Upload, Code-Ersetzung live, 8 Farbklassen, paralleles + gecachtes Metadaten-Laden, BILDER/INPUT+SENT
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
This commit is contained in:
1 parent
d100249c12
commit
c0ee93995f
18 files changed
+1311
-515
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import SwiftUI
|
||||
import LichtkastenCore
|
||||
|
||||
/// Main browser window in Photo Mechanic's layout:
|
||||
/// sidebar (Favorites / Navigator / Tasks) · tabs · filter bar · contact sheet · status bar.
|
||||
struct ContentView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@EnvironmentObject var uploads: UploadQueue
|
||||
@@ -9,10 +11,13 @@ struct ContentView: View {
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
SidebarView()
|
||||
.navigationSplitViewColumnWidth(min: 180, ideal: 220)
|
||||
PMSidebar()
|
||||
.navigationSplitViewColumnWidth(min: 200, ideal: 260, max: 420)
|
||||
} detail: {
|
||||
VStack(spacing: 0) {
|
||||
TabBar()
|
||||
if state.folder != nil { ContactSheetHeader() }
|
||||
Divider()
|
||||
if state.folder == nil {
|
||||
EmptyStateView()
|
||||
} else if state.previewMode {
|
||||
@@ -20,11 +25,7 @@ struct ContentView: View {
|
||||
} else {
|
||||
ContactSheetView()
|
||||
}
|
||||
StatusBar()
|
||||
}
|
||||
.inspector(isPresented: $state.showInspector) {
|
||||
IPTCInspectorView()
|
||||
.inspectorColumnWidth(min: 300, ideal: 360, max: 520)
|
||||
PMStatusBar()
|
||||
}
|
||||
}
|
||||
.navigationTitle(state.folder?.lastPathComponent ?? "Lichtkasten")
|
||||
@@ -36,7 +37,7 @@ struct ContentView: View {
|
||||
if let req { openWindow(id: req.id) }
|
||||
}
|
||||
.sheet(isPresented: $state.showTemplatePicker) { TemplatePickerSheet() }
|
||||
.sheet(isPresented: $state.showTemplateManager) { TemplateManagerView().frame(minWidth: 900, minHeight: 620) }
|
||||
.sheet(isPresented: $state.showTemplateManager) { TemplateManagerView().frame(minWidth: 1280, minHeight: 760) }
|
||||
.sheet(isPresented: $state.showIngest) { IngestView() }
|
||||
.alert(item: $state.alert) { a in
|
||||
Alert(title: Text(a.title), message: Text(a.message), dismissButton: .default(Text("OK")))
|
||||
@@ -49,7 +50,7 @@ struct EmptyStateView: View {
|
||||
var body: some View {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "photo.on.rectangle.angled").font(.system(size: 56)).foregroundStyle(.secondary)
|
||||
Text("Ordner öffnen oder Karte ingesten").font(.title2)
|
||||
Text("Ordner in Favoriten oder Navigator wählen").font(.title2)
|
||||
HStack {
|
||||
Button("Ordner öffnen … (⌘O)") { state.chooseFolder() }
|
||||
Button("Ingest … (⌘G)") { state.showIngest = true }
|
||||
@@ -60,6 +61,8 @@ struct EmptyStateView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Toolbar (actions only – filters live in the contact sheet header like PM)
|
||||
|
||||
struct MainToolbar: ToolbarContent {
|
||||
@EnvironmentObject var state: AppState
|
||||
@EnvironmentObject var uploads: UploadQueue
|
||||
@@ -67,65 +70,34 @@ struct MainToolbar: ToolbarContent {
|
||||
|
||||
var body: some ToolbarContent {
|
||||
ToolbarItemGroup(placement: .navigation) {
|
||||
Button { state.chooseFolder() } label: { Label("Öffnen", systemImage: "folder") }
|
||||
Button { state.toggleRawSent() } label: {
|
||||
Label(state.isInSentFolder ? "RAW" : state.sentFolderName,
|
||||
systemImage: state.isInSentFolder ? "camera" : "paperplane")
|
||||
}
|
||||
.help(state.isInSentFolder ? "Zum RAW-Ordner (⌘⌥S)" : "Zum \(state.sentFolderName)-Ordner (⌘⌥S)")
|
||||
.help(state.isInSentFolder ? "Zum RAW/INPUT-Ordner (⌘⌥S)" : "Zum \(state.sentFolderName)-Ordner (⌘⌥S)")
|
||||
.disabled(state.folder == nil)
|
||||
}
|
||||
ToolbarItemGroup(placement: .primaryAction) {
|
||||
Picker("Filter", selection: $state.filter) {
|
||||
Text("Alle").tag(ItemFilter.all)
|
||||
Text("Getaggt").tag(ItemFilter.tagged)
|
||||
Text("Nicht getaggt").tag(ItemFilter.untagged)
|
||||
Divider()
|
||||
ForEach(1...5, id: \.self) { n in Text("≥ \(n) ★").tag(ItemFilter.minRating(n)) }
|
||||
Divider()
|
||||
ForEach(ColorLabel.allCases, id: \.self) { l in Text(l.germanName).tag(ItemFilter.label(l)) }
|
||||
}
|
||||
.frame(width: 130)
|
||||
.help("Filter")
|
||||
|
||||
Picker("Sortierung", selection: $state.sortOrder) {
|
||||
ForEach(SortOrder.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
.frame(width: 130)
|
||||
|
||||
Slider(value: $state.settings.thumbnailSize, in: 110...420)
|
||||
.frame(width: 110)
|
||||
.help("Vorschaugröße")
|
||||
|
||||
Button { state.showTemplatePicker = true } label: { Label("Vorlage", systemImage: "text.badge.plus") }
|
||||
.help("IPTC-Vorlage anwenden (⌘⇧I)")
|
||||
|
||||
Button { state.showIngest = true } label: { Label("Ingest", systemImage: "sdcard") }
|
||||
.help("Ingest (⌘G)")
|
||||
Button { state.openWindow("iptc") } label: { Label("Info", systemImage: "info.circle") }
|
||||
.help("IPTC-Info für ein Bild (I)")
|
||||
Button { state.openWindow("iptc-batch") } label: { Label("Auswahl", systemImage: "square.stack.3d.up") }
|
||||
.help("IPTC für alle ausgewählten Bilder (⌘I)")
|
||||
Menu {
|
||||
Button("Bearbeiten (⌘E)") { state.sendToLightroom(export: false, develop: true) }
|
||||
Button("Nur importieren (⌘⇧L)") { state.sendToLightroom(export: false) }
|
||||
Button("Importieren + Vorgabe + JPEG (⌘⌥L)") { state.sendToLightroom(export: true) }
|
||||
Button("Vorgabe + JPEG nach SENT (⌘⌥L)") { state.sendToLightroom(export: true) }
|
||||
} label: {
|
||||
Label("Lightroom", systemImage: "square.and.arrow.up.on.square")
|
||||
Label("Lightroom", systemImage: "camera.aperture")
|
||||
} primaryAction: {
|
||||
state.sendToLightroom(export: false, develop: true)
|
||||
}
|
||||
.help("Auswahl an Lightroom Classic senden")
|
||||
|
||||
Menu {
|
||||
ForEach(state.settings.ftpDestinations) { d in
|
||||
Button("FTP: \(d.name)") { state.upload(to: d.id.uuidString) }
|
||||
}
|
||||
if state.settings.immich.enabled {
|
||||
Button("Immich") { state.upload(to: "immich") }
|
||||
}
|
||||
Divider()
|
||||
Button("Aufgaben-Fenster …") { state.openWindow("tasks") }
|
||||
} label: {
|
||||
.help("In Lightroom Classic bearbeiten (⌘E)")
|
||||
Button { state.openWindow("upload") } label: {
|
||||
Label(uploads.activeCount > 0 ? "Upload (\(uploads.activeCount))" : "Upload", systemImage: "icloud.and.arrow.up")
|
||||
}
|
||||
|
||||
Button { state.openWindow("iptc") } label: { Label("IPTC", systemImage: "info.circle") }
|
||||
.help("IPTC-Info (I / ⌘I)")
|
||||
.help("Upload-Fenster (⌘U)")
|
||||
Button { state.openWindow("tasks") } label: {
|
||||
Label(tasks.runningCount > 0 ? "Aufgaben (\(tasks.runningCount))" : "Aufgaben", systemImage: "list.bullet.rectangle")
|
||||
}
|
||||
@@ -133,83 +105,341 @@ struct MainToolbar: ToolbarContent {
|
||||
}
|
||||
}
|
||||
|
||||
struct StatusBar: View {
|
||||
// MARK: - Tabs
|
||||
|
||||
struct TabBar: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 4) {
|
||||
ForEach(state.tabs, id: \.self) { url in
|
||||
let active = state.folder == url
|
||||
HStack(spacing: 6) {
|
||||
Button { state.closeTab(url) } label: { Image(systemName: "xmark.circle.fill") }
|
||||
.buttonStyle(.plain).foregroundStyle(.secondary)
|
||||
Image(systemName: "folder.fill").foregroundStyle(.secondary)
|
||||
Text(url.lastPathComponent).lineLimit(1)
|
||||
if active {
|
||||
Text("\(state.visible.count)")
|
||||
.font(.caption.monospacedDigit())
|
||||
.padding(.horizontal, 5)
|
||||
.background(Capsule().fill(Color.secondary.opacity(0.3)))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.vertical, 3)
|
||||
.background(RoundedRectangle(cornerRadius: 5).fill(active ? Color.secondary.opacity(0.28) : Color.clear))
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { state.open(folder: url) }
|
||||
.help(url.path)
|
||||
}
|
||||
Button { state.newTab() } label: { Image(systemName: "plus.circle") }
|
||||
.buttonStyle(.plain)
|
||||
.help("Neuer Tab")
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.vertical, 4)
|
||||
.background(.bar)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - PM filter bar
|
||||
|
||||
struct ContactSheetHeader: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
Slider(value: $state.settings.thumbnailSize, in: 140...460)
|
||||
.frame(width: 140)
|
||||
.help("Vorschaugröße")
|
||||
|
||||
Picker("", selection: $state.sortOrder) {
|
||||
ForEach(SortOrder.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
.labelsHidden()
|
||||
.frame(width: 140)
|
||||
Toggle("Umkehren", isOn: $state.reverseSort).toggleStyle(.checkbox)
|
||||
|
||||
Picker("", selection: $state.filter.tag) {
|
||||
ForEach(TagFilter.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
.labelsHidden()
|
||||
.frame(width: 130)
|
||||
|
||||
Spacer(minLength: 8)
|
||||
|
||||
// Stars filter (PM: checkbox + 0★…5★ toggles)
|
||||
Toggle("", isOn: $state.filter.ratingOn).toggleStyle(.checkbox).labelsHidden()
|
||||
.help("Nach Sternen filtern")
|
||||
HStack(spacing: 0) {
|
||||
ForEach(0...5, id: \.self) { n in
|
||||
let on = state.filter.ratings.contains(n)
|
||||
Button { toggle(rating: n) } label: {
|
||||
Text("\(n)★").font(.system(size: 11, weight: on ? .bold : .regular))
|
||||
.frame(width: 30, height: 20)
|
||||
.background(on ? Color.accentColor.opacity(0.45) : Color.secondary.opacity(0.15))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.clipShape(RoundedRectangle(cornerRadius: 4))
|
||||
.opacity(state.filter.ratingOn ? 1 : 0.5)
|
||||
|
||||
// Color class filter (PM: checkbox + color swatches, last = no color)
|
||||
Toggle("", isOn: $state.filter.colorOn).toggleStyle(.checkbox).labelsHidden()
|
||||
.help("Nach Farbklasse filtern")
|
||||
HStack(spacing: 0) {
|
||||
ForEach(ColorLabel.allCases, id: \.self) { l in
|
||||
swatch(l.color, n: l.pmColorClass, help: "\(l.pmColorClass) – \(l.germanName)")
|
||||
}
|
||||
swatch(.clear, n: 0, help: "Ohne Farbklasse")
|
||||
}
|
||||
.clipShape(RoundedRectangle(cornerRadius: 4))
|
||||
.opacity(state.filter.colorOn ? 1 : 0.5)
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 6)
|
||||
}
|
||||
|
||||
private func swatch(_ c: Color, n: Int, help: String) -> some View {
|
||||
let on = state.filter.colors.contains(n)
|
||||
return Button { toggle(color: n) } label: {
|
||||
ZStack {
|
||||
if n == 0 {
|
||||
Image(systemName: "checkerboard.rectangle").font(.system(size: 12)).foregroundStyle(.secondary)
|
||||
} else {
|
||||
c
|
||||
}
|
||||
if on { Image(systemName: "checkmark").font(.system(size: 10, weight: .bold)).foregroundStyle(.white).shadow(radius: 1) }
|
||||
}
|
||||
.frame(width: 20, height: 20)
|
||||
.overlay(Rectangle().stroke(on ? Color.white : Color.clear, lineWidth: 1.5))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help(help)
|
||||
}
|
||||
|
||||
private func toggle(rating n: Int) {
|
||||
if state.filter.ratings.contains(n) { state.filter.ratings.remove(n) } else { state.filter.ratings.insert(n) }
|
||||
state.filter.ratingOn = !state.filter.ratings.isEmpty
|
||||
}
|
||||
|
||||
private func toggle(color n: Int) {
|
||||
if state.filter.colors.contains(n) { state.filter.colors.remove(n) } else { state.filter.colors.insert(n) }
|
||||
state.filter.colorOn = !state.filter.colors.isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Status bar
|
||||
|
||||
struct PMStatusBar: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@EnvironmentObject var uploads: UploadQueue
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
if state.loadingMetadata { ProgressView().controlSize(.small) }
|
||||
Text(state.statusText).lineLimit(1)
|
||||
Text(summary).lineLimit(1).truncationMode(.middle)
|
||||
Spacer()
|
||||
if state.lrPendingCount > 0 {
|
||||
Label("LR: \(state.lrPendingCount) Auftrag/Aufträge", systemImage: "hourglass")
|
||||
}
|
||||
if uploads.activeCount > 0 {
|
||||
Label("\(uploads.activeCount) Uploads", systemImage: "arrow.up.circle")
|
||||
.onTapGesture { state.openWindow("tasks") }
|
||||
}
|
||||
if state.lrPendingCount > 0 { Label("LR: \(state.lrPendingCount)", systemImage: "hourglass") }
|
||||
if uploads.failedCount > 0 {
|
||||
Label("\(uploads.failedCount) fehlgeschlagen", systemImage: "exclamationmark.triangle.fill")
|
||||
Label("\(uploads.failedCount) Upload(s) fehlgeschlagen", systemImage: "exclamationmark.triangle.fill")
|
||||
.foregroundStyle(.red)
|
||||
.onTapGesture { state.openWindow("tasks") }
|
||||
}
|
||||
Text("\(state.selection.count) / \(state.visible.count) ausgewählt")
|
||||
.foregroundStyle(.secondary)
|
||||
if !state.statusText.isEmpty { Text(state.statusText).foregroundStyle(.secondary).lineLimit(1) }
|
||||
}
|
||||
.font(.callout)
|
||||
.font(.system(size: 11))
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 5)
|
||||
.padding(.vertical, 4)
|
||||
.background(.bar)
|
||||
}
|
||||
|
||||
/// "Ausgewählt 1 von 2189 (3,22 MB) | 2189 gesamt | /Users/…/datei.jpg" like PM.
|
||||
private var summary: String {
|
||||
let sel = state.selectedItems.count
|
||||
let size = ByteCountFormatter.string(fromByteCount: state.selectedBytes, countStyle: .file)
|
||||
var parts = ["Ausgewählt \(sel) von \(state.visible.count) (\(size))", "\(state.items.count) gesamt"]
|
||||
if state.filter.isActive { parts.append("Filter aktiv") }
|
||||
if let c = state.cursorItem { parts.append(c.primary.path) }
|
||||
return parts.joined(separator: " | ")
|
||||
}
|
||||
}
|
||||
|
||||
struct SidebarView: View {
|
||||
// MARK: - Sidebar: Favorites / Navigator / Tasks
|
||||
|
||||
struct PMSidebar: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@EnvironmentObject var tasks: TaskCenter
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Section("Favoriten") {
|
||||
ForEach(state.settings.favoriteFolders, id: \.self) { path in
|
||||
folderRow(path)
|
||||
.contextMenu { Button("Aus Favoriten entfernen") { state.settings.favoriteFolders.removeAll { $0 == path } } }
|
||||
}
|
||||
if let f = state.folder, !state.settings.favoriteFolders.contains(f.path) {
|
||||
Button { state.settings.favoriteFolders.append(f.path) } label: {
|
||||
Label("Aktuellen Ordner merken", systemImage: "star")
|
||||
VSplitView {
|
||||
panel("Favoriten") {
|
||||
List {
|
||||
ForEach(state.settings.favoriteFolders, id: \.self) { path in
|
||||
folderRow(URL(fileURLWithPath: path))
|
||||
.contextMenu {
|
||||
Button("In neuem Tab öffnen") { state.open(folder: URL(fileURLWithPath: path), newTab: true) }
|
||||
Button("Aus Favoriten entfernen") { state.settings.favoriteFolders.removeAll { $0 == path } }
|
||||
}
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.onMove { state.settings.favoriteFolders.move(fromOffsets: $0, toOffset: $1) }
|
||||
}
|
||||
.listStyle(.sidebar)
|
||||
} accessory: {
|
||||
if let f = state.folder, !state.settings.favoriteFolders.contains(f.path) {
|
||||
Button { state.settings.favoriteFolders.append(f.path) } label: { Image(systemName: "plus") }
|
||||
.buttonStyle(.borderless).help("Aktuellen Ordner zu Favoriten")
|
||||
}
|
||||
}
|
||||
Section("Zuletzt") {
|
||||
ForEach(state.settings.recentFolders, id: \.self) { folderRow($0) }
|
||||
}
|
||||
Section("Wechseldatenträger") {
|
||||
ForEach(volumes(), id: \.self) { v in
|
||||
Button { state.showIngest = true } label: { Label(v.lastPathComponent, systemImage: "sdcard") }
|
||||
.buttonStyle(.borderless)
|
||||
.frame(minHeight: 90, idealHeight: 160)
|
||||
|
||||
panel("Navigator") {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
ForEach(navigatorRoots(), id: \.self) { FolderTreeRow(url: $0, depth: 0) }
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
} accessory: { EmptyView() }
|
||||
.frame(minHeight: 150, idealHeight: 320)
|
||||
|
||||
panel("Aufgaben") {
|
||||
if tasks.tasks.isEmpty {
|
||||
Text("Keine Aufgaben").font(.caption).foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
ForEach(tasks.tasks.prefix(12)) { t in MiniTaskRow(task: t) }
|
||||
}
|
||||
.padding(8)
|
||||
}
|
||||
}
|
||||
} accessory: {
|
||||
Button { state.openWindow("tasks") } label: { Image(systemName: "arrow.up.forward.app") }
|
||||
.buttonStyle(.borderless).help("Aufgaben-Fenster (⌘⌥U)")
|
||||
}
|
||||
.frame(minHeight: 80, idealHeight: 150)
|
||||
}
|
||||
.listStyle(.sidebar)
|
||||
}
|
||||
|
||||
private func folderRow(_ path: String) -> some View {
|
||||
let url = URL(fileURLWithPath: path)
|
||||
return Button { state.open(folder: url) } label: {
|
||||
Label(url.lastPathComponent, systemImage: state.folder?.path == path ? "folder.fill" : "folder")
|
||||
private func panel<C: View, A: View>(_ title: String, @ViewBuilder content: () -> C, @ViewBuilder accessory: () -> A) -> some View {
|
||||
VStack(spacing: 0) {
|
||||
HStack {
|
||||
Text(title).font(.system(size: 12, weight: .semibold))
|
||||
Spacer()
|
||||
accessory()
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 5)
|
||||
.background(Color.secondary.opacity(0.12))
|
||||
content()
|
||||
}
|
||||
}
|
||||
|
||||
private func folderRow(_ url: URL) -> some View {
|
||||
Button { state.open(folder: url) } label: {
|
||||
Label(url.lastPathComponent, systemImage: state.folder == url ? "folder.fill" : "folder")
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.help(path)
|
||||
.help(url.path)
|
||||
}
|
||||
|
||||
private func volumes() -> [URL] {
|
||||
let keys: [URLResourceKey] = [.volumeIsRemovableKey]
|
||||
let vols = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: keys, options: [.skipHiddenVolumes]) ?? []
|
||||
return vols.filter { v in
|
||||
(try? v.resourceValues(forKeys: Set(keys)).volumeIsRemovable) == true
|
||||
|| FileManager.default.fileExists(atPath: v.appendingPathComponent("DCIM").path)
|
||||
/// Like PM: volumes, home, and the usual home folders.
|
||||
private func navigatorRoots() -> [URL] {
|
||||
let fm = FileManager.default
|
||||
let home = fm.homeDirectoryForCurrentUser
|
||||
var roots: [URL] = []
|
||||
let vols = fm.mountedVolumeURLs(includingResourceValuesForKeys: nil, options: [.skipHiddenVolumes]) ?? []
|
||||
roots += vols
|
||||
roots.append(home)
|
||||
for name in ["Desktop", "Pictures", "Documents", "Downloads"] {
|
||||
let u = home.appendingPathComponent(name)
|
||||
if fm.fileExists(atPath: u.path) { roots.append(u) }
|
||||
}
|
||||
let nextcloud = home.appendingPathComponent("Nextcloud")
|
||||
if fm.fileExists(atPath: nextcloud.path) { roots.append(nextcloud) }
|
||||
return roots
|
||||
}
|
||||
}
|
||||
|
||||
struct MiniTaskRow: View {
|
||||
let task: BackgroundTask
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: task.systemImage).foregroundStyle(.secondary)
|
||||
Text(task.title).font(.caption).lineLimit(1)
|
||||
}
|
||||
if task.isRunning {
|
||||
if task.total > 0 { ProgressView(value: task.progress).controlSize(.small) } else { ProgressView().controlSize(.small) }
|
||||
} else {
|
||||
Text(task.detail).font(.caption2).foregroundStyle(.secondary).lineLimit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Lazily expanding folder tree (children are only read when a row is opened).
|
||||
struct FolderTreeRow: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
let url: URL
|
||||
let depth: Int
|
||||
@State private var expanded = false
|
||||
@State private var children: [URL]?
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
HStack(spacing: 4) {
|
||||
Button {
|
||||
expanded.toggle()
|
||||
if expanded && children == nil { children = Self.subfolders(of: url) }
|
||||
} label: {
|
||||
Image(systemName: expanded ? "chevron.down" : "chevron.right")
|
||||
.font(.system(size: 9, weight: .bold))
|
||||
.frame(width: 12)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
Image(systemName: depth == 0 && url.path.hasPrefix("/Volumes") ? "externaldrive" : "folder")
|
||||
.foregroundStyle(.secondary)
|
||||
Text(displayName).lineLimit(1)
|
||||
.fontWeight(state.folder == url ? .semibold : .regular)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.leading, CGFloat(depth) * 14 + 6)
|
||||
.padding(.vertical, 2)
|
||||
.background(state.folder == url ? Color.accentColor.opacity(0.25) : Color.clear)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture(count: 1) { state.open(folder: url) }
|
||||
.contextMenu {
|
||||
Button("In neuem Tab öffnen") { state.open(folder: url, newTab: true) }
|
||||
Button("Zu Favoriten") { if !state.settings.favoriteFolders.contains(url.path) { state.settings.favoriteFolders.append(url.path) } }
|
||||
Button("Im Finder zeigen") { NSWorkspace.shared.activateFileViewerSelecting([url]) }
|
||||
}
|
||||
if expanded, let children {
|
||||
ForEach(children, id: \.self) { FolderTreeRow(url: $0, depth: depth + 1) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var displayName: String {
|
||||
let fm = FileManager.default
|
||||
if url == fm.homeDirectoryForCurrentUser { return "@" + url.lastPathComponent }
|
||||
return fm.displayName(atPath: url.path)
|
||||
}
|
||||
|
||||
static func subfolders(of url: URL) -> [URL] {
|
||||
let keys: [URLResourceKey] = [.isDirectoryKey, .isPackageKey]
|
||||
let list = (try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: keys, options: [.skipsHiddenFiles])) ?? []
|
||||
return list.filter {
|
||||
let v = try? $0.resourceValues(forKeys: Set(keys))
|
||||
return v?.isDirectory == true && v?.isPackage != true
|
||||
}
|
||||
.sorted { $0.lastPathComponent.localizedStandardCompare($1.lastPathComponent) == .orderedAscending }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user