diff --git a/Base.lproj/MetadataSearch.xib b/Base.lproj/MetadataSearch.xib index e03b373..66402ea 100755 --- a/Base.lproj/MetadataSearch.xib +++ b/Base.lproj/MetadataSearch.xib @@ -79,9 +79,9 @@ Gw - + - + @@ -366,10 +366,10 @@ DQ - + - + @@ -446,7 +446,7 @@ DQ - + diff --git a/Base.lproj/SBChapterSearch.xib b/Base.lproj/SBChapterSearch.xib index 49c4652..acc5bf7 100644 --- a/Base.lproj/SBChapterSearch.xib +++ b/Base.lproj/SBChapterSearch.xib @@ -1,8 +1,8 @@ - + - + @@ -61,9 +61,9 @@ Gw - + - + @@ -82,6 +82,26 @@ Gw + + + + + + + + + + + + + + + + + + + + @@ -94,6 +114,26 @@ Gw + + + + + + + + + + + + + + + + + + + + @@ -106,6 +146,26 @@ Gw + + + + + + + + + + + + + + + + + + + + @@ -117,6 +177,22 @@ Gw + + + + + + + + + + + + + + + + @@ -145,9 +221,9 @@ Gw - + - + @@ -166,6 +242,26 @@ Gw + + + + + + + + + + + + + + + + + + + + @@ -179,6 +275,26 @@ Gw + + + + + + + + + + + + + + + + + + + + @@ -275,7 +391,7 @@ Gw - + diff --git a/Classes/ChapterSearchController.swift b/Classes/ChapterSearchController.swift index 02d3ebc..db83437 100644 --- a/Classes/ChapterSearchController.swift +++ b/Classes/ChapterSearchController.swift @@ -222,23 +222,39 @@ class ChapterSearchController: NSWindowController, NSTableViewDataSource, NSTabl return 0 } - func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { + private let titleCell = NSUserInterfaceItemIdentifier(rawValue: "titleCell") + private let chapterCountCell = NSUserInterfaceItemIdentifier(rawValue: "chapterCountCell") + private let durationCell = NSUserInterfaceItemIdentifier(rawValue: "durationCell") + private let confirmationsCell = NSUserInterfaceItemIdentifier(rawValue: "confirmationsCell") + + private let timeCell = NSUserInterfaceItemIdentifier(rawValue: "timeCell") + private let nameCell = NSUserInterfaceItemIdentifier(rawValue: "nameCell") + + func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { if tableView == resultsTable { switch state { case .completed(let results, _): let result = results[row] if tableColumn?.identifier.rawValue == "title" { - return result.title + let cell = tableView.makeView(withIdentifier: titleCell, owner:self) as? NSTableCellView + cell?.textField?.stringValue = result.title + return cell } else if tableColumn?.identifier.rawValue == "chaptercount" { - return "\(result.chapters.count)".smallMonospacedAttributedString() + let cell = tableView.makeView(withIdentifier: titleCell, owner:self) as? NSTableCellView + cell?.textField?.attributedStringValue = "\(result.chapters.count)".smallMonospacedAttributedString() + return cell } else if tableColumn?.identifier.rawValue == "duration" { - return StringFromTime(Int64(result.duration), 1000).smallMonospacedAttributedString() + let cell = tableView.makeView(withIdentifier: durationCell, owner:self) as? NSTableCellView + cell?.textField?.attributedStringValue = StringFromTime(Int64(result.duration), 1000).smallMonospacedAttributedString() + return cell } else if tableColumn?.identifier.rawValue == "confirmations" { - return NSNumber(value: result.confimations) + let cell = tableView.makeView(withIdentifier: confirmationsCell, owner:self) as? LevelIndicatorTableCellView + cell?.indicator.intValue = Int32(result.confimations) + return cell } default: break @@ -249,10 +265,14 @@ class ChapterSearchController: NSWindowController, NSTableViewDataSource, NSTabl case .completed(_, let result): let chapter = result.chapters[row] if tableColumn?.identifier.rawValue == "time" { - return StringFromTime(Int64(chapter.timestamp), 1000).boldMonospacedAttributedString() + let cell = tableView.makeView(withIdentifier: timeCell, owner:self) as? NSTableCellView + cell?.textField?.attributedStringValue = StringFromTime(Int64(chapter.timestamp), 1000).boldMonospacedAttributedString() + return cell } else if tableColumn?.identifier.rawValue == "name" { - return chapter.name + let cell = tableView.makeView(withIdentifier: nameCell, owner:self) as? NSTableCellView + cell?.textField?.stringValue = chapter.name + return cell } default: break @@ -262,3 +282,8 @@ class ChapterSearchController: NSWindowController, NSTableViewDataSource, NSTabl } } + +/// A NSTableCellView that contains a single level indicator. +class LevelIndicatorTableCellView: NSTableCellView { + @IBOutlet var indicator: NSLevelIndicator! +}