mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-24 22:33:52 +03:00
Make the color of the file name white when selected in the buffer list
This commit is contained in:
parent
f64c674e21
commit
cb380b0fae
@ -101,8 +101,8 @@ extension BufferListComponent {
|
||||
|
||||
@objc(tableView:viewForTableColumn:row:)
|
||||
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||
let cachedCell = tableView.make(withIdentifier: "buffer-list-row", owner: self)
|
||||
let cell = cachedCell as? ImageAndTextTableCell ?? ImageAndTextTableCell(withIdentifier: "buffer-list-row")
|
||||
let cachedCell = (tableView.make(withIdentifier: "buffer-list-row", owner: self) as? ImageAndTextTableCell)?.reset()
|
||||
let cell = cachedCell ?? ImageAndTextTableCell(withIdentifier: "buffer-list-row")
|
||||
|
||||
let buffer = self.buffers[row]
|
||||
cell.attributedText = self.text(for: buffer)
|
||||
|
@ -305,8 +305,8 @@ extension FileOutlineView {
|
||||
return nil
|
||||
}
|
||||
|
||||
let cachedCell = self.make(withIdentifier: "file-view-row", owner: self)
|
||||
let cell = cachedCell as? ImageAndTextTableCell ?? ImageAndTextTableCell(withIdentifier: "file-view-row")
|
||||
let cachedCell = (self.make(withIdentifier: "file-view-row", owner: self) as? ImageAndTextTableCell)?.reset()
|
||||
let cell = cachedCell ?? ImageAndTextTableCell(withIdentifier: "file-view-row")
|
||||
|
||||
cell.text = fileBrowserItem.fileItem.url.lastPathComponent
|
||||
cell.image = self.fileItemService.icon(forUrl: fileBrowserItem.fileItem.url)
|
||||
|
@ -8,15 +8,19 @@ import PureLayout
|
||||
|
||||
class ImageAndTextTableCell: NSTableCellView {
|
||||
|
||||
static let font = NSFont.systemFont(ofSize: 12)
|
||||
static let widthWithoutText = CGFloat(2 + 16 + 4 + 2)
|
||||
|
||||
fileprivate let _textField = NSTextField(forAutoLayout: ())
|
||||
fileprivate let _imageView = NSImageView(forAutoLayout: ())
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
static let font = NSFont.systemFont(ofSize: 12)
|
||||
static let widthWithoutText = CGFloat(2 + 16 + 4 + 2)
|
||||
|
||||
static func width(with text: String) -> CGFloat {
|
||||
let attrStr = NSAttributedString(string: text,
|
||||
attributes: [NSFontAttributeName: ImageAndTextTableCell.font])
|
||||
let attrStr = NSAttributedString(string: text, attributes: [NSFontAttributeName: ImageAndTextTableCell.font])
|
||||
|
||||
return self.widthWithoutText + attrStr.size().width
|
||||
}
|
||||
@ -26,6 +30,34 @@ class ImageAndTextTableCell: 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
|
||||
@ -89,7 +121,10 @@ class ImageAndTextTableCell: NSTableCellView {
|
||||
textField.autoPinEdge(.left, to: .right, of: imageView, withOffset: 4)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
func reset() -> ImageAndTextTableCell {
|
||||
self.text = ""
|
||||
self.image = nil
|
||||
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
@ -27,13 +27,13 @@ class OpenQuicklyWindowComponent: WindowComponent,
|
||||
fileprivate(set) var fileViewItems = [ScoredFileItem]()
|
||||
|
||||
fileprivate let userInitiatedScheduler = ConcurrentDispatchQueueScheduler(qos: .userInitiated)
|
||||
|
||||
|
||||
fileprivate let searchField = NSTextField(forAutoLayout: ())
|
||||
fileprivate let progressIndicator = NSProgressIndicator(forAutoLayout: ())
|
||||
fileprivate let cwdControl = NSPathControl(forAutoLayout: ())
|
||||
fileprivate let countField = NSTextField(forAutoLayout: ())
|
||||
fileprivate let fileView = NSTableView.standardTableView()
|
||||
|
||||
|
||||
fileprivate let fileItemService: FileItemService
|
||||
|
||||
fileprivate var count = 0
|
||||
@ -42,7 +42,7 @@ class OpenQuicklyWindowComponent: WindowComponent,
|
||||
fileprivate var cwdPathCompsCount = 0
|
||||
fileprivate let searchStream: Observable<String>
|
||||
fileprivate let filterOpQueue = OperationQueue()
|
||||
|
||||
|
||||
weak fileprivate var mainWindow: MainWindowComponent?
|
||||
|
||||
init(source: Observable<Any>, fileItemService: FileItemService) {
|
||||
@ -72,7 +72,7 @@ class OpenQuicklyWindowComponent: WindowComponent,
|
||||
fileView.intercellSpacing = CGSize(width: 4, height: 4)
|
||||
fileView.dataSource = self
|
||||
fileView.delegate = self
|
||||
|
||||
|
||||
let fileScrollView = NSScrollView.standardScrollView()
|
||||
fileScrollView.autoresizesSubviews = true
|
||||
fileScrollView.documentView = fileView
|
||||
@ -136,7 +136,7 @@ class OpenQuicklyWindowComponent: WindowComponent,
|
||||
func endProgress() {
|
||||
self.progressIndicator.stopAnimation(self)
|
||||
}
|
||||
|
||||
|
||||
func show(forMainWindow mainWindow: MainWindowComponent) {
|
||||
self.mainWindow = mainWindow
|
||||
self.mainWindow?.sink
|
||||
@ -148,13 +148,13 @@ class OpenQuicklyWindowComponent: WindowComponent,
|
||||
case .close:
|
||||
self.window.performClose(self)
|
||||
return
|
||||
|
||||
|
||||
default:
|
||||
return
|
||||
}
|
||||
})
|
||||
.addDisposableTo(self.perSessionDisposeBag)
|
||||
|
||||
|
||||
self.cwd = mainWindow.cwd
|
||||
let flatFiles = self.fileItemService.flatFileItems(ofUrl: self.cwd)
|
||||
|
||||
@ -213,13 +213,13 @@ extension OpenQuicklyWindowComponent {
|
||||
|
||||
@objc(tableView:viewForTableColumn:row:)
|
||||
func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? {
|
||||
let cachedCell = tableView.make(withIdentifier: "file-view-row", owner: self)
|
||||
let cell = cachedCell as? ImageAndTextTableCell ?? ImageAndTextTableCell(withIdentifier: "file-view-row")
|
||||
let cachedCell = (tableView.make(withIdentifier: "file-view-row", owner: self) as? ImageAndTextTableCell)?.reset()
|
||||
let cell = cachedCell ?? ImageAndTextTableCell(withIdentifier: "file-view-row")
|
||||
|
||||
let url = self.fileViewItems[row].url
|
||||
cell.attributedText = self.rowText(for: url as URL)
|
||||
cell.image = self.fileItemService.icon(forUrl: url)
|
||||
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ extension OpenQuicklyWindowComponent {
|
||||
rowText.addAttribute(NSForegroundColorAttributeName,
|
||||
value: NSColor.lightGray,
|
||||
range: NSRange(location:name.characters.count, length: pathInfo.characters.count + 3))
|
||||
|
||||
|
||||
return rowText
|
||||
}
|
||||
}
|
||||
@ -256,20 +256,20 @@ extension OpenQuicklyWindowComponent {
|
||||
case NSSelectorFromString("cancelOperation:"):
|
||||
self.window.performClose(self)
|
||||
return true
|
||||
|
||||
|
||||
case NSSelectorFromString("insertNewline:"):
|
||||
self.mainWindow?.open(urls: [self.fileViewItems[self.fileView.selectedRow].url])
|
||||
self.window.performClose(self)
|
||||
return true
|
||||
|
||||
|
||||
case NSSelectorFromString("moveUp:"):
|
||||
self.moveSelection(ofTableView: self.fileView, byDelta: -1)
|
||||
return true
|
||||
|
||||
|
||||
case NSSelectorFromString("moveDown:"):
|
||||
self.moveSelection(ofTableView: self.fileView, byDelta: 1)
|
||||
return true
|
||||
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
@ -298,9 +298,9 @@ extension OpenQuicklyWindowComponent {
|
||||
|
||||
func windowWillClose(_ notification: Notification) {
|
||||
self.endProgress()
|
||||
|
||||
|
||||
self.mainWindow = nil
|
||||
|
||||
|
||||
self.filterOpQueue.cancelAllOperations()
|
||||
|
||||
self.perSessionDisposeBag = DisposeBag()
|
||||
@ -311,7 +311,7 @@ extension OpenQuicklyWindowComponent {
|
||||
self.flatFileItems = []
|
||||
self.fileViewItems = []
|
||||
self.fileView.reloadData()
|
||||
|
||||
|
||||
self.searchField.stringValue = ""
|
||||
self.countField.stringValue = "0 items"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user