Use a view-based table view in the metadata search window.

This commit is contained in:
Damiano Galassi committed 2018-03-23 12:46:55 +01:00
1 parent d9c445d70b
commit 8e7f2e1b73
4 files changed
+128 -20

No files matched your search

+87 -4
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13528" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14105" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13528"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14105"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -342,7 +342,7 @@ DQ
<rect key="frame" x="1" y="0.0" width="508" height="135"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" rowHeight="14" headerView="29" id="28">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" rowHeight="14" rowSizeStyle="automatic" headerView="29" viewBased="YES" id="28">
<rect key="frame" x="0.0" y="0.0" width="508" height="112"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
@@ -361,6 +361,26 @@ DQ
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="resultCell" id="aPK-GO-H83">
<rect key="frame" x="1" y="1" width="505" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="oYO-2n-oqa">
<rect key="frame" x="0.0" y="0.0" width="505" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="bhn-G0-mkU">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="oYO-2n-oqa" id="e6I-gH-e84"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
</tableColumns>
<accessibility description="Search results"/>
@@ -402,7 +422,7 @@ DQ
<rect key="frame" x="1" y="0.0" width="508" height="238"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="14" headerView="20" id="19" customClass="ExpandedTableView" customModule="Subler" customModuleProvider="target">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="14" rowSizeStyle="automatic" headerView="20" viewBased="YES" id="19" customClass="ExpandedTableView" customModule="Subler" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="508" height="215"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
@@ -421,6 +441,26 @@ DQ
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<prototypeCellViews>
<tableCellView identifier="annotationCell" id="GPs-fF-KER">
<rect key="frame" x="1" y="1" width="101" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zGF-Qh-sGc">
<rect key="frame" x="0.0" y="0.0" width="101" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<textFieldCell key="cell" controlSize="small" sendsActionOnEndEditing="YES" alignment="right" title="Table View Cell" id="jdT-Ey-AUs">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="zGF-Qh-sGc" id="yvJ-Ae-6HS"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn identifier="value" editable="NO" width="401" minWidth="40" maxWidth="1000" id="22">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Value">
@@ -434,6 +474,49 @@ DQ
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="valueCellForSizing" id="Fcu-ce-uOy">
<rect key="frame" x="105" y="1" width="401" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Z5j-N2-hwq">
<rect key="frame" x="0.0" y="0.0" width="401" height="14"/>
<textFieldCell key="cell" controlSize="small" sendsActionOnEndEditing="YES" title="Table View Cell" id="xfd-6y-9kC">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="Z5j-N2-hwq" firstAttribute="leading" secondItem="Fcu-ce-uOy" secondAttribute="leading" constant="2" id="5EB-vB-B4R"/>
<constraint firstAttribute="bottom" secondItem="Z5j-N2-hwq" secondAttribute="bottom" id="NTF-f3-o57"/>
<constraint firstItem="Z5j-N2-hwq" firstAttribute="top" secondItem="Fcu-ce-uOy" secondAttribute="top" id="cJz-MZ-pHn"/>
<constraint firstAttribute="trailing" secondItem="Z5j-N2-hwq" secondAttribute="trailing" constant="2" id="fLH-rn-D2L"/>
</constraints>
<connections>
<outlet property="textField" destination="Z5j-N2-hwq" id="kCI-As-43n"/>
</connections>
</tableCellView>
<tableCellView identifier="valueCell" id="5pg-aP-P6j">
<rect key="frame" x="105" y="17" width="401" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eml-He-0u5">
<rect key="frame" x="0.0" y="0.0" width="401" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<textFieldCell key="cell" controlSize="small" selectable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="LFD-sH-prc">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="eml-He-0u5" id="BVy-4V-cz4"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
</tableColumns>
<accessibility description="Result details"/>
+1 -1
View File
@@ -12,7 +12,7 @@ import Foundation
var pathExtension: String {
return "sbpreset2"
}
var title: String
@objc var title: String
let metadata: MP42Metadata
var replaceArtworks: Bool
var replaceAnnotations: Bool
+39 -14
View File
@@ -508,8 +508,15 @@ class MetadataSearchController: NSWindowController, NSTableViewDataSource, NSTab
return 0
}
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
private let resultCell = NSUserInterfaceItemIdentifier(rawValue: "resultCell")
private let annotationCell = NSUserInterfaceItemIdentifier(rawValue: "annotationCell")
private let valueCell = NSUserInterfaceItemIdentifier(rawValue: "valueCell")
private let valueCellForSizing = NSUserInterfaceItemIdentifier(rawValue: "valueCellForSizing")
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
if tableView == resultsTable {
let cell = tableView.makeView(withIdentifier: resultCell, owner:self) as? NSTableCellView
switch state {
case .completed(let search, let results, _):
let result = results[row]
@@ -518,44 +525,62 @@ class MetadataSearchController: NSWindowController, NSTableViewDataSource, NSTab
if let season = result[.season] as? Int,
let episode = result[.episodeNumber] as? Int,
let title = result[.name] as? String {
return "\(season)x\(episode) - \(title)"
cell?.textField?.stringValue = "\(season)x\(episode) - \(title)"
}
case .movie:
if let title = result[.name] as? String {
return title
cell?.textField?.stringValue = title
}
}
return cell
default:
break
return nil
}
}
else if tableView == metadataTable {
switch state {
case .completed(_, _, let result):
let key = result.orderedKeys[row]
if tableColumn?.identifier.rawValue == "name" {
return key.localizedDisplayName.boldMonospacedAttributedString()
let cell = tableView.makeView(withIdentifier: annotationCell, owner:self) as? NSTableCellView
cell?.textField?.attributedStringValue = key.localizedDisplayName.boldMonospacedAttributedString()
return cell
}
else if tableColumn?.identifier.rawValue == "value" {
return result[key]
let cell = tableView.makeView(withIdentifier: valueCell, owner:self) as? NSTableCellView
cell?.textField?.objectValue = result[key]
return cell
}
default:
break
}
}
return nil
}
private lazy var dummyCell: NSTableCellView = { return metadataTable.makeView(withIdentifier: valueCellForSizing, owner:self) as? NSTableCellView }()!
private lazy var dummyCellWidth: NSLayoutConstraint = {
let constraint = NSLayoutConstraint(item: dummyCell, attribute: NSLayoutConstraint.Attribute.width,
relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 500)
dummyCell.addConstraint(constraint)
return constraint
}()
private static let minHeight = CGFloat(14.0)
func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
if tableView.tableColumns.count > 1 {
let tableColumnToWrap = tableView.tableColumns[1]
let columnToWrap = tableView.tableColumns.index(of: tableColumnToWrap)
let cell = tableView.preparedCell(atColumn: columnToWrap!, row: row)!
if tableView == metadataTable, case .completed(_, _, let result) = state {
let column = tableView.tableColumns[1]
let key = result.orderedKeys[row]
dummyCell.textField?.stringValue = result[key] as? String ?? ""
dummyCellWidth.constant = column.width
dummyCell.textField?.preferredMaxLayoutWidth = column.width - 4
let constrainedBounds = NSMakeRect(0, 0, tableColumnToWrap.width, CGFloat.greatestFiniteMagnitude)
let naturalSize = cell.cellSize(forBounds: constrainedBounds)
return naturalSize.height > tableView.rowHeight ? naturalSize.height : tableView.rowHeight
let height = dummyCell.fittingSize.height
return height > MetadataSearchController.minHeight ? height : MetadataSearchController.minHeight
}
return tableView.rowHeight
}
+1 -1
View File
@@ -137,7 +137,7 @@ final class PresetManager {
try save(preset: newPreset)
return newPreset
}
else if let preset = unarchiver.decodeObject(of: [MetadataPreset.self], forKey: NSKeyedArchiveRootObjectKey) as? MetadataPreset {
else if let preset = unarchiver.decodeObject(of: [MetadataPreset.self], forKey: NSKeyedArchiveRootObjectKey) as? MetadataPreset {
return preset
}
}