Add nested (hierarchical) conversation folders

Folders can now contain other folders, arbitrarily deep — e.g. "Work"
containing "Project A"/"Project B". v10 migration adds a
self-referencing parentId column; tree ordering, depth, and cycle
detection are pure Swift (Folder.orderedTree/isDescendant/
visibleFolderIds), not SQL, so listFolders() stays a simple flat
query.

- Create nested folders via "New Subfolder…" (context menu, both
  list views) or by dragging a folder onto another to reparent it.
  Dragging onto an existing descendant is rejected (cycle guard).
- Deleting a folder reparents its children and any conversations
  filed directly in it up one level to the deleted folder's own
  parent — conversations are never deleted. This also fixes a real
  bug: the previous deleteFolder never persisted unfiling to the
  database, only patched in-memory state, so a conversation whose
  folder was deleted kept a dangling folderId and silently vanished
  from view after the next relaunch.
- All "Move to Folder" pickers (sidebar, advanced list, per-row
  context menus, the Save dialog's folder popup) show an indented
  flat list reflecting the tree.
- New DraggedItem enum disambiguates a dragged folder from dragged
  conversation(s) in the shared string-based drag payload, and
  unifies both list views on the same bundled-multi-selection format
  — closes a gap where dragging a multi-selection in the advanced
  list (⌘L) only moved the one row grabbed, unlike the sidebar.

Confirmed working live, including relaunch-survival of the
delete/reparent fix.
This commit is contained in:
2026-08-02 17:52:10 +02:00
parent 7f5d858b2a
commit 2668555b98
8 changed files with 598 additions and 99 deletions
+7 -5
View File
@@ -35,6 +35,7 @@ private final class ConversationSaveAccessory: NSObject {
let nameField: NSTextField
private let folderPopup: NSPopUpButton
private var folders: [Folder]
private var entries: [(folder: Folder, depth: Int)] = [] // recomputed in rebuildMenu whenever folders changes
private var lastGoodSelection: UUID? // the folder to revert to if "New Folder" is cancelled
init(defaultName: String, folders: [Folder], selectedFolderId: UUID?) {
@@ -56,15 +57,16 @@ private final class ConversationSaveAccessory: NSObject {
}
private func rebuildMenu(selecting folderId: UUID?) {
entries = Folder.orderedTree(from: folders)
folderPopup.removeAllItems()
folderPopup.addItem(withTitle: "No Folder")
for folder in folders {
folderPopup.addItem(withTitle: folder.name)
for entry in entries {
folderPopup.addItem(withTitle: String(repeating: " ", count: entry.depth) + entry.folder.name)
}
folderPopup.menu?.addItem(.separator())
folderPopup.addItem(withTitle: "New Folder…")
if let folderId, let idx = folders.firstIndex(where: { $0.id == folderId }) {
if let folderId, let idx = entries.firstIndex(where: { $0.folder.id == folderId }) {
folderPopup.selectItem(at: idx + 1)
} else {
folderPopup.selectItem(at: 0)
@@ -104,8 +106,8 @@ private final class ConversationSaveAccessory: NSObject {
var resolvedFolderId: UUID? {
let idx = folderPopup.indexOfSelectedItem
guard idx >= 1, idx - 1 < folders.count else { return nil }
return folders[idx - 1].id
guard idx >= 1, idx - 1 < entries.count else { return nil }
return entries[idx - 1].folder.id
}
}
#endif