Rename presets in preferences.
This commit is contained in:
8 files changed
+70
-27
No files matched your search
+14
-10
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11535.1" systemVersion="16B2553a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13189.4" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11535.1"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13189.4"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
@@ -26,13 +26,13 @@
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<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="SBTableView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="355" height="198"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="354" height="198"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<size key="intercellSpacing" width="3" height="2"/>
|
||||
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
|
||||
<tableColumns>
|
||||
<tableColumn identifier="name" editable="NO" width="352" minWidth="40" maxWidth="1000" id="eNe-ax-OFR">
|
||||
<tableColumn identifier="name" editable="NO" width="351" minWidth="40" maxWidth="1000" id="eNe-ax-OFR">
|
||||
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -46,20 +46,23 @@
|
||||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||
<prototypeCellViews>
|
||||
<tableCellView identifier="nameCell" id="6bC-Va-s9o">
|
||||
<rect key="frame" x="1" y="1" width="352" height="17"/>
|
||||
<rect key="frame" x="1" y="1" 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="0.0" width="327" height="17"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="326" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" 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="6CG-pa-ocP">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="-2" id="2Uf-Z0-tF7"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<button toolTip="Show set details" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="IXy-8d-VMc">
|
||||
<rect key="frame" x="333" y="0.0" width="16" height="16"/>
|
||||
<rect key="frame" x="332" y="0.0" width="16" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="bevel" bezelStyle="regularSquare" image="info" imagePosition="overlaps" alignment="center" alternateImage="info-pressed" imageScaling="proportionallyDown" inset="2" id="BeK-4k-Hpl">
|
||||
<behavior key="behavior" lightByContents="YES"/>
|
||||
@@ -89,7 +92,7 @@
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="200" id="JWr-Hr-fVF"/>
|
||||
</constraints>
|
||||
<scroller key="horizontalScroller" verticalHuggingPriority="750" horizontal="YES" id="D9w-7o-pBY">
|
||||
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="D9w-7o-pBY">
|
||||
<rect key="frame" x="1" y="183" width="354" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
@@ -101,7 +104,7 @@
|
||||
<button toolTip="Remove selected set" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SIg-lA-6FA">
|
||||
<rect key="frame" x="20" y="19" width="25" height="21"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="25" id="KCi-qM-zwt"/>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="25" id="KCi-qM-zwt"/>
|
||||
</constraints>
|
||||
<buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" image="NSRemoveTemplate" imagePosition="overlaps" alignment="center" enabled="NO" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Y2I-ux-1v2">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
@@ -119,6 +122,7 @@
|
||||
<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="leading" secondItem="Sl5-b6-dQC" secondAttribute="leading" constant="20" id="SNz-hG-5Nz"/>
|
||||
<constraint firstAttribute="trailing" secondItem="Bgi-pA-eAO" secondAttribute="trailing" constant="20" id="cgL-bl-uVt"/>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="SIg-lA-6FA" secondAttribute="trailing" constant="20" symbolic="YES" id="ssz-R1-wNZ"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="-344" y="-648"/>
|
||||
</customView>
|
||||
@@ -18,7 +18,7 @@ import Foundation
|
||||
case replace
|
||||
}
|
||||
|
||||
let title: String
|
||||
var title: String
|
||||
@objc let metadata: MP42Metadata
|
||||
let replacementStragety: ReplacementStrategy
|
||||
|
||||
@@ -58,4 +58,10 @@ import Foundation
|
||||
}
|
||||
|
||||
static var supportsSecureCoding: Bool { return true }
|
||||
|
||||
// MARK: NSCopying
|
||||
|
||||
func copy(with zone: NSZone? = nil) -> Any {
|
||||
return MetadataPreset(title: title, metadata: metadata)
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc protocol Preset: AnyObject, NSSecureCoding {
|
||||
var title: String { get }
|
||||
var changed: Bool { get }
|
||||
@objc protocol Preset: AnyObject, NSSecureCoding, NSCopying {
|
||||
var title: String { get set }
|
||||
var changed: Bool { get set }
|
||||
var version: Int { get }
|
||||
|
||||
var pathExtension: String { get }
|
||||
|
||||
@@ -53,6 +53,7 @@ extension PresetManager.Error: LocalizedError {
|
||||
throw Error.alreadyExists
|
||||
}
|
||||
presets.append(newElement)
|
||||
try save(preset: newElement)
|
||||
sort()
|
||||
postNotification()
|
||||
}
|
||||
@@ -64,6 +65,12 @@ extension PresetManager.Error: LocalizedError {
|
||||
postNotification()
|
||||
}
|
||||
|
||||
func remove(item: Preset) {
|
||||
if let index = presets.index(where: { $0 === item }) {
|
||||
remove(at: index)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func item(name: String) -> Preset? {
|
||||
return presets.filter { $0.title == name }.first
|
||||
}
|
||||
@@ -146,14 +153,15 @@ extension PresetManager.Error: LocalizedError {
|
||||
sort()
|
||||
}
|
||||
|
||||
private func save(preset: Preset, to url: URL) throws {
|
||||
private func save(preset: Preset) throws {
|
||||
let data = NSMutableData()
|
||||
let archiver = NSKeyedArchiver(forWritingWith: data)
|
||||
archiver.requiresSecureCoding = true
|
||||
archiver.encode(preset, forKey: NSKeyedArchiveRootObjectKey)
|
||||
archiver.finishEncoding()
|
||||
|
||||
try data.write(to: url, options: [.atomic])
|
||||
try data.write(to: preset.fileURL, options: [.atomic])
|
||||
preset.changed = false
|
||||
}
|
||||
|
||||
@objc func save() throws {
|
||||
@@ -164,7 +172,7 @@ extension PresetManager.Error: LocalizedError {
|
||||
|
||||
for preset in presets {
|
||||
if preset.changed {
|
||||
try save(preset: preset, to: preset.fileURL)
|
||||
try save(preset: preset)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
|
||||
class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate, NSTextFieldDelegate {
|
||||
|
||||
let presetManager: PresetManager
|
||||
var popover: NSPopover?
|
||||
@@ -20,7 +20,7 @@ class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTabl
|
||||
var observer: Any?
|
||||
|
||||
override var nibName: NSNib.Name? {
|
||||
return NSNib.Name(rawValue: "SBSetPrefsViewController")
|
||||
return NSNib.Name(rawValue: "SBPresetPrefsViewController")
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -67,6 +67,25 @@ class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTabl
|
||||
|
||||
// MARK: UI Actions
|
||||
|
||||
override func controlTextDidEndEditing(_ obj: Notification) {
|
||||
if let view = obj.object as? NSTextField {
|
||||
let row = tableView.row(for: view)
|
||||
let preset = presetManager.presets[row]
|
||||
let copy = preset.copy() as! MetadataPreset
|
||||
copy.title = view.stringValue
|
||||
|
||||
do {
|
||||
try presetManager.append(newElement: copy)
|
||||
presetManager.remove(item: preset)
|
||||
}
|
||||
catch {
|
||||
view.window?.presentError(error)
|
||||
}
|
||||
|
||||
tableView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func deletePreset(_ sender: Any) {
|
||||
closePopOver(self)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import Foundation
|
||||
|
||||
class QueuePreset: NSObject, Preset {
|
||||
|
||||
let title: String
|
||||
var title: String
|
||||
let options: [String:Any]
|
||||
|
||||
let version: Int
|
||||
@@ -40,4 +40,10 @@ class QueuePreset: NSObject, Preset {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
// MARK: NSCopying
|
||||
|
||||
func copy(with zone: NSZone? = nil) -> Any {
|
||||
return QueuePreset(title: title, options: options)
|
||||
}
|
||||
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user