| 1 | #if os(macOS) |
| 2 | import DocsKit |
| 3 | import SwiftUI |
| 4 | |
| 5 | struct DocsDocumentWindow: View { |
| 6 | let windows: DocsWindows |
| 7 | /// For the subtitle's team, derived per window (spec D7). |
| 8 | @ObservedObject var oficina: DocsOficinaSession |
| 9 | let id: UUID? |
| 10 | @Environment(\.openWindow) private var openWindow |
| 11 | var body: some View { |
| 12 | if let entry = windows.entries.first(where: { $0.id == id }) { |
| 13 | DocsWorkspace(client: entry.client, accountID: entry.account, transport: windows.transports[entry.account], signOut: {}, documentID: entry.document, newDocument: entry.isDraft, documentChanged: { document, title in windows.attach(entry.id, document: document, title: title) }, |
| 14 | openDocument: { document, title in |
| 15 | // Open a document… (⌘K) opens or focuses that document's window. |
| 16 | let id = windows.reserve(account: entry.account, document: document, title: title, client: entry.client) |
| 17 | openWindow(id: "document", value: id) |
| 18 | }, team: Self.team(for: entry.account, oficina: oficina, windows: windows), |
| 19 | accountLabel: oficina.identityLabel(forAccount: entry.account), |
| 20 | // Delete…: File ▸ Recent forgets it as the window closes. |
| 21 | documentDeleted: { _ in windows.forget(entry.id) }) |
| 22 | .id(entry.id) |
| 23 | .focusedSceneValue(\.docsWindowAccount, entry.account) |
| 24 | .onAppear { windows.setOpen(entry.id, true) } |
| 25 | .onDisappear { windows.setOpen(entry.id, false) } |
| 26 | } else { |
| 27 | ContentUnavailableView { Label(docsMacString("Open a document from Home"), systemImage: "house") } actions: { |
| 28 | Button(docsMacString("Home")) { openWindow(id: "home") } |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | /// An Oficina ID team's name from the identity's own record, so a |
| 33 | /// renamed team or a window opened before the home window shows the |
| 34 | /// right one; a server account's from the home window's account list. |
| 35 | @MainActor static func team(for account: String, oficina: DocsOficinaSession, windows: DocsWindows) -> String? { |
| 36 | if DocsOficinaSession.isOficinaAccount(account) { return oficina.teamName(forAccount: account) ?? windows.teamNames[account] } |
| 37 | return windows.teamNames[account] |
| 38 | } |
| 39 | } |
| 40 | #endif |
| 41 | |