]> granicus.if.org Git - handbrake/commitdiff
MacGui: add a better check for regenerating the built-in presets after a user deletes...
authorritsuka <damiog@gmail.com>
Mon, 24 Nov 2014 07:38:17 +0000 (07:38 +0000)
committerritsuka <damiog@gmail.com>
Mon, 24 Nov 2014 07:38:17 +0000 (07:38 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6549 b64f7644-9d1e-0410-96f1-a4d463321fa5

macosx/HBPresetsManager.m

index 778963b7d73f07c1d9841b6f59739af9776ace7d..f7b53210720f517ed36f4b8de061044991385dd0 100644 (file)
@@ -105,9 +105,18 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
 
     [presetsArray release];
 
-    // If the preset list is empty,
-    // readd the built in presets.
-    if (self.root.children.count == 0)
+    // If the preset list contains no leaf,
+    // add back the built in presets.
+    __block BOOL leafFound = NO;
+    [self.root enumerateObjectsUsingBlock:^(id obj, NSIndexPath *idx, BOOL *stop) {
+        if ([obj isLeaf])
+        {
+            leafFound = YES;
+            *stop = YES;
+        }
+    }];
+
+    if (!leafFound)
     {
         [self generateBuiltInPresets];
     }
@@ -291,6 +300,7 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
 {
     __block HBPreset *normalPreset = nil;
     __block HBPreset *firstUserPreset = nil;
+    __block HBPreset *firstBuiltInPreset = nil;
 
     // Search for a possibile new default preset
     // Try to use "Normal" or the first user preset.
@@ -301,8 +311,12 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
             {
                 normalPreset = obj;
             }
+            if (firstBuiltInPreset == nil)
+            {
+                firstBuiltInPreset = obj;
+            }
         }
-        else if ([obj isLeaf])
+        else if ([obj isLeaf] && firstUserPreset == nil)
         {
             firstUserPreset = obj;
             *stop = YES;
@@ -319,6 +333,10 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
         self.defaultPreset = firstUserPreset;
         firstUserPreset.isDefault = YES;
     }
+    else if (firstBuiltInPreset) {
+        self.defaultPreset = firstBuiltInPreset;
+        firstBuiltInPreset.isDefault = YES;
+    }
 }
 
 - (void)setDefaultPreset:(HBPreset *)defaultPreset