forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuggestionPanelWindowController.swift
More file actions
61 lines (50 loc) · 1.7 KB
/
Copy pathSuggestionPanelWindowController.swift
File metadata and controls
61 lines (50 loc) · 1.7 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
import AppKit
import Foundation
import SwiftUI
final class SuggestionPanelWindowController: NSWindowController {
let suggestionPanel: SuggestionPanel
var suggestionPanelWindow: SuggestionPanelWindow { window as! SuggestionPanelWindow }
init() {
suggestionPanel = .init()
let window = SuggestionPanelWindow(suggestionPanel: suggestionPanel)
super.init(window: window)
window.delegate = self
observe { [weak self] in
guard let self else { return }
self.suggestionPanelWindow.alphaValue = self.suggestionPanel.opacity
self.suggestionPanelWindow.setFrame(
self.suggestionPanel.frame,
display: true,
animate: false
)
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
deinit {
window?.close()
window = nil
}
}
extension SuggestionPanelWindowController: NSWindowDelegate {}
final class SuggestionPanelWindow: WidgetWindow {
override var canBecomeKey: Bool { false }
override var canBecomeMain: Bool { false }
init(suggestionPanel: SuggestionPanel) {
super.init(
contentRect: .init(x: 0, y: 0, width: Style.panelWidth, height: Style.panelHeight),
styleMask: [.borderless],
backing: .buffered,
defer: false
)
isReleasedWhenClosed = false
isOpaque = false
backgroundColor = .clear
level = widgetLevel(2)
hasShadow = true
contentView = NSHostingView(rootView: SuggestionPanelView(store: suggestionPanel))
setIsVisible(true)
}
}