Fix the checkOnlySelectedTracks function to make it work with multiple files
This commit is contained in:
1 file changed
+26
-15
@@ -290,25 +290,36 @@ final class FileImportController: ViewController, NSTableViewDataSource, NSTable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.forEach { $0.checked = $0.importable && languages.contains($0.track.language) }
|
var modifiedIndexes = IndexSet()
|
||||||
reloadCheckColumn(forRowIndexes: IndexSet(integersIn: items.indices))
|
|
||||||
|
items.enumerated().forEach { (index, item) in
|
||||||
|
switch item {
|
||||||
|
case .file(_):
|
||||||
|
break
|
||||||
|
case .track(let settings):
|
||||||
|
settings.checked = settings.importable && languages.contains(settings.track.language)
|
||||||
|
modifiedIndexes.insert(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadCheckColumn(forRowIndexes: modifiedIndexes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func checkOnlySelectedTracks(_ sender: Any) {
|
@IBAction func checkOnlySelectedTracks(_ sender: Any) {
|
||||||
let targetedIndices = tracksTableView.targetedRowIndexes;
|
let targetedIndices = tracksTableView.targetedRowIndexes;
|
||||||
var selectedIndices = tracksTableView.selectedRowIndexes;
|
var modifiedIndexes = IndexSet()
|
||||||
if (!selectedIndices.contains(targetedIndices.first!))
|
|
||||||
{
|
items.enumerated().forEach { (index, item) in
|
||||||
// This is a shortcut for quickly selecting specific rows.
|
switch item {
|
||||||
// If the rows are selected and right-clicked, the target is within the selection.
|
case .file(_):
|
||||||
// If the user didn't both first selecting rows, use the target index (visible with a selection-border in the UI).
|
break
|
||||||
// If the user did select but targets another row, use the target row
|
case .track(let settings):
|
||||||
// because if it was intentional, only the targeted row is selected
|
settings.checked = targetedIndices.contains(index)
|
||||||
// and if it was not intentional, it's easy to fix and open the menu on top of an actual selected row.
|
modifiedIndexes.insert(index)
|
||||||
selectedIndices = targetedIndices;
|
}
|
||||||
}
|
}
|
||||||
settings.enumerated().forEach { (index, item) in item.checked = selectedIndices.contains(index + 1) }
|
|
||||||
reloadCheckColumn(forRowIndexes: IndexSet(integersIn: items.indices))
|
reloadCheckColumn(forRowIndexes: modifiedIndexes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: IBActions
|
// MARK: IBActions
|
||||||
|
|||||||
Reference in new issue
Block a user