Files
SnipMC/Sources/SettingsWindowController.swift
marcoandClaude Opus 4.6 062285abbf Add image editor with annotation tools
Integrates an editor accessible via "Letzte Aufnahme bearbeiten…" or
"Bild bearbeiten…" in the menu bar. Supports arrow, rectangle, ellipse,
and text annotations with color picker, line width, undo/redo, and
export to file or clipboard.

New files in Sources/Editor/:
- AnnotationItem/Document: data model and state management
- AnnotationCanvasView: NSView with CG rendering and mouse interaction
- AnnotationRenderer: shared rendering for canvas and image export
- EditorToolbarView: SwiftUI toolbar with tool selection and actions
- EditorWindowController: window lifecycle following SettingsWindowController pattern

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-01 17:44:20 +02:00

41 lines
1.4 KiB
Swift

import AppKit
import SwiftUI
/// Manages the settings window manually instead of relying on SwiftUI's
/// `Settings` scene, which is unreliable for LSUIElement (menu bar-only,
/// no dock icon) apps: there's no existing window for the app to focus,
/// so the scene sometimes never becomes key.
final class SettingsWindowController: NSWindowController, NSWindowDelegate {
static let shared = SettingsWindowController()
private convenience init() {
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 440, height: 420),
styleMask: [.titled, .closable, .miniaturizable],
backing: .buffered,
defer: false
)
window.title = "Einstellungen"
window.isReleasedWhenClosed = false
window.center()
self.init(window: window)
window.delegate = self
}
func show(coordinator: AppCoordinator) {
window?.contentView = NSHostingView(
rootView: SettingsView().environmentObject(coordinator)
)
NSApplication.shared.setActivationPolicy(.regular)
NSApplication.shared.activate(ignoringOtherApps: true)
window?.makeKeyAndOrderFront(nil)
}
func windowWillClose(_ notification: Notification) {
let otherVisible = NSApplication.shared.windows.filter { $0.isVisible && $0 != window }
if otherVisible.isEmpty {
NSApplication.shared.setActivationPolicy(.accessory)
}
}
}