forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMCPRegistryURLSheet.swift
More file actions
71 lines (63 loc) · 2.5 KB
/
MCPRegistryURLSheet.swift
File metadata and controls
71 lines (63 loc) · 2.5 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
70
71
import GitHubCopilotService
import SwiftUI
struct MCPRegistryURLSheet: View {
@AppStorage(\.mcpRegistryURL) private var mcpRegistryURL
@AppStorage(\.mcpRegistryURLHistory) private var mcpRegistryURLHistory
@Environment(\.dismiss) private var dismiss
@State private var originalMcpRegistryURL: String = ""
@State private var isFormValid: Bool = true
let mcpRegistryEntry: MCPRegistryEntry?
let onURLUpdated: (() -> Void)?
init(mcpRegistryEntry: MCPRegistryEntry? = nil, onURLUpdated: (() -> Void)? = nil) {
self.mcpRegistryEntry = mcpRegistryEntry
self.onURLUpdated = onURLUpdated
}
var body: some View {
Form {
VStack(alignment: .center, spacing: 20) {
HStack(alignment: .center) {
Spacer()
Text("MCP Registry URL").font(.headline)
Spacer()
AdaptiveHelpLink(action: openHelpLink)
}
VStack(alignment: .leading, spacing: 4) {
MCPRegistryURLInputField(
urlText: $originalMcpRegistryURL,
isSheet: true,
mcpRegistryEntry: mcpRegistryEntry,
onValidationChange: { isValid in
isFormValid = isValid
}
)
}
HStack(spacing: 8) {
Spacer()
Button("Cancel", role: .cancel) { dismiss() }
Button("Update") {
// Check if URL changed before updating
if originalMcpRegistryURL != mcpRegistryURL {
mcpRegistryURL = originalMcpRegistryURL
onURLUpdated?()
}
dismiss()
}
.buttonStyle(.borderedProminent)
.disabled(!isFormValid || mcpRegistryEntry?.registryAccess == .registryOnly)
}
}
.textFieldStyle(.plain)
.multilineTextAlignment(.trailing)
.padding(20)
}
.onAppear {
loadExistingURL()
}
}
private func loadExistingURL() {
originalMcpRegistryURL = mcpRegistryURL
}
private func openHelpLink() {
NSWorkspace.shared.open(URL(string: "https://docs.github.com/en/copilot/how-tos/provide-context/use-mcp/select-an-mcp-registry")!)
}
}