Implement multiple tracks drag & drop in the document window.
This commit is contained in:
3 files changed
+14
-8
No files matched your search
@@ -255,6 +255,12 @@ class Queue {
|
||||
}
|
||||
}
|
||||
|
||||
func swapAt(_ i: Int, _ j: Int) {
|
||||
arrayQueue.sync {
|
||||
items.swapAt(i, j)
|
||||
}
|
||||
}
|
||||
|
||||
func remove(_ item: SBQueueItem) {
|
||||
arrayQueue.sync {
|
||||
if let index = items.firstIndex(of: item) {
|
||||
|
||||
@@ -387,7 +387,7 @@ class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDelegate,
|
||||
|
||||
for item in items.reversed() {
|
||||
let sourceIndex = queue.index(of: item)
|
||||
queue.remove(at: IndexSet(integer: IndexSet.Element(sourceIndex)))
|
||||
queue.remove(at: IndexSet(integer: sourceIndex))
|
||||
|
||||
if sourceIndex < currentIndex {
|
||||
currentIndex -= 1
|
||||
@@ -398,7 +398,7 @@ class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDelegate,
|
||||
source.append(currentIndex)
|
||||
dest.append(sourceIndex)
|
||||
|
||||
table.moveRow(at: Int(sourceIndex), to: Int(currentIndex))
|
||||
table.moveRow(at: sourceIndex, to: currentIndex)
|
||||
}
|
||||
|
||||
table.endUpdates()
|
||||
@@ -424,8 +424,8 @@ class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDelegate,
|
||||
newSource.append(destIndex)
|
||||
newDest.append(sourceIndex)
|
||||
|
||||
if let item = queue.items(at: IndexSet(integer: IndexSet.Element(sourceIndex))).first {
|
||||
queue.remove(at: IndexSet(integer: IndexSet.Element(sourceIndex)))
|
||||
if let item = queue.items(at: IndexSet(integer: sourceIndex)).first {
|
||||
queue.remove(at: IndexSet(integer: sourceIndex))
|
||||
queue.insert(item, at: destIndex)
|
||||
|
||||
table.moveRow(at: sourceIndex, to: destIndex)
|
||||
|
||||
@@ -273,12 +273,12 @@ class TracksViewController: NSViewController, NSTableViewDataSource, NSTableView
|
||||
row: Int,
|
||||
dropOperation: NSTableView.DropOperation) -> Bool {
|
||||
let data: Data = info.draggingPasteboard.data(forType: pasteboardType)!
|
||||
let rowIndexes: IndexSet = NSKeyedUnarchiver.unarchiveObject(with: data) as! IndexSet
|
||||
if let rowIndexes: IndexSet = NSKeyedUnarchiver.unarchiveObject(with: data) as? IndexSet, rowIndexes.isEmpty == false {
|
||||
|
||||
let tracks = mp4.tracks.enumerated().filter { rowIndexes.contains($0.offset + 1)} .map { $0.element }
|
||||
mp4.moveTracks(tracks, to: UInt(row - 1))
|
||||
|
||||
if let dragRow = rowIndexes.first {
|
||||
mp4.moveTrack(at: UInt(dragRow - 1), to: UInt(row - 1))
|
||||
tableView.reloadData()
|
||||
// TODO: Support multiple rows drag
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user