Skip to content

Commit 0e8cad3

Browse files
committed
Merge branch 'feature/terminal-tab' into develop
2 parents daab571 + 9c1a592 commit 0e8cad3

8 files changed

Lines changed: 56 additions & 7 deletions

File tree

Core/Sources/ChatGPTChatTab/ChatGPTChatTab.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ public class ChatGPTChatTab: ChatTab {
4646
ChatTabItemView(chat: chat)
4747
}
4848

49+
public func buildIcon() -> any View {
50+
WithViewStore(chat, observe: \.isReceivingMessage) { viewStore in
51+
if viewStore.state {
52+
Image(systemName: "ellipsis.message")
53+
} else {
54+
Image(systemName: "message")
55+
}
56+
}
57+
}
58+
4959
public func buildMenu() -> any View {
5060
ChatContextMenu(store: chat.scope(state: \.chatMenu, action: Chat.Action.chatMenu))
5161
}
@@ -125,3 +135,4 @@ public class ChatGPTChatTab: ChatTab {
125135
}.store(in: &cancellable)
126136
}
127137
}
138+

Core/Sources/Service/GUI/ChatTabFactory.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum ChatTabFactory {
3131
),
3232
title: BrowserChatTab.name
3333
),
34+
folderIfNeeded(TerminalChatTab.chatBuilders(), title: TerminalChatTab.name),
3435
].compactMap { $0 }
3536

3637
return collection

Core/Sources/Service/GUI/GraphicalUserInterfaceController.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@ extension ChatTabPool {
388388
externalDependency: ChatTabFactory.externalDependenciesForBrowserChatTab()
389389
) else { break }
390390
return await createTab(id: data.id, from: builder)
391+
case TerminalChatTab.name:
392+
guard let builder = try? await TerminalChatTab.restore(
393+
from: data.data,
394+
externalDependency: ()
395+
) else { break }
396+
return await createTab(id: data.id, from: builder)
391397
default:
392398
break
393399
}
@@ -397,7 +403,7 @@ extension ChatTabPool {
397403
) else {
398404
return nil
399405
}
400-
return await createTab(from: builder)
406+
return await createTab(id: data.id, from: builder)
401407
}
402408
#endif
403409
}

Core/Sources/SuggestionWidget/ChatWindowView.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct ChatTabBar: View {
177177
store: store,
178178
info: info,
179179
content: { tab.tabItem },
180+
icon: { tab.icon },
180181
isSelected: info.id == viewStore.state.selectedTabId
181182
)
182183
.contextMenu {
@@ -280,7 +281,7 @@ struct ChatTabBarDropDelegate: DropDelegate {
280281
let tabs: IdentifiedArray<String, ChatTabInfo>
281282
let itemId: String
282283
@Binding var draggingTabId: String?
283-
284+
284285
func dropUpdated(info: DropInfo) -> DropProposal? {
285286
return DropProposal(operation: .move)
286287
}
@@ -299,20 +300,24 @@ struct ChatTabBarDropDelegate: DropDelegate {
299300
}
300301
}
301302

302-
struct ChatTabBarButton<Content: View>: View {
303+
struct ChatTabBarButton<Content: View, Icon: View>: View {
303304
let store: StoreOf<ChatPanelFeature>
304305
let info: ChatTabInfo
305306
let content: () -> Content
307+
let icon: () -> Icon
306308
let isSelected: Bool
307309
@State var isHovered: Bool = false
308310

309311
var body: some View {
310312
HStack(spacing: 0) {
311-
content()
313+
HStack(spacing: 4) {
314+
icon().foregroundColor(.secondary)
315+
content()
316+
}
312317
.font(.callout)
313318
.lineLimit(1)
314319
.frame(maxWidth: 120)
315-
.padding(.horizontal, 32)
320+
.padding(.horizontal, 28)
316321
.contentShape(Rectangle())
317322
.onTapGesture {
318323
store.send(.tabClicked(id: info.id))

Core/Sources/SuggestionWidget/FeatureReducers/ChatPanelFeature.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ public struct ChatPanelFeature: ReducerProtocol {
218218
state.chatTabGroup.tabInfo.insert(tab, at: to)
219219
return .none
220220

221+
case let .chatTab(id, .close):
222+
return .run { send in
223+
await send(.closeTabButtonClicked(id: id))
224+
}
225+
221226
case .chatTab:
222227
return .none
223228
}

Pro

Submodule Pro updated from 7796423 to ef0377c

Tool/Sources/ChatTab/ChatTab.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public protocol ChatTabType {
2626
/// Build the tabItem for this chat tab.
2727
@ViewBuilder
2828
func buildTabItem() -> any View
29+
/// Build the icon for this chat tab.
30+
@ViewBuilder
31+
func buildIcon() -> any View
2932
/// Build the menu for this chat tab.
3033
@ViewBuilder
3134
func buildMenu() -> any View
@@ -88,7 +91,7 @@ open class BaseChatTab {
8891
/// The tab item for this chat tab.
8992
@ViewBuilder
9093
public var tabItem: some View {
91-
let id = "ChatTabMenu\(id)"
94+
let id = "ChatTabTab\(id)"
9295
if let tab = self as? (any ChatTabType) {
9396
ContentView(buildView: tab.buildTabItem).id(id)
9497
.onAppear {
@@ -99,6 +102,17 @@ open class BaseChatTab {
99102
}
100103
}
101104

105+
/// The icon for this chat tab.
106+
@ViewBuilder
107+
public var icon: some View {
108+
let id = "ChatTabIcon\(id)"
109+
if let tab = self as? (any ChatTabType) {
110+
ContentView(buildView: tab.buildIcon).id(id)
111+
} else {
112+
EmptyView().id(id)
113+
}
114+
}
115+
102116
/// The tab item for this chat tab.
103117
@ViewBuilder
104118
public var menu: some View {
@@ -183,6 +197,10 @@ public class EmptyChatTab: ChatTab {
183197
Text("Empty-\(id)")
184198
}
185199

200+
public func buildIcon() -> any View {
201+
Image(systemName: "square")
202+
}
203+
186204
public func buildMenu() -> any View {
187205
Text("Empty-\(id)")
188206
}

Tool/Sources/ChatTab/ChatTabItem.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public struct ChatTabItem: ReducerProtocol {
2020
case updateTitle(String)
2121
case openNewTab(AnyChatTabBuilder)
2222
case tabContentUpdated
23+
case close
2324
}
2425

2526
public init() {}
@@ -34,6 +35,8 @@ public struct ChatTabItem: ReducerProtocol {
3435
return .none
3536
case .tabContentUpdated:
3637
return .none
38+
case .close:
39+
return .none
3740
}
3841
}
3942
}

0 commit comments

Comments
 (0)