Revision: 7733
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7733&view=rev
Author:   hofman
Date:     2012-10-19 10:08:07 +0000 (Fri, 19 Oct 2012)
Log Message:
-----------
replace deprecated API for 
NSSavePanel/NSOpenPanel/NSPropertyListSerialization/NSData

Modified Paths:
--------------
    trunk/NSString_SKExtensions.m
    trunk/SKBookmarkController.m
    trunk/SKDownloadPreferenceController.m
    trunk/SKMainDocument.m

Modified: trunk/NSString_SKExtensions.m
===================================================================
--- trunk/NSString_SKExtensions.m       2012-10-16 21:10:40 UTC (rev 7732)
+++ trunk/NSString_SKExtensions.m       2012-10-19 10:08:07 UTC (rev 7733)
@@ -480,7 +480,7 @@
 }
 
 - (NSString *)xmlString {
-    NSData *data = [NSPropertyListSerialization dataFromPropertyList:self 
format:NSPropertyListXMLFormat_v1_0 errorDescription:NULL];
+    NSData *data = [NSPropertyListSerialization dataWithPropertyList:self 
format:NSPropertyListXMLFormat_v1_0 options:0 error:NULL];
     NSMutableString *string = [[[NSMutableString alloc] initWithData:data 
encoding:NSUTF8StringEncoding] autorelease];
     NSInteger loc = NSMaxRange([string rangeOfString:@"<string>"]);
     if (loc == NSNotFound)

Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m        2012-10-16 21:10:40 UTC (rev 7732)
+++ trunk/SKBookmarkController.m        2012-10-19 10:08:07 UTC (rev 7733)
@@ -126,16 +126,15 @@
             NSMutableArray *bookmarks = [NSMutableArray array];
             NSData *data = [NSData dataWithContentsOfFile:[self 
bookmarksFilePath]];
             if (data) {
-                NSString *error = nil;
+                NSError *error = nil;
                 NSPropertyListFormat format = NSPropertyListBinaryFormat_v1_0;
-                id plist = [NSPropertyListSerialization 
propertyListFromData:data
-                                                            
mutabilityOption:NSPropertyListMutableContainers
+                id plist = [NSPropertyListSerialization 
propertyListWithData:data
+                                                                     
options:NSPropertyListMutableContainers
                                                                       
format:&format 
-                                                            
errorDescription:&error];
+                                                                       
error:&error];
                 
                 if (error) {
                     NSLog(@"Error deserializing: %@", error);
-                    [error release];
                 } else if ([plist isKindOfClass:[NSDictionary class]]) {
                     [recentDocuments addObjectsFromArray:[plist 
objectForKey:RECENTDOCUMENTS_KEY]];
                     for (NSDictionary *dict in [plist 
objectForKey:BOOKMARKS_KEY]) {
@@ -541,13 +540,12 @@
 - (void)handleApplicationWillTerminateNotification:(NSNotification 
*)notification  {
     [recentDocuments makeObjectsPerformSelector:@selector(removeObjectForKey:) 
withObject:ALIAS_KEY];
     NSDictionary *bookmarksDictionary = [NSDictionary 
dictionaryWithObjectsAndKeys:[[bookmarkRoot children] 
valueForKey:@"properties"], BOOKMARKS_KEY, recentDocuments, 
RECENTDOCUMENTS_KEY, nil];
-    NSString *error = nil;
+    NSError *error = nil;
     NSPropertyListFormat format = NSPropertyListBinaryFormat_v1_0;
-    NSData *data = [NSPropertyListSerialization 
dataFromPropertyList:bookmarksDictionary format:format errorDescription:&error];
+    NSData *data = [NSPropertyListSerialization 
dataWithPropertyList:bookmarksDictionary format:format options:0 error:&error];
     
        if (error) {
                NSLog(@"Error serializing: %@", error);
-        [error release];
        } else {
         [data writeToFile:[self bookmarksFilePath] atomically:YES];
     }

Modified: trunk/SKDownloadPreferenceController.m
===================================================================
--- trunk/SKDownloadPreferenceController.m      2012-10-16 21:10:40 UTC (rev 
7732)
+++ trunk/SKDownloadPreferenceController.m      2012-10-19 10:08:07 UTC (rev 
7733)
@@ -82,30 +82,25 @@
     [self updateDownloadsFolderPopUp];
 }
 
-- (void)openPanelDidEnd:(NSOpenPanel *)openPanel 
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
-    if (returnCode == NSFileHandlingPanelOKButton) {
-        [[NSUserDefaults standardUserDefaults] setObject:[[[openPanel URL] 
path] stringByAbbreviatingWithTildeInPath] forKey:SKDownloadsDirectoryKey];
-        [self updateDownloadsFolderPopUp];
-    }
-}
-
 - (IBAction)chooseDownloadsFolder:(id)sender {
     if ([sender selectedItem] == [sender lastItem]) {
         [sender selectItemAtIndex:0];
         
         NSString *downloadsFolder = [[[NSUserDefaults standardUserDefaults] 
stringForKey:SKDownloadsDirectoryKey] stringByExpandingTildeInPath];
+        NSURL *downloadsFolderURL = [NSURL fileURLWithPath:downloadsFolder];
         
         NSOpenPanel *openPanel = [NSOpenPanel openPanel];
         [openPanel setCanChooseDirectories:YES];
         [openPanel setCanChooseFiles:NO];
         [openPanel setPrompt:NSLocalizedString(@"Select", @"Button title")];
-        [openPanel beginSheetForDirectory:[downloadsFolder 
stringByDeletingLastPathComponent]
-                                     file:[downloadsFolder lastPathComponent]
-                                    types:nil
-                           modalForWindow:[self window]
-                            modalDelegate:self
-                           
didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
-                              contextInfo:NULL];               
+        [openPanel setDirectoryURL:[downloadsFolderURL 
URLByDeletingLastPathComponent]];
+        [openPanel setNameFieldStringValue:[downloadsFolderURL 
lastPathComponent]];
+        [openPanel beginSheetModalForWindow:[self window] 
completionHandler:^(NSInteger result){
+                if (result == NSFileHandlingPanelOKButton) {
+                    [[NSUserDefaults standardUserDefaults] 
setObject:[[[openPanel URL] path] stringByAbbreviatingWithTildeInPath] 
forKey:SKDownloadsDirectoryKey];
+                    [self updateDownloadsFolderPopUp];
+                }
+            }];
     }
 }
 

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2012-10-16 21:10:40 UTC (rev 7732)
+++ trunk/SKMainDocument.m      2012-10-19 10:08:07 UTC (rev 7733)
@@ -579,7 +579,7 @@
     [fileWrapper addRegularFileWithContents:pdfData preferredFilename:[name 
stringByAppendingPathExtension:@"pdf"]];
     if ((data = [[[self pdfDocument] string] 
dataUsingEncoding:NSUTF8StringEncoding]))
         [fileWrapper addRegularFileWithContents:data 
preferredFilename:[BUNDLE_DATA_FILENAME stringByAppendingPathExtension:@"txt"]];
-    if ((data = [NSPropertyListSerialization dataFromPropertyList:info 
format:NSPropertyListXMLFormat_v1_0 errorDescription:NULL]))
+    if ((data = [NSPropertyListSerialization dataWithPropertyList:info 
format:NSPropertyListXMLFormat_v1_0 options:0 error:NULL]))
         [fileWrapper addRegularFileWithContents:data 
preferredFilename:[BUNDLE_DATA_FILENAME 
stringByAppendingPathExtension:@"plist"]];
     if ([[self notes] count] > 0) {
         if ((data = [self notesData]))
@@ -763,7 +763,7 @@
         NSString *pdfFile = [[NSFileManager defaultManager] 
bundledFileWithExtension:@"pdf" inPDFBundleAtPath:path error:&error];
         if (pdfFile) {
             NSURL *pdfURL = [NSURL fileURLWithPath:pdfFile];
-            if ((data = [[NSData alloc] initWithContentsOfURL:pdfURL 
options:NSUncachedRead error:&error]) &&
+            if ((data = [[NSData alloc] initWithContentsOfURL:pdfURL 
options:NSDataReadingUncached error:&error]) &&
                 (pdfDoc = [[SKPDFDocument alloc] initWithURL:pdfURL])) {
                 NSArray *array = [[NSFileManager defaultManager] 
readSkimNotesFromPDFBundleAtURL:absoluteURL error:&error];
                 if (array == nil) {
@@ -783,7 +783,7 @@
             }
         }
     } else  {
-        if ((fileData = [[NSData alloc] initWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error])) {
+        if ((fileData = [[NSData alloc] initWithContentsOfURL:absoluteURL 
options:NSDataReadingUncached error:&error])) {
             if ([docType isEqualToString:SKPDFDocumentType]) {
                 data = [fileData retain];
                 pdfDoc = [[SKPDFDocument alloc] initWithURL:absoluteURL];
@@ -857,11 +857,8 @@
             if ([docType isEqualToString:SKPDFBundleDocumentType]) {
                 NSData *infoData = [NSData 
dataWithContentsOfFile:[[[absoluteURL path] 
stringByAppendingPathComponent:BUNDLE_DATA_FILENAME] 
stringByAppendingPathExtension:@"plist"]];
                 if (infoData) {
-                    NSString *errorString = nil;
-                    NSDictionary *info = [NSPropertyListSerialization 
propertyListFromData:infoData mutabilityOption:NSPropertyListImmutable 
format:NULL errorDescription:&errorString];
-                    if (info == nil) {
-                        [errorString release];
-                    } else if ([info isKindOfClass:[NSDictionary class]]) {
+                    NSDictionary *info = [NSPropertyListSerialization 
propertyListWithData:infoData options:NSPropertyListImmutable format:NULL 
error:NULL];
+                    if ([info isKindOfClass:[NSDictionary class]]) {
                         dictionary = [info 
objectForKey:SKPresentationOptionsKey];
                         array = [info objectForKey:SKTagsKey];
                         number = [info objectForKey:SKRatingKey];
@@ -949,7 +946,7 @@
 
 #pragma mark Actions
 
-- (void)readNotesFromURL:(NSURL *)notesURL replace:(BOOL)replace {
+- (void)readNotesFromURL:(NSURL *)notesURL replace:(BOOL)replace 
{log_method();return;
     NSString *extension = [[notesURL path] pathExtension];
     NSArray *array = nil;
     
@@ -968,17 +965,9 @@
         NSBeep();
 }
 
-- (void)readNotesPanelDidEnd:(NSOpenPanel *)oPanel 
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
-    if (returnCode == NSFileHandlingPanelOKButton) {
-        NSURL *notesURL = [[oPanel URLs] objectAtIndex:0];
-        BOOL replace = ([[oPanel accessoryView] 
isEqual:readNotesAccessoryView] && [replaceNotesCheckButton state] == 
NSOnState);
-        [self readNotesFromURL:notesURL replace:replace];
-    }
-}
-
 - (IBAction)readNotes:(id)sender{
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
-    NSString *path = [[self fileURL] path];
+    NSURL *fileURL = [self fileURL];
     
     if ([[[self mainWindowController] notes] count]) {
         if (readNotesAccessoryView == nil) {
@@ -994,13 +983,16 @@
         [replaceNotesCheckButton setState:NSOnState];
     }
     
-    [oPanel beginSheetForDirectory:[path stringByDeletingLastPathComponent]
-                              file:[path 
lastPathComponentReplacingPathExtension:@"skim"]
-                             types:[NSArray arrayWithObjects:@"skim", nil]
-                    modalForWindow:[self windowForSheet]
-                     modalDelegate:self
-                    
didEndSelector:@selector(readNotesPanelDidEnd:returnCode:contextInfo:)
-                       contextInfo:NULL];              
+    [oPanel setDirectoryURL:[fileURL URLByDeletingLastPathComponent]];
+    [oPanel setNameFieldStringValue:[fileURL lastPathComponent]];
+    [oPanel setAllowedFileTypes:[NSArray arrayWithObjects:@"skim", nil]];
+    [oPanel beginSheetModalForWindow:[self windowForSheet] 
completionHandler:^(NSInteger result){
+            if (result == NSFileHandlingPanelOKButton) {
+                NSURL *notesURL = [[oPanel URLs] objectAtIndex:0];
+                BOOL replace = ([[oPanel accessoryView] 
isEqual:readNotesAccessoryView] && [replaceNotesCheckButton state] == 
NSOnState);
+                [self readNotesFromURL:notesURL replace:replace];
+            }
+        }];
 }
 
 - (void)convertNotesUsingPDFDocument:(PDFDocument *)pdfDocWithoutNotes {
@@ -1139,23 +1131,17 @@
                     currentDirectoryPath:[[[self fileURL] path] 
stringByDeletingLastPathComponent]];
 }
 
-- (void)archiveSavePanelDidEnd:(NSSavePanel *)sheet 
returnCode:(NSInteger)returnCode  contextInfo:(void  *)contextInfo {
-    if (NSFileHandlingPanelOKButton == returnCode && [self fileURL])
-        [self saveArchiveToFile:[sheet filename]];
-}
-
 - (IBAction)saveArchive:(id)sender {
     NSString *path = [[self fileURL] path];
     if (path && [[NSFileManager defaultManager] fileExistsAtPath:path] && 
[self isDocumentEdited] == NO) {
         NSSavePanel *sp = [NSSavePanel savePanel];
         [sp setRequiredFileType:@"tgz"];
         [sp setCanCreateDirectories:YES];
-        [sp beginSheetForDirectory:nil
-                              file:[path 
lastPathComponentReplacingPathExtension:@"tgz"]
-                    modalForWindow:[self windowForSheet]
-                     modalDelegate:self
-                    
didEndSelector:@selector(archiveSavePanelDidEnd:returnCode:contextInfo:)
-                       contextInfo:NULL];
+        [sp setNameFieldStringValue:[path 
lastPathComponentReplacingPathExtension:@"tgz"]];
+        [sp beginSheetModalForWindow:[self windowForSheet] 
completionHandler:^(NSInteger result){
+                if (NSFileHandlingPanelOKButton == result && [self fileURL])
+                    [self saveArchiveToFile:[[sp URL] path]];
+            }];
     } else {
         NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"You 
must save this file first", @"Alert text when trying to create archive for 
unsaved document") defaultButton:nil alternateButton:nil otherButton:nil 
informativeTextWithFormat:NSLocalizedString(@"The document has unsaved changes, 
or has not previously been saved to disk.", @"Informative text in alert 
dialog")];
         [alert beginSheetModalForWindow:[self windowForSheet] 
modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
@@ -1273,23 +1259,17 @@
     [NSThread detachNewThreadSelector:@selector(saveDiskImageWithInfo:) 
toTarget:self withObject:info];
 }
 
-- (void)diskImageSavePanelDidEnd:(NSSavePanel *)sheet 
returnCode:(NSInteger)returnCode  contextInfo:(void  *)contextInfo {
-    if (NSFileHandlingPanelOKButton == returnCode && [self fileURL])
-        [self saveDiskImageToFile:[sheet filename] email:NO];
-}
-
 - (IBAction)saveDiskImage:(id)sender {
     NSString *path = [[self fileURL] path];
     if (path && [[NSFileManager defaultManager] fileExistsAtPath:path] && 
[self isDocumentEdited] == NO) {
         NSSavePanel *sp = [NSSavePanel savePanel];
         [sp setRequiredFileType:@"dmg"];
         [sp setCanCreateDirectories:YES];
-        [sp beginSheetForDirectory:nil
-                              file:[path 
lastPathComponentReplacingPathExtension:@"dmg"]
-                    modalForWindow:[self windowForSheet]
-                     modalDelegate:self
-                    
didEndSelector:@selector(diskImageSavePanelDidEnd:returnCode:contextInfo:)
-                       contextInfo:NULL];
+        [sp setNameFieldStringValue:[path 
lastPathComponentReplacingPathExtension:@"dmg"]];
+        [sp beginSheetModalForWindow:[self windowForSheet] 
completionHandler:^(NSInteger result){
+                if (NSFileHandlingPanelOKButton == result && [self fileURL])
+                    [self saveDiskImageToFile:[[sp URL] path] email:NO];
+            }];
     } else {
         NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"You 
must save this file first", @"Alert text when trying to create archive for 
unsaved document") defaultButton:nil alternateButton:nil otherButton:nil 
informativeTextWithFormat:NSLocalizedString(@"The document has unsaved changes, 
or has not previously been saved to disk.", @"Informative text in alert 
dialog")];
         [alert beginSheetModalForWindow:[self windowForSheet] 
modalDelegate:nil didEndSelector:NULL contextInfo:NULL];

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


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to