Make it on par with the old controller.
This commit is contained in:
1 parent
747eb97682
commit
1be37f9e15
2 files changed
+34
-5
No files matched your search
@@ -11,7 +11,7 @@ import Cocoa
|
||||
func chapterImportDone(chaptersToBeImported: [MP42TextSample])
|
||||
}
|
||||
|
||||
@objc class ChapterSearchController: NSWindowController, NSTableViewDataSource, NSTableViewDelegate {
|
||||
@objc class ChapterSearchController: NSWindowController, NSTableViewDataSource, NSTableViewDelegate, NSTextFieldDelegate {
|
||||
|
||||
@IBOutlet var searchTitle: NSTextField!
|
||||
|
||||
@@ -126,8 +126,8 @@ import Cocoa
|
||||
private func updateUI() {
|
||||
switch state {
|
||||
case .none:
|
||||
searchButton.isEnabled = true
|
||||
searchButton.keyEquivalent = "\r"
|
||||
updateSearchButtonVisibility()
|
||||
case .searching(_):
|
||||
progress.startAnimation(self)
|
||||
progress.isHidden = false
|
||||
@@ -158,6 +158,16 @@ import Cocoa
|
||||
}
|
||||
}
|
||||
|
||||
private func updateSearchButtonVisibility() {
|
||||
searchButton.isEnabled = searchTitle.stringValue.count > 0 ? true : false
|
||||
}
|
||||
|
||||
override func controlTextDidChange(_ obj: Notification) {
|
||||
updateSearchButtonVisibility()
|
||||
searchButton.keyEquivalent = "\r"
|
||||
addButton.keyEquivalent = ""
|
||||
}
|
||||
|
||||
// MARK: - Table View
|
||||
|
||||
func tableViewSelectionDidChange(_ notification: Notification) {
|
||||
@@ -213,7 +223,7 @@ import Cocoa
|
||||
let chapter = result.chapters[row]
|
||||
|
||||
if tableColumn?.identifier.rawValue == "time" {
|
||||
return StringFromTime(Int64(chapter.timestamp), 1000).monospacedAttributedString()
|
||||
return StringFromTime(Int64(chapter.timestamp), 1000).boldMonospacedAttributedString()
|
||||
}
|
||||
else if tableColumn?.identifier.rawValue == "name" {
|
||||
return chapter.name
|
||||
@@ -222,4 +232,17 @@ import Cocoa
|
||||
return nil
|
||||
}
|
||||
|
||||
func tableView(_ tableView: NSTableView, willDisplayCell cell: Any, for tableColumn: NSTableColumn?, row: Int) {
|
||||
if tableView == chapterTable && tableColumn?.identifier.rawValue == "time", let cell = cell as? NSTextFieldCell {
|
||||
if tableView.selectedRowIndexes.contains(row) {
|
||||
let highlightedString = NSMutableAttributedString(attributedString: cell.attributedStringValue)
|
||||
highlightedString.addAttribute(NSAttributedStringKey.foregroundColor, value: NSColor.black, range: NSMakeRange(0, highlightedString.length))
|
||||
cell.attributedStringValue = highlightedString
|
||||
}
|
||||
else {
|
||||
cell.textColor = NSColor.gray
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user