Revision: 26652
          http://sourceforge.net/p/bibdesk/svn/26652
Author:   hofman
Date:     2021-08-15 15:23:51 +0000 (Sun, 15 Aug 2021)
Log Message:
-----------
No separate method for string matching for completion

Modified Paths:
--------------
    trunk/bibdesk/BDSKCompletionServer.m
    trunk/bibdesk/BDSKSearchForCommand.m
    trunk/bibdesk/BibDocument_Search.h
    trunk/bibdesk/BibDocument_Search.m

Modified: trunk/bibdesk/BDSKCompletionServer.m
===================================================================
--- trunk/bibdesk/BDSKCompletionServer.m        2021-08-15 15:03:47 UTC (rev 
26651)
+++ trunk/bibdesk/BDSKCompletionServer.m        2021-08-15 15:23:51 UTC (rev 
26652)
@@ -39,8 +39,8 @@
 #import "BDSKCompletionServer.h"
 #import "BDSKCompletionServerProtocol.h"
 #import "BibDocument.h"
-#import "BibDocument_Search.h"
 #import "BDSKPublicationsArray.h"
+#import "BibItem.h"
 
 #define BIBDESK_SERVER_NAME @"BDSKCompletionServer"
 
@@ -88,11 +88,15 @@
        NSMutableArray *results = [NSMutableArray array];
 
     // for empty search string, return all items
-
-    for (BibDocument *document in [NSApp orderedDocuments]) {
-        
-        NSArray *pubs = [NSString isEmptyString:searchString] ? [document 
publications] : [document publicationsMatchingString:searchString];
-        [results addObjectsFromArray:[pubs valueForKey:@"completionObject"]];
+    if ([NSString isEmptyString:searchString]) {
+        [results addObjectsFromArray:[[NSApp orderedDocuments] 
valueForKeyPath:@"publications.@unionOfObjects.completionObject"]];
+    } else {
+        for (BibDocument *document in [NSApp orderedDocuments]) {
+            for (BibItem *pub in [document publications]) {
+                if ([pub matchesString:searchString])
+                    [results addObject:[pub completionObject]];
+            }
+        }
     }
        return results;
 }

Modified: trunk/bibdesk/BDSKSearchForCommand.m
===================================================================
--- trunk/bibdesk/BDSKSearchForCommand.m        2021-08-15 15:03:47 UTC (rev 
26651)
+++ trunk/bibdesk/BDSKSearchForCommand.m        2021-08-15 15:23:51 UTC (rev 
26652)
@@ -40,7 +40,6 @@
 #import "BibAuthor.h"
 #import "BibItem.h"
 #import "BibDocument.h"
-#import "BibDocument_Search.h"
 
 
 @interface BibItem (Finding)
@@ -99,21 +98,17 @@
        id receiver = [self evaluatedReceivers];
     NSScriptObjectSpecifier *dP = [self directParameter];
        id dPO = [dP objectsByEvaluatingSpecifier];
+    NSArray *docs = nil;
 
        if ([receiver isKindOfClass:[NSApplication class]] && dP == nil) {
-               // we are sent to the application and there is no direct 
paramter that might redirect the command
-               for (BibDocument *bd in [NSApp orderedDocuments])
-                       [results addObjectsFromArray:[bd 
publicationsMatchingString:searchterm]];
+        // we are sent to the application and there is no direct paramter that 
might redirect the command
+        docs = [NSApp orderedDocuments];
        } else if ([receiver isKindOfClass:[BibDocument class]] || [dPO 
isKindOfClass:[BibDocument class]]) {
-               // the condition above might not be good enough
-               // we are sent or addressed to a document
-               [results addObjectsFromArray:[(BibDocument*)dPO 
publicationsMatchingString:searchterm]];
+        // the condition above might not be good enough
+        // we are sent or addressed to a document
+        docs = [NSArray arrayWithObject:dPO];
        } else if ([receiver isKindOfClass:[NSArray class]]){
-        for (id anObject in receiver) {
-            if ([anObject isKindOfClass:[BibDocument class]])
-                [results addObjectsFromArray:[anObject 
publicationsMatchingString:searchterm]];
-        }
-        
+        docs = receiver;
     } else {
                // give up
                [self 
setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
@@ -120,8 +115,14 @@
                [self setScriptErrorString:@"The search command can only be 
sent to the application itself or to documents. Usually it is used in the form 
\"search for search_term\"."];
                return [NSArray array];
        }
-
-       
+    
+    for (BibDocument *doc in docs) {
+        for (BibItem *pub in [doc publications]) {
+            if ([pub matchesString:searchterm])
+                [results addObject:pub];
+        }
+    }
+    
        if (forCompletion) {
                // we're doing this for completion, so return a different 
array. Instead of an array of publications (BibItems) this will simply be an 
array of strings containing the cite key, the authors' surnames and the title 
for the publication. This could be sufficient for completion and allows the 
application possibly integrating with BibDesk to remain ignorant of the inner 
workings of BibItems.
                NSInteger i, n = [results count];

Modified: trunk/bibdesk/BibDocument_Search.h
===================================================================
--- trunk/bibdesk/BibDocument_Search.h  2021-08-15 15:03:47 UTC (rev 26651)
+++ trunk/bibdesk/BibDocument_Search.h  2021-08-15 15:23:51 UTC (rev 26652)
@@ -59,8 +59,4 @@
 
 @property (nonatomic, readonly) NSString *selectedStringForFind;
 
-#pragma mark Completion
-
-- (NSArray *)publicationsMatchingString:(NSString *)searchterm;
-
 @end

Modified: trunk/bibdesk/BibDocument_Search.m
===================================================================
--- trunk/bibdesk/BibDocument_Search.m  2021-08-15 15:03:47 UTC (rev 26651)
+++ trunk/bibdesk/BibDocument_Search.m  2021-08-15 15:23:51 UTC (rev 26652)
@@ -536,17 +536,4 @@
     return nil;
 }
 
-#pragma mark Completion
-
-- (NSArray *)publicationsMatchingString:(NSString *)searchterm {
-       NSMutableArray *found = [NSMutableArray array];
-       
-       for (BibItem *pub in publications) {
-               if ([pub matchesString:searchterm])
-                       [found addObject:pub];
-       }
-
-       return found;
-}
-
 @end

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to