Revision: 22665
          http://sourceforge.net/p/bibdesk/svn/22665
Author:   hofman
Date:     2018-09-25 09:14:20 +0000 (Tue, 25 Sep 2018)
Log Message:
-----------
evaluate specifiers and flatten array in one go, no need to use KVC

Modified Paths:
--------------
    trunk/bibdesk/BDSKAddCommand.m
    trunk/bibdesk/BDSKRemoveCommand.m

Modified: trunk/bibdesk/BDSKAddCommand.m
===================================================================
--- trunk/bibdesk/BDSKAddCommand.m      2018-09-25 06:30:35 UTC (rev 22664)
+++ trunk/bibdesk/BDSKAddCommand.m      2018-09-25 09:14:20 UTC (rev 22665)
@@ -53,12 +53,23 @@
     NSArray *insertionObjects = [directParameter objCObjectValue];
     
     // evaluate object specifiers
-    if ([insertionObjects 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)] ||
-        ([insertionObjects isKindOfClass:[NSArray class]] &&
-         NSNotFound == [insertionObjects indexOfObjectPassingTest:^BOOL(id 
obj, NSUInteger idx, BOOL *stop){ return NO == [obj 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)]; }])) {
-        insertionObjects = [insertionObjects 
valueForKey:@"objectsByEvaluatingSpecifier"];
-        if ([insertionObjects isKindOfClass:[NSArray class]] && 
[insertionObjects containsObject:[NSNull null]])
-            insertionObjects = nil;
+    if ([insertionObjects 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)]) {
+        insertionObjects = [(NSScriptObjectSpecifier *)insertionObjects 
objectsByEvaluatingSpecifier];
+    } else if ([insertionObjects isKindOfClass:[NSArray class]] && NSNotFound 
!= [insertionObjects indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, 
BOOL *stop){ return [obj 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)]; }]) {
+        NSMutableArray *tmpArray = [NSMutableArray array];
+        for (id obj in insertionObjects) {
+            if ([obj 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)])
+                obj = [obj objectsByEvaluatingSpecifier];
+            if ([obj isKindOfClass:[NSArray class]]) {
+                [tmpArray addObjectsFromArray:obj];
+            } else if (obj) {
+                [tmpArray addObject:obj];
+            } else {
+                tmpArray = nil;
+                break;
+            }
+        }
+        insertionObjects = tmpArray;
     }
     
     if (insertionObjects == nil) {
@@ -66,13 +77,9 @@
         [self setScriptErrorString:NSLocalizedString(@"Invalid or missing 
objects to add", @"Error description")];
     } else {
         
-        BOOL isArray = [insertionObjects isKindOfClass:[NSArray class]];
-        
         // make sure we have an (unnested) array
-        if (isArray == NO)
+        if ([insertionObjects isKindOfClass:[NSArray class]] == NO)
             insertionObjects = [NSArray arrayWithObjects:insertionObjects, 
nil];
-        else if (NSNotFound == [insertionObjects 
indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop){ return NO 
== [obj isKindOfClass:[NSArray class]]; }])
-            insertionObjects = [insertionObjects 
valueForKeyPath:@"@unionOfArrays.self"];
         
         if ([insertionObjects count]) {
             

Modified: trunk/bibdesk/BDSKRemoveCommand.m
===================================================================
--- trunk/bibdesk/BDSKRemoveCommand.m   2018-09-25 06:30:35 UTC (rev 22664)
+++ trunk/bibdesk/BDSKRemoveCommand.m   2018-09-25 09:14:20 UTC (rev 22665)
@@ -52,14 +52,25 @@
     NSArray *removeObjects = [directParameter objCObjectValue];
     
     // evaluate object specifiers
-    if ([removeObjects 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)] ||
-        ([removeObjects isKindOfClass:[NSArray class]] &&
-         NSNotFound == [removeObjects indexOfObjectPassingTest:^BOOL(id obj, 
NSUInteger idx, BOOL *stop){ return NO == [obj 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)]; }])) {
-            removeObjects = [removeObjects 
valueForKey:@"objectsByEvaluatingSpecifier"];
-        if ([removeObjects isKindOfClass:[NSArray class]] && [removeObjects 
containsObject:[NSNull null]])
-            removeObjects = nil;
+    if ([removeObjects 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)]) {
+        removeObjects = [(NSScriptObjectSpecifier *)removeObjects 
objectsByEvaluatingSpecifier];
+    } else if ([removeObjects isKindOfClass:[NSArray class]] && NSNotFound != 
[removeObjects indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL 
*stop){ return [obj 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)]; }]) {
+        NSMutableArray *tmpArray = [NSMutableArray array];
+        for (id obj in removeObjects) {
+            if ([obj 
respondsToSelector:@selector(objectsByEvaluatingSpecifier)])
+                obj = [obj objectsByEvaluatingSpecifier];
+            if ([obj isKindOfClass:[NSArray class]]) {
+                [tmpArray addObjectsFromArray:obj];
+            } else if (obj) {
+                [tmpArray addObject:obj];
+            } else {
+                tmpArray = nil;
+                break;
+            }
+        }
+        removeObjects = tmpArray;
     }
-    
+
     if (removeObjects == nil) {
         [self setScriptErrorNumber:NSArgumentsWrongScriptError];
         [self setScriptErrorString:NSLocalizedString(@"Invalid or missing 
objects to remove", @"Error description")];
@@ -68,8 +79,6 @@
         // make sure we have an (unnested) array
         if ([removeObjects isKindOfClass:[NSArray class]] == NO)
             removeObjects = [NSArray arrayWithObjects:removeObjects, nil];
-        else if (NSNotFound == [removeObjects 
indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop){ return NO 
== [obj isKindOfClass:[NSArray class]]; }])
-            removeObjects = [removeObjects 
valueForKeyPath:@"@unionOfArrays.self"];
         
         if ([removeObjects count]) {
             

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



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to