1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-29 03:53:38 +03:00

GH-436 Add stub themed table row

This commit is contained in:
Tae Won Ha 2017-06-25 18:31:00 +02:00
parent 4da10078be
commit da4d9db6fd
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 28 additions and 32 deletions

View File

@ -333,15 +333,18 @@ extension FileOutlineView {
// MARK: - NSOutlineViewDelegate
extension FileOutlineView {
@objc(outlineView: viewForTableColumn:item:)
func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
return self.make(withIdentifier: "file-row-view", owner: self) as? ThemedTableRow
?? ThemedTableRow(withIdentifier: "file-row-view")
}
func outlineView(_: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
guard let fileBrowserItem = item as? FileBrowserItem else {
return nil
}
let cachedCell =
(self.make(withIdentifier: "file-view-row", owner: self) as? ThemedTableCell)?.reset()
let cell = cachedCell ?? ThemedTableCell(withIdentifier: "file-view-row")
let cell = (self.make(withIdentifier: "file-cell-view", owner: self) as? ThemedTableCell)?.reset()
?? ThemedTableCell(withIdentifier: "file-cell-view")
cell.text = fileBrowserItem.url.lastPathComponent
let icon = FileUtils.icon(forUrl: fileBrowserItem.url)

View File

@ -6,6 +6,26 @@
import Cocoa
import PureLayout
class ThemedTableRow: NSTableRowView {
init(withIdentifier identifier: String) {
super.init(frame: .zero)
self.identifier = identifier
}
override func drawSelection(in dirtyRect: NSRect) {
super.drawSelection(in: dirtyRect)
NSColor.red.set()
NSRectFill(dirtyRect)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ThemedTableCell: NSTableCellView {
// MARK: - API
@ -23,34 +43,6 @@ class ThemedTableCell: NSTableCellView {
height: max(self._textField.intrinsicContentSize.height, 16))
}
override var backgroundStyle: NSBackgroundStyle {
didSet {
let attrStr = NSMutableAttributedString(attributedString: self.attributedText)
let wholeRange = NSRange(location: 0, length: attrStr.length)
var nameRange = NSRange(location: 0, length: 0)
let _ = attrStr.attributes(at: 0, longestEffectiveRange: &nameRange, in: wholeRange)
if nameRange.length == attrStr.length {
// If we only have one style, Cocoa automatically inverts the color of the text.
return
}
switch self.backgroundStyle {
case .light:
attrStr.addAttribute(NSForegroundColorAttributeName, value: NSColor.black, range: nameRange)
case .dark:
attrStr.addAttribute(NSForegroundColorAttributeName, value: NSColor.white, range: nameRange)
default:
return
}
self.attributedText = attrStr
}
}
var attributedText: NSAttributedString {
get {
return self.textField!.attributedStringValue
@ -91,6 +83,7 @@ class ThemedTableCell: NSTableCellView {
let textField = self._textField
textField.font = ThemedTableCell.font
textField.textColor = NSColor.blue
textField.isBordered = false
textField.isBezeled = false
textField.allowsEditingTextAttributes = false