Revision: 28892
          http://sourceforge.net/p/bibdesk/svn/28892
Author:   hofman
Date:     2024-05-07 14:11:04 +0000 (Tue, 07 May 2024)
Log Message:
-----------
fix getting item template from one-page template

Modified Paths:
--------------
    trunk/bibdesk/BDSKTemplate.m

Modified: trunk/bibdesk/BDSKTemplate.m
===================================================================
--- trunk/bibdesk/BDSKTemplate.m        2024-05-07 09:25:52 UTC (rev 28891)
+++ trunk/bibdesk/BDSKTemplate.m        2024-05-07 14:11:04 UTC (rev 28892)
@@ -61,7 +61,7 @@
 static NSString *BDSKExportTemplateTree = @"BDSKExportTemplateTree";
 static NSString *BDSKServiceTemplateTree = @"BDSKServiceTemplateTree";
 
-static inline NSString *itemTemplateSubstring(NSString *templateString){
+static inline NSRange itemTemplateRange(NSString *templateString){
     NSInteger start, end, length = [templateString length];
     NSUInteger nonwsLoc;
     NSRange range = [templateString rangeOfString:@"<$publications>"];
@@ -73,7 +73,7 @@
             if ([[NSCharacterSet newlineCharacterSet] 
characterIsMember:firstChar]) {
                 if (firstChar == NSCarriageReturnCharacter && 
(NSInteger)nonwsLoc + 1 < length && [templateString characterAtIndex:nonwsLoc + 
1] == NSNewlineCharacter)
                     start = nonwsLoc + 2;
-                else 
+                else
                     start = nonwsLoc + 1;
             }
         }
@@ -89,12 +89,26 @@
                     end = nonwsLoc + 1;
             }
         } else
-            return nil;
+            return NSMakeRange(NSNotFound, 0);
     } else
+        return NSMakeRange(NSNotFound, 0);
+    return NSMakeRange(start, end - start);
+}
+
+static inline NSString *itemTemplateSubstring(NSString *templateString){
+    NSRange range = itemTemplateRange(templateString);
+    if (range.location == NSNotFound)
         return nil;
-    return [templateString substringWithRange:NSMakeRange(start, end - start)];
+    return [templateString substringWithRange:range];
 }
 
+static inline NSAttributedString 
*itemTemplateAttributedSubstring(NSAttributedString *templateAttributedString){
+    NSRange range = itemTemplateRange([templateAttributedString string]);
+    if (range.location == NSNotFound)
+        return nil;
+    return [templateAttributedString attributedSubstringFromRange:range];
+}
+
 @implementation BDSKTemplate
 
 @dynamic templateFormat, templateFormatNoUI, fileExtension, documentType, 
mainPageString, scriptPath, mainPageTemplateURL, hasMainPageTemplateURL, 
defaultItemTemplateURL, accessoryFileURLs, scriptURL, representedFileURL, 
representedFileURLNoUI;
@@ -512,8 +526,6 @@
         theURL = [self defaultItemTemplateURL];
     if(nil != theURL)
         return [NSString stringWithContentsOfURL:theURL 
encoding:NSUTF8StringEncoding error:NULL];
-    if([type isEqualToString:BDSKTemplateMainPageString] == NO)
-        return nil;
     // get the item template from the main page template
     return itemTemplateSubstring([self mainPageString]);
 }
@@ -527,7 +539,10 @@
     // return default template string if no type or no type-specific template
     if(nil == theURL)
         theURL = [self defaultItemTemplateURL];
-    return [[NSAttributedString alloc] initWithURL:theURL options:@{} 
documentAttributes:NULL error:NULL];
+    if(nil != theURL)
+        return [[NSAttributedString alloc] initWithURL:theURL options:@{} 
documentAttributes:NULL error:NULL];
+    // get the item template from the main page template
+    return itemTemplateAttributedSubstring([self 
mainPageAttributedStringWithDocumentAttributes:NULL]);
 }
 
 - (NSString *)scriptPath;

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