Route AppleScript chapter imports and make File > Optimize work on MKV

importFilesDirectly mirrors the open panel's extension dispatch, so
AppleScript `import file` now sends .txt/.csv to addChapters/
updateChapters and everything else to FileImportController; the chapter
track created on an MKV doc gets the tags-only trackId/
updateChangeCount bookkeeping in didSelect(chapters:). searchChapters
moves to the always-valid validation group, though CLAUDE.md now
records that it is orphaned dead code with no UI entry point.

File > Optimize on a Matroska document forces writeMatroska's
structural branch: a full remuxer rebuild from the existing tracks,
the container-equivalent of atom-order optimize. Its validation uses
fileURL instead of hasFileRepresentation, which is always false for
tags-only models and kept the menu disabled forever.

Bump MP42Foundation for the tagsOnly importer fix that mirrors the
file's chapter atoms verbatim (offset first starts and tied zero
starts survive an edit); harness matrix PASS=324/0.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
Scott GarrettandClaude Code committed 2026-11-26 19:14:59 -05:00
1 parent f457b4e89c
commit 06ecb0af5f
4 files changed
+46 -15

No files matched your search

+29 -9
View File
@@ -280,7 +280,8 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate, Trac
#selector(searchMetadata(_:)),
#selector(sendToQueue(_:)),
#selector(insertChapter(_:)),
#selector(addChaptersEvery(_:)):
#selector(addChaptersEvery(_:)),
#selector(searchChapters(_:)):
return true
// Matroska documents may import subtitle text files (written as
@@ -288,12 +289,11 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate, Trac
case #selector(selectFile(_:)):
return true
// Track bulk modifications (and the chapter-DB search, whose apply
// path lacks the tags-only bookkeeping): unavailable in Matroska
// tags-only mode. The Insert-a-chapter actions are NOT on this list —
// chapter changes ride the stream-copy remuxer, so they work on MKV.
case #selector(searchChapters(_:)),
#selector(iTunesFriendlyTrackGroups(_:)),
// Track bulk modifications: unavailable in Matroska tags-only mode.
// Chapter actions (searchChapters, the Insert-a-chapter commands) are
// NOT on this list — chapter changes ride the stream-copy remuxer,
// so they work on MKV too.
case #selector(iTunesFriendlyTrackGroups(_:)),
#selector(clearTrackNames(_:)),
#selector(prettifyAudioTrackNames(_:)),
#selector(fixAudioFallbacks(_:)):
@@ -552,7 +552,13 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate, Trac
chapterTrack.addChapter(chapter)
}
mp4.addTrack(chapterTrack)
mp4.addTrack(chapterTrack) // addTrack: replaces any previous chapter track
if doc.isMatroska {
// Tags-only bookkeeping, same as addChapters/insertChapter:
// addTrack: zeroes trackId, and nothing else marks the document.
chapterTrack.trackId = (mp4.tracks.map { $0.trackId }.max() ?? 0) + 1
doc.updateChangeCount(.changeDone)
}
tracksViewController.reloadData()
tracksViewController.selectTracks([chapterTrack])
}
@@ -761,8 +767,22 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate, Trac
}
@objc func importFilesDirectly(_ fileURLs: [URL]) {
// Mirror the open panel's extension routing (selectFile): chapter
// text files go to the chapter commands — addChapters bootstraps the
// chapter track on both containers — everything else to the regular
// track importer.
var mediaURLs: [URL] = []
for url in fileURLs {
switch url.pathExtension.lowercased() {
case "txt": addChapters(fileURL: url)
case "csv": updateChapters(fileURL: url)
default: mediaURLs.append(url)
}
}
guard mediaURLs.isEmpty == false else { return }
do {
let controller = try FileImportController(fileURLs: fileURLs, delegate: self)
let controller = try FileImportController(fileURLs: mediaURLs, delegate: self)
// Call addTracks directly - the Settings initialization logic runs when the controller is created
controller.addTracks(self)