Repository navigation
Expand file tree
/
Copy pathSEFoldersRowItem.swift
More file actions
182 lines (140 loc) · 5.11 KB
/
Copy pathSEFoldersRowItem.swift
File metadata and controls
182 lines (140 loc) · 5.11 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import Cocoa
import TGUIKit
import TelegramCore
import Postbox
import SwiftSignalKit
import InAppSettings
class SEFoldersRowItem: TableStickItem {
fileprivate let action:((ChatListFilter)->Void)?
fileprivate let context: AccountContext?
fileprivate let tabs: [ChatListFilter]
fileprivate let selected: ChatListFilter
fileprivate let presentation: TelegramPresentationTheme
init(_ initialSize: NSSize, context: AccountContext, tabs: [ChatListFilter], selected: ChatListFilter, action: ((ChatListFilter)->Void)? = nil, presentation: TelegramPresentationTheme = theme) {
self.action = action
self.context = context
self.tabs = tabs
self.presentation = presentation
self.selected = selected
super.init(initialSize)
}
required init(_ initialSize: NSSize) {
self.action = nil
self.context = nil
self.tabs = []
self.presentation = theme
self.selected = .allChats
super.init(initialSize)
}
override var backdorColor: NSColor {
return self.presentation.colors.background
}
override var borderColor: NSColor {
return self.presentation.colors.border
}
override var singletonItem: Bool {
return false
}
override var stableId: AnyHashable {
return SelectablePeersEntryStableId.folders
}
override func viewClass() -> AnyClass {
return FoldersRowView.self
}
override var identifier: String {
return "FoldersRowView"
}
override var height: CGFloat {
return 36
}
}
final class FoldersRowView : TableStickView {
private let containerView = View()
private var animated: Bool = false
let segmentView: ScrollableSegmentView = ScrollableSegmentView(frame: NSZeroRect)
required init(frame frameRect: NSRect) {
super.init(frame: frameRect)
addSubview(containerView)
containerView.addSubview(segmentView)
}
override func mouseUp(with event: NSEvent) {
}
override func mouseDown(with event: NSEvent) {
if mouseInside() {
}
}
override func updateIsVisible(_ visible: Bool, animated: Bool) {
super.updateIsVisible(visible, animated: animated)
}
override var backdorColor: NSColor {
return .clear
}
override func updateColors() {
super.updateColors()
if let item = item as? SEFoldersRowItem {
segmentView.updateLocalizationAndTheme(theme: item.presentation)
}
needsDisplay = true
}
private var splitViewState: SplitViewState?
override func set(item: TableRowItem, animated: Bool = false) {
super.set(item: item, animated: animated)
guard let item = item as? SEFoldersRowItem else {
return
}
var animated = (self.animated || animated)
self.animated = true
guard let context = item.context else {
return
}
animated = animated && splitViewState == context.layout
self.splitViewState = context.layout
let segmentTheme = ScrollableSegmentTheme(background: item.presentation.colors.background, border: item.presentation.colors.border, selector: item.presentation.colors.accent, inactiveText: item.presentation.colors.grayText, activeText: item.presentation.colors.accent, textFont: .normal(.title))
var index: Int = 0
let insets = NSEdgeInsets(left: 10, right: 10, bottom: 6)
var items:[ScrollableSegmentItem] = []
for tab in item.tabs {
let title: String = tab.title
items.append(ScrollableSegmentItem(title: title, index: index, uniqueId: Int64(tab.id), selected: item.selected == tab, insets: insets, icon: nil, theme: segmentTheme, equatable: UIEquatable(tab)))
index += 1
}
segmentView.updateItems(items, animated: animated)
segmentView.didChangeSelectedItem = { [weak item] selected in
if let item = item {
if selected.uniqueId == -1 {
item.action?(.allChats)
} else {
item.action?(item.tabs[selected.index])
}
}
}
}
override var isHidden: Bool {
didSet {
if isHidden {
var bp:Int = 0
bp += 1
}
}
}
override var isAlwaysUp: Bool {
return true
}
override func removeFromSuperview() {
super.removeFromSuperview()
}
public override func setFrameOrigin(_ newOrigin: NSPoint) {
super.setFrameOrigin(newOrigin)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
override func layout() {
super.layout()
containerView.frame = NSMakeRect(0, 0, bounds.width - 1, bounds.height)
segmentView.frame = containerView.bounds
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}