]> granicus.if.org Git - handbrake/commitdiff
MacGui: partial undo/redo support in the defaults sheets.
authorDamiano Galassi <damiog@gmail.com>
Thu, 22 Oct 2015 14:22:46 +0000 (16:22 +0200)
committerDamiano Galassi <damiog@gmail.com>
Thu, 22 Oct 2015 14:22:46 +0000 (16:22 +0200)
macosx/HBAudioDefaults.h
macosx/HBAudioDefaults.m
macosx/HBAudioDefaultsController.m
macosx/HBAudioTrackPreset.h
macosx/HBAudioTrackPreset.m
macosx/HBSubtitlesDefaults.h
macosx/HBSubtitlesDefaults.m
macosx/HBSubtitlesDefaultsController.m

index 8042eeb32cb4d6291f2862f90a1a1b4e0ee4e2e2..fce26045dd281a3c196ea1e71abebb073917e284 100644 (file)
@@ -47,6 +47,8 @@ typedef NS_ENUM(NSUInteger, HBAudioTrackSelectionBehavior) {
 
 - (void)validateEncoderFallbackForVideoContainer:(int)container;
 
+@property (nonatomic, readwrite, weak, nullable) NSUndoManager *undo;
+
 @end
 
 NS_ASSUME_NONNULL_END
index 2772b58f559c9706d1bb6b09fdf74f903a3b0cde..4905afa8a5e3627c71cce11a51e098bcefbc579c 100644 (file)
 - (void)addTrack
 {
     HBAudioTrackPreset *track = [[HBAudioTrackPreset alloc] initWithContainer:self.container];
+    track.undo = self.undo;
     [self insertObject:track inTracksArrayAtIndex:[self countOfTracksArray]];
 }
 
+#pragma mark - Properties
+
+- (void)setTrackSelectionBehavior:(HBAudioTrackSelectionBehavior)trackSelectionBehavior
+{
+    if (trackSelectionBehavior != _trackSelectionBehavior)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setTrackSelectionBehavior:_trackSelectionBehavior];
+    }
+    _trackSelectionBehavior = trackSelectionBehavior;
+}
+
+- (void)setAllowAACPassthru:(BOOL)allowAACPassthru
+{
+    if (allowAACPassthru != _allowAACPassthru)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAllowAACPassthru:_allowAACPassthru];
+    }
+    _allowAACPassthru = allowAACPassthru;
+}
+
+- (void)setAllowAC3Passthru:(BOOL)allowAC3Passthru
+{
+    if (allowAC3Passthru != _allowAC3Passthru)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAllowAC3Passthru:_allowAC3Passthru];
+    }
+    _allowAC3Passthru = allowAC3Passthru;
+}
+
+- (void)setAllowEAC3Passthru:(BOOL)allowEAC3Passthru
+{
+    if (allowEAC3Passthru != _allowEAC3Passthru)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAllowEAC3Passthru:_allowEAC3Passthru];
+    }
+    _allowEAC3Passthru = allowEAC3Passthru;
+}
+
+- (void)setAllowDTSHDPassthru:(BOOL)allowDTSHDPassthru
+{
+    if (allowDTSHDPassthru != _allowDTSHDPassthru)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAllowDTSHDPassthru:_allowDTSHDPassthru];
+    }
+    _allowDTSHDPassthru = allowDTSHDPassthru;
+}
+
+- (void)setAllowDTSPassthru:(BOOL)allowDTSPassthru
+{
+    if (allowDTSPassthru != _allowDTSPassthru)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAllowDTSPassthru:_allowDTSPassthru];
+    }
+    _allowDTSPassthru = allowDTSPassthru;
+}
+
+- (void)setAllowMP3Passthru:(BOOL)allowMP3Passthru
+{
+    if (allowMP3Passthru != _allowMP3Passthru)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAllowMP3Passthru:_allowMP3Passthru];
+    }
+    _allowMP3Passthru = allowMP3Passthru;
+}
+
+- (void)setAllowTrueHDPassthru:(BOOL)allowTrueHDPassthru
+{
+    if (allowTrueHDPassthru != _allowTrueHDPassthru)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAllowTrueHDPassthru:_allowTrueHDPassthru];
+    }
+    _allowTrueHDPassthru = allowTrueHDPassthru;
+}
+
+- (void)setAllowFLACPassthru:(BOOL)allowFLACPassthru
+{
+    if (allowFLACPassthru != _allowFLACPassthru)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAllowFLACPassthru:_allowFLACPassthru];
+    }
+    _allowFLACPassthru = allowFLACPassthru;
+}
+
+- (void)setEncoderFallback:(int)encoderFallback
+{
+    if (encoderFallback != _encoderFallback)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setEncoderFallback:_encoderFallback];
+    }
+    _encoderFallback = encoderFallback;
+}
+
+- (void)setSecondaryEncoderMode:(BOOL)secondaryEncoderMode
+{
+    if (secondaryEncoderMode != _secondaryEncoderMode)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setSecondaryEncoderMode:_secondaryEncoderMode];
+    }
+    _secondaryEncoderMode = secondaryEncoderMode;
+}
+
 - (NSArray *)audioEncoderFallbacks
 {
     NSMutableArray *fallbacks = [[NSMutableArray alloc] init];
     return nil;
 }
 
+#pragma mark - HBPresetCoding
+
 - (void)applyPreset:(HBPreset *)preset
 {
     // Track selection behavior
     self.container = container;
 }
 
+- (void)setUndo:(NSUndoManager *)undo
+{
+    _undo = undo;
+    [self.tracksArray makeObjectsPerformSelector:@selector(setUndo:) withObject:undo];
+}
+
 #pragma mark - NSCopying
 
 - (instancetype)copyWithZone:(NSZone *)zone
 
 - (void)insertObject:(HBAudioTrackPreset *)track inTracksArrayAtIndex:(NSUInteger)index;
 {
+    [[self.undo prepareWithInvocationTarget:self] removeObjectFromTracksArrayAtIndex:index];
     [self.tracksArray insertObject:track atIndex:index];
 }
 
 - (void)removeObjectFromTracksArrayAtIndex:(NSUInteger)index
 {
+    id obj = self.tracksArray[index];
+    [[self.undo prepareWithInvocationTarget:self] insertObject:obj inTracksArrayAtIndex:index];
     [self.tracksArray removeObjectAtIndex:index];
 }
 
index dc693a3fc36f98ee31ed204e4e0e48c3bbd3edd1..413fba72716ebfcabacd21140e22eaa24a8f41a5 100644 (file)
@@ -32,6 +32,7 @@ static void *HBAudioDefaultsContex = &HBAudioDefaultsContex;
     {
         _settings = settings;
         _languagesList = [[HBLanguagesSelection alloc] initWithLanguages:_settings.trackSelectionLanguages];
+        _settings.undo = self.window.undoManager;
     }
     return self;
 }
index f8f09ea14e372dd557a36a914792ec2efa88719f..0c96a3af89ec32abde3edfbc22b52e5a0544c2fb 100644 (file)
@@ -37,6 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, readonly) NSArray *samplerates;
 @property (nonatomic, readonly) NSArray *bitrates;
 
+@property (nonatomic, readwrite, weak, nullable) NSUndoManager *undo;
+
 @end
 
 NS_ASSUME_NONNULL_END
index fc73fe333ac4332f81896b39c0578eeffb6bfcb4..56c6f65e06cdc58a3356a19a1f123c82c606968c 100644 (file)
@@ -54,22 +54,55 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex;
 
 - (void)setEncoder:(int)encoder
 {
+    if (encoder != _encoder)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setEncoder:_encoder];
+    }
     _encoder = encoder;
-    [self validateMixdown];
-    [self validateSamplerate];
-    [self validateBitrate];
+
+    if (!(self.undo.isUndoing || self.undo.isRedoing))
+    {
+        [self validateMixdown];
+        [self validateSamplerate];
+        [self validateBitrate];
+    }
 }
 
 - (void)setMixdown:(int)mixdown
 {
+    if (mixdown != _mixdown)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setMixdown:_mixdown];
+    }
     _mixdown = mixdown;
-    [self validateBitrate];
+
+    if (!(self.undo.isUndoing || self.undo.isRedoing))
+    {
+        [self validateBitrate];
+    }
 }
 
 - (void)setSampleRate:(int)sampleRate
 {
+    if (sampleRate != _sampleRate)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setSampleRate:_sampleRate];
+    }
     _sampleRate = sampleRate;
-    [self validateBitrate];
+
+    if (!(self.undo.isUndoing || self.undo.isRedoing))
+    {
+        [self validateBitrate];
+    }
+}
+
+- (void)setBitRate:(int)bitRate
+{
+    if (bitRate != _bitRate)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setBitRate:_bitRate];
+    }
+    _bitRate = bitRate;
 }
 
 #pragma mark -
@@ -153,6 +186,15 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex;
     return retval;
 }
 
+- (void)setGain:(double)gain
+{
+    if (gain != _gain)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setGain:_gain];
+    }
+    _gain = gain;
+}
+
 // Because we have indicated that the binding for the gain validates immediately we can implement the
 // key value binding method to ensure the gain stays in our accepted range.
 - (BOOL)validateGain:(id *)ioValue error:(NSError * __autoreleasing *)outError
@@ -174,6 +216,15 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex;
     return retval;
 }
 
+- (void)setDrc:(double)drc
+{
+    if (drc != _drc)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setDrc:_drc];
+    }
+    _drc = drc;
+}
+
 #pragma mark - Options
 
 - (NSArray *)encoders
index 8b3fa6d4fa72b7df98623a22a0608aba9d997d7e..148f8ad825d4e0e056a1ce3765e07e431e62b7dc 100644 (file)
@@ -25,7 +25,7 @@ typedef NS_ENUM(NSUInteger, HBSubtitleTrackBurnInBehavior) {
 @interface HBSubtitlesDefaults : NSObject <NSSecureCoding, NSCopying, HBPresetCoding>
 
 @property (nonatomic, readwrite) HBSubtitleTrackSelectionBehavior trackSelectionBehavior;
-@property (nonatomic, readwrite, strong) NSMutableArray *trackSelectionLanguages;
+@property (nonatomic, readwrite, strong) NSMutableArray<NSString *> *trackSelectionLanguages;
 
 @property (nonatomic, readwrite) BOOL addForeignAudioSearch;
 @property (nonatomic, readwrite) BOOL addForeignAudioSubtitle;
@@ -35,6 +35,8 @@ typedef NS_ENUM(NSUInteger, HBSubtitleTrackBurnInBehavior) {
 @property (nonatomic, readwrite) BOOL burnInDVDSubtitles;
 @property (nonatomic, readwrite) BOOL burnInBluraySubtitles;
 
+@property (nonatomic, readwrite, weak, nullable) NSUndoManager *undo;
+
 @end
 
 NS_ASSUME_NONNULL_END
index a390a86b3cfa8d3742412104dc9b5737dc6bda50..ac52c4a52a7ab0064f17a72167908da7f254c1e3 100644 (file)
     return self;
 }
 
+#pragma mark - Properties
+
+- (void)setTrackSelectionBehavior:(HBSubtitleTrackSelectionBehavior)trackSelectionBehavior
+{
+    if (trackSelectionBehavior != _trackSelectionBehavior)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setTrackSelectionBehavior:_trackSelectionBehavior];
+    }
+    _trackSelectionBehavior = trackSelectionBehavior;
+}
+
+- (void)setAddForeignAudioSearch:(BOOL)addForeignAudioSearch
+{
+    if (addForeignAudioSearch != _addForeignAudioSearch)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAddForeignAudioSearch:_addForeignAudioSearch];
+    }
+    _addForeignAudioSearch = addForeignAudioSearch;
+}
+
+- (void)setAddForeignAudioSubtitle:(BOOL)addForeignAudioSubtitle
+{
+    if (addForeignAudioSubtitle != _addForeignAudioSubtitle)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAddForeignAudioSubtitle:_addForeignAudioSubtitle];
+    }
+    _addForeignAudioSubtitle = addForeignAudioSubtitle;
+}
+
+- (void)setAddCC:(BOOL)addCC
+{
+    if (addCC != _addCC)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setAddCC:_addCC];
+    }
+    _addCC = addCC;
+}
+
+- (void)setBurnInBehavior:(HBSubtitleTrackBurnInBehavior)burnInBehavior
+{
+    if (burnInBehavior != _burnInBehavior)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setBurnInBehavior:_burnInBehavior];
+    }
+    _burnInBehavior = burnInBehavior;
+}
+
+- (void)setBurnInDVDSubtitles:(BOOL)burnInDVDSubtitles
+{
+    if (burnInDVDSubtitles != _burnInDVDSubtitles)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setBurnInDVDSubtitles:_burnInDVDSubtitles];
+    }
+    _burnInDVDSubtitles = burnInDVDSubtitles;
+}
+
+- (void)setBurnInBluraySubtitles:(BOOL)burnInBluraySubtitles
+{
+    if (burnInBluraySubtitles != _burnInBluraySubtitles)
+    {
+        [[self.undo prepareWithInvocationTarget:self] setBurnInBluraySubtitles:_burnInBluraySubtitles];
+    }
+    _burnInBluraySubtitles = burnInBluraySubtitles;
+}
+
+#pragma mark - HBPresetCoding
+
 - (void)applyPreset:(HBPreset *)preset
 {
     if ([preset[@"SubtitleTrackSelectionBehavior"] isEqualToString:@"first"])
index 9d1c7f8757e05363b4bef53915c0ccf3b1c20436..83d98b72e62d04928c6b70ae907d0621d9eac401 100644 (file)
@@ -29,6 +29,7 @@ static void *HBSubtitlesDefaultsContex = &HBSubtitlesDefaultsContex;
     {
         _settings = settings;
         _languagesList = [[HBLanguagesSelection alloc] initWithLanguages:_settings.trackSelectionLanguages];
+        _settings.undo = self.window.undoManager;
     }
     return self;
 }