| 1 | #if os(macOS) |
| 2 | import AppKit |
| 3 | import RastrilloApple |
| 4 | import SwiftUI |
| 5 | |
| 6 | struct DocsEditorContext { |
| 7 | let model: DocsModel |
| 8 | let rename: () -> Void |
| 9 | let client: NativeTransport |
| 10 | /// The document's origin, for what waits while it is offline. |
| 11 | let origin: URL |
| 12 | let zoom: Binding<Double> |
| 13 | let paged: Binding<Bool> |
| 14 | /// File ▸ Share…: the popover under Share… (spec §1). |
| 15 | let share: () -> Void |
| 16 | /// File ▸ Delete… (owners only). |
| 17 | let delete: () -> Void |
| 18 | let exportRequest: Binding<String?> |
| 19 | /// Open a document… (⌘K): the jump sheet over this window. |
| 20 | let jumping: Binding<Bool> |
| 21 | /// Tools ▸ Word count… and Help ▸ Keyboard shortcuts…, as sheets. |
| 22 | let wordCount: Binding<Bool> |
| 23 | let shortcuts: Binding<Bool> |
| 24 | /// Share…, Delete…, Export and Print need the server (spec §6, Offline). |
| 25 | @MainActor var offline: Bool { model.connectivity.isOffline(origin) } |
| 26 | @MainActor var actions: DocumentCommands? { |
| 27 | guard NSApp.keyWindow?.firstResponder is DocsTextView, model.history.loaded else { return nil } |
| 28 | return DocumentCommands(model: model, content: model.surface.content) |
| 29 | } |
| 30 | /// A Format menu command: now, or once the input pending when it was |
| 31 | /// chosen has been drawn (`DocsModel.whenCommandsReady`). |
| 32 | @MainActor func ready(_ command: @escaping @MainActor (DocumentCommands) -> Void) { |
| 33 | guard actions != nil else { return } |
| 34 | #if DOCS_PROBES |
| 35 | DocsProbes.menuCommands += 1 |
| 36 | #endif |
| 37 | model.whenCommandsReady(command) |
| 38 | } |
| 39 | } |
| 40 | extension FocusedValues { @Entry var docsEditor: DocsEditorContext? } |
| 41 | #endif |
| 42 | |