Skip to content

Commit 1c81ab1

Browse files
committed
Add attach button to title bar
1 parent 2541553 commit 1c81ab1

2 files changed

Lines changed: 32 additions & 36 deletions

File tree

Core/Sources/SuggestionWidget/ChatWindowView.swift

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ struct ChatTitleBar: View {
5252

5353
var body: some View {
5454
HStack(spacing: 6) {
55-
TrafficLightButton(
56-
isHovering: isHovering,
57-
isActive: true,
58-
color: Color(nsColor: .systemOrange),
59-
action: {
60-
store.send(.hideButtonClicked)
61-
}
62-
) {
63-
Image(systemName: "minus")
64-
.foregroundStyle(.black.opacity(0.5))
65-
.font(Font.system(size: 8).weight(.heavy))
66-
}
67-
.keyboardShortcut("m", modifiers: [.command])
68-
6955
WithViewStore(store, observe: { $0.chatPanelInASeparateWindow }) { viewStore in
7056
TrafficLightButton(
7157
isHovering: isHovering,
@@ -82,6 +68,8 @@ struct ChatTitleBar: View {
8268
}
8369
}
8470

71+
Spacer()
72+
8573
Button(action: {
8674
store.send(.closeActiveTabClicked)
8775
}) {
@@ -90,25 +78,20 @@ struct ChatTitleBar: View {
9078
.opacity(0)
9179
.keyboardShortcut("w", modifiers: [.command])
9280

93-
Spacer()
94-
}
95-
.buttonStyle(.plain)
96-
.overlay {
97-
RoundedRectangle(cornerRadius: 2)
98-
.fill(.tertiary)
99-
.frame(width: 120, height: 4)
100-
.background {
101-
if isHovering {
102-
RoundedRectangle(cornerRadius: 6)
103-
.fill(.tertiary.opacity(0.3))
104-
.frame(width: 128, height: 12)
105-
}
81+
Button(
82+
action: {
83+
store.send(.hideButtonClicked)
10684
}
85+
) {
86+
Image(systemName: "minus")
87+
.foregroundStyle(.black.opacity(0.5))
88+
.font(Font.system(size: 8).weight(.heavy))
89+
}
90+
.opacity(0)
91+
.keyboardShortcut("m", modifiers: [.command])
10792
}
108-
.padding(.horizontal, 6)
109-
.padding(.top, 1)
110-
.frame(maxWidth: .infinity)
111-
.frame(height: Style.chatWindowTitleBarHeight)
93+
.buttonStyle(.plain)
94+
.padding(.leading, 2)
11295
.onHover(perform: { hovering in
11396
isHovering = hovering
11497
})

Core/Sources/SuggestionWidget/SuggestionWidgetController.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ public final class SuggestionWidgetController: NSObject {
129129
it.minimizeWindow = { [weak self] in
130130
self?.store.send(.chatPanel(.hideButtonClicked))
131131
}
132+
it.titleVisibility = .hidden
133+
it.addTitlebarAccessoryViewController({
134+
let controller = NSTitlebarAccessoryViewController()
135+
let view = NSHostingView(rootView: ChatTitleBar(store: store.scope(
136+
state: \.chatPanelState,
137+
action: WidgetFeature.Action.chatPanel
138+
)))
139+
controller.view = view
140+
view.frame = .init(x: 0, y: 0, width: 100, height: 40)
141+
controller.layoutAttribute = .left
142+
return controller
143+
}())
132144
it.isReleasedWhenClosed = false
133145
it.isOpaque = false
134146
it.backgroundColor = .clear
@@ -138,7 +150,7 @@ public final class SuggestionWidgetController: NSObject {
138150
.transient,
139151
.fullScreenPrimary,
140152
.fullScreenAllowsTiling,
141-
if #available(macOS 13, *) { [.primary] }
153+
if #available(macOS 13, *) { [.primary] },
142154
]
143155
it.hasShadow = true
144156
it.contentView = NSHostingView(
@@ -276,21 +288,22 @@ class CanBecomeKeyWindow: NSWindow {
276288
class ChatWindow: NSWindow {
277289
override var canBecomeKey: Bool { true }
278290
override var canBecomeMain: Bool { true }
279-
291+
280292
var minimizeWindow: () -> Void = {}
281-
293+
282294
var isWindowHidden: Bool = false {
283295
didSet {
284296
alphaValue = isPanelDisplayed && !isWindowHidden ? 1 : 0
285297
}
286298
}
299+
287300
var isPanelDisplayed: Bool = false {
288301
didSet {
289302
alphaValue = isPanelDisplayed && !isWindowHidden ? 1 : 0
290303
}
291304
}
292-
293-
override func miniaturize(_ sender: Any?) {
305+
306+
override func miniaturize(_: Any?) {
294307
minimizeWindow()
295308
}
296309
}

0 commit comments

Comments
 (0)