Make it on par with the old controller.

This commit is contained in:
Damiano Galassi committed 2017-08-01 12:27:03 +02:00
1 parent 747eb97682
commit 1be37f9e15
2 files changed
+34 -5

No files matched your search

+26 -3
View File
@@ -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
}
}
}
}
+8 -2
View File
@@ -15,8 +15,14 @@ public struct ChapterDB : ChapterService {
let data = fetch(url: url)
else { return [] }
let delta: Int64 = 10000
return parse(data: data).filter { $0.duration < (Int64(duration) + delta) && $0.duration > (Int64(duration) - delta) }
let parsed = parse(data: data)
if (duration > 0) {
let delta: Int64 = 10000
return parsed.filter { $0.duration < (Int64(duration) + delta) && $0.duration > (Int64(duration) - delta) }
}
else {
return parsed
}
}
private func fetch(url: URL) -> Data? {