Make chapter tracks deletable, insertable, and language-editable

Delete: the phase-1 gate against deleting the chapter pseudo-track on
Matroska documents is obsolete now that chapter changes ride the
stream-copy remuxer — a removed pseudo-track simply makes the model
report "no chapters", which removes the Chapters element on save (the
same path emptying the Chapters tab already took). The toolbar Delete
button's validation is corrected too; it still rejected chapter-only
selections after deleteSelection was opened up.

Insert: the Actions toolbar gets a single "Insert a chapter" item, and
"Insert a chapter every" (previously MP4-only) is enabled on Matroska.
Both create the chapter track when the document has none, doing the
tags-only bookkeeping the model needs (dense display trackId,
updateChangeCount). A single insert lands 1s after the latest start,
clamped to the track duration, so it can never tie with a stored
chapter — ties get clamped +1ms on write and would silently shift the
user's own chapter times.

Language: the chapter row's language popup stays editable on MKV
documents (the value rides the remuxer's chapter rebuild, not the tag
writer, since the pseudo-track has no TrackEntry), and the Matroska
chapters snapshot carries it so a language-only edit triggers the
remux. Pairs with the submodule's ChapterLanguage round trip.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
Scott GarrettandClaude Code committed 2026-11-26 18:17:37 -05:00
1 parent 8520d729c6
commit f457b4e89c
13 files changed
+124 -30

No files matched your search

+15 -3
View File
@@ -46,6 +46,14 @@ final class TracksViewController: NSViewController, NSTableViewDataSource, NSTab
return document.isMatroska == false || track.isMember(of: MP42ChapterTrack.self) == false
}
// The chapter pseudo-track has no TrackEntry for the tag writer, but it
// carries the language the remuxer stamps into every ChapterDisplay on
// save, so its language popup is editable on Matroska documents too.
private func isLanguageEditable(_ track: MP42Track?) -> Bool {
guard let track = track else { return false }
return isFieldEditable(track) || track.isMember(of: MP42ChapterTrack.self)
}
private static let languagesMenu: NSMenu = {
let menu = NSMenu()
menu.autoenablesItems = false
@@ -125,8 +133,12 @@ final class TracksViewController: NSViewController, NSTableViewDataSource, NSTab
func deleteSelection(in tableview: NSTableView) {
// On MKV documents real tracks are deletable too (the remuxer drops
// their blocks on save); the chapter pseudo-track still is not.
let deletable = document.isMatroska ? selectedTracks.filter { isFieldEditable($0) } : selectedTracks
// their blocks on save) and so is the chapter pseudo-track: with it
// gone the model reports "no chapters", so the save remuxes and the
// Chapters element is deleted (same as emptying the Chapters tab).
let deletable = document.isMatroska
? selectedTracks.filter { isFieldEditable($0) || $0.isMember(of: MP42ChapterTrack.self) }
: selectedTracks
guard deletable.isEmpty == false else { return }
delegate?.delete(tracks: deletable)
}
@@ -236,7 +248,7 @@ final class TracksViewController: NSViewController, NSTableViewDataSource, NSTab
}
cell?.textField?.stringValue = MP42Languages.defaultManager.localizedLang(forExtendedTag: track.language)
cell?.popUpButton?.isEnabled = isFieldEditable(track)
cell?.popUpButton?.isEnabled = isLanguageEditable(track)
return cell
case trackInfoColumn?: