Files
lichtkasten/Sources/Lichtkasten/LichtkastenApp.swift
T

156 lines
7.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import AppKit
import SwiftUI
import LichtkastenCore
final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
// Needed when started via `swift run` (no app bundle).
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }
}
@main
struct LichtkastenApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var delegate
@StateObject private var state = AppState()
var body: some Scene {
WindowGroup("Lichtkasten") {
ContentView()
.environmentObject(state)
.environmentObject(state.uploads)
.environmentObject(state.tasks)
.frame(minWidth: 1100, minHeight: 680)
}
.commands { AppCommands(state: state) }
// PM: "Metadata (IPTC) Info" for one image (I)
Window("IPTC-Info", id: "iptc") {
IPTCInfoWindow()
.environmentObject(state)
.frame(minWidth: 1020, minHeight: 680)
}
.defaultSize(width: 1240, height: 860)
// ⌘I – mass edit for the selection (PM template layout with checkboxes)
Window("IPTC für Auswahl", id: "iptc-batch") {
BatchEditWindow()
.environmentObject(state)
.frame(minWidth: 1200, minHeight: 700)
}
.defaultSize(width: 1400, height: 900)
// ⌘U – upload dialog
Window("Hochladen", id: "upload") {
UploadWindow().environmentObject(state)
}
.windowResizability(.contentSize)
// PM: Tasks window
Window("Aufgaben", id: "tasks") {
TasksWindow()
.environmentObject(state)
.environmentObject(state.tasks)
.environmentObject(state.uploads)
.frame(minWidth: 620, minHeight: 360)
}
.defaultSize(width: 760, height: 520)
Window("Code-Ersetzungen", id: "codes") {
CodesWindow()
.environmentObject(state)
.frame(minWidth: 640, minHeight: 480)
}
Settings {
SettingsView()
.environmentObject(state)
.frame(width: 760, height: 600)
}
}
}
struct AppCommands: Commands {
@ObservedObject var state: AppState
var body: some Commands {
// Replaces "New Window" (⌘N) – ⌘N is "Save & previous" in the IPTC window like in PM.
CommandGroup(replacing: .newItem) {
Button("Ordner öffnen …") { state.chooseFolder() }.keyboardShortcut("o")
Button("Neuer Tab …") { state.newTab() }.keyboardShortcut("t")
Button("Ingest (von Karte kopieren) …") { state.showIngest = true }.keyboardShortcut("g")
.disabled(state.ingestRunning)
Button("Ordner neu laden") { state.reload() }.keyboardShortcut("r")
Divider()
Button("Im Finder zeigen") {
NSWorkspace.shared.activateFileViewerSelecting(state.selectedItems.map(\.primary))
}.keyboardShortcut("r", modifiers: [.command, .shift])
}
CommandMenu("Bild") {
Button("Alle auswählen") { state.selectAll() }.keyboardShortcut("a", modifiers: [.command, .option])
Button("Getaggte auswählen") { state.selectTagged() }.keyboardShortcut("t", modifiers: [.command, .option])
Button("Auswahl aufheben") { state.deselectAll() }.keyboardShortcut("d")
Divider()
Button("Tag umschalten (T)") { state.toggleTag() }
Menu("Farbklasse (1–8)") {
ForEach(ColorLabel.allCases, id: \.self) { l in
Button("\(l.pmColorClass) – \(l.germanName) (\(l.pmName))") { state.setLabel(l) }
}
Button("0 – Keine") { state.setLabel(nil) }
}
Menu("Bewertung (⌥1–5)") {
ForEach(0...5, id: \.self) { n in
Button(n == 0 ? "Keine" : String(repeating: "★", count: n)) { state.setRating(n) }
}
}
Divider()
Button(state.previewMode ? "Kontaktabzug (Leertaste)" : "Vorschau (Leertaste)") { state.previewMode.toggle() }
Button(state.isInSentFolder ? "Zum INPUT/RAW-Ordner" : "Zum SENT-Ordner") { state.toggleRawSent() }
.keyboardShortcut("s", modifiers: [.command, .option])
.disabled(state.folder == nil)
}
CommandMenu("IPTC") {
Button("IPTC für Auswahl bearbeiten …") { state.openWindow("iptc-batch") }
.keyboardShortcut("i")
Button("IPTC-Info (einzeln) … (I)") { state.openWindow("iptc") }
Divider()
Button("Vorlage anwenden …") { state.showTemplatePicker = true }.keyboardShortcut("i", modifiers: [.command, .shift])
Button("Letzte Vorlage erneut anwenden") {
if let id = state.settings.lastTemplateID, let t = state.templates.first(where: { $0.id == id }) {
state.applyTemplate(t)
}
}.keyboardShortcut("v", modifiers: [.command, .shift])
Button("Vorlagen verwalten …") { state.showTemplateManager = true }.keyboardShortcut("t", modifiers: [.command, .shift])
Divider()
Button("Code-Ersetzungen …") { state.openWindow("codes") }.keyboardShortcut("k", modifiers: [.command, .shift])
Button("Photo-Mechanic-Einstellungen importieren (alle) …") { state.showPMImport = true }
Button("Photo-Mechanic-Vorlage importieren …") { state.importPMTemplate() }
}
CommandMenu("Ausgabe") {
Button("In Lightroom Classic bearbeiten") { state.sendToLightroom(export: false, develop: true) }
.keyboardShortcut("e")
Button("An Lightroom Classic senden (nur Import)") { state.sendToLightroom(export: false) }
.keyboardShortcut("l", modifiers: [.command, .shift])
Button("Lightroom: Vorgabe anwenden + JPEG nach SENT") { state.sendToLightroom(export: true) }
.keyboardShortcut("l", modifiers: [.command, .option])
Divider()
Button("Hochladen …") { state.openWindow("upload") }.keyboardShortcut("u")
ForEach(Array(state.settings.ftpDestinations.enumerated()), id: \.element.id) { idx, d in
if idx == 0 {
Button("Sofort hochladen: \(d.name)") { state.upload(to: d.id.uuidString) }.keyboardShortcut("u", modifiers: [.command, .shift])
} else {
Button("Sofort hochladen: \(d.name)") { state.upload(to: d.id.uuidString) }
}
}
Button("Zu Immich hochladen") { state.upload(to: "immich") }
.keyboardShortcut("m", modifiers: [.command, .shift])
.disabled(!state.settings.immich.enabled)
Divider()
Button("Aufgaben-Fenster") { state.openWindow("tasks") }.keyboardShortcut("u", modifiers: [.command, .option])
}
}
}