Initial work for the queue presets.
This commit is contained in:
11 files changed
+317
-386
No files matched your search
@@ -26,7 +26,7 @@
|
|||||||
<rect key="frame" x="1" y="1" width="354" height="198"/>
|
<rect key="frame" x="1" y="1" width="354" height="198"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="firstColumnOnly" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowSizeStyle="automatic" viewBased="YES" id="iRF-P7-a3Q" customClass="ExpandedTableView" customModule="Subler" customModuleProvider="target">
|
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="firstColumnOnly" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowSizeStyle="automatic" viewBased="YES" id="iRF-P7-a3Q" customClass="SectionsTableView" customModule="Subler" customModuleProvider="target">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="354" height="198"/>
|
<rect key="frame" x="0.0" y="0.0" width="354" height="198"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<size key="intercellSpacing" width="3" height="2"/>
|
<size key="intercellSpacing" width="3" height="2"/>
|
||||||
@@ -46,18 +46,39 @@
|
|||||||
</textFieldCell>
|
</textFieldCell>
|
||||||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||||
<prototypeCellViews>
|
<prototypeCellViews>
|
||||||
<tableCellView identifier="nameCell" id="6bC-Va-s9o">
|
<tableCellView identifier="nameCell" id="GIN-Ob-GcI">
|
||||||
<rect key="frame" x="1" y="1" width="351" height="17"/>
|
<rect key="frame" x="1" y="1" width="351" height="17"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="G0s-9P-sPN">
|
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gVw-WH-PIZ">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="350" height="17"/>
|
<rect key="frame" x="0.0" y="0.0" width="350" height="17"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="6CG-pa-ocP">
|
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="06q-GJ-S35">
|
||||||
<font key="font" metaFont="system"/>
|
<font key="font" metaFont="system"/>
|
||||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||||
</textFieldCell>
|
</textFieldCell>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="-2" id="qYR-Dw-H1z"/>
|
||||||
|
</connections>
|
||||||
|
</textField>
|
||||||
|
</subviews>
|
||||||
|
<connections>
|
||||||
|
<outlet property="textField" destination="gVw-WH-PIZ" id="ns3-cf-Uwz"/>
|
||||||
|
</connections>
|
||||||
|
</tableCellView>
|
||||||
|
<tableCellView identifier="headerCell" id="6bC-Va-s9o">
|
||||||
|
<rect key="frame" x="1" y="20" width="351" height="17"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
|
<subviews>
|
||||||
|
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="G0s-9P-sPN">
|
||||||
|
<rect key="frame" x="0.0" y="1" width="350" height="14"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
|
||||||
|
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="6CG-pa-ocP">
|
||||||
|
<font key="font" metaFont="system" size="11"/>
|
||||||
|
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
</textFieldCell>
|
||||||
<connections>
|
<connections>
|
||||||
<outlet property="delegate" destination="-2" id="2Uf-Z0-tF7"/>
|
<outlet property="delegate" destination="-2" id="2Uf-Z0-tF7"/>
|
||||||
</connections>
|
</connections>
|
||||||
@@ -92,7 +113,7 @@
|
|||||||
</scroller>
|
</scroller>
|
||||||
</scrollView>
|
</scrollView>
|
||||||
<button toolTip="Remove selected set" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SIg-lA-6FA">
|
<button toolTip="Remove selected set" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SIg-lA-6FA">
|
||||||
<rect key="frame" x="20" y="19" width="25" height="23"/>
|
<rect key="frame" x="44" y="19" width="25" height="23"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="25" id="KCi-qM-zwt"/>
|
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="25" id="KCi-qM-zwt"/>
|
||||||
<constraint firstAttribute="height" constant="21" id="MLy-Qh-J3X"/>
|
<constraint firstAttribute="height" constant="21" id="MLy-Qh-J3X"/>
|
||||||
@@ -106,7 +127,7 @@
|
|||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button toolTip="Edit selected set" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="C1d-lu-T7S">
|
<button toolTip="Edit selected set" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="C1d-lu-T7S">
|
||||||
<rect key="frame" x="53" y="19" width="45" height="23"/>
|
<rect key="frame" x="85" y="19" width="45" height="23"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="45" id="8we-xP-MsB"/>
|
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="45" id="8we-xP-MsB"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
@@ -118,23 +139,36 @@
|
|||||||
<action selector="editPreset:" target="-2" id="u8x-oY-2Gk"/>
|
<action selector="editPreset:" target="-2" id="u8x-oY-2Gk"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
|
<button toolTip="Remove selected set" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gBf-6T-hQv">
|
||||||
|
<rect key="frame" x="20" y="19" width="25" height="23"/>
|
||||||
|
<constraints>
|
||||||
|
<constraint firstAttribute="height" constant="21" id="6f5-Cg-MfD"/>
|
||||||
|
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="25" id="x23-FV-5XN"/>
|
||||||
|
</constraints>
|
||||||
|
<buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" image="NSAddTemplate" imagePosition="overlaps" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="f7j-PR-nTF">
|
||||||
|
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||||
|
<font key="font" metaFont="system"/>
|
||||||
|
</buttonCell>
|
||||||
|
</button>
|
||||||
</subviews>
|
</subviews>
|
||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstItem="SIg-lA-6FA" firstAttribute="top" secondItem="Bgi-pA-eAO" secondAttribute="bottom" constant="7" id="0sg-zC-Z0Q"/>
|
<constraint firstItem="gBf-6T-hQv" firstAttribute="top" secondItem="Bgi-pA-eAO" secondAttribute="bottom" constant="7" id="7F4-d2-isf"/>
|
||||||
<constraint firstItem="SIg-lA-6FA" firstAttribute="leading" secondItem="Sl5-b6-dQC" secondAttribute="leading" constant="20" id="4SR-ez-TOh"/>
|
|
||||||
<constraint firstItem="Bgi-pA-eAO" firstAttribute="top" secondItem="Sl5-b6-dQC" secondAttribute="top" constant="20" id="CfB-Vj-Oio"/>
|
<constraint firstItem="Bgi-pA-eAO" firstAttribute="top" secondItem="Sl5-b6-dQC" secondAttribute="top" constant="20" id="CfB-Vj-Oio"/>
|
||||||
<constraint firstItem="C1d-lu-T7S" firstAttribute="centerY" secondItem="SIg-lA-6FA" secondAttribute="centerY" id="D3e-th-GNg"/>
|
<constraint firstItem="C1d-lu-T7S" firstAttribute="centerY" secondItem="SIg-lA-6FA" secondAttribute="centerY" id="D3e-th-GNg"/>
|
||||||
<constraint firstItem="C1d-lu-T7S" firstAttribute="leading" secondItem="SIg-lA-6FA" secondAttribute="trailing" constant="8" id="R2g-fk-MQZ"/>
|
<constraint firstItem="C1d-lu-T7S" firstAttribute="leading" secondItem="SIg-lA-6FA" secondAttribute="trailing" constant="16" id="R2g-fk-MQZ"/>
|
||||||
<constraint firstItem="Bgi-pA-eAO" firstAttribute="leading" secondItem="Sl5-b6-dQC" secondAttribute="leading" constant="20" id="SNz-hG-5Nz"/>
|
<constraint firstItem="Bgi-pA-eAO" firstAttribute="leading" secondItem="Sl5-b6-dQC" secondAttribute="leading" constant="20" id="SNz-hG-5Nz"/>
|
||||||
|
<constraint firstAttribute="bottom" secondItem="gBf-6T-hQv" secondAttribute="bottom" constant="20" id="UFw-zI-fr5"/>
|
||||||
<constraint firstAttribute="trailing" secondItem="Bgi-pA-eAO" secondAttribute="trailing" constant="20" id="cgL-bl-uVt"/>
|
<constraint firstAttribute="trailing" secondItem="Bgi-pA-eAO" secondAttribute="trailing" constant="20" id="cgL-bl-uVt"/>
|
||||||
<constraint firstAttribute="bottom" secondItem="SIg-lA-6FA" secondAttribute="bottom" constant="20" symbolic="YES" id="iX7-35-KVJ"/>
|
<constraint firstItem="gBf-6T-hQv" firstAttribute="leading" secondItem="Sl5-b6-dQC" secondAttribute="leading" constant="20" id="faN-Ws-UIJ"/>
|
||||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="SIg-lA-6FA" secondAttribute="trailing" constant="20" symbolic="YES" id="ssz-R1-wNZ"/>
|
<constraint firstItem="SIg-lA-6FA" firstAttribute="leading" secondItem="gBf-6T-hQv" secondAttribute="trailing" constant="-1" id="opb-OA-4BC"/>
|
||||||
|
<constraint firstItem="gBf-6T-hQv" firstAttribute="centerY" secondItem="SIg-lA-6FA" secondAttribute="centerY" id="ux5-dx-1Iq"/>
|
||||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="C1d-lu-T7S" secondAttribute="trailing" constant="20" symbolic="YES" id="ydN-Lk-gHL"/>
|
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="C1d-lu-T7S" secondAttribute="trailing" constant="20" symbolic="YES" id="ydN-Lk-gHL"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<point key="canvasLocation" x="-347" y="-669"/>
|
<point key="canvasLocation" x="-347" y="-669"/>
|
||||||
</customView>
|
</customView>
|
||||||
</objects>
|
</objects>
|
||||||
<resources>
|
<resources>
|
||||||
|
<image name="NSAddTemplate" width="11" height="11"/>
|
||||||
<image name="NSRemoveTemplate" width="11" height="11"/>
|
<image name="NSRemoveTemplate" width="11" height="11"/>
|
||||||
</resources>
|
</resources>
|
||||||
</document>
|
</document>
|
||||||
@@ -13,14 +13,14 @@ import Foundation
|
|||||||
return "sbpreset2"
|
return "sbpreset2"
|
||||||
}
|
}
|
||||||
var title: String
|
var title: String
|
||||||
@objc let metadata: MP42Metadata
|
let metadata: MP42Metadata
|
||||||
@objc var replaceArtworks: Bool
|
var replaceArtworks: Bool
|
||||||
@objc var replaceAnnotations: Bool
|
var replaceAnnotations: Bool
|
||||||
|
|
||||||
let version: Int
|
let version: Int
|
||||||
var changed: Bool
|
var changed: Bool
|
||||||
|
|
||||||
@objc init(title: String, metadata: MP42Metadata, replaceArtworks: Bool, replaceAnnotations: Bool) {
|
init(title: String, metadata: MP42Metadata, replaceArtworks: Bool, replaceAnnotations: Bool) {
|
||||||
self.title = title
|
self.title = title
|
||||||
self.metadata = metadata.copy() as! MP42Metadata
|
self.metadata = metadata.copy() as! MP42Metadata
|
||||||
self.replaceArtworks = replaceArtworks
|
self.replaceArtworks = replaceArtworks
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ extension PresetManager.Error: LocalizedError {
|
|||||||
case alreadyExists
|
case alreadyExists
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func append(newElement: Preset) throws {
|
func append(newElement: Preset) throws {
|
||||||
if item(name: newElement.title) != nil {
|
if item(name: newElement.title) != nil {
|
||||||
throw Error.alreadyExists
|
throw Error.alreadyExists
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,12 @@
|
|||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate, NSTextFieldDelegate {
|
class PresetPrefsViewController: NSViewController, SectionsTableViewDataSource, SectionsTableViewDelegate, NSTextFieldDelegate {
|
||||||
|
|
||||||
let presetManager: PresetManager
|
let presetManager: PresetManager
|
||||||
var currentRow: Int
|
var currentRow: Int
|
||||||
|
|
||||||
@IBOutlet var tableView: NSTableView!
|
@IBOutlet var tableView: SectionsTableView!
|
||||||
@IBOutlet var removeSetButton: NSButton!
|
@IBOutlet var removeSetButton: NSButton!
|
||||||
@IBOutlet var editSetButton: NSButton!
|
@IBOutlet var editSetButton: NSButton!
|
||||||
|
|
||||||
@@ -33,6 +33,11 @@ class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTabl
|
|||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
tableView.dataSource = self
|
||||||
|
tableView.delegate = self
|
||||||
|
|
||||||
|
tableView.reloadData()
|
||||||
|
|
||||||
observer = NotificationCenter.default.addObserver(forName: presetManager.updateNotification,
|
observer = NotificationCenter.default.addObserver(forName: presetManager.updateNotification,
|
||||||
object: nil,
|
object: nil,
|
||||||
queue: OperationQueue.main) { [weak self] notification in
|
queue: OperationQueue.main) { [weak self] notification in
|
||||||
@@ -45,17 +50,34 @@ class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTabl
|
|||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Table View data source
|
// MARK: Table View with sections
|
||||||
|
|
||||||
func numberOfRows(in tableView: NSTableView) -> Int {
|
func numberOfSections(in tableView: NSTableView) -> Int { return 2 }
|
||||||
return presetManager.presets.count
|
|
||||||
|
func tableView(_ tableView: NSTableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
if section == 0 {
|
||||||
|
return presetManager.metadataPresets.count
|
||||||
|
} else {
|
||||||
|
return presetManager.queuePresets.count
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
func tableView(_ tableView: NSTableView, viewForHeaderInSection section: Int) -> NSView? {
|
||||||
|
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("headerCell"), owner: self) as? NSTableCellView {
|
||||||
|
cell.textField?.stringValue = section == 0 ? "Metadata" : "Queue"
|
||||||
|
cell.textField?.isSelectable = false
|
||||||
|
cell.textField?.isEditable = false
|
||||||
|
return cell
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: (section: Int, sectionRow: Int)) -> NSView? {
|
||||||
if tableColumn?.identifier == NSUserInterfaceItemIdentifier("name"),
|
if tableColumn?.identifier == NSUserInterfaceItemIdentifier("name"),
|
||||||
let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("nameCell"), owner: self) as? NSTableCellView {
|
let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("nameCell"), owner: self) as? NSTableCellView {
|
||||||
cell.textField?.stringValue = presetManager.presets[row].title
|
cell.textField?.stringValue = presetManager.presets[row.sectionRow].title
|
||||||
|
cell.textField?.isSelectable = true
|
||||||
|
cell.textField?.isEditable = true
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +112,8 @@ class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTabl
|
|||||||
override func controlTextDidEndEditing(_ obj: Notification) {
|
override func controlTextDidEndEditing(_ obj: Notification) {
|
||||||
if let view = obj.object as? NSTextField {
|
if let view = obj.object as? NSTextField {
|
||||||
let row = tableView.row(for: view)
|
let row = tableView.row(for: view)
|
||||||
let preset = presetManager.presets[row]
|
let sectionRow = tableView.section(for: row)
|
||||||
|
let preset = presetManager.presets[sectionRow.row]
|
||||||
rename(preset: preset, to: view.stringValue)
|
rename(preset: preset, to: view.stringValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,8 +127,9 @@ class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTabl
|
|||||||
|
|
||||||
@IBAction func editPreset(_ sender: NSView) {
|
@IBAction func editPreset(_ sender: NSView) {
|
||||||
let rowIndex = tableView.selectedRow
|
let rowIndex = tableView.selectedRow
|
||||||
|
let sectionRow = tableView.section(for: rowIndex)
|
||||||
if let preset = presetManager.presets[rowIndex] as? MetadataPreset {
|
|
||||||
|
if let preset = presetManager.presets[sectionRow.row] as? MetadataPreset {
|
||||||
currentRow = rowIndex
|
currentRow = rowIndex
|
||||||
controller = PresetEditorViewController.init(preset: preset)
|
controller = PresetEditorViewController.init(preset: preset)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
//
|
||||||
|
// MovieViewControllerAdditions.swift
|
||||||
|
// Subler
|
||||||
|
//
|
||||||
|
// Created by Damiano Galassi on 22/03/2018.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
extension SBMovieViewController {
|
||||||
|
|
||||||
|
@IBAction func applySet(_ sender: NSMenuItem) {
|
||||||
|
let index = sender.tag
|
||||||
|
let preset = PresetManager.shared.metadataPresets[index]
|
||||||
|
|
||||||
|
let dataTypes: UInt = MP42MetadataItemDataType.string.rawValue | MP42MetadataItemDataType.stringArray.rawValue |
|
||||||
|
MP42MetadataItemDataType.bool.rawValue | MP42MetadataItemDataType.integer.rawValue |
|
||||||
|
MP42MetadataItemDataType.integerArray.rawValue | MP42MetadataItemDataType.date.rawValue
|
||||||
|
|
||||||
|
let items = preset.metadata.metadataItemsFiltered(by: MP42MetadataItemDataType(rawValue: dataTypes))
|
||||||
|
|
||||||
|
if preset.replaceAnnotations {
|
||||||
|
remove(metadata.metadataItemsFiltered(by: MP42MetadataItemDataType(rawValue: dataTypes)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if items.isEmpty == false {
|
||||||
|
let identifiers = items.map { $0.identifier }
|
||||||
|
remove(metadata.metadataItemsFiltered(byIdentifiers: identifiers))
|
||||||
|
add(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
let artworkItems = preset.metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyCoverArt)
|
||||||
|
|
||||||
|
if preset.replaceArtworks {
|
||||||
|
removeMetadataCoverArtItems(metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyCoverArt))
|
||||||
|
}
|
||||||
|
|
||||||
|
if artworkItems.isEmpty == false {
|
||||||
|
addMetadataCoverArtItems(artworkItems)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBAction func showSaveSet(_ sender: Any) {
|
||||||
|
view.window?.beginCriticalSheet(saveSetWindow, completionHandler: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBAction func closeSaveSheet(_ sender: Any) {
|
||||||
|
view.window?.endSheet(saveSetWindow)
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBAction func saveSet(_ sender: Any) {
|
||||||
|
guard let title = saveSetName?.stringValue else { return }
|
||||||
|
|
||||||
|
let preset = MetadataPreset(title: title, metadata: metadata,
|
||||||
|
replaceArtworks: keepArtworks?.state == .off,
|
||||||
|
replaceAnnotations: keepAnnotations?.state == .off)
|
||||||
|
|
||||||
|
do {
|
||||||
|
try PresetManager.shared.append(newElement: preset)
|
||||||
|
view.window?.endSheet(saveSetWindow)
|
||||||
|
} catch {
|
||||||
|
NSAlert(error: error).runModal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@class MP42Metadata;
|
@class MP42Metadata;
|
||||||
|
@class MP42MetadataItem;
|
||||||
|
|
||||||
@interface SBMovieViewController : NSViewController
|
@interface SBMovieViewController : NSViewController
|
||||||
|
|
||||||
@@ -21,9 +22,18 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
- (IBAction)addMetadataSet:(id)sender;
|
- (IBAction)addMetadataSet:(id)sender;
|
||||||
|
|
||||||
- (IBAction)showSaveSet:(id)sender;
|
- (void)addMetadataItems:(NSArray<MP42MetadataItem *> *)items;
|
||||||
- (IBAction)closeSaveSheet:(id)sender;
|
- (void)removeMetadataItems:(NSArray<MP42MetadataItem *> *)items;
|
||||||
- (IBAction)saveSet:(id)sender;
|
|
||||||
|
- (void)addMetadataCoverArtItems:(NSArray<MP42MetadataItem *> *)items;
|
||||||
|
- (void)removeMetadataCoverArtItems:(NSArray<MP42MetadataItem *> *)items;
|
||||||
|
|
||||||
|
// Set save window
|
||||||
|
@property (nonatomic, strong) IBOutlet NSWindow *saveSetWindow;
|
||||||
|
@property (nonatomic, weak) IBOutlet NSTextField *saveSetName;
|
||||||
|
|
||||||
|
@property (nonatomic, weak) IBOutlet NSButton *keepArtworks;
|
||||||
|
@property (nonatomic, weak) IBOutlet NSButton *keepAnnotations;
|
||||||
|
|
||||||
- (IBAction)zoomSliderDidChange:(id)sender;
|
- (IBAction)zoomSliderDidChange:(id)sender;
|
||||||
|
|
||||||
|
|||||||
@@ -43,13 +43,6 @@ NSString *SublerCoverArtPBoardType = @"SublerCoverArtPBoardType";
|
|||||||
@property (nonatomic, weak) IBOutlet NSButton *removeArtworkButton;
|
@property (nonatomic, weak) IBOutlet NSButton *removeArtworkButton;
|
||||||
@property (nonatomic, weak) IBOutlet SBImageBrowserView *artworksView;
|
@property (nonatomic, weak) IBOutlet SBImageBrowserView *artworksView;
|
||||||
|
|
||||||
// Set save window
|
|
||||||
@property (nonatomic, strong) IBOutlet NSWindow *saveSetWindow;
|
|
||||||
@property (nonatomic, weak) IBOutlet NSTextField *saveSetName;
|
|
||||||
|
|
||||||
@property (nonatomic, weak) IBOutlet NSButton *keepArtworks;
|
|
||||||
@property (nonatomic, weak) IBOutlet NSButton *keepAnnotations;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SBMovieViewController
|
@implementation SBMovieViewController
|
||||||
@@ -311,40 +304,6 @@ static NSDateFormatter *_formatter;
|
|||||||
[self addMetadataItems:itemsToBeAdded];
|
[self addMetadataItems:itemsToBeAdded];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applySet:(id)sender
|
|
||||||
{
|
|
||||||
NSInteger tag = [sender tag];
|
|
||||||
SBMetadataPreset *preset = SBPresetManager.shared.metadataPresets[tag];
|
|
||||||
|
|
||||||
MP42MetadataItemDataType dataTypes = MP42MetadataItemDataTypeString | MP42MetadataItemDataTypeStringArray |
|
|
||||||
MP42MetadataItemDataTypeBool | MP42MetadataItemDataTypeInteger |
|
|
||||||
MP42MetadataItemDataTypeIntegerArray | MP42MetadataItemDataTypeDate;
|
|
||||||
NSArray<MP42MetadataItem *> *items = [preset.metadata metadataItemsFilteredByDataType:dataTypes];
|
|
||||||
|
|
||||||
if (preset.replaceAnnotations) {
|
|
||||||
[self removeMetadataItems:[self.metadata metadataItemsFilteredByDataType:dataTypes]];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items) {
|
|
||||||
NSMutableArray<NSString *> *identifiers = [NSMutableArray array];
|
|
||||||
for (MP42MetadataItem *item in items) {
|
|
||||||
[identifiers addObject:item.identifier];
|
|
||||||
}
|
|
||||||
[self removeMetadataItems:[self.metadata metadataItemsFilteredByIdentifiers:identifiers]];
|
|
||||||
[self addMetadataItems:items];
|
|
||||||
}
|
|
||||||
|
|
||||||
items = [preset.metadata metadataItemsFilteredByIdentifier:MP42MetadataKeyCoverArt];
|
|
||||||
|
|
||||||
if (preset.replaceArtworks) {
|
|
||||||
[self removeMetadataCoverArtItems:[self.metadata metadataItemsFilteredByIdentifier:MP42MetadataKeyCoverArt]];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items.count) {
|
|
||||||
[self addMetadataCoverArtItems:items];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)updateSetsMenu:(id)sender
|
- (void)updateSetsMenu:(id)sender
|
||||||
{
|
{
|
||||||
NSArray<SBMetadataPreset *> *presets = SBPresetManager.shared.metadataPresets;
|
NSArray<SBMetadataPreset *> *presets = SBPresetManager.shared.metadataPresets;
|
||||||
@@ -397,33 +356,6 @@ static NSDateFormatter *_formatter;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)showSaveSet:(id)sender
|
|
||||||
{
|
|
||||||
[self.view.window beginCriticalSheet:self.saveSetWindow completionHandler:NULL];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (IBAction)saveSet:(id)sender
|
|
||||||
{
|
|
||||||
SBPresetManager *manager = SBPresetManager.shared;
|
|
||||||
SBMetadataPreset *preset = [[SBMetadataPreset alloc] initWithTitle:self.saveSetName.stringValue
|
|
||||||
metadata:self.metadata
|
|
||||||
replaceArtworks:self.keepArtworks.state == NSControlStateValueOff
|
|
||||||
replaceAnnotations:self.keepAnnotations.state == NSControlStateValueOff];
|
|
||||||
|
|
||||||
NSError *error = nil;
|
|
||||||
if ([manager appendWithNewElement:preset error:&error]) {
|
|
||||||
[self.view.window endSheet:self.saveSetWindow];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[[NSAlert alertWithError:error] runModal];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (IBAction)closeSaveSheet:(id)sender
|
|
||||||
{
|
|
||||||
[self.view.window endSheet:self.saveSetWindow];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - TableView data source
|
#pragma mark - TableView data source
|
||||||
|
|
||||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView;
|
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class QueuePreset: NSObject, Preset {
|
|||||||
self.title = title
|
self.title = title
|
||||||
self.options = options
|
self.options = options
|
||||||
self.changed = true
|
self.changed = true
|
||||||
self.version = 2
|
self.version = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: NSCoding
|
// MARK: NSCoding
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
//
|
|
||||||
// SBMediaTagsController.h
|
|
||||||
// Subler
|
|
||||||
//
|
|
||||||
// Created by Damiano Galassi on 12/09/15.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@class MP42Track;
|
|
||||||
@class SBMediaTag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A SBMediaTagsControllert takes a MP42Track in input,
|
|
||||||
* and show a windows to configure the media characteristic tags
|
|
||||||
* of the input track. The new set of tags is added to the track
|
|
||||||
* after the user press the OK button.
|
|
||||||
*
|
|
||||||
* Custom media tags are preserved.
|
|
||||||
*/
|
|
||||||
@interface SBMediaTagsController : NSViewController
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes an SBMediaTagsController with the tags
|
|
||||||
* from the provided track.
|
|
||||||
*
|
|
||||||
* @param track the track
|
|
||||||
*
|
|
||||||
* @return an SBMediaTagsController.
|
|
||||||
*/
|
|
||||||
- (instancetype)initWithTrack:(MP42Track *)track;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
@@ -1,250 +0,0 @@
|
|||||||
//
|
|
||||||
// SBMediaTagsController.m
|
|
||||||
// Subler
|
|
||||||
//
|
|
||||||
// Created by Damiano Galassi on 12/09/15.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "SBMediaTagsController.h"
|
|
||||||
#import <MP42Foundation/MP42Track.h>
|
|
||||||
|
|
||||||
#pragma mark - Helpers
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A SBMediaTag is composed of a tag value and a boolean state.
|
|
||||||
*/
|
|
||||||
@interface SBMediaTag : NSObject {
|
|
||||||
@private
|
|
||||||
BOOL _state;
|
|
||||||
NSString *_value;
|
|
||||||
NSString *_localizedTitle;
|
|
||||||
NSString *_localizedDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the complete array of the predefined tags.
|
|
||||||
*/
|
|
||||||
+ (NSArray<NSString *> *)predefinedTags;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the predefined supported media tags
|
|
||||||
* for a particular media type.
|
|
||||||
*
|
|
||||||
* @param mediaType a MP42MediaType type.
|
|
||||||
*
|
|
||||||
* @return an array of NSString with the supported tags.
|
|
||||||
*/
|
|
||||||
+ (NSArray<NSString *> *)predefinedTagsForMediaType:(MP42MediaType)mediaType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the localized human readable title of a partical tag.
|
|
||||||
*/
|
|
||||||
+ (nullable NSString *)localizedTitleForTag:(NSString *)tag;
|
|
||||||
|
|
||||||
@property (nonatomic, readwrite) BOOL state;
|
|
||||||
@property (nonatomic, readonly) NSString *value;
|
|
||||||
@property (nonatomic, readonly) NSString *localizedTitle;
|
|
||||||
@property (nonatomic, readonly) NSString *localizedDescription;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
|
|
||||||
@implementation SBMediaTag
|
|
||||||
|
|
||||||
- (instancetype)initWithValue:(NSString *)value state:(BOOL)state {
|
|
||||||
self = [super init];
|
|
||||||
if (self) {
|
|
||||||
_state = state;
|
|
||||||
_value = [value copy];
|
|
||||||
_localizedTitle = [[SBMediaTag localizedTitleForTag:_value] copy];
|
|
||||||
|
|
||||||
if (_localizedTitle == nil) {
|
|
||||||
_localizedTitle = _value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray<NSString *> *)predefinedTags {
|
|
||||||
return @[@"public.main-program-content", @"public.auxiliary-content",
|
|
||||||
@"public.subtitles.forced-only", @"public.accessibility.transcribes-spoken-dialog",
|
|
||||||
@"public.accessibility.describes-music-and-sound", @"public.easy-to-read",
|
|
||||||
@"public.accessibility.describes-video", @"public.translation.dubbed",
|
|
||||||
@"public.translation.voice-over", @"public.translation"];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray<NSString *> *)predefinedTagsForMediaType:(MP42MediaType)mediaType {
|
|
||||||
NSMutableArray *tags = [NSMutableArray array];
|
|
||||||
[tags addObjectsFromArray:@[@"public.main-program-content",
|
|
||||||
@"public.auxiliary-content"]];
|
|
||||||
|
|
||||||
if (mediaType == kMP42MediaType_Audio) {
|
|
||||||
[tags addObjectsFromArray:@[@"public.accessibility.describes-video",
|
|
||||||
@"public.translation.dubbed",
|
|
||||||
@"public.translation.voice-over"]];
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (mediaType == kMP42MediaType_Subtitle ||
|
|
||||||
mediaType == kMP42MediaType_ClosedCaption) {
|
|
||||||
|
|
||||||
[tags addObjectsFromArray:@[@"public.subtitles.forced-only",
|
|
||||||
@"public.accessibility.transcribes-spoken-dialog",
|
|
||||||
@"public.accessibility.describes-music-and-sound",
|
|
||||||
@"public.easy-to-read"]];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mediaType == kMP42MediaType_Subtitle ||
|
|
||||||
mediaType == kMP42MediaType_ClosedCaption ||
|
|
||||||
mediaType == kMP42MediaType_Audio) {
|
|
||||||
|
|
||||||
[tags addObjectsFromArray:@[@"public.translation"]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (nullable NSString *)localizedTitleForTag:(NSString *)tag {
|
|
||||||
NSDictionary *localizedDescriptions = @{@"public.main-program-content": NSLocalizedString(@"Main Program Content", @"Media characteristic."),
|
|
||||||
@"public.auxiliary-content": NSLocalizedString(@"Auxiliary Content", @"Media characteristic."),
|
|
||||||
@"public.subtitles.forced-only": NSLocalizedString(@"Contains Only Forced Subtitles", @"Media characteristic."),
|
|
||||||
@"public.accessibility.transcribes-spoken-dialog": NSLocalizedString(@"Transcribes Spoken Dialog For Accessibility", @"Media characteristic."),
|
|
||||||
@"public.accessibility.describes-music-and-sound": NSLocalizedString(@"Describes Music And Sound For Accessibility", @"Media characteristic."),
|
|
||||||
@"public.easy-to-read": NSLocalizedString(@"Easy To Read", @"Media characteristic."),
|
|
||||||
@"public.accessibility.describes-video": NSLocalizedString(@"Describes Video For Accessibility", @"Media characteristic."),
|
|
||||||
@"public.translation.dubbed": NSLocalizedString(@"Dubbed Translation", @"Media characteristic."),
|
|
||||||
@"public.translation.voice-over": NSLocalizedString(@"Voice Over Translation", @"Media characteristic."),
|
|
||||||
@"public.translation": NSLocalizedString(@"Language Translation", @"Media characteristic.") };
|
|
||||||
return localizedDescriptions[tag];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)description
|
|
||||||
{
|
|
||||||
NSString *description = super.description;
|
|
||||||
description = [description stringByAppendingFormat:@" %@, state = %d", _value, _state];
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A NSTableCellView that contains a single checkbox.
|
|
||||||
*/
|
|
||||||
@interface SBCheckBoxTableCellView : NSTableCellView {
|
|
||||||
IBOutlet NSButton *_checkBox;
|
|
||||||
SBMediaTag *_representedTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property (nonatomic, readwrite, strong) SBMediaTag *representedTag;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
|
|
||||||
@implementation SBCheckBoxTableCellView
|
|
||||||
|
|
||||||
- (void)setRepresentedTag:(SBMediaTag *)representedTag {
|
|
||||||
_representedTag = representedTag;
|
|
||||||
|
|
||||||
_checkBox.title = _representedTag.localizedTitle;
|
|
||||||
_checkBox.state = _representedTag.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface SBMediaTagsController () <NSTableViewDataSource, NSTableViewDelegate>
|
|
||||||
|
|
||||||
@property (nonatomic, readonly, nonnull) MP42Track *track;
|
|
||||||
@property (nonatomic, readonly, nonnull) NSArray<SBMediaTag *> *tags;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#pragma mark - Main Class
|
|
||||||
|
|
||||||
@implementation SBMediaTagsController {
|
|
||||||
IBOutlet NSTableView *_tableView;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)init {
|
|
||||||
self = [super initWithNibName:@"SBMediaTagsController" bundle:nil];
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithTrack:(MP42Track *)track {
|
|
||||||
self = [self init];
|
|
||||||
if (self) {
|
|
||||||
_track = track;
|
|
||||||
NSArray<NSString *> *predefinedTags = [SBMediaTag predefinedTagsForMediaType:track.mediaType];
|
|
||||||
|
|
||||||
NSMutableArray<SBMediaTag *> *tags = [[NSMutableArray alloc] init];
|
|
||||||
|
|
||||||
// Add the predefined tags
|
|
||||||
for (NSString *availableTag in predefinedTags) {
|
|
||||||
BOOL state = [track.mediaCharacteristicTags containsObject:availableTag] ? YES : NO;
|
|
||||||
SBMediaTag *tag = [[SBMediaTag alloc] initWithValue:availableTag
|
|
||||||
state:state];
|
|
||||||
[tags addObject:tag];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep the custom ones if present
|
|
||||||
NSMutableSet<NSString *> *custom = [track.mediaCharacteristicTags mutableCopy];
|
|
||||||
[custom minusSet:[NSSet setWithArray:predefinedTags]];
|
|
||||||
|
|
||||||
for (NSString *customTag in custom) {
|
|
||||||
SBMediaTag *tag = [[SBMediaTag alloc] initWithValue:customTag state:YES];
|
|
||||||
[tags addObject:tag];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_tags = [tags copy];
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)dealloc
|
|
||||||
{
|
|
||||||
[_tableView setDelegate:nil];
|
|
||||||
[_tableView setDataSource:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
|
|
||||||
return self.tags.count;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row {
|
|
||||||
SBCheckBoxTableCellView *result = [tableView makeViewWithIdentifier:@"SBCheckBoxTableCellView" owner:self];
|
|
||||||
result.representedTag = self.tags[row];
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (IBAction)setTagState:(NSButton *)sender {
|
|
||||||
NSInteger row = [_tableView rowForView:sender];
|
|
||||||
self.tags[row].state = sender.state;
|
|
||||||
|
|
||||||
[self updateTrack];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)updateTrack {
|
|
||||||
NSMutableSet *set = [NSMutableSet set];
|
|
||||||
|
|
||||||
for (SBMediaTag *tag in self.tags) {
|
|
||||||
if (tag.state == YES) {
|
|
||||||
[set addObject:tag.value];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.track.mediaCharacteristicTags = set;
|
|
||||||
|
|
||||||
[self.view.window.windowController.document updateChangeCount:NSChangeDone];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
//
|
||||||
|
// SectionsTableView.swift
|
||||||
|
// Subler
|
||||||
|
//
|
||||||
|
// Created by Damiano Galassi on 20/03/2018.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
protocol SectionsTableViewDataSource: NSTableViewDataSource {
|
||||||
|
func numberOfSections(in tableView: NSTableView) -> Int
|
||||||
|
func tableView(_ tableView: NSTableView, numberOfRowsInSection section: Int) -> Int
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SectionsTableViewDataSourceImplementation: NSObject, NSTableViewDataSource {
|
||||||
|
|
||||||
|
fileprivate init(dataSource: SectionsTableViewDataSource) {
|
||||||
|
self.wrappedDataSource = dataSource
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate weak var wrappedDataSource: SectionsTableViewDataSource?
|
||||||
|
|
||||||
|
func numberOfRows(in tableView: NSTableView) -> Int {
|
||||||
|
guard let wrappedDataSource = wrappedDataSource else { return 0 }
|
||||||
|
var total = 0
|
||||||
|
|
||||||
|
for section in 0..<wrappedDataSource.numberOfSections(in: tableView) {
|
||||||
|
let count = wrappedDataSource.tableView(tableView, numberOfRowsInSection: section)
|
||||||
|
total += count > 0 ? count + 1 : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protocol SectionsTableViewDelegate: NSTableViewDelegate {
|
||||||
|
func tableView(_ tableView: NSTableView, viewForHeaderInSection section: Int) -> NSView?
|
||||||
|
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: (section: Int, sectionRow: Int)) -> NSView?
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SectionsTableViewDelegateImplementation: NSObject, NSTableViewDelegate {
|
||||||
|
|
||||||
|
fileprivate init(delegate: SectionsTableViewDelegate) {
|
||||||
|
self.wrappedDelegate = delegate
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate weak var wrappedDelegate: SectionsTableViewDelegate?
|
||||||
|
|
||||||
|
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||||
|
guard let wrappedDelegate = wrappedDelegate,
|
||||||
|
let tableView = tableView as? SectionsTableView else { return nil }
|
||||||
|
let (section, sectionRow) = tableView.section(for: row)
|
||||||
|
|
||||||
|
if sectionRow == -1 {
|
||||||
|
return wrappedDelegate.tableView(tableView, viewForHeaderInSection: section)
|
||||||
|
} else {
|
||||||
|
return wrappedDelegate.tableView(tableView, viewFor: tableColumn, row: (section, sectionRow))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: NSTableView, isGroupRow row: Int) -> Bool {
|
||||||
|
guard let tableView = tableView as? SectionsTableView else { return false }
|
||||||
|
|
||||||
|
let (_, sectionRow) = tableView.section(for: row)
|
||||||
|
return sectionRow == -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
|
||||||
|
if let tableView = tableView as? SectionsTableView {
|
||||||
|
let (_
|
||||||
|
, sectionRow) = tableView.section(for: row)
|
||||||
|
|
||||||
|
if sectionRow == -1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableViewSelectionDidChange(_ notification: Notification) {
|
||||||
|
wrappedDelegate?.tableViewSelectionDidChange!(notification)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A Table View with iOS-like section headers
|
||||||
|
class SectionsTableView: ExpandedTableView {
|
||||||
|
|
||||||
|
private var strongDataSource: SectionsTableViewDataSourceImplementation?
|
||||||
|
private var strongDelegate: SectionsTableViewDelegateImplementation?
|
||||||
|
|
||||||
|
override var dataSource: NSTableViewDataSource? {
|
||||||
|
set(newDataSource) {
|
||||||
|
if newDataSource != nil {
|
||||||
|
strongDataSource = SectionsTableViewDataSourceImplementation(dataSource: newDataSource as! SectionsTableViewDataSource)
|
||||||
|
super.dataSource = strongDataSource
|
||||||
|
} else {
|
||||||
|
strongDataSource = nil
|
||||||
|
super.dataSource = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get {
|
||||||
|
return super.dataSource
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override var delegate: NSTableViewDelegate? {
|
||||||
|
set(newDelegate) {
|
||||||
|
if newDelegate != nil {
|
||||||
|
strongDelegate = SectionsTableViewDelegateImplementation(delegate: newDelegate as! SectionsTableViewDelegate)
|
||||||
|
super.delegate = strongDelegate
|
||||||
|
} else {
|
||||||
|
strongDelegate = nil
|
||||||
|
super.delegate = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get {
|
||||||
|
return super.delegate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func sectionForRow(row: Int, counts: [Int]) -> (section: Int?, row: Int?) {
|
||||||
|
var c = counts[0]
|
||||||
|
for section in 0..<counts.count {
|
||||||
|
if (section > 0) {
|
||||||
|
c = c + counts[section]
|
||||||
|
}
|
||||||
|
if (row >= c - counts[section]) && row < c {
|
||||||
|
return (section: section, row: row - (c - counts[section]) - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (section: nil, row: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func section(for row: Int) -> (section: Int, row: Int) {
|
||||||
|
guard let wrappedDataSource = strongDataSource?.wrappedDataSource else { return (section: 0, row: 0) }
|
||||||
|
|
||||||
|
let numberOfSections = wrappedDataSource.numberOfSections(in: self)
|
||||||
|
var counts = [Int](repeating: 0, count: numberOfSections)
|
||||||
|
|
||||||
|
for section in 0..<numberOfSections {
|
||||||
|
let count = wrappedDataSource.tableView(self, numberOfRowsInSection: section)
|
||||||
|
counts[section] = count > 0 ? count + 1 : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = sectionForRow(row: row, counts: counts)
|
||||||
|
return (section: result.section ?? 0, row: result.row ?? 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user