Lichtkasten v0.1: Culling, IPTC (PM-kompatibel), Vorlagen, FTP/Immich, Lightroom-Bridge
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
This commit is contained in:
37 files changed
+4431
No files matched your search
@@ -0,0 +1,156 @@
|
||||
import SwiftUI
|
||||
import LichtkastenCore
|
||||
|
||||
struct ContactSheetView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geo in
|
||||
let size = CGFloat(state.settings.thumbnailSize)
|
||||
let spacing: CGFloat = 10
|
||||
let cols = max(1, Int((geo.size.width - 20 + spacing) / (size + spacing)))
|
||||
ScrollViewReader { proxy in
|
||||
ScrollView {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.fixed(size), spacing: spacing), count: cols), spacing: spacing) {
|
||||
ForEach(state.visible) { item in
|
||||
ThumbnailCell(item: item, size: size,
|
||||
selected: state.selection.contains(item.id),
|
||||
isCursor: state.cursorID == item.id)
|
||||
.id(item.id)
|
||||
.contentShape(Rectangle())
|
||||
.gesture(TapGesture(count: 2).onEnded {
|
||||
state.cursorID = item.id
|
||||
state.selection = [item.id]
|
||||
state.previewMode = true
|
||||
}.exclusively(before: TapGesture().onEnded {
|
||||
state.click(item.id, modifiers: NSEvent.modifierFlags)
|
||||
}))
|
||||
.contextMenu { ItemContextMenu(item: item) }
|
||||
}
|
||||
}
|
||||
.padding(10)
|
||||
}
|
||||
.background(Color(nsColor: .underPageBackgroundColor))
|
||||
.onChange(of: state.cursorID) { _, id in
|
||||
if let id { proxy.scrollTo(id) }
|
||||
}
|
||||
.onAppear { state.gridColumns = cols }
|
||||
.onChange(of: cols) { _, c in state.gridColumns = c }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ItemContextMenu: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
let item: PhotoItem
|
||||
|
||||
var body: some View {
|
||||
Button("Tag umschalten") { ensureSelected(); state.toggleTag() }
|
||||
Menu("Bewertung") {
|
||||
ForEach(0...5, id: \.self) { n in
|
||||
Button(n == 0 ? "Keine" : String(repeating: "★", count: n)) { ensureSelected(); state.setRating(n) }
|
||||
}
|
||||
}
|
||||
Menu("Farbmarkierung") {
|
||||
ForEach(ColorLabel.allCases, id: \.self) { l in Button(l.germanName) { ensureSelected(); state.setLabel(l) } }
|
||||
}
|
||||
Divider()
|
||||
Button("An Lightroom senden") { ensureSelected(); state.sendToLightroom(export: false) }
|
||||
Button("Im Finder zeigen") { NSWorkspace.shared.activateFileViewerSelecting([item.primary]) }
|
||||
Button("Als Vorlage übernehmen") {
|
||||
state.templates.append(IPTCTemplate(name: item.baseName, values: item.iptc))
|
||||
}
|
||||
}
|
||||
|
||||
private func ensureSelected() {
|
||||
if !state.selection.contains(item.id) { state.selection = [item.id]; state.cursorID = item.id }
|
||||
}
|
||||
}
|
||||
|
||||
struct ThumbnailCell: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
let item: PhotoItem
|
||||
let size: CGFloat
|
||||
let selected: Bool
|
||||
let isCursor: Bool
|
||||
@State private var image: NSImage?
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 4) {
|
||||
ZStack {
|
||||
Rectangle().fill(Color.black.opacity(0.25))
|
||||
if let image {
|
||||
Image(nsImage: image).resizable().interpolation(.medium).scaledToFit()
|
||||
} else {
|
||||
ProgressView().controlSize(.small)
|
||||
}
|
||||
}
|
||||
.frame(width: size - 12, height: (size - 12) * 0.72)
|
||||
.clipped()
|
||||
|
||||
HStack(spacing: 4) {
|
||||
Button {
|
||||
if !state.selection.contains(item.id) { state.selection = [item.id]; state.cursorID = item.id }
|
||||
state.toggleTag()
|
||||
} label: {
|
||||
Image(systemName: item.tagged ? "checkmark.square.fill" : "square")
|
||||
.foregroundStyle(item.tagged ? Color.accentColor : .secondary)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help("Tag (T)")
|
||||
|
||||
Text(item.filename).font(.caption).lineLimit(1).truncationMode(.middle)
|
||||
Spacer(minLength: 2)
|
||||
if !item.companions.isEmpty {
|
||||
Text("+\(item.companions.map { $0.pathExtension.uppercased() }.joined(separator: "+"))")
|
||||
.font(.system(size: 9, weight: .semibold))
|
||||
.padding(.horizontal, 3)
|
||||
.background(RoundedRectangle(cornerRadius: 3).fill(Color.secondary.opacity(0.25)))
|
||||
}
|
||||
}
|
||||
HStack(spacing: 1) {
|
||||
ForEach(1...5, id: \.self) { n in
|
||||
Image(systemName: n <= item.rating ? "star.fill" : "star")
|
||||
.font(.system(size: 9))
|
||||
.foregroundStyle(n <= item.rating ? Color.yellow : Color.secondary.opacity(0.4))
|
||||
}
|
||||
Spacer()
|
||||
if !item.iptc.isEmpty(IPTCField.byID["caption"]!) {
|
||||
Image(systemName: "text.alignleft").font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
.help("Hat Bildunterschrift")
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(6)
|
||||
.frame(width: size)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.fill(selected ? Color.accentColor.opacity(0.35) : Color.gray.opacity(0.14))
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.strokeBorder(item.label.map(\.color) ?? .clear, lineWidth: 3)
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.strokeBorder(isCursor ? Color.white.opacity(0.9) : .clear, lineWidth: 1)
|
||||
)
|
||||
.task(id: item.primary) {
|
||||
image = ImageLoader.shared.cachedThumbnail(state.previewURL(for: item))
|
||||
if image == nil { image = await ImageLoader.shared.thumbnail(for: state.previewURL(for: item)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ColorLabel {
|
||||
var color: Color {
|
||||
switch self {
|
||||
case .red: return .red
|
||||
case .yellow: return .yellow
|
||||
case .green: return .green
|
||||
case .blue: return .blue
|
||||
case .purple: return .purple
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
import SwiftUI
|
||||
import LichtkastenCore
|
||||
|
||||
struct ContentView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@EnvironmentObject var uploads: UploadQueue
|
||||
@State private var keyboard = KeyboardMonitor()
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
SidebarView()
|
||||
.navigationSplitViewColumnWidth(min: 180, ideal: 220)
|
||||
} detail: {
|
||||
VStack(spacing: 0) {
|
||||
if state.folder == nil {
|
||||
EmptyStateView()
|
||||
} else if state.previewMode {
|
||||
PreviewView()
|
||||
} else {
|
||||
ContactSheetView()
|
||||
}
|
||||
StatusBar()
|
||||
}
|
||||
.inspector(isPresented: $state.showInspector) {
|
||||
IPTCInspectorView()
|
||||
.inspectorColumnWidth(min: 300, ideal: 360, max: 520)
|
||||
}
|
||||
}
|
||||
.navigationTitle(state.folder?.lastPathComponent ?? "Lichtkasten")
|
||||
.toolbar { MainToolbar() }
|
||||
.searchable(text: $state.searchText, placement: .toolbar, prompt: "Dateiname, IPTC …")
|
||||
.onAppear { keyboard.install(state: state) }
|
||||
.sheet(isPresented: $state.showTemplatePicker) { TemplatePickerSheet() }
|
||||
.sheet(isPresented: $state.showTemplateManager) { TemplateManagerView().frame(minWidth: 900, minHeight: 620) }
|
||||
.sheet(isPresented: $state.showIngest) { IngestView() }
|
||||
.sheet(isPresented: $state.showUploads) { UploadsView() }
|
||||
.alert(item: $state.alert) { a in
|
||||
Alert(title: Text(a.title), message: Text(a.message), dismissButton: .default(Text("OK")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct EmptyStateView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
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)
|
||||
HStack {
|
||||
Button("Ordner öffnen … (⌘O)") { state.chooseFolder() }
|
||||
Button("Ingest … (⌘G)") { state.showIngest = true }
|
||||
}
|
||||
.controlSize(.large)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
|
||||
struct MainToolbar: ToolbarContent {
|
||||
@EnvironmentObject var state: AppState
|
||||
@EnvironmentObject var uploads: UploadQueue
|
||||
|
||||
var body: some ToolbarContent {
|
||||
ToolbarItemGroup(placement: .navigation) {
|
||||
Button { state.chooseFolder() } label: { Label("Öffnen", systemImage: "folder") }
|
||||
}
|
||||
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)")
|
||||
|
||||
Menu {
|
||||
Button("Nur importieren (⌘⇧L)") { state.sendToLightroom(export: false) }
|
||||
Button("Importieren + Vorgabe + JPEG (⌘⌥L)") { state.sendToLightroom(export: true) }
|
||||
} label: {
|
||||
Label("Lightroom", systemImage: "square.and.arrow.up.on.square")
|
||||
} primaryAction: {
|
||||
state.sendToLightroom(export: false)
|
||||
}
|
||||
.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("Warteschlange anzeigen …") { state.showUploads = true }
|
||||
} label: {
|
||||
Label(uploads.activeCount > 0 ? "Upload (\(uploads.activeCount))" : "Upload", systemImage: "icloud.and.arrow.up")
|
||||
}
|
||||
|
||||
Button { state.showInspector.toggle() } label: { Label("IPTC", systemImage: "sidebar.right") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct StatusBar: 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)
|
||||
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.showUploads = true }
|
||||
}
|
||||
if uploads.failedCount > 0 {
|
||||
Label("\(uploads.failedCount) fehlgeschlagen", systemImage: "exclamationmark.triangle.fill")
|
||||
.foregroundStyle(.red)
|
||||
.onTapGesture { state.showUploads = true }
|
||||
}
|
||||
Text("\(state.selection.count) / \(state.visible.count) ausgewählt")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.font(.callout)
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 5)
|
||||
.background(.bar)
|
||||
}
|
||||
}
|
||||
|
||||
struct SidebarView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
|
||||
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")
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
.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")
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.help(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
import SwiftUI
|
||||
import LichtkastenCore
|
||||
|
||||
/// Editor texts for all fields (lists are kept as raw "a, b, c" text while typing).
|
||||
typealias FieldTexts = [String: String]
|
||||
|
||||
extension IPTCValues {
|
||||
func texts() -> FieldTexts {
|
||||
var t: FieldTexts = [:]
|
||||
for f in IPTCField.all { t[f.id] = self[f] }
|
||||
return t
|
||||
}
|
||||
|
||||
init(texts: FieldTexts) {
|
||||
self.init()
|
||||
for f in IPTCField.all { self[f] = (texts[f.id] ?? "").trimmingCharacters(in: .whitespaces) }
|
||||
}
|
||||
}
|
||||
|
||||
/// The field layout used everywhere (inspector + template editor) – PM Stationery Pad order.
|
||||
struct IPTCFieldsForm: View {
|
||||
@Binding var texts: FieldTexts
|
||||
var mixed: Set<String> = []
|
||||
var dirty: Set<String> = []
|
||||
var onEdit: (String) -> Void = { _ in }
|
||||
@AppStorage("collapsedIPTCSections") private var collapsedRaw = ""
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
ForEach(IPTCSection.allCases, id: \.self) { section in
|
||||
let fields = IPTCField.all.filter { $0.section == section }
|
||||
DisclosureGroup(isExpanded: expandedBinding(section)) {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
ForEach(fields) { field in
|
||||
FieldRow(field: field, text: binding(field), isMixed: mixed.contains(field.id) && !dirty.contains(field.id),
|
||||
isDirty: dirty.contains(field.id))
|
||||
}
|
||||
}
|
||||
.padding(.top, 4)
|
||||
} label: {
|
||||
Text(section.rawValue).font(.headline)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func expandedBinding(_ s: IPTCSection) -> Binding<Bool> {
|
||||
Binding(get: { !collapsedRaw.components(separatedBy: "|").contains(s.rawValue) },
|
||||
set: { expanded in
|
||||
var set = Set(collapsedRaw.components(separatedBy: "|").filter { !$0.isEmpty })
|
||||
if expanded { set.remove(s.rawValue) } else { set.insert(s.rawValue) }
|
||||
collapsedRaw = set.sorted().joined(separator: "|")
|
||||
})
|
||||
}
|
||||
|
||||
private func binding(_ f: IPTCField) -> Binding<String> {
|
||||
Binding(get: { texts[f.id] ?? "" },
|
||||
set: { texts[f.id] = $0; onEdit(f.id) })
|
||||
}
|
||||
}
|
||||
|
||||
struct FieldRow: View {
|
||||
let field: IPTCField
|
||||
@Binding var text: String
|
||||
let isMixed: Bool
|
||||
let isDirty: Bool
|
||||
|
||||
private static let variableFields: Set<String> = ["caption", "headline", "objectName", "instructions", "event",
|
||||
"transmissionReference", "keywords"]
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
HStack(spacing: 4) {
|
||||
Text(field.label).font(.caption).foregroundStyle(isDirty ? Color.accentColor : .secondary)
|
||||
if field.kind == .list { Text("(Komma-getrennt)").font(.caption2).foregroundStyle(.tertiary) }
|
||||
Spacer()
|
||||
if let max = field.iimMaxBytes {
|
||||
let used = text.utf8.count
|
||||
if used > 0 {
|
||||
Text("\(used)/\(max)")
|
||||
.font(.caption2.monospacedDigit())
|
||||
.foregroundStyle(used > max && !text.contains("{") ? .red : .secondary)
|
||||
.help("IPTC-IIM-Limit in Bytes. Agenturen kürzen oder lehnen längere Werte ab.")
|
||||
}
|
||||
}
|
||||
if Self.variableFields.contains(field.id) {
|
||||
Menu {
|
||||
ForEach(VariableExpander.documented, id: \.0) { v in
|
||||
Button("\(v.0) – \(v.1)") { text += v.0 }
|
||||
}
|
||||
} label: { Image(systemName: "curlybraces") }
|
||||
.menuStyle(.borderlessButton)
|
||||
.menuIndicator(.hidden)
|
||||
.fixedSize()
|
||||
.help("Variable einfügen")
|
||||
}
|
||||
}
|
||||
if field.kind == .multiline || field.id == "keywords" {
|
||||
TextField(isMixed ? "‹mehrere Werte›" : "", text: $text, axis: .vertical)
|
||||
.lineLimit(field.id == "caption" ? 4...12 : 2...6)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
} else {
|
||||
TextField(isMixed ? "‹mehrere Werte›" : "", text: $text)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Right-hand inspector: edit IPTC of the current selection.
|
||||
struct IPTCInspectorView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@State private var texts: FieldTexts = [:]
|
||||
@State private var mixed: Set<String> = []
|
||||
@State private var dirty: Set<String> = []
|
||||
@State private var loadedSelection: [String] = []
|
||||
@State private var newTemplateName = ""
|
||||
@State private var showSaveTemplate = false
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
header
|
||||
Divider()
|
||||
ScrollView {
|
||||
IPTCFieldsForm(texts: $texts, mixed: mixed, dirty: dirty) { dirty.insert($0) }
|
||||
.padding(12)
|
||||
}
|
||||
Divider()
|
||||
footer
|
||||
}
|
||||
.onAppear(perform: reload)
|
||||
.onChange(of: state.selection) { _, _ in reload() }
|
||||
.onChange(of: state.cursorID) { _, _ in if state.selection.isEmpty { reload() } }
|
||||
.onReceive(state.$items) { _ in
|
||||
// Refresh when metadata arrives / changes, unless the user is editing.
|
||||
if dirty.isEmpty { DispatchQueue.main.async { reload() } }
|
||||
}
|
||||
.alert("Als Vorlage speichern", isPresented: $showSaveTemplate) {
|
||||
TextField("Name", text: $newTemplateName)
|
||||
Button("Speichern") {
|
||||
let values = IPTCValues(texts: texts)
|
||||
state.templates.append(IPTCTemplate(name: newTemplateName.isEmpty ? "Neue Vorlage" : newTemplateName, values: values))
|
||||
}
|
||||
Button("Abbrechen", role: .cancel) {}
|
||||
}
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
HStack {
|
||||
let n = state.selectedItems.count
|
||||
VStack(alignment: .leading) {
|
||||
Text("IPTC").font(.headline)
|
||||
Text(n == 0 ? "Keine Auswahl" : n == 1 ? state.selectedItems[0].filename : "\(n) Bilder ausgewählt")
|
||||
.font(.caption).foregroundStyle(.secondary).lineLimit(1)
|
||||
}
|
||||
Spacer()
|
||||
Menu {
|
||||
ForEach(state.templates) { t in
|
||||
Button(t.name) { state.applyTemplate(t) }
|
||||
}
|
||||
if state.templates.isEmpty { Text("Noch keine Vorlagen") }
|
||||
Divider()
|
||||
Button("Vorlagen verwalten …") { state.showTemplateManager = true }
|
||||
Button("PM-Vorlage importieren …") { state.importPMTemplate() }
|
||||
} label: {
|
||||
Label("Vorlage", systemImage: "doc.on.clipboard")
|
||||
}
|
||||
.fixedSize()
|
||||
}
|
||||
.padding(12)
|
||||
}
|
||||
|
||||
private var footer: some View {
|
||||
HStack {
|
||||
Button("Als Vorlage …") { newTemplateName = ""; showSaveTemplate = true }
|
||||
Spacer()
|
||||
Button("Verwerfen") { dirty = []; reload() }.disabled(dirty.isEmpty)
|
||||
Button("Übernehmen") {
|
||||
let fields = IPTCField.all.filter { dirty.contains($0.id) }
|
||||
state.applyIPTC(IPTCValues(texts: texts), fields: fields)
|
||||
dirty = []
|
||||
}
|
||||
.keyboardShortcut(.return, modifiers: .command)
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(dirty.isEmpty || state.selectedItems.isEmpty)
|
||||
}
|
||||
.padding(12)
|
||||
}
|
||||
|
||||
private func reload() {
|
||||
let items = state.selectedItems
|
||||
let ids = items.map(\.id)
|
||||
if ids != loadedSelection { dirty = [] }
|
||||
loadedSelection = ids
|
||||
guard dirty.isEmpty else { return }
|
||||
guard let first = items.first else { texts = [:]; mixed = []; return }
|
||||
var t = first.iptc.texts()
|
||||
var m = Set<String>()
|
||||
for item in items.dropFirst() {
|
||||
let other = item.iptc.texts()
|
||||
for f in IPTCField.all where (other[f.id] ?? "") != (t[f.id] ?? "") {
|
||||
m.insert(f.id)
|
||||
t[f.id] = ""
|
||||
}
|
||||
}
|
||||
texts = t
|
||||
mixed = m
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import SwiftUI
|
||||
import LichtkastenCore
|
||||
|
||||
struct IngestView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var sources: [URL] = []
|
||||
@State private var running = false
|
||||
@State private var progress: IngestProgress?
|
||||
@State private var error = ""
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Ingest – von Karte kopieren").font(.headline)
|
||||
Form {
|
||||
Section("Quelle") {
|
||||
ForEach(sources, id: \.self) { Text($0.path) }
|
||||
HStack {
|
||||
Button("Quelle hinzufügen …") { pickSource() }
|
||||
Button("Karten automatisch finden") { sources = detectCards() }
|
||||
if !sources.isEmpty { Button("Leeren") { sources = [] } }
|
||||
}
|
||||
}
|
||||
Section("Ziel") {
|
||||
folderRow("Hauptziel", path: $state.settings.ingest.primaryDestination)
|
||||
folderRow("Backup (optional)", path: $state.settings.ingest.backupDestination)
|
||||
TextField("Unterordner", text: $state.settings.ingest.folderPattern, prompt: Text("{year4}/{isodate}"))
|
||||
TextField("Umbenennen (leer = Original)", text: $state.settings.ingest.renamePattern, prompt: Text("{isodate}_{seqn4}"))
|
||||
Stepper("Startnummer {seqn}: \(state.settings.ingest.startSequence)", value: $state.settings.ingest.startSequence, in: 0...999_999)
|
||||
Toggle("Duplikate überspringen", isOn: $state.settings.ingest.skipDuplicates)
|
||||
}
|
||||
Section("Metadaten") {
|
||||
Picker("IPTC-Vorlage", selection: $state.settings.ingest.templateID) {
|
||||
Text("Keine").tag(UUID?.none)
|
||||
ForEach(state.templates) { Text($0.name).tag(UUID?.some($0.id)) }
|
||||
}
|
||||
Toggle("Danach Ordner öffnen", isOn: $state.settings.ingest.openAfterIngest)
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
if let p = progress {
|
||||
ProgressView(value: Double(p.done), total: Double(max(p.total, 1))) {
|
||||
Text("\(p.done)/\(p.total) – \(p.currentFile)").font(.caption)
|
||||
}
|
||||
}
|
||||
if !error.isEmpty { Text(error).foregroundStyle(.red).font(.caption) }
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Abbrechen") { dismiss() }.keyboardShortcut(.cancelAction).disabled(running)
|
||||
Button("Ingest starten") { start() }
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(running || sources.isEmpty || state.settings.ingest.primaryDestination.isEmpty)
|
||||
}
|
||||
}
|
||||
.padding(16)
|
||||
.frame(width: 620, height: 680)
|
||||
.onAppear { if sources.isEmpty { sources = detectCards() } }
|
||||
}
|
||||
|
||||
private func folderRow(_ title: String, path: Binding<String>) -> some View {
|
||||
HStack {
|
||||
TextField(title, text: path)
|
||||
Button("Wählen …") {
|
||||
let p = NSOpenPanel(); p.canChooseDirectories = true; p.canChooseFiles = false; p.canCreateDirectories = true
|
||||
if p.runModal() == .OK, let u = p.url { path.wrappedValue = u.path }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func pickSource() {
|
||||
let p = NSOpenPanel(); p.canChooseDirectories = true; p.canChooseFiles = false; p.allowsMultipleSelection = true
|
||||
if p.runModal() == .OK { sources += p.urls }
|
||||
}
|
||||
|
||||
private func detectCards() -> [URL] {
|
||||
let vols = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: nil, options: [.skipHiddenVolumes]) ?? []
|
||||
return vols.map { $0.appendingPathComponent("DCIM") }.filter { FileManager.default.fileExists(atPath: $0.path) }
|
||||
}
|
||||
|
||||
private func start() {
|
||||
guard let et = state.requireExifTool() else { return }
|
||||
running = true
|
||||
error = ""
|
||||
let settings = state.settings.ingest
|
||||
let srcs = sources
|
||||
Task {
|
||||
do {
|
||||
let folders = try await IngestService.run(sources: srcs, settings: settings, exiftool: et) { p in
|
||||
Task { @MainActor in progress = p }
|
||||
}
|
||||
running = false
|
||||
if let tid = settings.templateID, let template = state.templates.first(where: { $0.id == tid }) {
|
||||
for f in folders {
|
||||
let items = try FolderScanner.scan(folder: f)
|
||||
let meta = try await et.readMetadata(files: items.map(\.primary))
|
||||
let loaded = items.map { item -> PhotoItem in
|
||||
var i = item; i.apply(fileMeta: meta[item.primary.path] ?? [:], sidecarMeta: nil); return i
|
||||
}
|
||||
await state.applyTemplateAndWait(template, to: loaded)
|
||||
}
|
||||
}
|
||||
if settings.openAfterIngest, let first = folders.first { state.open(folder: first) }
|
||||
dismiss()
|
||||
} catch let e {
|
||||
running = false
|
||||
error = e.localizedDescription
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import SwiftUI
|
||||
import LichtkastenCore
|
||||
|
||||
struct PreviewView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@State private var image: NSImage?
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .bottom) {
|
||||
Color.black
|
||||
if let image {
|
||||
if state.zoom100 {
|
||||
ScrollView([.horizontal, .vertical]) {
|
||||
Image(nsImage: image)
|
||||
.frame(width: image.size.width / (NSScreen.main?.backingScaleFactor ?? 2),
|
||||
height: image.size.height / (NSScreen.main?.backingScaleFactor ?? 2))
|
||||
}
|
||||
} else {
|
||||
Image(nsImage: image).resizable().scaledToFit().padding(8)
|
||||
}
|
||||
} else {
|
||||
ProgressView()
|
||||
}
|
||||
if let item = state.cursorItem { infoBar(item) }
|
||||
}
|
||||
.onTapGesture(count: 2) { state.previewMode = false }
|
||||
.task(id: "\(state.cursorID ?? "")|\(state.zoom100)") { await load() }
|
||||
}
|
||||
|
||||
private func load() async {
|
||||
guard let item = state.cursorItem else { image = nil; return }
|
||||
let url = state.previewURL(for: item)
|
||||
// Show the thumbnail immediately, then the big preview.
|
||||
image = ImageLoader.shared.cachedPreview(url) ?? ImageLoader.shared.cachedThumbnail(url)
|
||||
let maxPixel = state.zoom100 ? 8000 : 3200
|
||||
if let big = await ImageLoader.shared.preview(for: url, maxPixel: maxPixel), state.cursorID == item.id {
|
||||
image = big
|
||||
}
|
||||
}
|
||||
|
||||
private func infoBar(_ item: PhotoItem) -> some View {
|
||||
HStack(spacing: 14) {
|
||||
Image(systemName: item.tagged ? "checkmark.square.fill" : "square")
|
||||
Text(item.filename).bold()
|
||||
HStack(spacing: 1) {
|
||||
ForEach(1...5, id: \.self) { n in Image(systemName: n <= item.rating ? "star.fill" : "star") }
|
||||
}
|
||||
.foregroundStyle(.yellow)
|
||||
if let l = item.label { Circle().fill(l.color).frame(width: 10, height: 10) }
|
||||
Spacer()
|
||||
Text([item.exif["Model"], item.exif["LensModel"], item.exif["FocalLength"],
|
||||
item.exif["ExposureTime"].map { "\($0) s" }, item.exif["FNumber"].map { "f/\($0)" },
|
||||
item.exif["ISO"].map { "ISO \($0)" }].compactMap { $0 }.joined(separator: " · "))
|
||||
.foregroundStyle(.secondary)
|
||||
Text(state.zoom100 ? "100 % (Z)" : "Einpassen (Z)").foregroundStyle(.secondary)
|
||||
}
|
||||
.font(.callout)
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 8)
|
||||
.background(.ultraThinMaterial)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
import SwiftUI
|
||||
import LichtkastenCore
|
||||
|
||||
struct SettingsView: View {
|
||||
var body: some View {
|
||||
TabView {
|
||||
GeneralSettings().tabItem { Label("Allgemein", systemImage: "gearshape") }
|
||||
FTPSettings().tabItem { Label("FTP", systemImage: "server.rack") }
|
||||
ImmichSettingsView().tabItem { Label("Immich", systemImage: "photo.stack") }
|
||||
LightroomSettingsView().tabItem { Label("Lightroom", systemImage: "camera.aperture") }
|
||||
CodesSettings().tabItem { Label("Codes", systemImage: "character.textbox") }
|
||||
}
|
||||
.padding(16)
|
||||
}
|
||||
}
|
||||
|
||||
struct GeneralSettings: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("Tastatur") {
|
||||
Picker("Belegung", selection: $state.settings.keyScheme) {
|
||||
ForEach(KeyScheme.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
Toggle("Nach Bewertung/Tag automatisch zum nächsten Bild", isOn: $state.settings.autoAdvance)
|
||||
Text("T = Tag · Leertaste = Vorschau · Z = 100 % · Pfeile = Navigation · ⌘⌥A = alle auswählen")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
}
|
||||
Section("exiftool") {
|
||||
HStack {
|
||||
TextField("Pfad (leer = automatisch)", text: $state.settings.exiftoolPath)
|
||||
Button("Neu verbinden") { state.resetExifTool() }
|
||||
}
|
||||
if let url = ExifTool.locate(custom: state.settings.exiftoolPath) {
|
||||
Label("Gefunden: \(url.path)", systemImage: "checkmark.circle.fill").foregroundStyle(.green)
|
||||
} else {
|
||||
Label("Nicht gefunden – Terminal: brew install exiftool", systemImage: "xmark.octagon.fill").foregroundStyle(.red)
|
||||
}
|
||||
}
|
||||
Section("Variablen") {
|
||||
TextField("Datumsformat für {date}", text: $state.settings.dateFormat)
|
||||
Text("z. B. dd.MM.yyyy → 03.11.2026 · d. MMMM yyyy → 3. November 2026")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
}
|
||||
}
|
||||
|
||||
struct FTPSettings: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@State private var selected: UUID?
|
||||
@State private var password = ""
|
||||
@State private var testResult = ""
|
||||
@State private var testing = false
|
||||
|
||||
private var index: Int? { state.settings.ftpDestinations.firstIndex { $0.id == selected } }
|
||||
|
||||
var body: some View {
|
||||
HSplitView {
|
||||
VStack(spacing: 0) {
|
||||
List(selection: $selected) {
|
||||
ForEach(state.settings.ftpDestinations) { d in Text(d.name).tag(d.id) }
|
||||
}
|
||||
HStack {
|
||||
Button { let d = FTPDestination(); state.settings.ftpDestinations.append(d); selected = d.id } label: { Image(systemName: "plus") }
|
||||
Button {
|
||||
if let i = index { Keychain.set("", account: state.settings.ftpDestinations[i].keychainAccount)
|
||||
state.settings.ftpDestinations.remove(at: i); selected = nil }
|
||||
} label: { Image(systemName: "minus") }.disabled(index == nil)
|
||||
Spacer()
|
||||
}
|
||||
.buttonStyle(.borderless).padding(6)
|
||||
}
|
||||
.frame(minWidth: 170, maxWidth: 220)
|
||||
|
||||
if let i = index {
|
||||
Form {
|
||||
TextField("Name", text: $state.settings.ftpDestinations[i].name)
|
||||
Picker("Protokoll", selection: Binding(
|
||||
get: { state.settings.ftpDestinations[i].proto },
|
||||
set: { p in
|
||||
state.settings.ftpDestinations[i].proto = p
|
||||
state.settings.ftpDestinations[i].port = p.defaultPort
|
||||
})) {
|
||||
ForEach(FTPProtocol.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
TextField("Server", text: $state.settings.ftpDestinations[i].host)
|
||||
TextField("Port", value: $state.settings.ftpDestinations[i].port, format: .number.grouping(.never))
|
||||
TextField("Benutzer", text: $state.settings.ftpDestinations[i].username)
|
||||
SecureField("Passwort (Schlüsselbund)", text: $password)
|
||||
.onSubmit { Keychain.set(password, account: state.settings.ftpDestinations[i].keychainAccount) }
|
||||
.onChange(of: password) { _, p in Keychain.set(p, account: state.settings.ftpDestinations[i].keychainAccount) }
|
||||
if state.settings.ftpDestinations[i].proto == .sftp {
|
||||
TextField("SSH-Schlüssel (optional)", text: $state.settings.ftpDestinations[i].sshKeyPath)
|
||||
}
|
||||
TextField("Zielordner", text: $state.settings.ftpDestinations[i].remoteDirectory)
|
||||
Picker("Dateien", selection: $state.settings.ftpDestinations[i].variant) {
|
||||
ForEach(UploadVariant.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
TextField("Umbenennen (leer = Originalname)", text: $state.settings.ftpDestinations[i].renamePattern)
|
||||
Toggle("Passiver Modus", isOn: $state.settings.ftpDestinations[i].passive)
|
||||
Toggle("Mit .part hochladen und danach umbenennen", isOn: $state.settings.ftpDestinations[i].uploadWithTempName)
|
||||
Toggle("TLS-Zertifikat nicht prüfen (nur wenn nötig)", isOn: $state.settings.ftpDestinations[i].allowInsecureTLS)
|
||||
HStack {
|
||||
Button("Verbindung testen") { test(state.settings.ftpDestinations[i]) }.disabled(testing)
|
||||
if testing { ProgressView().controlSize(.small) }
|
||||
Text(testResult).font(.caption).lineLimit(3)
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.onAppear { password = Keychain.get(state.settings.ftpDestinations[i].keychainAccount) ?? "" }
|
||||
.onChange(of: selected) { _, _ in
|
||||
testResult = ""
|
||||
if let i = index { password = Keychain.get(state.settings.ftpDestinations[i].keychainAccount) ?? "" }
|
||||
}
|
||||
} else {
|
||||
Text("Server hinzufügen oder auswählen").foregroundStyle(.secondary).frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func test(_ d: FTPDestination) {
|
||||
testing = true
|
||||
testResult = ""
|
||||
Task {
|
||||
do {
|
||||
try await FTPUploader().testConnection(d, password: Keychain.get(d.keychainAccount))
|
||||
testResult = "✅ Verbindung OK"
|
||||
} catch { testResult = "❌ " + error.localizedDescription }
|
||||
testing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ImmichSettingsView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@State private var apiKey = ""
|
||||
@State private var result = ""
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Toggle("Immich-Upload aktivieren", isOn: $state.settings.immich.enabled)
|
||||
TextField("Server-URL", text: $state.settings.immich.serverURL, prompt: Text("https://immich.example.de"))
|
||||
SecureField("API-Schlüssel (Schlüsselbund)", text: $apiKey)
|
||||
.onChange(of: apiKey) { _, k in Keychain.set(k, account: ImmichSettings.keychainAccount); state.uploads.resetImmich() }
|
||||
TextField("Album (leer = keins, wird angelegt)", text: $state.settings.immich.albumName)
|
||||
Picker("Dateien", selection: $state.settings.immich.variant) {
|
||||
ForEach(UploadVariant.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
HStack {
|
||||
Button("Verbindung testen") { test() }
|
||||
Text(result).font(.caption)
|
||||
}
|
||||
Text("API-Schlüssel in Immich: Konto-Einstellungen → API-Schlüssel. Benötigte Rechte: asset.upload, album.read, album.create, albumAsset.create.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.onAppear { apiKey = Keychain.get(ImmichSettings.keychainAccount) ?? "" }
|
||||
.onChange(of: state.settings.immich) { _, _ in state.uploads.resetImmich() }
|
||||
}
|
||||
|
||||
private func test() {
|
||||
result = "…"
|
||||
Task {
|
||||
do {
|
||||
let c = try ImmichClient(settings: state.settings.immich, apiKey: apiKey)
|
||||
result = "✅ Angemeldet als \(try await c.testConnection())"
|
||||
} catch { result = "❌ " + error.localizedDescription }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LightroomSettingsView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@State private var pluginMessage = ""
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("Lichtkasten-Bridge-Plugin") {
|
||||
HStack {
|
||||
if LightroomBridge.pluginIsAlive {
|
||||
Label("Plugin aktiv (Lightroom läuft)", systemImage: "checkmark.circle.fill").foregroundStyle(.green)
|
||||
} else if LightroomBridge.pluginInstalled {
|
||||
Label("Installiert – Lightroom starten", systemImage: "pause.circle").foregroundStyle(.orange)
|
||||
} else {
|
||||
Label("Nicht installiert", systemImage: "xmark.circle").foregroundStyle(.red)
|
||||
}
|
||||
Spacer()
|
||||
Button(LightroomBridge.pluginInstalled ? "Neu installieren" : "Plugin installieren") { install() }
|
||||
}
|
||||
if !pluginMessage.isEmpty { Text(pluginMessage).font(.caption) }
|
||||
Text("Ohne Plugin öffnet ⌘⇧L den normalen Importdialog von Lightroom.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
}
|
||||
Section("Import") {
|
||||
TextField("Entwicklungsvorgabe (exakter Name, optional „Ordner/Name“)", text: $state.settings.lightroom.developPreset)
|
||||
TextField("Sammlung (leer = keine)", text: $state.settings.lightroom.collection)
|
||||
}
|
||||
Section("JPEG-Export (⌘⌥L)") {
|
||||
HStack {
|
||||
TextField("Exportordner (leer = Unterordner „Export“)", text: $state.settings.lightroom.exportFolder)
|
||||
Button("Wählen …") {
|
||||
let p = NSOpenPanel(); p.canChooseDirectories = true; p.canChooseFiles = false; p.canCreateDirectories = true
|
||||
if p.runModal() == .OK, let u = p.url { state.settings.lightroom.exportFolder = u.path }
|
||||
}
|
||||
}
|
||||
Stepper("JPEG-Qualität: \(state.settings.lightroom.jpegQuality)", value: $state.settings.lightroom.jpegQuality, in: 50...100, step: 5)
|
||||
TextField("Lange Kante in px (0 = volle Größe)", value: $state.settings.lightroom.longEdge, format: .number.grouping(.never))
|
||||
Picker("Ausgabeschärfung", selection: $state.settings.lightroom.sharpening) {
|
||||
Text("Keine").tag("none"); Text("Bildschirm").tag("screen"); Text("Matt").tag("matte"); Text("Glanz").tag("glossy")
|
||||
}
|
||||
Picker("Farbraum", selection: $state.settings.lightroom.colorSpace) {
|
||||
Text("sRGB").tag("sRGB"); Text("Adobe RGB").tag("AdobeRGB")
|
||||
}
|
||||
Toggle("Original-IPTC nach Export erneut schreiben (PM-identischer Aufbau)", isOn: $state.settings.lightroom.rewriteIPTCAfterExport)
|
||||
}
|
||||
Section("Nach dem Export automatisch hochladen") {
|
||||
ForEach(state.settings.ftpDestinations) { d in
|
||||
Toggle("FTP: \(d.name)", isOn: uploadBinding(d.id.uuidString))
|
||||
}
|
||||
Toggle("Immich", isOn: uploadBinding("immich")).disabled(!state.settings.immich.enabled)
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
}
|
||||
|
||||
private func uploadBinding(_ id: String) -> Binding<Bool> {
|
||||
Binding(get: { state.settings.lightroom.autoUploadTargets.contains(id) },
|
||||
set: { on in
|
||||
state.settings.lightroom.autoUploadTargets.removeAll { $0 == id }
|
||||
if on { state.settings.lightroom.autoUploadTargets.append(id) }
|
||||
})
|
||||
}
|
||||
|
||||
private func install() {
|
||||
guard let bundle = Bundle.main.url(forResource: "LichtkastenBridge", withExtension: "lrplugin") else {
|
||||
pluginMessage = "Plugin nicht im App-Bundle gefunden. Bitte LightroomPlugin/LichtkastenBridge.lrplugin über Lightroom → Zusatzmodul-Manager hinzufügen."
|
||||
return
|
||||
}
|
||||
do {
|
||||
try LightroomBridge.installPlugin(from: bundle)
|
||||
pluginMessage = "Installiert. Lightroom Classic bitte neu starten."
|
||||
} catch { pluginMessage = error.localizedDescription }
|
||||
}
|
||||
}
|
||||
|
||||
struct CodesSettings: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@State private var testInput = "\\bvb\\ gegen \\s04\\"
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section("Code-Ersetzung (wie Photo Mechanic)") {
|
||||
HStack {
|
||||
Text("\(state.codes.table.count) Codes geladen")
|
||||
Spacer()
|
||||
Button("Datei laden …") { state.importCodeReplacements() }
|
||||
Button("Leeren") { state.codes = CodeReplacements() }
|
||||
}
|
||||
Text("Tab-getrennte Textdatei: Code ⇥ Ersetzung ⇥ weitere Spalten. Im Text: \\code\\ oder \\code#2\\ für Spalte 2.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
TextField("Test", text: $testInput)
|
||||
Text(state.codes.expand(testInput)).font(.callout).textSelection(.enabled)
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
import LichtkastenCore
|
||||
|
||||
/// ⌘⇧I – quick picker (type to filter, Return applies to the selection).
|
||||
struct TemplatePickerSheet: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var query = ""
|
||||
@State private var selected: UUID?
|
||||
|
||||
private var filtered: [IPTCTemplate] {
|
||||
let q = query.lowercased()
|
||||
return state.templates.filter { q.isEmpty || $0.name.lowercased().contains(q) }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("Vorlage auf \(state.selectedItems.count) Bild(er) anwenden").font(.headline)
|
||||
TextField("Suchen …", text: $query).textFieldStyle(.roundedBorder)
|
||||
List(filtered, selection: $selected) { t in
|
||||
VStack(alignment: .leading) {
|
||||
Text(t.name)
|
||||
Text(summary(t)).font(.caption).foregroundStyle(.secondary).lineLimit(1)
|
||||
}
|
||||
.tag(t.id)
|
||||
}
|
||||
.frame(minHeight: 260)
|
||||
HStack {
|
||||
Button("Vorlagen verwalten …") { dismiss(); state.showTemplateManager = true }
|
||||
Spacer()
|
||||
Button("Abbrechen") { dismiss() }.keyboardShortcut(.cancelAction)
|
||||
Button("Anwenden") { apply() }
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled((selected ?? filtered.first?.id) == nil || state.selectedItems.isEmpty)
|
||||
}
|
||||
}
|
||||
.padding(16)
|
||||
.frame(width: 520, height: 440)
|
||||
.onAppear { selected = state.settings.lastTemplateID ?? state.templates.first?.id }
|
||||
}
|
||||
|
||||
private func summary(_ t: IPTCTemplate) -> String {
|
||||
["creator", "credit", "city", "headline", "caption"].compactMap { id in
|
||||
IPTCField.byID[id].map { t.values[$0] }.flatMap { $0.isEmpty ? nil : $0 }
|
||||
}.joined(separator: " · ")
|
||||
}
|
||||
|
||||
private func apply() {
|
||||
guard let id = selected ?? filtered.first?.id, let t = state.templates.first(where: { $0.id == id }) else { return }
|
||||
state.applyTemplate(t)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
struct TemplateManagerView: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var selected: UUID?
|
||||
@State private var texts: FieldTexts = [:]
|
||||
|
||||
private var index: Int? { state.templates.firstIndex { $0.id == selected } }
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
HSplitView {
|
||||
VStack(spacing: 0) {
|
||||
List(selection: $selected) {
|
||||
ForEach(state.templates) { t in Text(t.name).tag(t.id) }
|
||||
.onMove { state.templates.move(fromOffsets: $0, toOffset: $1) }
|
||||
}
|
||||
Divider()
|
||||
HStack(spacing: 6) {
|
||||
Button { addNew() } label: { Image(systemName: "plus") }.help("Neue Vorlage")
|
||||
Button { duplicate() } label: { Image(systemName: "plus.square.on.square") }
|
||||
.help("Duplizieren").disabled(index == nil)
|
||||
Button { delete() } label: { Image(systemName: "minus") }.help("Löschen").disabled(index == nil)
|
||||
Spacer()
|
||||
Menu {
|
||||
Button("Photo-Mechanic-Vorlage (.xmp) …") { state.importPMTemplate() }
|
||||
Button("Aus Bild mit IPTC …") { state.importPMTemplate() }
|
||||
if let first = state.selectedItems.first {
|
||||
Button("Aus ausgewähltem Bild (\(first.filename))") {
|
||||
state.templates.append(IPTCTemplate(name: first.baseName, values: first.iptc))
|
||||
}
|
||||
}
|
||||
} label: { Text("Importieren") }
|
||||
.fixedSize()
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.padding(8)
|
||||
}
|
||||
.frame(minWidth: 220, idealWidth: 240, maxWidth: 320)
|
||||
|
||||
if let i = index {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
HStack {
|
||||
TextField("Name", text: $state.templates[i].name).font(.title3).textFieldStyle(.roundedBorder)
|
||||
Button("Als XMP exportieren …") { state.exportTemplate(state.templates[i]) }
|
||||
}
|
||||
HStack(spacing: 18) {
|
||||
Picker("Listenfelder (Stichwörter …)", selection: $state.templates[i].listMergeMode) {
|
||||
ForEach(ListMergeMode.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||
}
|
||||
.fixedSize()
|
||||
Toggle("Leere Felder löschen beim Anwenden", isOn: $state.templates[i].clearEmptyFields)
|
||||
}
|
||||
.font(.callout)
|
||||
if !state.templates[i].extras.isEmpty {
|
||||
Text("\(state.templates[i].extras.count) zusätzliche XMP-Felder aus PM werden beim Export beibehalten.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
}
|
||||
Divider()
|
||||
ScrollView {
|
||||
IPTCFieldsForm(texts: $texts) { _ in save() }
|
||||
.padding(.trailing, 8)
|
||||
}
|
||||
}
|
||||
.padding(14)
|
||||
.frame(minWidth: 520)
|
||||
} else {
|
||||
Text("Vorlage auswählen oder neu anlegen").foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
Divider()
|
||||
HStack {
|
||||
Text("Variablen wie {date}, {city} und PM-Codes wie \\code\\ werden beim Anwenden pro Bild ersetzt.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
Spacer()
|
||||
Button("Fertig") { dismiss() }.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
.padding(12)
|
||||
}
|
||||
.onAppear { selected = selected ?? state.templates.first?.id; loadTexts() }
|
||||
.onChange(of: selected) { _, _ in loadTexts() }
|
||||
}
|
||||
|
||||
private func loadTexts() {
|
||||
if let i = index { texts = state.templates[i].values.texts() } else { texts = [:] }
|
||||
}
|
||||
|
||||
private func save() {
|
||||
guard let i = index else { return }
|
||||
state.templates[i].values = IPTCValues(texts: texts)
|
||||
state.templates[i].modified = Date()
|
||||
}
|
||||
|
||||
private func addNew() {
|
||||
let t = IPTCTemplate(name: "Neue Vorlage")
|
||||
state.templates.append(t)
|
||||
selected = t.id
|
||||
}
|
||||
|
||||
private func duplicate() {
|
||||
guard let i = index else { return }
|
||||
var t = state.templates[i]
|
||||
t.id = UUID()
|
||||
t.name += " Kopie"
|
||||
state.templates.append(t)
|
||||
selected = t.id
|
||||
}
|
||||
|
||||
private func delete() {
|
||||
guard let i = index else { return }
|
||||
state.templates.remove(at: i)
|
||||
selected = state.templates.first?.id
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import SwiftUI
|
||||
|
||||
struct UploadsView: View {
|
||||
@EnvironmentObject var uploads: UploadQueue
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("Uploads").font(.headline)
|
||||
Table(uploads.jobs) {
|
||||
TableColumn("Datei") { j in Text(j.file.lastPathComponent) }
|
||||
TableColumn("Als") { j in Text(j.remoteName).foregroundStyle(.secondary) }
|
||||
TableColumn("Ziel") { j in Text(j.targetName) }
|
||||
TableColumn("Status") { j in statusView(j.status) }
|
||||
}
|
||||
.frame(minHeight: 300)
|
||||
HStack {
|
||||
Button("Fehlgeschlagene wiederholen") { uploads.retryFailed() }.disabled(uploads.failedCount == 0)
|
||||
Button("Erledigte entfernen") { uploads.clearFinished() }
|
||||
Spacer()
|
||||
Button("Schließen") { dismiss() }.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
}
|
||||
.padding(16)
|
||||
.frame(width: 760, height: 460)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func statusView(_ s: UploadJob.Status) -> some View {
|
||||
switch s {
|
||||
case .waiting: Label("Wartet", systemImage: "clock").foregroundStyle(.secondary)
|
||||
case .running: HStack { ProgressView().controlSize(.small); Text("Lädt …") }
|
||||
case .done: Label("Fertig", systemImage: "checkmark.circle.fill").foregroundStyle(.green)
|
||||
case .duplicate: Label("Schon vorhanden", systemImage: "equal.circle").foregroundStyle(.secondary)
|
||||
case .failed(let m): Label(m, systemImage: "xmark.octagon.fill").foregroundStyle(.red).help(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user