forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromptToCodePanelGroupView.swift
More file actions
141 lines (127 loc) · 4.45 KB
/
PromptToCodePanelGroupView.swift
File metadata and controls
141 lines (127 loc) · 4.45 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import ComposableArchitecture
import Foundation
import SwiftUI
struct PromptToCodePanelGroupView: View {
let store: StoreOf<PromptToCodeGroup>
var body: some View {
WithPerceptionTracking {
VStack(spacing: 0) {
PromptToCodeTabBar(store: store)
.frame(height: 26)
Divider()
if let store = self.store.scope(
state: \.activePromptToCode,
action: \.activePromptToCode
) {
PromptToCodePanelView(store: store)
}
}
.background(.ultraThickMaterial)
.xcodeStyleFrame()
}
}
}
struct PromptToCodeTabBar: View {
let store: StoreOf<PromptToCodeGroup>
struct TabInfo: Equatable, Identifiable {
var id: URL
var tabTitle: String
var isProcessing: Bool
}
var body: some View {
HStack(spacing: 0) {
Tabs(store: store)
}
.background {
Button(action: { store.send(.switchToNextTab) }) { EmptyView() }
.opacity(0)
.keyboardShortcut("]", modifiers: [.command, .shift])
Button(action: { store.send(.switchToPreviousTab) }) { EmptyView() }
.opacity(0)
.keyboardShortcut("[", modifiers: [.command, .shift])
}
}
struct Tabs: View {
let store: StoreOf<PromptToCodeGroup>
var body: some View {
WithPerceptionTracking {
let tabInfo = store.promptToCodes.map {
TabInfo(
id: $0.id,
tabTitle: $0.filename,
isProcessing: $0.promptToCodeState.isGenerating
)
}
let selectedTabId = store.selectedTabId
?? store.promptToCodes.first?.id
ScrollViewReader { proxy in
ScrollView(.horizontal) {
HStack(spacing: 0) {
ForEach(tabInfo) { info in
WithPerceptionTracking {
PromptToCodeTabBarButton(
store: store,
info: info,
isSelected: info.id == store.selectedTabId
)
.id(info.id)
}
}
}
}
.hideScrollIndicator()
.onChange(of: selectedTabId) { id in
withAnimation(.easeInOut(duration: 0.2)) {
proxy.scrollTo(id)
}
}
}
}
}
}
}
struct PromptToCodeTabBarButton: View {
let store: StoreOf<PromptToCodeGroup>
let info: PromptToCodeTabBar.TabInfo
let isSelected: Bool
@State var isHovered: Bool = false
var body: some View {
HStack(spacing: 0) {
HStack(spacing: 4) {
if info.isProcessing {
ProgressView()
.controlSize(.small)
}
Text(info.tabTitle)
.truncationMode(.middle)
.allowsTightening(true)
}
.font(.callout)
.lineLimit(1)
.frame(maxWidth: 120)
.padding(.horizontal, 28)
.contentShape(Rectangle())
.onTapGesture {
store.send(.tabClicked(id: info.id))
}
.overlay(alignment: .leading) {
Button(action: {
store.send(.closeTabButtonClicked(id: info.id))
}) {
Image(systemName: "xmark")
.foregroundColor(.secondary)
}
.buttonStyle(.plain)
.padding(2)
.padding(.leading, 8)
.opacity(isHovered ? 1 : 0)
}
.onHover { isHovered = $0 }
.animation(.linear(duration: 0.1), value: isHovered)
.animation(.linear(duration: 0.1), value: isSelected)
Divider().padding(.vertical, 6)
}
.background(isSelected ? Color(nsColor: .selectedControlColor) : Color.clear)
.frame(maxHeight: .infinity)
}
}