forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatContextMenu.swift
More file actions
69 lines (61 loc) · 1.76 KB
/
ChatContextMenu.swift
File metadata and controls
69 lines (61 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import AppKit
import SharedUIComponents
import SwiftUI
struct ChatContextMenu: View {
@ObservedObject var chat: ChatProvider
@AppStorage(\.customCommands) var customCommands
var body: some View {
Group {
currentSystemPrompt
currentExtraSystemPrompt
resetPrompt
Divider()
customCommandMenu
}
}
@ViewBuilder
var currentSystemPrompt: some View {
Text("System Prompt:")
Text({
var text = chat.systemPrompt
if text.isEmpty { text = "N/A" }
if text.count > 30 { text = String(text.prefix(30)) + "..." }
return text
}() as String)
}
@ViewBuilder
var currentExtraSystemPrompt: some View {
Text("Extra Prompt:")
Text({
var text = chat.extraSystemPrompt
if text.isEmpty { text = "N/A" }
if text.count > 30 { text = String(text.prefix(30)) + "..." }
return text
}() as String)
}
var resetPrompt: some View {
Button("Reset System Prompt") {
chat.resetPrompt()
}
}
var customCommandMenu: some View {
Menu("Custom Commands") {
ForEach(
customCommands.filter {
switch $0.feature {
case .chatWithSelection, .customChat: return true
case .promptToCode: return false
case .singleRoundDialog: return false
}
},
id: \.name
) { command in
Button(action: {
chat.triggerCustomCommand(command)
}) {
Text(command.name)
}
}
}
}
}