Use some modern APIs and fix warnings on the latest macOS SDK
This commit is contained in:
14 files changed
+254
-156
No files matched your search
@@ -10,7 +10,7 @@ import AVFoundation
|
||||
|
||||
final class ArtworkSelectorViewItemLabel : NSTextField {
|
||||
|
||||
@IBInspectable var highlightColor: NSColor = .alternateSelectedControlColor
|
||||
@IBInspectable var highlightColor: NSColor = .selectedContentBackgroundColor
|
||||
@IBInspectable var highlightTextColor: NSColor = .alternateSelectedControlTextColor
|
||||
@IBInspectable var cornerRadius: CGFloat = 3
|
||||
|
||||
@@ -162,7 +162,7 @@ final class ArtworkSelectorViewItemView: NSView {
|
||||
|
||||
backgroundLayer.anchorPoint = CGPoint.zero
|
||||
backgroundLayer.position = CGPoint(x: 0, y: paddingBottom)
|
||||
backgroundLayer.backgroundColor = NSColor.controlHighlightColor.cgColor
|
||||
backgroundLayer.backgroundColor = NSColor.unemphasizedSelectedContentBackgroundColor.cgColor
|
||||
backgroundLayer.cornerRadius = 8
|
||||
backgroundLayer.isHidden = true
|
||||
backgroundLayer.isOpaque = true
|
||||
@@ -171,7 +171,7 @@ final class ArtworkSelectorViewItemView: NSView {
|
||||
emptyLayer.position = CGPoint(x: padding, y: padding + paddingBottom)
|
||||
emptyLayer.lineWidth = 3.0
|
||||
emptyLayer.lineDashPattern = [12,5]
|
||||
emptyLayer.strokeColor = NSColor.secondarySelectedControlColor.cgColor
|
||||
emptyLayer.strokeColor = NSColor.unemphasizedSelectedContentBackgroundColor.cgColor
|
||||
emptyLayer.fillColor = NSColor.windowBackgroundColor.cgColor
|
||||
emptyLayer.isOpaque = true
|
||||
|
||||
@@ -197,7 +197,14 @@ final class ArtworkSelectorViewItemView: NSView {
|
||||
}
|
||||
|
||||
private func updateBackgroundColor() {
|
||||
if #available(OSX 10.14, *) {
|
||||
if #available(macOS 11, *) {
|
||||
effectiveAppearance.performAsCurrentDrawingAppearance {
|
||||
imageLayer.shadowColor = NSColor.labelColor.cgColor
|
||||
backgroundLayer.backgroundColor = NSColor.unemphasizedSelectedContentBackgroundColor.cgColor
|
||||
emptyLayer.strokeColor = NSColor.unemphasizedSelectedContentBackgroundColor.cgColor
|
||||
emptyLayer.fillColor = NSColor.windowBackgroundColor.cgColor
|
||||
}
|
||||
} else {
|
||||
let saved = NSAppearance.current
|
||||
NSAppearance.current = effectiveAppearance
|
||||
|
||||
@@ -337,6 +344,7 @@ final class ArtworkSelectorViewItem: NSCollectionViewItem {
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
// FIXME
|
||||
override func mouseUp(with event: NSEvent) {
|
||||
if event.clickCount > 1, let action = doubleAction {
|
||||
target?.performSelector(onMainThread: action, with: nil, waitUntilDone: true)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="24127" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="25098" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="24127"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="25098"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
@@ -19,7 +19,7 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="128" height="171"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<subviews>
|
||||
<textField wantsLayer="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Wkh-6c-0tU" customClass="ArtworkSelectorViewItemLabel" customModule="Subler" customModuleProvider="target">
|
||||
<textField wantsLayer="YES" focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Wkh-6c-0tU" customClass="ArtworkSelectorViewItemLabel" customModule="Subler" customModuleProvider="target">
|
||||
<rect key="frame" x="-4" y="17" width="136" height="15"/>
|
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" allowsUndo="NO" alignment="center" title="Label" usesSingleLineMode="YES" id="TsL-Ak-xnf">
|
||||
<font key="font" metaFont="cellTitle"/>
|
||||
@@ -27,7 +27,7 @@
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField wantsLayer="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fGU-Kh-WjD">
|
||||
<textField wantsLayer="YES" focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fGU-Kh-WjD">
|
||||
<rect key="frame" x="-4" y="4" width="136" height="13"/>
|
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" allowsUndo="NO" alignment="center" title="Label" usesSingleLineMode="YES" id="ggX-Q2-CZ0">
|
||||
<font key="font" metaFont="system" size="10"/>
|
||||
@@ -40,7 +40,6 @@
|
||||
<constraint firstItem="fGU-Kh-WjD" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="-2" id="0Wf-6t-6Lg"/>
|
||||
<constraint firstAttribute="trailing" secondItem="Wkh-6c-0tU" secondAttribute="trailing" constant="-2" id="9df-FA-2lX"/>
|
||||
<constraint firstAttribute="bottom" secondItem="Wkh-6c-0tU" secondAttribute="bottom" constant="17" id="EOh-x3-ntT"/>
|
||||
<constraint firstItem="Wkh-6c-0tU" firstAttribute="top" relation="greaterThanOrEqual" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="20" id="HaR-VX-NRg"/>
|
||||
<constraint firstAttribute="bottom" secondItem="fGU-Kh-WjD" secondAttribute="bottom" constant="4" id="Xx6-ak-lcw"/>
|
||||
<constraint firstItem="Wkh-6c-0tU" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="-2" id="cPi-y8-nFz"/>
|
||||
<constraint firstAttribute="trailing" secondItem="fGU-Kh-WjD" secondAttribute="trailing" constant="-2" id="fLm-DU-mGT"/>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import Cocoa
|
||||
import MP42Foundation
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
final class DocumentWindowController: NSWindowController, TracksViewControllerDelegate, MetadataSearchViewControllerDelegate, FileImportControllerDelegate, ProgressViewControllerDelegate, NSDraggingDestination, NSUserInterfaceValidations {
|
||||
|
||||
@@ -464,7 +465,13 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
|
||||
panel.allowsMultipleSelection = false
|
||||
panel.canChooseFiles = true
|
||||
panel.canChooseDirectories = false
|
||||
panel.allowedFileTypes = ["mp4", "m4v", "m4a", "xml", "nfo"]
|
||||
if #available(macOS 12, *) {
|
||||
panel.allowedContentTypes = [.mpeg4Movie, .mpeg4Audio,
|
||||
.appleProtectedMPEG4Video,
|
||||
.xml, UTType(filenameExtension: "nfo")!]
|
||||
} else {
|
||||
panel.allowedFileTypes = ["mp4", "m4v", "m4a", "xml", "nfo"]
|
||||
}
|
||||
|
||||
panel.beginSheetModal(for: windowForSheet) { (response) in
|
||||
if response == NSApplication.ModalResponse.OK, let url = panel.url {
|
||||
|
||||
@@ -117,12 +117,12 @@ final class PresetManager {
|
||||
let resourceValues = try fileURL.resourceValues(forKeys: [.isDirectoryKey])
|
||||
if resourceValues.isDirectory == false, let version = version(of: fileURL) {
|
||||
let data = try Data(contentsOf: fileURL)
|
||||
let unarchiver = NSKeyedUnarchiver(forReadingWith: data)
|
||||
unarchiver.requiresSecureCoding = true
|
||||
defer { unarchiver.finishDecoding() }
|
||||
if let unarchiver = try? NSKeyedUnarchiver(forReadingFrom: data) {
|
||||
defer { unarchiver.finishDecoding() }
|
||||
|
||||
if version == 2, let preset = try? unarchiver.decodeTopLevelObject(of: [MetadataPreset.self], forKey: NSKeyedArchiveRootObjectKey) as? MetadataPreset {
|
||||
return preset
|
||||
if version == 2, let preset = try? unarchiver.decodeTopLevelObject(of: [MetadataPreset.self], forKey: NSKeyedArchiveRootObjectKey) as? MetadataPreset {
|
||||
return preset
|
||||
}
|
||||
}
|
||||
}
|
||||
throw LoadError.unsupportedFile
|
||||
@@ -148,13 +148,11 @@ final class PresetManager {
|
||||
}
|
||||
|
||||
private func save(preset: Preset) throws {
|
||||
let data = NSMutableData()
|
||||
let archiver = NSKeyedArchiver(forWritingWith: data)
|
||||
archiver.requiresSecureCoding = true
|
||||
let archiver = NSKeyedArchiver(requiringSecureCoding: true)
|
||||
archiver.encode(preset, forKey: NSKeyedArchiveRootObjectKey)
|
||||
archiver.finishEncoding()
|
||||
|
||||
try data.write(to: preset.fileURL, options: [.atomic])
|
||||
try archiver.encodedData.write(to: preset.fileURL, options: [.atomic])
|
||||
preset.changed = false
|
||||
}
|
||||
|
||||
|
||||
@@ -932,7 +932,11 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie
|
||||
panel.allowsMultipleSelection = true
|
||||
panel.canChooseFiles = true
|
||||
panel.canChooseDirectories = false
|
||||
panel.allowedFileTypes = ["public.image"]
|
||||
if #available(macOS 11, *) {
|
||||
panel.allowedContentTypes = [.image]
|
||||
} else {
|
||||
panel.allowedFileTypes = ["public.image"]
|
||||
}
|
||||
|
||||
guard let window = view.window else { return }
|
||||
|
||||
@@ -994,14 +998,11 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie
|
||||
func filePromiseProvider(_ filePromiseProvider: NSFilePromiseProvider, writePromiseTo url: URL, completionHandler: @escaping (Error?) -> Void) {
|
||||
if let userInfo = filePromiseProvider.userInfo as? [String: AnyObject] {
|
||||
do {
|
||||
if let indexPathData = userInfo[FilePromiseProvider.UserInfoKeys.indexPathKey] as? Data {
|
||||
if let indexPath = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(indexPathData) as? IndexPath {
|
||||
let item = artworks[indexPath.last!]
|
||||
if let image = item.imageValue {
|
||||
try image.data?.write(to: url)
|
||||
completionHandler(nil)
|
||||
}
|
||||
}
|
||||
if let indexPathData = userInfo[FilePromiseProvider.UserInfoKeys.indexPathKey] as? Data,
|
||||
let indexPath = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSIndexPath.classForCoder()], from: indexPathData) as? IndexPath,
|
||||
let image = artworks[indexPath.last!].imageValue {
|
||||
try image.data?.write(to: url)
|
||||
completionHandler(nil)
|
||||
}
|
||||
} catch {
|
||||
fatalError("failed to unarchive indexPath from promise provider.")
|
||||
@@ -1114,7 +1115,7 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie
|
||||
if let pasteboardItem = draggingItem.item as? NSPasteboardItem {
|
||||
do {
|
||||
if let indexPathData = pasteboardItem.data(forType: .artworkDragType),
|
||||
let itemIndexPath = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(indexPathData) as? IndexPath {
|
||||
let itemIndexPath = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSIndexPath.classForCoder()], from:indexPathData) as? IndexPath {
|
||||
indexes.insert(itemIndexPath)
|
||||
}
|
||||
} catch {
|
||||
@@ -1246,7 +1247,7 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie
|
||||
for pasteboardItem in items {
|
||||
do {
|
||||
if let indexPathData = pasteboardItem.data(forType: .artworkDragType),
|
||||
let itemIndexPath = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(indexPathData) as? IndexPath {
|
||||
let itemIndexPath = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSIndexPath.classForCoder()], from:indexPathData) as? IndexPath {
|
||||
indexes.insert(itemIndexPath)
|
||||
}
|
||||
} catch {
|
||||
|
||||
+3
-6
@@ -46,8 +46,7 @@ final class Queue {
|
||||
|
||||
do {
|
||||
let data = try Data(contentsOf: url)
|
||||
let unarchiver = NSKeyedUnarchiver(forReadingWith: data)
|
||||
unarchiver.requiresSecureCoding = true
|
||||
let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data)
|
||||
if let decodedItems = try unarchiver.decodeTopLevelObject(of: [NSArray.classForCoder(), NSMutableArray.classForCoder(), QueueItem.classForCoder()], forKey: NSKeyedArchiveRootObjectKey) as? [QueueItem] {
|
||||
items = decodedItems
|
||||
} else {
|
||||
@@ -63,13 +62,11 @@ final class Queue {
|
||||
|
||||
func saveToDisk() throws {
|
||||
arrayQueue.sync {
|
||||
let data = NSMutableData()
|
||||
let archiver = NSKeyedArchiver(forWritingWith: data)
|
||||
archiver.requiresSecureCoding = true
|
||||
let archiver = NSKeyedArchiver(requiringSecureCoding: true)
|
||||
archiver.encode(items, forKey: NSKeyedArchiveRootObjectKey)
|
||||
archiver.finishEncoding()
|
||||
|
||||
data.write(to: url, atomically: true)
|
||||
try? archiver.encodedData.write(to: url, options: [.atomic])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,15 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
|
||||
private var windowController: OptionsViewController?
|
||||
private let toolbarDelegate = QueueToolbarDelegate()
|
||||
|
||||
private let tablePasteboardType = NSPasteboard.PasteboardType("SublerQueueTableViewDataType")
|
||||
private lazy var docImg: NSImage = {
|
||||
// Load a generic movie icon to display in the table view
|
||||
let img = NSWorkspace.shared.icon(forFileType: "mov")
|
||||
let img = {
|
||||
if #available(macOS 12, *) {
|
||||
return NSWorkspace.shared.icon(for: .quickTimeMovie)
|
||||
} else {
|
||||
return NSWorkspace.shared.icon(forFileType: "mov")
|
||||
}
|
||||
}()
|
||||
img.size = NSSize(width: 16, height: 16)
|
||||
return img
|
||||
}()
|
||||
@@ -74,7 +79,7 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
|
||||
}
|
||||
self.window?.toolbar = toolbar
|
||||
|
||||
table.registerForDraggedTypes([NSPasteboard.PasteboardType.fileURL, tablePasteboardType])
|
||||
table.registerForDraggedTypes([NSPasteboard.PasteboardType.fileURL, .tableViewIndex])
|
||||
progressBar.isHidden = true
|
||||
|
||||
let main = OperationQueue.main
|
||||
@@ -771,41 +776,48 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
|
||||
|
||||
//MARK: Drag & Drop
|
||||
|
||||
func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {
|
||||
let data = try? NSKeyedArchiver.archivedData(withRootObject: rowIndexes, requiringSecureCoding: true)
|
||||
pboard.declareTypes([tablePasteboardType], owner: self)
|
||||
pboard.setData(data, forType: tablePasteboardType)
|
||||
return true
|
||||
func tableView(_ tableView: NSTableView,
|
||||
pasteboardWriterForRow row: Int) -> (any NSPasteboardWriting)? {
|
||||
let item = PasteboardItem(index: row, type: .tableViewIndex)
|
||||
return item
|
||||
}
|
||||
|
||||
func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
|
||||
if info.draggingSource == nil {
|
||||
tableView.setDropRow(row, dropOperation: .above)
|
||||
func tableView(_ tableView: NSTableView,
|
||||
validateDrop info: NSDraggingInfo,
|
||||
proposedRow row: Int,
|
||||
proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
|
||||
guard dropOperation == .above else { return [] }
|
||||
|
||||
if let source = info.draggingSource as? NSTableView,
|
||||
tableView == source
|
||||
{
|
||||
return .move
|
||||
} else if info.draggingSource == nil {
|
||||
return .copy
|
||||
} else if let source = info.draggingSource as? NSTableView, tableView == source && dropOperation == .above {
|
||||
return .every
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {
|
||||
let pboard = info.draggingPasteboard
|
||||
|
||||
if let source = info.draggingSource as? NSTableView, source == tableView, let rowData = pboard.data(forType: tablePasteboardType), let rowIndexes = NSKeyedUnarchiver.unarchiveObject(with: rowData) as? IndexSet {
|
||||
func tableView(_ tableView: NSTableView,
|
||||
acceptDrop info: NSDraggingInfo,
|
||||
row: Int,
|
||||
dropOperation: NSTableView.DropOperation) -> Bool {
|
||||
guard let pasteboardItems = info.draggingPasteboard.pasteboardItems
|
||||
else { return false }
|
||||
|
||||
if let source = info.draggingSource as? NSTableView,
|
||||
source == tableView
|
||||
{
|
||||
let rowIndexes = IndexSet(pasteboardItems.compactMap { $0.integer(forType: .tableViewIndex) })
|
||||
let items = queue.items(at: rowIndexes)
|
||||
move(items: items, at: row)
|
||||
return true
|
||||
|
||||
} else {
|
||||
|
||||
if pboard.types?.contains(NSPasteboard.PasteboardType.fileURL) ?? false {
|
||||
if let items = pboard.readObjects(forClasses: [NSURL.classForCoder()], options: [:]) as? [URL] {
|
||||
insert(contentOf: items, at: row)
|
||||
}
|
||||
return true
|
||||
} else if info.draggingPasteboard.types?.contains(NSPasteboard.PasteboardType.fileURL) ?? false {
|
||||
if let items = info.draggingPasteboard.readObjects(forClasses: [NSURL.classForCoder()], options: [:]) as? [URL] {
|
||||
insert(contentOf: items, at: row)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
@@ -43,10 +43,15 @@ final class SaveOptions: NSViewController {
|
||||
let types = doc.writableTypes(for: .saveAsOperation)
|
||||
|
||||
fileFormat.removeAllItems()
|
||||
|
||||
|
||||
for type in types {
|
||||
let name = UTTypeCopyDescription(type as CFString)?.takeRetainedValue() as String? ?? type
|
||||
fileFormat.addItem(withTitle: name)
|
||||
if #available(macOS 11, *) {
|
||||
let name = UTType(type)?.localizedDescription ?? type
|
||||
fileFormat.addItem(withTitle: name)
|
||||
} else {
|
||||
let name = UTTypeCopyDescription(type as CFString)?.takeRetainedValue() as String? ?? type
|
||||
fileFormat.addItem(withTitle: name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ final class TokenFieldCell : NSTokenFieldCell {
|
||||
set (newBackgroundStyle) {
|
||||
super.backgroundStyle = newBackgroundStyle
|
||||
if newBackgroundStyle == NSView.BackgroundStyle.emphasized {
|
||||
textColor = NSColor.controlHighlightColor
|
||||
textColor = NSColor.highlightColor
|
||||
} else {
|
||||
textColor = NSColor.controlTextColor
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ final class TracksViewController: NSViewController, NSTableViewDataSource, NSTab
|
||||
}
|
||||
|
||||
@IBOutlet var tracksTable: ExpandedTableView!
|
||||
private let pasteboardType = NSPasteboard.PasteboardType(rawValue: "SublerTableViewDataType")
|
||||
|
||||
private static let languagesMenu: NSMenu = {
|
||||
let menu = NSMenu()
|
||||
@@ -50,7 +49,7 @@ final class TracksViewController: NSViewController, NSTableViewDataSource, NSTab
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
tracksTable.registerForDraggedTypes([pasteboardType])
|
||||
tracksTable.registerForDraggedTypes([.tableViewIndex])
|
||||
tracksTable.doubleAction = #selector(doubleClickAction)
|
||||
tracksTable.scrollRowToVisible(0)
|
||||
}
|
||||
@@ -245,32 +244,26 @@ final class TracksViewController: NSViewController, NSTableViewDataSource, NSTab
|
||||
// MARK: Drag & drop
|
||||
|
||||
func tableView(_ tableView: NSTableView,
|
||||
writeRowsWith rowIndexes: IndexSet,
|
||||
to pboard: NSPasteboard) -> Bool {
|
||||
guard let firstRow = rowIndexes.first,
|
||||
let track = track(at: firstRow), track.isMuxed == false
|
||||
else { return false }
|
||||
|
||||
let data = try? NSKeyedArchiver.archivedData(withRootObject: rowIndexes, requiringSecureCoding: true)
|
||||
pboard.declareTypes([pasteboardType], owner: self)
|
||||
pboard.setData(data, forType: pasteboardType)
|
||||
return true
|
||||
pasteboardWriterForRow row: Int) -> (any NSPasteboardWriting)? {
|
||||
return PasteboardItem(index: row, type: .tableViewIndex)
|
||||
}
|
||||
|
||||
func tableView(_ tableView: NSTableView,
|
||||
validateDrop info: NSDraggingInfo,
|
||||
proposedRow row: Int,
|
||||
proposedDropOperation: NSTableView.DropOperation) -> NSDragOperation {
|
||||
let count = mp4.tracks.count + 1
|
||||
proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
|
||||
guard dropOperation == .above else { return [] }
|
||||
|
||||
if proposedDropOperation == .above {
|
||||
if row < count && row != 0, let track = track(at: row), track.isMuxed == false {
|
||||
return .every
|
||||
}
|
||||
else if row == count {
|
||||
return .every
|
||||
}
|
||||
guard let source = info.draggingSource as? NSTableView,
|
||||
tableView == source else { return [] }
|
||||
|
||||
let count = mp4.tracks.count + 1
|
||||
if row < count && row != 0, let track = track(at: row), track.isMuxed == false {
|
||||
return .move
|
||||
} else if row == count {
|
||||
return .move
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -278,12 +271,15 @@ final class TracksViewController: NSViewController, NSTableViewDataSource, NSTab
|
||||
acceptDrop info: NSDraggingInfo,
|
||||
row: Int,
|
||||
dropOperation: NSTableView.DropOperation) -> Bool {
|
||||
let data: Data = info.draggingPasteboard.data(forType: pasteboardType)!
|
||||
if let rowIndexes: IndexSet = NSKeyedUnarchiver.unarchiveObject(with: data) as? IndexSet, rowIndexes.isEmpty == false {
|
||||
guard let pasteboardItems = info.draggingPasteboard.pasteboardItems
|
||||
else { return false }
|
||||
|
||||
if let source = info.draggingSource as? NSTableView,
|
||||
source == tableView
|
||||
{
|
||||
let rowIndexes = IndexSet(pasteboardItems.compactMap { $0.integer(forType: .tableViewIndex) })
|
||||
let tracks = mp4.tracks.enumerated().filter { rowIndexes.contains($0.offset + 1)} .map { $0.element }
|
||||
mp4.moveTracks(tracks, to: UInt(row - 1))
|
||||
|
||||
tableView.reloadData()
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user