PM-Einstellungen komplett importieren (Vorlagen, Code-Dateien, Trennzeichen, Feld-Listen, Ingest), ▾-Wertelisten, Info-Fenster ⌘B/⌘N + Pfeiltasten, Keyword-Limit pro Eintrag
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
12f61b5d66
commit
2bf0d851aa
11 files changed
+516
-15
No files matched your search
@@ -30,7 +30,7 @@ struct BatchEditWindow: View {
|
||||
.padding(12)
|
||||
Divider()
|
||||
ScrollView {
|
||||
PMMetadataForm(texts: $texts, columns: 2, mixed: mixed, applied: $applied, codes: state.codes)
|
||||
PMMetadataForm(texts: $texts, columns: 2, mixed: mixed, applied: $applied, codes: state.codes, fieldLists: state.settings.fieldLists)
|
||||
.padding(14)
|
||||
}
|
||||
Divider()
|
||||
|
||||
@@ -41,6 +41,7 @@ struct ContentView: View {
|
||||
.sheet(isPresented: $state.showTemplatePicker) { TemplatePickerSheet() }
|
||||
.sheet(isPresented: $state.showTemplateManager) { TemplateManagerView().frame(minWidth: 1280, minHeight: 760) }
|
||||
.sheet(isPresented: $state.showIngest) { IngestView() }
|
||||
.sheet(isPresented: $state.showPMImport) { PMImportSheet() }
|
||||
.alert(item: $state.alert) { a in
|
||||
Alert(title: Text(a.title), message: Text(a.message), dismissButton: .default(Text("OK")))
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ struct PMMetadataForm: View {
|
||||
/// PM checkboxes; nil = no checkboxes (info window).
|
||||
var applied: Binding<Set<String>>? = nil
|
||||
var codes: CodeReplacements? = nil
|
||||
/// ▾ lists (PM drop-down values)
|
||||
var fieldLists: [String: [String]] = [:]
|
||||
var onEdit: (String) -> Void = { _ in }
|
||||
/// Extra rows (e.g. "Image Preferences → Label") inserted after Image Content.
|
||||
var extraAfterContent: AnyView? = nil
|
||||
@@ -72,7 +74,7 @@ struct PMMetadataForm: 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), codes: codes,
|
||||
PMFieldRow(field: field, text: binding(field), codes: codes, listValues: fieldLists[field.id] ?? [],
|
||||
isMixed: mixed.contains(field.id) && !dirty.contains(field.id),
|
||||
isDirty: dirty.contains(field.id),
|
||||
applied: appliedBinding(field))
|
||||
@@ -103,6 +105,7 @@ struct PMFieldRow: View {
|
||||
let field: IPTCField
|
||||
@Binding var text: String
|
||||
var codes: CodeReplacements?
|
||||
var listValues: [String] = []
|
||||
let isMixed: Bool
|
||||
let isDirty: Bool
|
||||
let applied: Binding<Bool>?
|
||||
@@ -126,9 +129,18 @@ struct PMFieldRow: View {
|
||||
.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.")
|
||||
// IIM limit: for keywords etc. it applies to each entry, not to the whole field.
|
||||
if let max = field.iimMaxBytes, !text.contains("{") {
|
||||
if field.kind == .list {
|
||||
let long = IPTCValues.splitList(text).filter { $0.utf8.count > max }
|
||||
if !long.isEmpty {
|
||||
Text("\(long.count)× > \(max)").font(.caption2.monospacedDigit()).foregroundStyle(.red)
|
||||
.help("Diese Einträge sind länger als \(max) Bytes (IIM-Limit pro Eintrag): " + long.joined(separator: ", "))
|
||||
}
|
||||
} else if text.utf8.count > max {
|
||||
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)
|
||||
@@ -153,6 +165,20 @@ struct PMFieldRow: View {
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
Menu {
|
||||
if !listValues.isEmpty {
|
||||
Section("Werte") {
|
||||
ForEach(listValues.prefix(40), id: \.self) { v in
|
||||
Button(v) {
|
||||
if field.kind == .list {
|
||||
let items = IPTCValues.splitList(text)
|
||||
if !items.contains(v) { text = (items + [v]).joined(separator: ", ") }
|
||||
} else {
|
||||
text = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Section("Variablen") {
|
||||
ForEach(VariableExpander.documented, id: \.0) { v in
|
||||
Button("\(v.0) – \(v.1)") { text += v.0 }
|
||||
|
||||
@@ -11,6 +11,8 @@ struct IPTCInfoWindow: View {
|
||||
@State private var image: NSImage?
|
||||
@State private var saving = false
|
||||
@AppStorage("iptcWindowUploadTarget") private var uploadTarget = ""
|
||||
@State private var window: NSWindow?
|
||||
@State private var arrowMonitor: Any?
|
||||
|
||||
private var item: PhotoItem? { state.cursorItem }
|
||||
|
||||
@@ -18,7 +20,7 @@ struct IPTCInfoWindow: View {
|
||||
HSplitView {
|
||||
VStack(spacing: 0) {
|
||||
ScrollView {
|
||||
PMMetadataForm(texts: $texts, columns: 1, dirty: dirty, codes: state.codes,
|
||||
PMMetadataForm(texts: $texts, columns: 1, dirty: dirty, codes: state.codes, fieldLists: state.settings.fieldLists,
|
||||
onEdit: { dirty.insert($0) }, extraAfterContent: AnyView(labelSection))
|
||||
.padding(14)
|
||||
}
|
||||
@@ -42,7 +44,14 @@ struct IPTCInfoWindow: View {
|
||||
sidePanel.frame(minWidth: 380, idealWidth: 520)
|
||||
}
|
||||
.navigationTitle(item.map { "IPTC-Info – \($0.filename)" } ?? "IPTC-Info")
|
||||
.onAppear { load(force: true) }
|
||||
.background(WindowAccessor { window = $0 })
|
||||
.onAppear {
|
||||
load(force: true)
|
||||
installArrowKeys()
|
||||
}
|
||||
.onDisappear {
|
||||
if let m = arrowMonitor { NSEvent.removeMonitor(m); arrowMonitor = nil }
|
||||
}
|
||||
.onChange(of: state.cursorID) { _, _ in load(force: true) }
|
||||
.onReceive(state.$items) { _ in if dirty.isEmpty { DispatchQueue.main.async { load(force: false) } } }
|
||||
.task(id: item.map { state.previewURL(for: $0) }) { await loadImage() }
|
||||
@@ -101,14 +110,14 @@ struct IPTCInfoWindow: View {
|
||||
|
||||
Grid(horizontalSpacing: 8, verticalSpacing: 8) {
|
||||
GridRow {
|
||||
Button("Speichern & ←") { saveAndMove(-1) }
|
||||
.keyboardShortcut(.leftArrow, modifiers: [.command, .option])
|
||||
Button("Speichern & →") { saveAndMove(1) }
|
||||
.keyboardShortcut(.rightArrow, modifiers: [.command, .option])
|
||||
Button("Speichern & ← (⌘N)") { saveAndMove(-1) }
|
||||
.keyboardShortcut("n", modifiers: .command)
|
||||
Button("Speichern & → (⌘B)") { saveAndMove(1) }
|
||||
.keyboardShortcut("b", modifiers: .command)
|
||||
}
|
||||
GridRow {
|
||||
Button("←") { move(-1) }
|
||||
Button("→") { move(1) }
|
||||
Button("←") { move(-1) }.help("Ohne Speichern zurück (Pfeil links)")
|
||||
Button("→") { move(1) }.help("Ohne Speichern weiter (Pfeil rechts)")
|
||||
}
|
||||
GridRow {
|
||||
Button("Speichern, Hochladen & →") { saveUploadAndMove() }
|
||||
@@ -180,6 +189,23 @@ struct IPTCInfoWindow: View {
|
||||
return ok
|
||||
}
|
||||
|
||||
/// ←/→ = previous/next image WITHOUT saving (when no text field is being edited);
|
||||
/// ⌃←/⌃→ work even while typing.
|
||||
private func installArrowKeys() {
|
||||
guard arrowMonitor == nil else { return }
|
||||
arrowMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in
|
||||
guard let w = window, event.window === w, w.attachedSheet == nil else { return event }
|
||||
let mods = event.modifierFlags.intersection(.deviceIndependentFlagsMask)
|
||||
guard event.keyCode == 123 || event.keyCode == 124 else { return event }
|
||||
let typing = w.firstResponder is NSText
|
||||
let ctrlOnly = mods == [.control] || mods == [.control, .function] || mods == [.function, .control]
|
||||
let plain = mods.subtracting([.function, .numericPad]).isEmpty
|
||||
guard ctrlOnly || (plain && !typing) else { return event }
|
||||
move(event.keyCode == 123 ? -1 : 1)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private func move(_ delta: Int) {
|
||||
dirty = []
|
||||
state.iptcNavigate(delta)
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
import SwiftUI
|
||||
import LichtkastenCore
|
||||
|
||||
/// IPTC → "Photo-Mechanic-Einstellungen importieren …": scans PM's folders and imports everything at once.
|
||||
struct PMImportSheet: View {
|
||||
@EnvironmentObject var state: AppState
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var scan: PMSettingsScan?
|
||||
@State private var scanning = false
|
||||
@State private var roots: [URL] = PMSettingsImporter.defaultRoots
|
||||
@State private var pickTemplates: Set<UUID> = []
|
||||
@State private var pickCodes: Set<UUID> = []
|
||||
@State private var importLists = true
|
||||
@State private var importIngest = true
|
||||
@State private var importDelimiter = true
|
||||
@State private var result = ""
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Photo-Mechanic-Einstellungen importieren").font(.title3.bold())
|
||||
Text("Durchsucht: " + (roots.isEmpty ? "– keine PM-Ordner gefunden –" : roots.map(\.path).joined(separator: ", ")))
|
||||
.font(.caption).foregroundStyle(.secondary).lineLimit(3)
|
||||
HStack {
|
||||
Button("Ordner oder Datei hinzufügen …") { addRoot() }
|
||||
.help("z. B. exportierte PM-Einstellungen, einen Ordner mit .snap-Vorlagen oder Code-TXT-Dateien")
|
||||
Button("Erneut suchen") { runScan() }
|
||||
if scanning { ProgressView().controlSize(.small) }
|
||||
}
|
||||
|
||||
if let scan {
|
||||
if scan.isEmpty {
|
||||
Text("Nichts gefunden. Wähle den Ordner mit deinen PM-Vorlagen (.snap) bzw. die exportierten Einstellungen über „Ordner oder Datei hinzufügen …“.")
|
||||
.foregroundStyle(.orange)
|
||||
}
|
||||
List {
|
||||
if !scan.templates.isEmpty {
|
||||
Section("IPTC-Vorlagen (\(scan.templates.count))") {
|
||||
ForEach(scan.templates) { t in
|
||||
Toggle(isOn: bind(t.id, in: $pickTemplates)) {
|
||||
VStack(alignment: .leading) {
|
||||
Text(t.template.name)
|
||||
Text(t.origin).font(.caption2).foregroundStyle(.secondary).lineLimit(1).truncationMode(.middle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !scan.codeFiles.isEmpty {
|
||||
Section("Code-Ersetzungsdateien (\(scan.codeFiles.count)) → werden Teams") {
|
||||
ForEach(scan.codeFiles) { c in
|
||||
Toggle(isOn: bind(c.id, in: $pickCodes)) {
|
||||
HStack {
|
||||
Text(c.url.lastPathComponent)
|
||||
if !c.exists { Text("Datei fehlt").font(.caption).foregroundStyle(.red) }
|
||||
if !c.enabled { Text("in PM deaktiviert").font(.caption).foregroundStyle(.secondary) }
|
||||
}
|
||||
}
|
||||
.disabled(!c.exists)
|
||||
}
|
||||
}
|
||||
}
|
||||
if scan.codeDelimiter != nil || scan.codeDefaultReplacement != nil {
|
||||
Section("Code-Optionen") {
|
||||
Toggle("Trennzeichen „\(scan.codeDelimiter ?? "–")“, Standard-Ersetzung „\(scan.codeDefaultReplacement ?? "")“", isOn: $importDelimiter)
|
||||
}
|
||||
}
|
||||
if !scan.fieldLists.isEmpty {
|
||||
Section("Feld-Listen (▾)") {
|
||||
Toggle(scan.fieldLists.map { "\(IPTCField.byID[$0.key]?.pmLabel ?? $0.key): \($0.value.count)" }.sorted().joined(separator: " · "),
|
||||
isOn: $importLists)
|
||||
}
|
||||
}
|
||||
if scan.renamePattern != nil || scan.sequence != nil || scan.ingestFolderPattern != nil {
|
||||
Section("Ingest") {
|
||||
Toggle("Umbenennen „\(scan.renamePattern ?? "–")“, Sequenz \(scan.sequence.map(String.init) ?? "–"), Ordner „\(scan.ingestFolderPattern ?? "–")“",
|
||||
isOn: $importIngest)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(minHeight: 300)
|
||||
DisclosureGroup("Gefundene Einstellungs-Schlüssel (\(scan.keyReport.count)) – zum Verfeinern an Claude schicken") {
|
||||
HStack {
|
||||
Text("\(scan.scannedFiles.count) Dateien gelesen. Nur Schlüsselnamen, keine Werte/Passwörter.").font(.caption)
|
||||
Spacer()
|
||||
Button("In Zwischenablage kopieren") {
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString((scan.scannedFiles + [""] + scan.keyReport).joined(separator: "\n"), forType: .string)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if scanning {
|
||||
Text("Suche PM-Einstellungen …").foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
if !result.isEmpty { Text(result).font(.callout).foregroundStyle(.green) }
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Schließen") { dismiss() }.keyboardShortcut(.cancelAction)
|
||||
Button("Importieren") { doImport() }
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(scan == nil || scan?.isEmpty == true)
|
||||
}
|
||||
}
|
||||
.padding(18)
|
||||
.frame(width: 760, height: 640)
|
||||
.onAppear(perform: runScan)
|
||||
}
|
||||
|
||||
private func bind(_ id: UUID, in set: Binding<Set<UUID>>) -> Binding<Bool> {
|
||||
Binding(get: { set.wrappedValue.contains(id) },
|
||||
set: { on in if on { set.wrappedValue.insert(id) } else { set.wrappedValue.remove(id) } })
|
||||
}
|
||||
|
||||
private func addRoot() {
|
||||
let p = NSOpenPanel()
|
||||
p.canChooseDirectories = true; p.canChooseFiles = true; p.allowsMultipleSelection = true
|
||||
p.showsHiddenFiles = true
|
||||
p.directoryURL = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library")
|
||||
if p.runModal() == .OK { roots += p.urls; runScan() }
|
||||
}
|
||||
|
||||
private func runScan() {
|
||||
scanning = true
|
||||
let r = roots
|
||||
Task {
|
||||
let s = await Task.detached(priority: .userInitiated) { PMSettingsImporter.scan(roots: r) }.value
|
||||
scan = s
|
||||
pickTemplates = Set(s.templates.map(\.id))
|
||||
pickCodes = Set(s.codeFiles.filter(\.exists).map(\.id))
|
||||
scanning = false
|
||||
}
|
||||
}
|
||||
|
||||
private func doImport() {
|
||||
guard let scan else { return }
|
||||
var notes: [String] = []
|
||||
// templates (same name → replaced)
|
||||
var tCount = 0
|
||||
for t in scan.templates where pickTemplates.contains(t.id) {
|
||||
state.templates.removeAll { $0.name == t.template.name }
|
||||
state.templates.append(t.template)
|
||||
tCount += 1
|
||||
}
|
||||
if tCount > 0 { notes.append("\(tCount) Vorlagen") }
|
||||
// code files → teams
|
||||
var lib = state.codeLibrary
|
||||
var teams = 0, players = 0
|
||||
for c in scan.codeFiles where pickCodes.contains(c.id) {
|
||||
if let r = try? lib.importFile(c.url) {
|
||||
teams += 1; players += r.added
|
||||
if let i = lib.sets.firstIndex(where: { $0.sourcePath == c.url.path }) { lib.sets[i].enabled = c.enabled }
|
||||
}
|
||||
}
|
||||
if importDelimiter {
|
||||
if let d = scan.codeDelimiter { lib.delimiter = d }
|
||||
if let d = scan.codeDefaultReplacement { lib.defaultReplacement = d }
|
||||
}
|
||||
state.codeLibrary = lib
|
||||
if teams > 0 { notes.append("\(teams) Teams mit \(players) Codes") }
|
||||
if importLists {
|
||||
for (k, v) in scan.fieldLists {
|
||||
var list = state.settings.fieldLists[k] ?? []
|
||||
for x in v where !list.contains(x) { list.append(x) }
|
||||
state.settings.fieldLists[k] = list
|
||||
}
|
||||
if !scan.fieldLists.isEmpty { notes.append("\(scan.fieldLists.count) Feld-Listen") }
|
||||
}
|
||||
if importIngest {
|
||||
if let r = scan.renamePattern { state.settings.ingest.renamePattern = r; state.settings.ingest.renameEnabled = true }
|
||||
if let n = scan.sequence { state.settings.ingest.startSequence = n }
|
||||
if let f = scan.ingestFolderPattern { state.settings.ingest.folderPattern = f }
|
||||
}
|
||||
result = notes.isEmpty ? "Nichts ausgewählt." : "Importiert: " + notes.joined(separator: ", ")
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ struct TemplateManagerView: View {
|
||||
applied: state.templates[i].appliedFields == nil ? nil : Binding(
|
||||
get: { state.templates[i].appliedFields ?? [] },
|
||||
set: { state.templates[i].appliedFields = $0 }),
|
||||
codes: state.codes, onEdit: { _ in save() })
|
||||
codes: state.codes, fieldLists: state.settings.fieldLists, onEdit: { _ in save() })
|
||||
.padding(.trailing, 8)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user