Revision: 28909
          http://sourceforge.net/p/bibdesk/svn/28909
Author:   hofman
Date:     2024-05-15 14:43:54 +0000 (Wed, 15 May 2024)
Log Message:
-----------
Copy app support files in +initialize methods for classes that use the 
particular files

Modified Paths:
--------------
    trunk/bibdesk/BDSKAppController.m
    trunk/bibdesk/BDSKBookmarkController.m
    trunk/bibdesk/BDSKTeXTask.m
    trunk/bibdesk/BDSKTemplate.h
    trunk/bibdesk/BDSKTemplate.m
    trunk/bibdesk/BibDocument.m
    trunk/bibdesk/BibPref_TeX.m

Modified: trunk/bibdesk/BDSKAppController.m
===================================================================
--- trunk/bibdesk/BDSKAppController.m   2024-05-15 14:20:41 UTC (rev 28908)
+++ trunk/bibdesk/BDSKAppController.m   2024-05-15 14:43:54 UTC (rev 28909)
@@ -273,11 +273,10 @@
 
 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification{
     NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-    NSFileManager *fm = [NSFileManager defaultManager];
     
     // make sure the temporary base directory is created
     // balanced for cleanup in applicationWillTerminate
-    [fm uniqueTemporaryDirectoryURLWithBasename:nil];
+    [[NSFileManager defaultManager] 
uniqueTemporaryDirectoryURLWithBasename:nil];
     
     // this makes sure that the defaults are registered
     [BDSKPreferenceController sharedPreferenceController];
@@ -314,22 +313,6 @@
     
     // register URL handler
     [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self 
andSelector:@selector(handleGetURLEvent:withReplyEvent:) 
forEventClass:kInternetEventClass andEventID:kAEGetURL];
-    
-    NSURL *defaultPreviewURL = [BDSKTemplate defaultPreviewTemplateURL];
-    BOOL hadPreviewTemplate = [defaultPreviewURL 
checkResourceIsReachableAndReturnError:NULL];
-    
-    // copy files to application support, do this before any document may be 
opened
-    [fm copyFileFromSharedSupportToApplicationSupport:@"Templates" 
overwrite:NO];
-    [fm copyFileFromSharedSupportToApplicationSupport:@"previewtemplate.tex" 
overwrite:NO];
-    [fm copyFileFromSharedSupportToApplicationSupport:@"template.txt" 
overwrite:NO];
-    [fm copyFileFromSharedSupportToApplicationSupport:@"Bookmarks.plist" 
overwrite:NO];
-    
-    if (hadPreviewTemplate == NO && [defaultPreviewURL 
checkResourceIsReachableAndReturnError:NULL])
-        [BDSKTemplate addDefaultPreviewTemplateIfNeeded];
-    
-    NSURL *scriptsURL = [[fm applicationSupportDirectoryURL] 
URLByAppendingPathComponent:@"Scripts" isDirectory:YES];
-    if ([scriptsURL checkResourceIsReachableAndReturnError:NULL] == NO)
-        [fm createDirectoryAtURL:scriptsURL withIntermediateDirectories:NO 
attributes:nil error:NULL];
 }
 
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
@@ -350,6 +333,10 @@
     // register server for cite key completion
     [BDSKCompletionServer sharedCompletionServer];
     
+    NSURL *scriptsURL = [[[NSFileManager defaultManager] 
applicationSupportDirectoryURL] URLByAppendingPathComponent:@"Scripts" 
isDirectory:YES];
+    if ([scriptsURL checkResourceIsReachableAndReturnError:NULL] == NO)
+        [[NSFileManager defaultManager] createDirectoryAtURL:scriptsURL 
withIntermediateDirectories:NO attributes:nil error:NULL];
+    
     NSString *versionString = [[[NSBundle mainBundle] infoDictionary] 
objectForKey:@"CFBundleShortVersionString"];
     if(![versionString isEqualToString:[[NSUserDefaults standardUserDefaults] 
stringForKey:BDSKLastVersionLaunchedKey]])
         [self showRelNotes:nil];

Modified: trunk/bibdesk/BDSKBookmarkController.m
===================================================================
--- trunk/bibdesk/BDSKBookmarkController.m      2024-05-15 14:20:41 UTC (rev 
28908)
+++ trunk/bibdesk/BDSKBookmarkController.m      2024-05-15 14:43:54 UTC (rev 
28909)
@@ -107,6 +107,8 @@
         if (self) {
             undoManager = nil;
             
+            [[NSFileManager defaultManager] 
copyFileFromSharedSupportToApplicationSupport:@"Bookmarks.plist" overwrite:NO];
+            
             NSURL *bookmarksURL = [[[NSFileManager defaultManager] 
applicationSupportDirectoryURL] URLByAppendingPathComponent:@"Bookmarks.plist" 
isDirectory:NO];
             NSArray *bookmarksData = [NSArray 
arrayWithContentsOfURL:bookmarksURL];
             

Modified: trunk/bibdesk/BDSKTeXTask.m
===================================================================
--- trunk/bibdesk/BDSKTeXTask.m 2024-05-15 14:20:41 UTC (rev 28908)
+++ trunk/bibdesk/BDSKTeXTask.m 2024-05-15 14:43:54 UTC (rev 28909)
@@ -101,27 +101,6 @@
 
 @end
 
-// modify the TeX template in application support
-static void upgradeTemplate()
-{
-    NSURL *texTemplateURL = [[[NSFileManager defaultManager] 
applicationSupportDirectoryURL] 
URLByAppendingPathComponent:@"previewtemplate.tex" isDirectory:NO];
-    NSStringEncoding encoding = [[NSUserDefaults standardUserDefaults] 
integerForKey:BDSKTeXPreviewFileEncodingKey];
-    
-    NSMutableString *texFile = [[NSMutableString alloc] 
initWithContentsOfURL:texTemplateURL encoding:encoding error:NULL];
-    
-    // This is a change required for latex2rtf compatibility.  Old versions 
used a peculiar "%latex2rtf:" comment at the beginning of a line to indicate a 
command or section that was needed for latex2rtf.  The latest version (in our 
vendorsrc tree as of 15 Dec 2007) uses a more typical \if\else\fi construct.
-    NSString *oldString = @"%% The following command is provided for LaTeX2RTF 
compatibility\n"
-    @"%% with amslatex.  DO NOT UNCOMMENT THE NEXT LINE!\n"
-    @"%latex2rtf:\\providecommand{\\bysame}{\\_\\_\\_\\_\\_}";
-    NSString *newString = @"% The following command is provided for LaTeX2RTF 
compatibility with amslatex.\n"
-    @"\\newif\\iflatextortf\n"
-    @"\\iflatextortf\n"
-    @"\\providecommand{\\bysame}{\\_\\_\\_\\_\\_}\n"
-    @"\\fi";
-    if ([texFile replaceOccurrencesOfString:oldString withString:newString 
options:0 range:NSMakeRange(0, [texFile length])])
-        [texFile writeToURL:texTemplateURL atomically:YES encoding:encoding 
error:NULL];
-}
-
 static double runLoopTimeout = 30;
 
 @implementation BDSKTeXTask
@@ -136,9 +115,8 @@
     // returns 0 if the key doesn't exist
     if ([[NSUserDefaults standardUserDefaults] 
doubleForKey:BDSKTeXTaskRunLoopTimeoutKey] > 1)
         runLoopTimeout = [[NSUserDefaults standardUserDefaults] 
doubleForKey:BDSKTeXTaskRunLoopTimeoutKey];
-        
-    upgradeTemplate();
     
+    [[NSFileManager defaultManager] 
copyFileFromSharedSupportToApplicationSupport:@"previewTemplate.tex" 
overwrite:NO];
 }
 
 - (instancetype)init{

Modified: trunk/bibdesk/BDSKTemplate.h
===================================================================
--- trunk/bibdesk/BDSKTemplate.h        2024-05-15 14:20:41 UTC (rev 28908)
+++ trunk/bibdesk/BDSKTemplate.h        2024-05-15 14:43:54 UTC (rev 28909)
@@ -84,9 +84,6 @@
 + (NSArray *)allStyleNamesForFormat:(BDSKTemplateFormat)format;
 + (NSString *)defaultStyleNameForFileType:(NSString *)fileType;
 
-@property (class, nonatomic, readonly) NSURL *defaultPreviewTemplateURL;
-+ (void)addDefaultPreviewTemplateIfNeeded;
-
 // export templates
 + (BDSKTemplate *)templateForStyle:(NSString *)styleName;
 

Modified: trunk/bibdesk/BDSKTemplate.m
===================================================================
--- trunk/bibdesk/BDSKTemplate.m        2024-05-15 14:20:41 UTC (rev 28908)
+++ trunk/bibdesk/BDSKTemplate.m        2024-05-15 14:43:54 UTC (rev 28909)
@@ -109,6 +109,10 @@
     return [templateAttributedString attributedSubstringFromRange:range];
 }
 
+@interface BDSKTemplate (BDSKPrivate)
++ (void)addDefaultPreviewTemplateIfNeeded;
+@end
+
 @implementation BDSKTemplate
 
 @dynamic templateFormat, templateFormatNoUI, fileExtension, documentType, 
mainPageString, scriptPath, mainPageTemplateURL, hasMainPageTemplateURL, 
defaultItemTemplateURL, accessoryFileURLs, scriptURL, representedFileURL, 
representedFileURLNoUI;
@@ -116,6 +120,19 @@
 static NSArray *exportTemplateTree = nil;
 static NSArray *serviceTemplateTree = nil;
 
++ (void)initialize {
+    BDSKINITIALIZE;
+    
+    NSFileManager *fm = [NSFileManager defaultManager];
+    NSURL *defaultPreviewURL = [[[fm applicationSupportDirectoryURL] 
URLByAppendingPathComponent:@"Templates" isDirectory:YES] 
URLByAppendingPathComponent:@"rtfPreviewTemplate.rtf" isDirectory:NO];
+    BOOL hadPreviewTemplate = [defaultPreviewURL 
checkResourceIsReachableAndReturnError:NULL];
+    
+    [fm copyFileFromSharedSupportToApplicationSupport:@"Templates" 
overwrite:NO];
+    
+    if (hadPreviewTemplate == NO && [defaultPreviewURL 
checkResourceIsReachableAndReturnError:NULL])
+        [self addDefaultPreviewTemplateIfNeeded];
+}
+
 + (NSString *)localizedAccessoryString {
     static NSString *localizedAccessoryString = nil;
     if (localizedAccessoryString == nil)

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2024-05-15 14:20:41 UTC (rev 28908)
+++ trunk/bibdesk/BibDocument.m 2024-05-15 14:43:54 UTC (rev 28909)
@@ -204,6 +204,12 @@
     return NO;
 }
 
++ (void)initialize {
+    BDSKINITIALIZE;
+    // copy template file to application support, do this before any document 
may be opened
+    [[NSFileManager defaultManager] 
copyFileFromSharedSupportToApplicationSupport:@"template.txt" overwrite:NO];
+}
+
 - (instancetype)init{
     if(self = [super init]){
         

Modified: trunk/bibdesk/BibPref_TeX.m
===================================================================
--- trunk/bibdesk/BibPref_TeX.m 2024-05-15 14:20:41 UTC (rev 28908)
+++ trunk/bibdesk/BibPref_TeX.m 2024-05-15 14:43:54 UTC (rev 28909)
@@ -145,8 +145,8 @@
     NSURL *fileURL = [applicationSupportURL 
URLByAppendingPathComponent:@"previewtemplate.tex" isDirectory:NO];
     
     if([fileURL checkResourceIsReachableAndReturnError:NULL] == NO)
-        [self resetTeXPreviewFile:nil];
-
+        [[NSFileManager defaultManager] 
copyFileFromSharedSupportToApplicationSupport:@"previewtemplate.tex" 
overwrite:NO];
+    
     if([[NSWorkspace sharedWorkspace] openURL:fileURL] == NO && [[NSWorkspace 
sharedWorkspace] openURLs:@[fileURL] 
withAppBundleIdentifier:@"com.apple.textedit" options:0 
additionalEventParamDescriptor:nil launchIdentifiers:NULL] == NO) {
         NSAlert *alert = [[NSAlert alloc] init];
         [alert setMessageText:NSLocalizedString(@"Unable to Open File", 
@"Message in alert dialog when unable to open file")];
@@ -167,16 +167,9 @@
     [alert addButtonWithTitle:NSLocalizedString(@"OK", @"Button title")];
     [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Button title")];
     [alert beginSheetModalForWindow:[[self view] window] 
completionHandler:^(NSInteger returnCode){
-        if (returnCode == NSAlertFirstButtonReturn) {
-            NSFileManager *fileManager = [NSFileManager defaultManager];
-            NSURL *applicationSupportURL = [[NSFileManager defaultManager] 
applicationSupportDirectoryURL];
-            NSURL *previewTemplateURL = [applicationSupportURL 
URLByAppendingPathComponent:@"previewtemplate.tex" isDirectory:NO];
-            if([previewTemplateURL 
checkResourceIsReachableAndReturnError:NULL])
-                [fileManager removeItemAtURL:previewTemplateURL error:NULL];
+        if (returnCode == NSAlertFirstButtonReturn)
             // copy previewtemplate.tex file from the bundle
-            [fileManager copyItemAtURL:[[[NSBundle mainBundle] 
sharedSupportURL] URLByAppendingPathComponent:@"previewtemplate.tex" 
isDirectory:NO]
-                                 toURL:previewTemplateURL error:NULL];
-        }
+            [[NSFileManager defaultManager] 
copyFileFromSharedSupportToApplicationSupport:@"previewtemplate.tex" 
overwrite:YES];
     }];
 }
 

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