| 1 | #if os(macOS) |
| 2 | import SwiftUI |
| 3 | import DocsKit |
| 4 | |
| 5 | struct DocsWindowCommands: Commands { |
| 6 | let windows: DocsWindows |
| 7 | @FocusedValue(\.docsWindowAccount) private var account |
| 8 | @FocusedValue(\.docsAccountActions) private var accountActions |
| 9 | @Environment(\.openWindow) private var openWindow |
| 10 | var body: some Commands { |
| 11 | CommandGroup(after: .appSettings) { |
| 12 | Button(docsMacString("Accounts")) { |
| 13 | if let action = accountActions?.accounts { action() } |
| 14 | else { windows.accountsRequested = true; openWindow(id: "home") } |
| 15 | }.disabled(accountActions?.canManage == false) |
| 16 | Button(docsMacString("Sign out")) { accountActions?.signOut() } |
| 17 | .disabled(accountActions?.canSignOut != true) |
| 18 | Divider() |
| 19 | } |
| 20 | |
| 21 | CommandGroup(replacing: .newItem) { |
| 22 | Button(docsMacString("New document")) { |
| 23 | if let entry = windows.entries.first(where: { $0.account == account && $0.isOpen }) { |
| 24 | let id = windows.reserveDraft(account: entry.account, client: entry.client) |
| 25 | openWindow(id: "document", value: id) |
| 26 | } else { |
| 27 | windows.createRequested = true |
| 28 | openWindow(id: "home") |
| 29 | } |
| 30 | }.keyboardShortcut("n") |
| 31 | Menu(docsMacString("Recent")) { |
| 32 | ForEach(windows.entries.filter { $0.account == (account ?? windows.activeAccount) }.prefix(20)) { entry in |
| 33 | Button(entry.title) { |
| 34 | windows.setOpen(entry.id, true) |
| 35 | openWindow(id: "document", value: entry.id) |
| 36 | } |
| 37 | } |
| 38 | if !windows.entries.contains(where: { $0.account == (account ?? windows.activeAccount) }) { |
| 39 | Text(docsMacString("No recent documents")) |
| 40 | } |
| 41 | } |
| 42 | Divider() |
| 43 | DocsDocumentMenu() |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | } |
| 48 | #endif |
| 49 | |