oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1import AppKit
2import EquipoKit
3import SwiftUI
4
5struct MacPowerCommands: Commands {
6 let model: EquipoAppModel
7 @FocusedValue(MacWorkspace.self) private var workspace
8 @Environment(\.openWindow) private var openWindow
9 var body: some Commands {
10 CommandGroup(replacing: .newItem) {
11 Button(EquipoStrings.text("native.mac.new_message")) {
12 MacWorkspace.newMessage(app: model, focused: workspace)
13 if workspace == nil || workspace?.standalone == true { openWindow(id: "main") }
14 }.keyboardShortcut("n")
15 }
16 CommandMenu(EquipoStrings.text("native.mac.go")) {
17 Button(EquipoStrings.text("native.mac.jump")) {
18 workspace?.palette = true
19 }.keyboardShortcut("k").disabled(workspace == nil)
20 Divider()
21 pane("tab.conversation", .conversation, "1")
22 pane("tab.needs", .needs, "2")
23 pane("tab.tasks", .tasks, "3")
24 pane("nav.projects", .projects, "4")
25 Divider()
26 Button(EquipoStrings.text("native.mac.back")) { workspace?.back() }.keyboardShortcut("[").disabled(workspace?.history.canBack != true || workspace?.standalone == true)
27 Button(EquipoStrings.text("native.mac.forward")) { workspace?.forward() }.keyboardShortcut("]").disabled(workspace?.history.canForward != true || workspace?.standalone == true)
28 Button(EquipoStrings.text("native.mac.refresh")) { Task { await workspace?.refresh() } }.keyboardShortcut("r").disabled(workspace == nil)
29 }
30 CommandMenu(EquipoStrings.text("task.title")) {
31 Button(EquipoStrings.text("native.mac.open_window")) {
32 if let workspace, let context = workspace.context {
33 openWindow(id: "task", value: MacTaskWindowID(taskID: context.taskID, session: workspace.session))
34 }
35 }.disabled(workspace?.context == nil)
36 // ⌘Return belongs to Send in an editor, and opens a task only in
37 // the palette. No global shortcut can steal an unfinished message.
38 Divider()
39 action(.merge, shortcut: "m")
40 action(.retry)
41 action(.move)
42 action(.web)
43 Divider()
44 action(.cancel)
45 }
46 }
47 private func pane(_ key: String, _ pane: Destination.Pane, _ keyEquivalent: KeyEquivalent) -> some View {
48 Button(EquipoStrings.text(.init(key))) {
49 workspace?.go(.pane(pane)); if workspace?.standalone == true { openWindow(id: "main") }
50 }.keyboardShortcut(keyEquivalent).disabled(workspace == nil)
51 }
52 @ViewBuilder private func action(_ action: MacTaskAction, shortcut: KeyEquivalent? = nil) -> some View {
53 let button = Button(action.title, role: action == .cancel ? .destructive : nil) {
54 let target = workspace
55 Task { await target?.performMenuAction(action) }
56 }.disabled(workspace?.context?.actions.contains(action) != true || workspace?.palette == true)
57 if let shortcut { button.keyboardShortcut(shortcut, modifiers: [.command, .shift]) }
58 else { button }
59 }
60}
61