mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 03:25:03 +03:00
Display tabs
This commit is contained in:
parent
0572cec9eb
commit
c550da8845
@ -10,10 +10,13 @@ import Tabs
|
||||
|
||||
extension NvimView {
|
||||
|
||||
struct TabEntry: Equatable, Hashable, TabRepresentative {
|
||||
var title: String
|
||||
var tabpage: RxNeovimApi.Tabpage
|
||||
var isSelected = false
|
||||
public struct TabEntry: Hashable, TabRepresentative {
|
||||
public static func ==(lhs: TabEntry, rhs: TabEntry) -> Bool { lhs.tabpage == rhs.tabpage }
|
||||
|
||||
public var title: String
|
||||
public var isSelected = false
|
||||
|
||||
public var tabpage: RxNeovimApi.Tabpage
|
||||
}
|
||||
|
||||
public struct Config {
|
||||
|
@ -594,10 +594,10 @@ extension NvimView {
|
||||
let tabpageValue = dict[.string("tab")],
|
||||
let tabpage = RxNeovimApi.Tabpage(tabpageValue) else { return nil }
|
||||
|
||||
return TabEntry(title: name, tabpage: tabpage, isSelected: tabpage.handle == curTab.handle)
|
||||
return TabEntry(title: name, isSelected: tabpage.handle == curTab.handle, tabpage: tabpage)
|
||||
}
|
||||
|
||||
Swift.print("!!!!!!!!!!!! all tabs: \(tabEntries)")
|
||||
gui.async { self.tabBar?.update(tabRepresentatives: tabEntries) }
|
||||
}
|
||||
|
||||
private func bufferWritten(_ handle: Int) {
|
||||
|
@ -29,7 +29,7 @@ public class NvimView: NSView,
|
||||
public static let maxLinespacing = 8.cgf
|
||||
|
||||
public let usesCustomTabBar: Bool
|
||||
public private(set) var tabBar: TabBar?
|
||||
public let tabBar: TabBar<TabEntry>?
|
||||
|
||||
public var isLeftOptionMeta = false
|
||||
public var isRightOptionMeta = false
|
||||
@ -157,7 +157,8 @@ public class NvimView: NSView,
|
||||
self.sourceFileUrls = config.sourceFiles
|
||||
|
||||
self.usesCustomTabBar = config.usesCustomTabBar
|
||||
if self.usesCustomTabBar { self.tabBar = TabBar(withTheme: .default) }
|
||||
if self.usesCustomTabBar { self.tabBar = TabBar<TabEntry>(withTheme: .default) }
|
||||
else { self.tabBar = nil }
|
||||
|
||||
super.init(frame: .zero)
|
||||
self.bridge.consumer = self
|
||||
|
@ -52,14 +52,9 @@ class Tab<Entry: TabRepresentative>: NSView {
|
||||
@available(*, unavailable)
|
||||
required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
var isSelected: Bool = false {
|
||||
didSet {
|
||||
self.adjustToSelectionChange()
|
||||
self.needsDisplay = true
|
||||
}
|
||||
}
|
||||
var isSelected: Bool { self.tabRepresentative.isSelected }
|
||||
|
||||
weak private(set) var tabBar: TabBar<Entry>?
|
||||
private(set) weak var tabBar: TabBar<Entry>?
|
||||
var position = Position.inBetween {
|
||||
didSet { self.needsDisplay = true }
|
||||
}
|
||||
|
@ -6,8 +6,9 @@
|
||||
import Cocoa
|
||||
import PureLayout
|
||||
|
||||
public protocol TabRepresentative: Hashable, Equatable {
|
||||
public protocol TabRepresentative: Hashable {
|
||||
var title: String { get }
|
||||
var isSelected: Bool { get }
|
||||
}
|
||||
|
||||
public class TabBar<Entry: TabRepresentative>: NSView {
|
||||
@ -24,7 +25,24 @@ public class TabBar<Entry: TabRepresentative>: NSView {
|
||||
self.addViews()
|
||||
}
|
||||
|
||||
// public func update(tabRepresentatives _: [Entry]) {}
|
||||
public func update(tabRepresentatives entries: [Entry]) {
|
||||
var result = [Tab<Entry>]()
|
||||
entries.forEach { entry in
|
||||
if let existingTab = self.tabs.first(where: { $0.tabRepresentative == entry }) {
|
||||
existingTab.tabRepresentative = entry
|
||||
result.append(existingTab)
|
||||
} else {
|
||||
result.append(Tab(withTabRepresentative: entry, in: self))
|
||||
}
|
||||
}
|
||||
|
||||
result.forEach { $0.position = .inBetween }
|
||||
result.first?.position = .first
|
||||
result.last?.position = .last
|
||||
|
||||
self.tabs = result
|
||||
self.stackView.update(views: self.tabs)
|
||||
}
|
||||
|
||||
override public func draw(_: NSRect) {
|
||||
self.drawSeparator()
|
||||
@ -41,9 +59,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>) {
|
||||
// self.stackView.arrangedSubviews.forEach { ($0 as? Tab<Entry>)?.isSelected = false }
|
||||
// tab.isSelected = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
self.tabBar.autoPinEdge(toSuperviewEdge: .left)
|
||||
self.tabBar.autoPinEdge(toSuperviewEdge: .right)
|
||||
self.tabBar.autoSetDimension(.height, toSize: Theme().tabBarHeight)
|
||||
|
||||
self.tabBar.update(tabRepresentatives: [
|
||||
DummyTabEntry(title: "Test 1"),
|
||||
DummyTabEntry(title: "Test 2"),
|
||||
DummyTabEntry(title: "Test 3"),
|
||||
DummyTabEntry(title: "Very long long long title, and some more text!"),
|
||||
])
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_: Notification) {
|
||||
@ -34,6 +41,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private let tabBar: TabBar<DummyTabEntry>
|
||||
}
|
||||
|
||||
struct DummyTabEntry: Hashable, Equatable, TabRepresentative {
|
||||
struct DummyTabEntry: Hashable, TabRepresentative {
|
||||
var title: String
|
||||
var isSelected = false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user