1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 14:52:19 +03:00

Add stub select handler

This commit is contained in:
Tae Won Ha 2020-12-06 19:22:16 +01:00
parent f0c9ff4a93
commit 728974601a
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 11 additions and 5 deletions

View File

@ -27,7 +27,7 @@ public class NvimView: NSView,
public static let minLinespacing = (0.5).cgf
public static let maxLinespacing = 8.cgf
public let usesCustomTabBar: Bool
public let tabBar: TabBar<TabEntry>?
@ -155,12 +155,17 @@ public class NvimView: NSView,
)
self.sourceFileUrls = config.sourceFiles
self.usesCustomTabBar = config.usesCustomTabBar
if self.usesCustomTabBar { self.tabBar = TabBar<TabEntry>(withTheme: .default) }
else { self.tabBar = nil }
super.init(frame: .zero)
self.tabBar?.selectHandler = { [weak self] (index, tabEntry) in
Swift.print("tab \(index): \(tabEntry) selected")
}
self.bridge.consumer = self
self.registerForDraggedTypes([NSPasteboard.PasteboardType(String(kUTTypeFileURL))])

View File

@ -13,6 +13,7 @@ public protocol TabRepresentative: Hashable {
public class TabBar<Entry: TabRepresentative>: NSView {
public var theme: Theme { self._theme }
public var selectHandler: ((Int, Entry) -> Void)?
public init(withTheme theme: Theme) {
self._theme = theme
@ -59,9 +60,9 @@ public class TabBar<Entry: TabRepresentative>: NSView {
}
extension TabBar {
func select(tab _: Tab<Entry>) {
// self.stackView.arrangedSubviews.forEach { ($0 as? Tab<Entry>)?.isSelected = false }
// tab.isSelected = true
func select(tab: Tab<Entry>) {
guard let index = self.tabs.firstIndex(where: { $0 == tab }) else { return }
self.selectHandler?(index, tab.tabRepresentative)
}
}