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:
Lichtkasten DevandClaude Opus 5.5 committed 2026-11-03 23:51:33 +00:00
1 parent d100249c12
commit c0ee93995f
18 files changed
+1311 -515

No files matched your search

+127 -176
View File
@@ -17,208 +17,159 @@ extension IPTCValues {
}
}
/// The field layout used everywhere (inspector + template editor) – PM Stationery Pad order.
struct IPTCFieldsForm: View {
/// PM's blue section header bar.
struct PMSectionHeader: View {
let title: String
var body: some View {
Text(title)
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(.white)
.frame(maxWidth: .infinity)
.padding(.vertical, 3)
.background(
Capsule().fill(LinearGradient(colors: [Color(red: 0.30, green: 0.55, blue: 0.90), Color(red: 0.14, green: 0.38, blue: 0.75)],
startPoint: .top, endPoint: .bottom))
)
}
}
/// The metadata form in Photo Mechanic's layout: blue section bars, labels left, big caption box,
/// optional PM checkboxes ("apply this field"), two columns for template / mass edit, one for the info window.
struct PMMetadataForm: View {
@Binding var texts: FieldTexts
var columns = 2
var mixed: Set<String> = []
var dirty: Set<String> = []
var onEdit: (String) -> Void = { _ in }
/// PM-style "apply" checkboxes (template editor only).
/// PM checkboxes; nil = no checkboxes (info window).
var applied: Binding<Set<String>>? = nil
@AppStorage("collapsedIPTCSections") private var collapsedRaw = ""
var codes: CodeReplacements? = nil
var onEdit: (String) -> Void = { _ in }
/// Extra rows (e.g. "Image Preferences → Label") inserted after Image Content.
var extraAfterContent: AnyView? = nil
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
HStack(alignment: .top, spacing: 6) {
if let applied {
Toggle("", isOn: Binding(
get: { applied.wrappedValue.contains(field.id) },
set: { on in
if on { applied.wrappedValue.insert(field.id) } else { applied.wrappedValue.remove(field.id) }
}))
.toggleStyle(.checkbox)
.labelsHidden()
.padding(.top, 16)
.help("Feld beim Anwenden schreiben (wie das Häkchen in Photo Mechanic)")
}
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)
}
if columns == 2 {
HStack(alignment: .top, spacing: 18) {
column(0)
column(1)
}
} else {
VStack(alignment: .leading, spacing: 14) {
ForEach(IPTCSection.allCases, id: \.self) { sectionView($0) }
}
}
}
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 column(_ c: Int) -> some View {
VStack(alignment: .leading, spacing: 14) {
ForEach(IPTCSection.allCases.filter { $0.column == c }, id: \.self) { sectionView($0) }
}
.frame(maxWidth: .infinity, alignment: .top)
}
@ViewBuilder
private func sectionView(_ section: IPTCSection) -> some View {
VStack(alignment: .leading, spacing: 6) {
PMSectionHeader(title: section.rawValue)
ForEach(IPTCField.all.filter { $0.section == section }) { field in
PMFieldRow(field: field, text: binding(field),
isMixed: mixed.contains(field.id) && !dirty.contains(field.id),
isDirty: dirty.contains(field.id),
applied: appliedBinding(field))
}
if section == .imageContent, let extra = extraAfterContent { extra }
}
}
private func appliedBinding(_ f: IPTCField) -> Binding<Bool>? {
guard let applied else { return nil }
return Binding(get: { applied.wrappedValue.contains(f.id) },
set: { on in if on { applied.wrappedValue.insert(f.id) } else { applied.wrappedValue.remove(f.id) } })
}
private func binding(_ f: IPTCField) -> Binding<String> {
Binding(get: { texts[f.id] ?? "" },
set: { texts[f.id] = $0; onEdit(f.id) })
set: { new in
var value = new
// PM code replacement while typing: "\bvb\" expands as soon as the closing delimiter is typed.
if let codes, !codes.table.isEmpty, new.last == codes.delimiter, new.count > (texts[f.id]?.count ?? 0) {
value = codes.expand(new)
}
texts[f.id] = value
// Editing a field ticks its checkbox (PM behaviour).
applied?.wrappedValue.insert(f.id)
onEdit(f.id)
})
}
}
struct FieldRow: View {
struct PMFieldRow: View {
let field: IPTCField
@Binding var text: String
let isMixed: Bool
let isDirty: Bool
let applied: Binding<Bool>?
private static let variableFields: Set<String> = ["caption", "headline", "objectName", "instructions", "event",
"transmissionReference", "keywords"]
private var height: CGFloat? {
switch field.id {
case "caption": return 210
case "keywords": return 130
case "headline", "altText", "extDescription", "personInImage", "instructions", "usageTerms": return 62
default: return nil
}
}
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.")
HStack(alignment: .top, spacing: 6) {
if let applied {
Toggle("", isOn: applied).toggleStyle(.checkbox).labelsHidden().padding(.top, 3)
}
VStack(alignment: .leading, spacing: 2) {
Text(field.pmLabel + ":")
.font(.system(size: 12))
.foregroundStyle(isDirty ? Color.accentColor : .primary)
.help(field.label)
if let max = field.iimMaxBytes, text.utf8.count > max, !text.contains("{") {
Text("\(text.utf8.count)/\(max)").font(.caption2.monospacedDigit()).foregroundStyle(.red)
.help("IPTC-IIM-Limit in Bytes – Agenturen kürzen längere Werte.")
}
}
.frame(width: 150, alignment: .leading)
.padding(.top, 3)
Group {
if let h = height {
TextEditor(text: $text)
.font(.system(size: 13))
.scrollContentBackground(.hidden)
.padding(4)
.background(Color(nsColor: .textBackgroundColor))
.overlay(alignment: .topLeading) {
if isMixed && text.isEmpty {
Text("‹mehrere Werte›").foregroundStyle(.tertiary).padding(8).allowsHitTesting(false)
}
}
.overlay(RoundedRectangle(cornerRadius: 3).stroke(Color.secondary.opacity(0.4)))
.frame(height: h)
} else {
TextField(isMixed ? "‹mehrere Werte›" : "", text: $text)
.textFieldStyle(.roundedBorder)
}
}
.frame(maxWidth: .infinity)
Menu {
Section("Variablen") {
ForEach(VariableExpander.documented, id: \.0) { v in
Button("\(v.0) – \(v.1)") { text += v.0 }
}
}
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)
}
Button("Feld leeren") { text = "" }
} label: { Image(systemName: "chevron.down") }
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.frame(width: 22)
.padding(.top, 2)
}
}
}
/// 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
}
}