Fix some undo issues

This commit is contained in:
Damiano Galassi committed 2026-10-03 11:46:29 +02:00
1 parent 37cd9b40b9
commit bfa477b799
1 file changed
+27 -12
+27 -12
View File
@@ -95,7 +95,6 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
@end
MP42_OBJC_DIRECT_MEMBERS
@implementation MP42File
@synthesize itracks = _tracks;
@@ -451,6 +450,7 @@ MP42_OBJC_DIRECT_MEMBERS
NSAssert(self.status != MP42StatusWriting, @"Unsupported operation: trying to add a track while the file is open for writing");
NSAssert(![self.itracks containsObject:track], @"Unsupported operation: trying to add a track that is already present.");
if (!(self.undo.isUndoing || self.undo.isRedoing)) {
track.sourceId = track.trackId;
track.trackId = 0;
track.muxed = NO;
@@ -470,14 +470,6 @@ MP42_OBJC_DIRECT_MEMBERS
NSAssert(track.conversionSettings, @"Missing conversion settings");
}
if (track.importer && track.URL) {
if (self.importers[track.URL.path]) {
track.importer = self.importers[track.URL.path];
} else {
self.importers[track.URL.path] = track.importer;
}
}
if ([track isMemberOfClass:[MP42AudioTrack class]]) {
MP42AudioTrack *audioTrack = (MP42AudioTrack *)track;
MP42Track *fallbackTrack = audioTrack.fallbackTrack;
@@ -489,21 +481,35 @@ MP42_OBJC_DIRECT_MEMBERS
if ([track isMemberOfClass:[MP42ChapterTrack class]]) {
track.duration = self.duration;
}
}
track.undo = self.undo;
[[self.undo prepareWithInvocationTarget:self] removeTracks:@[track]];
[self.itracks addObject:track];
}
- (void)addToBeDeleted:(MP42Track *)track
{
[[self.undo prepareWithInvocationTarget:self] removeFromToBeDeleted:track];
[_tracksToBeDeleted addObject:track];
}
- (void)removeFromToBeDeleted:(MP42Track *)track
{
[[self.undo prepareWithInvocationTarget:self] addToBeDeleted:track];
[_tracksToBeDeleted removeObject:track];
}
- (void)removeTracks:(NSArray<MP42Track *> *)tracks {
NSAssert(self.status != MP42StatusWriting, @"Unsupported operation: trying to remove a track while the file is open for writing");
if (!(self.undo.isUndoing || self.undo.isRedoing)) {
for (MP42Track *track in tracks) {
// track is muxed, it needs to be removed from the file
if (track.muxed)
[_tracksToBeDeleted addObject:track];
if (track.muxed) {
[self addToBeDeleted:track];
}
// Remove the reference
for (MP42Track *ref in self.itracks) {
@@ -520,6 +526,15 @@ MP42_OBJC_DIRECT_MEMBERS
a.forcedTrack = nil;
}
}
if (track.importer && track.URL) {
if (self.importers[track.URL.path]) {
track.importer = self.importers[track.URL.path];
} else {
self.importers[track.URL.path] = track.importer;
}
}
}
}
for (MP42Track *track in tracks) {