Build the board popover — title widget, rename, styling, git slot

The window-title widget arrives as a leading titlebar accessory — a
quiet chevron on board windows only, installed and removed by the
window controller's own attach lifecycle — anchoring the one
board-level surface as a transient popover (the board window
deliberately grows no toolbar item for it). Inside: board rename
editing frontmatter title only (the folder is never renamed; an empty
commit removes the key and the window title falls back to the folder
name), the embedded shared style editor permanently targeting the
board, and the labeled Git section that this milestone only reserves
— a mode-none explanation and a disabled stub where m7's add-git,
branch, remote, and authentication controls land. Cmd-I (File >
Board Info) toggles it per window through a focused scene value,
kept apart from board-scoped transient state since a titlebar
popover belongs to one window, not to the board. Escape reverts a
dirty rename field and falls through to dismiss otherwise; a foreign
rename resyncs the field only while unfocused. 12 new tests.

Claude-Session: https://claude.ai/code/session_01SR4XGjmBE16ZUYWpfFHXwY
This commit is contained in:
2026-07-27 15:08:06 -04:00
parent c6298c2e41
commit aa6aaf2a11
8 changed files with 745 additions and 11 deletions
+44 -3
View File
@@ -60,6 +60,12 @@ final class HostedWindowController: NSObject, NSWindowDelegate {
/// instead of starting a second flush.
private var isFlushed = false
/// The titlebar accessory this window shows, once something has given it one today the board
/// popover's window-title widget (03-board-ui.md § Board popover), and only on board windows.
/// `nil` on welcome, the bootstrap and card windows, which is why it is a slot rather than a
/// constructor argument.
private var titlebarAccessory: NSTitlebarAccessoryViewController?
private static let logger = Logger(subsystem: "dev.rzen.indie.Kanban", category: "window")
// MARK: Attachment
@@ -75,17 +81,52 @@ final class HostedWindowController: NSObject, NSWindowDelegate {
window.delegate = self
}
onAttach?(window)
// After `onAttach`, so placement has already happened: an accessory handed over before the
// window existed is installed here instead, and one handed over later installs immediately.
addTitlebarAccessoryIfPossible()
}
/// Puts the previous delegate back. Called when the hosting view goes away; a no-op if something
/// else has since taken the delegate, because stomping a third party's would be the bug this
/// whole file exists to avoid.
/// Puts the previous delegate back, and takes the titlebar accessory back out. Called when the
/// hosting view goes away; the delegate half is a no-op if something else has since taken the
/// delegate, because stomping a third party's would be the bug this whole file exists to avoid.
func detach() {
removeTitlebarAccessory()
titlebarAccessory = nil
guard let window, window.delegate === self else { return }
window.delegate = previousDelegate
self.window = nil
}
// MARK: Titlebar accessory
/// Gives this window a titlebar accessory **once**, whatever the caller does.
///
/// The guard is the whole of the install-once rule: AppKit keeps accessories in an array and
/// would happily hold two identical widgets, and a board window's host may configure itself more
/// than once (the load returns, the window attaches, SwiftUI re-evaluates). Installing before
/// the window exists is legal the accessory is held and goes in at `attach`.
func installTitlebarAccessory(_ accessory: NSTitlebarAccessoryViewController) {
guard titlebarAccessory == nil else { return }
titlebarAccessory = accessory
addTitlebarAccessoryIfPossible()
}
private func addTitlebarAccessoryIfPossible() {
guard let window, let accessory = titlebarAccessory,
!window.titlebarAccessoryViewControllers.contains(where: { $0 === accessory })
else { return }
window.addTitlebarAccessoryViewController(accessory)
}
/// Removes ours and only ours, by identity: the index is looked up rather than assumed, because
/// nothing promises this app owns the only accessory a window carries.
private func removeTitlebarAccessory() {
guard let window, let accessory = titlebarAccessory,
let index = window.titlebarAccessoryViewControllers.firstIndex(where: { $0 === accessory })
else { return }
window.removeTitlebarAccessoryViewController(at: index)
}
/// Closes the window for real, after the flush has run. `performClose` rather than `close` so the
/// standard path runs SwiftUI's own delegate gets its callbacks, tabbing behaves with the
/// flag telling our own `windowShouldClose` to stand aside.