oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1#if os(macOS)
2import RastrilloApple
3import SwiftUI
4import DocsKit
5
6struct DocsWindowCommands: Commands {
7 let windows: DocsWindows
8 @FocusedValue(\.docsWindowAccount) private var account
9 @FocusedValue(\.docsAccountActions) private var accountActions
10 @Environment(\.openWindow) private var openWindow
11 var body: some Commands {
12 // Help → Colophon. It replaces the default "Docs Help" item, which
13 // has no help book to open and only says so.
14 CommandGroup(replacing: .help) {
15 Button(DocsColophonView.title) { openWindow(id: "colophon") }
16 }
17 CommandGroup(after: .appSettings) {
18 Button(accountActions?.accountsLabel ?? docsMacString("Accounts")) {
19 if let action = accountActions?.accounts { action() }
20 else { windows.accountsRequested = true; openWindow(id: "home") }
21 }.disabled(accountActions?.canManage == false)
22 // Only for an Oficina ID, only while signed in, and refused with a
23 // document window of the identity open (the home window re-checks).
24 if let useAnother = accountActions?.useAnother {
25 Button(OficinaIDText.text("continue.another")) { useAnother() }
26 .disabled(accountActions?.canSignOut != true)
27 }
28 Button(accountActions?.signOutLabel ?? docsMacString("Sign out")) { accountActions?.signOut() }
29 .disabled(accountActions?.canSignOut != true)
30 Divider()
31 }
32
33 CommandGroup(replacing: .newItem) {
34 Button(docsMacString("New document")) {
35 if let entry = windows.entries.first(where: { $0.account == account && $0.isOpen }) {
36 let id = windows.reserveDraft(account: entry.account, client: entry.client)
37 openWindow(id: "document", value: id)
38 } else {
39 windows.createRequested = true
40 openWindow(id: "home")
41 }
42 }.keyboardShortcut("n")
43 DocsOpenDocumentMenuItem()
44 Menu(docsMacString("Recent")) {
45 ForEach(windows.entries.filter { $0.account == (account ?? windows.activeAccount) && !$0.isDeleted }.prefix(20)) { entry in
46 Button(entry.title) {
47 windows.setOpen(entry.id, true)
48 openWindow(id: "document", value: entry.id)
49 }
50 }
51 if !windows.entries.contains(where: { $0.account == (account ?? windows.activeAccount) && !$0.isDeleted }) {
52 Text(docsMacString("No recent documents"))
53 }
54 }
55 Divider()
56 DocsDocumentMenu()
57 }
58
59 }
60}
61#endif
62