Bilder per Drag & Drop verschieben, neue Ordner anlegen
- Bilder aus dem Kontaktabzug auf einen Ordner in der Seitenleiste ziehen = verschieben (ganze Auswahl, RAW + JPEG + XMP zusammen, Namenskollision → -1, Gesendet-Status zieht mit, alles-oder-nichts pro Bild) - aus dem Finder gezogene Bilder werden in den Ordner kopiert - Ordner hebt sich beim Darüberziehen hervor, Vorschau mit Anzahl unter dem Zeiger - „Neuer Ordner …“ per Rechtsklick auf jeden Ordner, Knopf bei Favoriten legt ihn in INPUT an (Name mit heutigem Datum vorbelegt), danach wird er geöffnet 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
244734c59f
commit
223d8b0610
7 files changed
+211
-1
No files matched your search
@@ -814,6 +814,110 @@ final class AppState: ObservableObject {
|
||||
|
||||
func selectAll() { selection = Set(visible.map(\.id)) }
|
||||
|
||||
// MARK: - Moving photos / folders
|
||||
|
||||
/// Prefix of the drag payload for photos dragged out of the contact sheet (one path per line).
|
||||
static let dragPrefix = "lichtkasten-photos\n"
|
||||
|
||||
/// Drag payload: the whole selection if the dragged photo is part of it, else just that photo.
|
||||
func dragPayload(for item: PhotoItem) -> String {
|
||||
let ids = selection.contains(item.id) ? selectedItems.map(\.id) : [item.id]
|
||||
return Self.dragPrefix + ids.joined(separator: "\n")
|
||||
}
|
||||
|
||||
/// Drop on a folder in the sidebar. Photos from the contact sheet are moved (RAW + JPEG + XMP together,
|
||||
/// sent status and selection follow); files dragged in from the Finder are copied.
|
||||
@discardableResult
|
||||
func handleDrop(_ strings: [String], urls: [URL], on folder: URL) -> Bool {
|
||||
if let payload = strings.first(where: { $0.hasPrefix(Self.dragPrefix) }) {
|
||||
let ids = payload.dropFirst(Self.dragPrefix.count).split(separator: "\n").map(String.init)
|
||||
let photos = ids.compactMap { item($0) }
|
||||
guard !photos.isEmpty else { return false }
|
||||
movePhotos(photos, to: folder)
|
||||
return true
|
||||
}
|
||||
let files = urls.filter { $0.isFileURL && (FileKind(url: $0).isImage || $0.pathExtension.lowercased() == "xmp") }
|
||||
guard !files.isEmpty else { return false }
|
||||
copyFiles(files, to: folder)
|
||||
return true
|
||||
}
|
||||
|
||||
func movePhotos(_ photos: [PhotoItem], to folder: URL) {
|
||||
let fm = FileManager.default
|
||||
guard photos.contains(where: { $0.primary.deletingLastPathComponent().standardizedFileURL != folder.standardizedFileURL }) else { return }
|
||||
var moved = 0
|
||||
var failed: [String] = []
|
||||
for p in photos where p.primary.deletingLastPathComponent().standardizedFileURL != folder.standardizedFileURL {
|
||||
var files = [p.primary] + p.companions
|
||||
if p.kind.usesSidecar, fm.fileExists(atPath: p.sidecarURL.path) { files.append(p.sidecarURL) }
|
||||
let name = IngestService.uniqueName(p.baseName, files: files, in: folder, skipDuplicates: false).name
|
||||
var done: [(URL, URL)] = []
|
||||
do {
|
||||
for f in files {
|
||||
let dest = folder.appendingPathComponent(name).appendingPathExtension(f.pathExtension)
|
||||
try fm.moveItem(at: f, to: dest)
|
||||
done.append((f, dest))
|
||||
}
|
||||
for (from, to) in done { sentLog.move(from: from, to: to) }
|
||||
moved += 1
|
||||
} catch {
|
||||
for (from, to) in done.reversed() { try? fm.moveItem(at: to, to: from) } // all or nothing per photo
|
||||
failed.append("\(p.filename): \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
scheduleSentLogSave()
|
||||
refreshFolder()
|
||||
statusText = "\(moved) Bild(er) nach „\(folder.lastPathComponent)“ verschoben"
|
||||
if !failed.isEmpty { alert = AppAlert(title: "Nicht alles verschoben", message: failed.joined(separator: "\n")) }
|
||||
}
|
||||
|
||||
private func copyFiles(_ files: [URL], to folder: URL) {
|
||||
let fm = FileManager.default
|
||||
var copied = 0
|
||||
for f in files {
|
||||
let base = f.deletingPathExtension().lastPathComponent
|
||||
let name = IngestService.uniqueName(base, files: [f], in: folder, skipDuplicates: true)
|
||||
if name.skip { continue }
|
||||
do {
|
||||
try fm.copyItem(at: f, to: folder.appendingPathComponent(name.name).appendingPathExtension(f.pathExtension))
|
||||
copied += 1
|
||||
} catch { report(error) }
|
||||
}
|
||||
if folder == self.folder { refreshFolder() }
|
||||
statusText = "\(copied) Datei(en) nach „\(folder.lastPathComponent)“ kopiert"
|
||||
}
|
||||
|
||||
/// "Neuer Ordner …" – asks for a name (preset with today's date like the game folders) and opens it.
|
||||
@discardableResult
|
||||
func createFolder(in parent: URL) -> URL? {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Neuer Ordner in „\(parent.lastPathComponent)“"
|
||||
let f = DateFormatter(); f.dateFormat = "dd.MM.yyyy"
|
||||
let field = NSTextField(string: f.string(from: Date()) + " - ")
|
||||
field.frame = NSRect(x: 0, y: 0, width: 320, height: 24)
|
||||
alert.accessoryView = field
|
||||
alert.addButton(withTitle: "Anlegen")
|
||||
alert.addButton(withTitle: "Abbrechen")
|
||||
alert.window.initialFirstResponder = field
|
||||
guard alert.runModal() == .alertFirstButtonReturn else { return nil }
|
||||
let name = field.stringValue.trimmingCharacters(in: .whitespaces)
|
||||
.replacingOccurrences(of: "/", with: "-").replacingOccurrences(of: ":", with: "-")
|
||||
guard !name.isEmpty else { return nil }
|
||||
let url = parent.appendingPathComponent(name, isDirectory: true)
|
||||
if FileManager.default.fileExists(atPath: url.path) {
|
||||
self.alert = AppAlert(title: "Ordner existiert schon", message: url.path)
|
||||
return nil
|
||||
}
|
||||
do {
|
||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: false)
|
||||
folderTreeVersion += 1
|
||||
return url
|
||||
} catch { report(error); return nil }
|
||||
}
|
||||
|
||||
/// Bumped when folders are created → the sidebar tree re-reads its sub folders.
|
||||
@Published var folderTreeVersion = 0
|
||||
|
||||
/// ⌘⌫ – moves the selected photos (RAW, JPEG, XMP sidecar) to the Trash (Finder: "Put Back" restores them).
|
||||
func trashSelected() {
|
||||
let targets = selectedItems
|
||||
|
||||
Reference in new issue
Block a user