Favoriten aufklappbar (Unterordner, neueste zuerst), leere Ordner zeigen ihre Unterordner
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
25729ebfe3
commit
1e72b97164
1 file changed
+70
-13
@@ -20,6 +20,8 @@ struct ContentView: View {
|
|||||||
Divider()
|
Divider()
|
||||||
if state.folder == nil {
|
if state.folder == nil {
|
||||||
EmptyStateView()
|
EmptyStateView()
|
||||||
|
} else if state.items.isEmpty && !state.loadingMetadata {
|
||||||
|
SubfolderPicker()
|
||||||
} else if state.previewMode {
|
} else if state.previewMode {
|
||||||
PreviewView()
|
PreviewView()
|
||||||
} else {
|
} else {
|
||||||
@@ -277,17 +279,15 @@ struct PMSidebar: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
VSplitView {
|
VSplitView {
|
||||||
panel("Favoriten") {
|
panel("Favoriten") {
|
||||||
List {
|
// Like PM: favorites are expandable – INPUT shows its game folders (newest first).
|
||||||
|
ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
ForEach(state.settings.favoriteFolders, id: \.self) { path in
|
ForEach(state.settings.favoriteFolders, id: \.self) { path in
|
||||||
folderRow(URL(fileURLWithPath: path))
|
FolderTreeRow(url: URL(fileURLWithPath: path), depth: 0, isFavorite: true, newestFirst: true)
|
||||||
.contextMenu {
|
|
||||||
Button("In neuem Tab öffnen") { state.open(folder: URL(fileURLWithPath: path), newTab: true) }
|
|
||||||
Button("Aus Favoriten entfernen") { state.settings.favoriteFolders.removeAll { $0 == path } }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onMove { state.settings.favoriteFolders.move(fromOffsets: $0, toOffset: $1) }
|
.padding(.vertical, 4)
|
||||||
}
|
}
|
||||||
.listStyle(.sidebar)
|
|
||||||
} accessory: {
|
} accessory: {
|
||||||
if let f = state.folder, !state.settings.favoriteFolders.contains(f.path) {
|
if let f = state.folder, !state.settings.favoriteFolders.contains(f.path) {
|
||||||
Button { state.settings.favoriteFolders.append(f.path) } label: { Image(systemName: "plus") }
|
Button { state.settings.favoriteFolders.append(f.path) } label: { Image(systemName: "plus") }
|
||||||
@@ -388,6 +388,9 @@ struct FolderTreeRow: View {
|
|||||||
@EnvironmentObject var state: AppState
|
@EnvironmentObject var state: AppState
|
||||||
let url: URL
|
let url: URL
|
||||||
let depth: Int
|
let depth: Int
|
||||||
|
var isFavorite = false
|
||||||
|
/// Sort sub folders by date (newest first) – handy for INPUT with one folder per game.
|
||||||
|
var newestFirst = false
|
||||||
@State private var expanded = false
|
@State private var expanded = false
|
||||||
@State private var children: [URL]?
|
@State private var children: [URL]?
|
||||||
|
|
||||||
@@ -396,7 +399,7 @@ struct FolderTreeRow: View {
|
|||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
Button {
|
Button {
|
||||||
expanded.toggle()
|
expanded.toggle()
|
||||||
if expanded && children == nil { children = Self.subfolders(of: url) }
|
if expanded { children = Self.subfolders(of: url, newestFirst: newestFirst) } // re-read: new ingest folders
|
||||||
} label: {
|
} label: {
|
||||||
Image(systemName: expanded ? "chevron.down" : "chevron.right")
|
Image(systemName: expanded ? "chevron.down" : "chevron.right")
|
||||||
.font(.system(size: 9, weight: .bold))
|
.font(.system(size: 9, weight: .bold))
|
||||||
@@ -414,14 +417,25 @@ struct FolderTreeRow: View {
|
|||||||
.padding(.vertical, 2)
|
.padding(.vertical, 2)
|
||||||
.background(state.folder == url ? Color.accentColor.opacity(0.25) : Color.clear)
|
.background(state.folder == url ? Color.accentColor.opacity(0.25) : Color.clear)
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
.onTapGesture(count: 1) { state.open(folder: url) }
|
.onTapGesture(count: 1) {
|
||||||
|
state.open(folder: url)
|
||||||
|
// A folder without photos but with sub folders (e.g. INPUT) opens its list right away.
|
||||||
|
if state.items.isEmpty {
|
||||||
|
children = Self.subfolders(of: url, newestFirst: newestFirst)
|
||||||
|
if !(children ?? []).isEmpty { expanded = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
Button("In neuem Tab öffnen") { state.open(folder: url, newTab: true) }
|
Button("In neuem Tab öffnen") { state.open(folder: url, newTab: true) }
|
||||||
Button("Zu Favoriten") { if !state.settings.favoriteFolders.contains(url.path) { state.settings.favoriteFolders.append(url.path) } }
|
Button("Zu Favoriten") { if !state.settings.favoriteFolders.contains(url.path) { state.settings.favoriteFolders.append(url.path) } }
|
||||||
Button("Im Finder zeigen") { NSWorkspace.shared.activateFileViewerSelecting([url]) }
|
Button("Im Finder zeigen") { NSWorkspace.shared.activateFileViewerSelecting([url]) }
|
||||||
|
if isFavorite {
|
||||||
|
Divider()
|
||||||
|
Button("Aus Favoriten entfernen") { state.settings.favoriteFolders.removeAll { $0 == url.path } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if expanded, let children {
|
if expanded, let children {
|
||||||
ForEach(children, id: \.self) { FolderTreeRow(url: $0, depth: depth + 1) }
|
ForEach(children, id: \.self) { FolderTreeRow(url: $0, depth: depth + 1, newestFirst: newestFirst) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,14 +446,21 @@ struct FolderTreeRow: View {
|
|||||||
return fm.displayName(atPath: url.path)
|
return fm.displayName(atPath: url.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func subfolders(of url: URL) -> [URL] {
|
static func subfolders(of url: URL, newestFirst: Bool = false) -> [URL] {
|
||||||
let keys: [URLResourceKey] = [.isDirectoryKey, .isPackageKey]
|
let keys: [URLResourceKey] = [.isDirectoryKey, .isPackageKey, .creationDateKey]
|
||||||
let list = (try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: keys, options: [.skipsHiddenFiles])) ?? []
|
let list = (try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: keys, options: [.skipsHiddenFiles])) ?? []
|
||||||
return list.filter {
|
return list.filter {
|
||||||
let v = try? $0.resourceValues(forKeys: Set(keys))
|
let v = try? $0.resourceValues(forKeys: Set(keys))
|
||||||
return v?.isDirectory == true && v?.isPackage != true
|
return v?.isDirectory == true && v?.isPackage != true
|
||||||
}
|
}
|
||||||
.sorted { $0.lastPathComponent.localizedStandardCompare($1.lastPathComponent) == .orderedAscending }
|
.sorted { a, b in
|
||||||
|
if newestFirst {
|
||||||
|
let da = (try? a.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? .distantPast
|
||||||
|
let db = (try? b.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? .distantPast
|
||||||
|
if da != db { return da > db }
|
||||||
|
}
|
||||||
|
return a.lastPathComponent.localizedStandardCompare(b.lastPathComponent) == .orderedAscending
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,3 +478,39 @@ struct WindowAccessor: NSViewRepresentable {
|
|||||||
DispatchQueue.main.async { onWindow(nsView.window) }
|
DispatchQueue.main.async { onWindow(nsView.window) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Folder without photos (e.g. INPUT): show its sub folders as big buttons instead of an empty sheet.
|
||||||
|
struct SubfolderPicker: View {
|
||||||
|
@EnvironmentObject var state: AppState
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
let subs = state.folder.map { FolderTreeRow.subfolders(of: $0, newestFirst: true) } ?? []
|
||||||
|
VStack(spacing: 14) {
|
||||||
|
if subs.isEmpty {
|
||||||
|
Image(systemName: "photo.on.rectangle").font(.system(size: 44)).foregroundStyle(.secondary)
|
||||||
|
Text("Keine Fotos in diesem Ordner").foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
Text("Keine Fotos direkt in „\(state.folder?.lastPathComponent ?? "")“ – Unterordner:").foregroundStyle(.secondary)
|
||||||
|
ScrollView {
|
||||||
|
LazyVGrid(columns: [GridItem(.adaptive(minimum: 260), spacing: 12)], spacing: 12) {
|
||||||
|
ForEach(subs, id: \.self) { sub in
|
||||||
|
Button { state.open(folder: sub) } label: {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "folder.fill").font(.title2).foregroundStyle(.secondary)
|
||||||
|
Text(sub.lastPathComponent).lineLimit(2).multilineTextAlignment(.leading)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(12)
|
||||||
|
.background(RoundedRectangle(cornerRadius: 8).fill(Color.secondary.opacity(0.15)))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.contextMenu { Button("In neuem Tab öffnen") { state.open(folder: sub, newTab: true) } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(20)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user