Revision: 22489
          http://sourceforge.net/p/bibdesk/svn/22489
Author:   hofman
Date:     2018-08-09 09:31:43 +0000 (Thu, 09 Aug 2018)
Log Message:
-----------
convenience method to perform a selector delayed only once, canceling earlier 
calls

Modified Paths:
--------------
    trunk/bibdesk/BDSKPersonController.m
    trunk/bibdesk/BDSKSharingServer.m
    trunk/bibdesk/BDSKTableView.m
    trunk/bibdesk/BibDocument_UI.m
    trunk/bibdesk/NSObject_BDSKExtensions.h
    trunk/bibdesk/NSObject_BDSKExtensions.m

Modified: trunk/bibdesk/BDSKPersonController.m
===================================================================
--- trunk/bibdesk/BDSKPersonController.m        2018-08-09 06:30:44 UTC (rev 
22488)
+++ trunk/bibdesk/BDSKPersonController.m        2018-08-09 09:31:43 UTC (rev 
22489)
@@ -50,6 +50,7 @@
 #import "BDSKTableView.h"
 #import <AddressBook/AddressBook.h>
 #import "BDSKGroupsArray.h"
+#import "NSObject_BDSKExtensions.h"
 
 @implementation BDSKPersonController
 
@@ -343,8 +344,7 @@
 - (void)handleBibItemChanged:(NSNotification *)note{
     NSString *key = [[note userInfo] valueForKey:BDSKBibItemKeyKey];
     if (([key isPersonField] || key == nil) && owner) {
-        [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(setPublicationItems:) object:nil];
-        [self performSelector:@selector(setPublicationItems:) withObject:nil 
afterDelay:0.0];
+        [self performSelectorOnce:@selector(setPublicationItems:) 
withObject:nil afterDelay:0.0];
     }
 }
 
@@ -351,8 +351,7 @@
 - (void)handleBibItemAddDel:(NSNotification *)note{
     // we may be adding or removing items, so we can't check publications for 
containment
     if (owner) {
-        [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(setPublicationItems:) object:nil];
-        [self performSelector:@selector(setPublicationItems:) withObject:nil 
afterDelay:0.0];
+        [self performSelectorOnce:@selector(setPublicationItems:) 
withObject:nil afterDelay:0.0];
     }
 }
 

Modified: trunk/bibdesk/BDSKSharingServer.m
===================================================================
--- trunk/bibdesk/BDSKSharingServer.m   2018-08-09 06:30:44 UTC (rev 22488)
+++ trunk/bibdesk/BDSKSharingServer.m   2018-08-09 09:31:43 UTC (rev 22489)
@@ -50,6 +50,7 @@
 #import "BDSKReadWriteLock.h"
 #import "BDSKPublicationsArray.h"
 #import "BDSKMacroResolver.h"
+#import "NSObject_BDSKExtensions.h"
 
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -240,8 +241,7 @@
 - (void)queueDataChangedNotification:(NSNotification *)note;
 {
     SEL theSEL = @selector(handleQueuedDataChanged);
-    [[self class] cancelPreviousPerformRequestsWithTarget:self selector:theSEL 
object:nil];
-    [self performSelector:theSEL withObject:nil afterDelay:5.0];
+    [self performSelectorOnce:theSEL withObject:nil afterDelay:5.0];
 }
 
 //  handle changes from the OS

Modified: trunk/bibdesk/BDSKTableView.m
===================================================================
--- trunk/bibdesk/BDSKTableView.m       2018-08-09 06:30:44 UTC (rev 22488)
+++ trunk/bibdesk/BDSKTableView.m       2018-08-09 09:31:43 UTC (rev 22489)
@@ -39,6 +39,7 @@
 #import "BDSKTableView.h"
 #import "NSFont_BDSKExtensions.h"
 #import "NSEvent_BDSKExtensions.h"
+#import "NSObject_BDSKExtensions.h"
 
 
 static char BDSKTableViewFontDefaultsObservationContext;
@@ -81,8 +82,7 @@
     [super reloadData];
     if (typeSelectHelper) {
         if ([[self class] shouldQueueTypeSelectHelper]) {
-            [[typeSelectHelper class] 
cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(rebuildTypeSelectSearchCache) object:nil];
-            [typeSelectHelper 
performSelector:@selector(rebuildTypeSelectSearchCache) withObject:nil 
afterDelay:0.0];
+            [typeSelectHelper 
performSelectorOnce:@selector(rebuildTypeSelectSearchCache) withObject:nil 
afterDelay:0.0];
         } else {
             [typeSelectHelper rebuildTypeSelectSearchCache];
         }

Modified: trunk/bibdesk/BibDocument_UI.m
===================================================================
--- trunk/bibdesk/BibDocument_UI.m      2018-08-09 06:30:44 UTC (rev 22488)
+++ trunk/bibdesk/BibDocument_UI.m      2018-08-09 09:31:43 UTC (rev 22489)
@@ -78,6 +78,7 @@
 #import "NSColor_BDSKExtensions.h"
 #import "NSGeometry_BDSKExtensions.h"
 #import "BDSKRatingButton.h"
+#import "NSObject_BDSKExtensions.h"
 
 #define BDSKDisableMigrationWarningKey @"BDSKDisableMigrationWarning"
 
@@ -130,8 +131,7 @@
     // changed key, so we have to update all the previews each time.  This 
should be safer than using cancelPrevious... since those
     // don't get performed on the main thread (apparently), and can lead to 
problems.
     if (docFlags.isDocumentClosed == NO && [documentWindow isVisible]) {
-        [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(doUpdatePreviews) object:nil];
-        [self performSelector:@selector(doUpdatePreviews) withObject:nil 
afterDelay:0.0];
+        [self performSelectorOnce:@selector(doUpdatePreviews) withObject:nil 
afterDelay:0.0];
     }
 }
 
@@ -1148,8 +1148,7 @@
     
     // queue for UI updating, in case the item is changed as part of a batch 
process such as Find & Replace or AutoFile
     if (docFlags.isDocumentClosed == NO) {
-        [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(handlePrivateBibItemChanged) object:nil];
-        [self performSelector:@selector(handlePrivateBibItemChanged) 
withObject:nil afterDelay:0.0];
+        [self performSelectorOnce:@selector(handlePrivateBibItemChanged) 
withObject:nil afterDelay:0.0];
     }
 }
 

Modified: trunk/bibdesk/NSObject_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/NSObject_BDSKExtensions.h     2018-08-09 06:30:44 UTC (rev 
22488)
+++ trunk/bibdesk/NSObject_BDSKExtensions.h     2018-08-09 09:31:43 UTC (rev 
22489)
@@ -43,4 +43,6 @@
 
 - (NSScriptClassDescription *)scriptClassDescription;
 
+- (void)performSelectorOnce:(SEL)aSelector withObject:(id)anArgument 
afterDelay:(NSTimeInterval)delay;
+
 @end

Modified: trunk/bibdesk/NSObject_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSObject_BDSKExtensions.m     2018-08-09 06:30:44 UTC (rev 
22488)
+++ trunk/bibdesk/NSObject_BDSKExtensions.m     2018-08-09 09:31:43 UTC (rev 
22489)
@@ -46,4 +46,9 @@
     return [NSScriptClassDescription classDescriptionForClass:[self class]];
 }
 
+- (void)performSelectorOnce:(SEL)aSelector withObject:(id)anArgument 
afterDelay:(NSTimeInterval)delay {
+    [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:aSelector object:anArgument];
+    [self performSelector:aSelector withObject:anArgument afterDelay:delay];
+}
+
 @end

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to