]> granicus.if.org Git - handbrake/commitdiff
MacGui: batch the preview updates so we don't reload the same preview multiple times.
authorDamiano Galassi <damiog@gmail.com>
Fri, 15 Jan 2016 18:45:08 +0000 (19:45 +0100)
committerDamiano Galassi <damiog@gmail.com>
Fri, 15 Jan 2016 18:45:08 +0000 (19:45 +0100)
macosx/HBPreviewGenerator.m

index 06f4423170b1638f6f2a51fd160f561a8066855c..bf27b10e7f87c50e62909226e6708abfdf031f3f 100644 (file)
@@ -21,6 +21,8 @@
 
 @property (nonatomic, strong) HBCore *core;
 
+@property (nonatomic) BOOL reloadInQueue;
+
 @end
 
 @implementation HBPreviewGenerator
@@ -53,6 +55,7 @@
 - (void)dealloc
 {
     [[NSNotificationCenter defaultCenter] removeObserver:self];
+    [[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];
     [self.core cancelEncode];
 }
 
 {
     // Purge the existing picture previews so they get recreated the next time
     // they are needed.
-
     [self purgeImageCache];
+
+    // Enquee the reload call on the main runloop
+    // to avoid reloading the same image multiple times.
+    if (self.reloadInQueue == NO)
+    {
+        [[NSRunLoop mainRunLoop] performSelector:@selector(postReloadNotification) target:self argument:nil order:0 modes:@[NSDefaultRunLoopMode]];
+        self.reloadInQueue = YES;
+    }
+}
+
+- (void)postReloadNotification
+{
     [self.delegate reloadPreviews];
+    self.reloadInQueue = NO;
 }
 
 - (NSString *)info