Revision: 6946
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6946&view=rev
Author:   hofman
Date:     2010-12-08 11:10:56 +0000 (Wed, 08 Dec 2010)

Log Message:
-----------
reorganize code to create new scripting bookmark

Modified Paths:
--------------
    trunk/SKBookmark.m

Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m  2010-12-07 22:44:56 UTC (rev 6945)
+++ trunk/SKBookmark.m  2010-12-08 11:10:56 UTC (rev 6946)
@@ -565,19 +565,19 @@
 - (id)newScriptingObjectOfClass:(Class)objectClass forValueForKey:(NSString 
*)key withContentsValue:(id)contentsValue properties:(NSDictionary *)properties 
{
     if ([key isEqualToString:@"bookmarks"]) {
         SKBookmark *bookmark = nil;
+        NSURL *aURL = [properties objectForKey:@"scriptingFile"] ?: 
contentsValue;
+        NSString *aPath = [aURL respondsToSelector:@selector(path)] ? [aURL 
path] : nil;
+        NSString *aLabel = [properties objectForKey:@"label"];
         FourCharCode type = [[properties 
objectForKey:@"scriptingBookmarkType"] unsignedIntValue];
         if (type == 0) {
-            if (contentsValue || [properties objectForKey:@"scriptingFile"])
+            if (aURL)
                 type = SKScriptingBookmarkTypeBookmark;
-            else if ([properties objectForKey:@"label"])
-                type = SKScriptingBookmarkTypeFolder;
+            else if (aLabel)
+                type = SKScriptingBookmarkTypeSession;
         }
         switch (type) {
             case SKScriptingBookmarkTypeBookmark:
             {
-                NSURL *aURL = [properties objectForKey:@"scriptingFile"] ?: 
contentsValue;
-                NSString *aPath = [aURL respondsToSelector:@selector(path)] ? 
[aURL path] : nil;
-                NSString *aLabel = [properties objectForKey:@"label"] ?: 
[aPath lastPathComponent] ?: @"";
                 Class docClass;
                 if (aPath == nil) {
                     [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
@@ -591,7 +591,9 @@
                         aPageNumber--;
                     else
                         aPageNumber = [docClass isPDFDocument] ? 0 : 
NSNotFound;
-                    bookmark = [[SKBookmark alloc] initWithPath:aPath 
pageIndex:aPageNumber label:aLabel];
+                    if (aLabel == nil && aPath)
+                        aLabel = [[NSFileManager defaultManager] 
displayNameAtPath:aPath];
+                    bookmark = [[SKBookmark alloc] initWithPath:aPath 
pageIndex:aPageNumber label:aLabel ?: @""];
                 } else {
                     [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
                     [[NSScriptCommand currentCommand] 
setScriptErrorString:@"Unsupported file type for new bookmark."];
@@ -600,24 +602,22 @@
             }
             case SKScriptingBookmarkTypeFolder:
             {
-                NSURL *aURL = [properties objectForKey:@"scriptingFile"] ?: 
contentsValue;
-                NSString *aPath = [aURL respondsToSelector:@selector(path)] ? 
[aURL path] : nil;
-                NSString *aLabel = [properties objectForKey:@"label"] ?: 
[aPath lastPathComponent] ?: @"";
-                bookmark = [[SKBookmark alloc] initFolderWithLabel:aLabel];
+                if (aLabel == nil && aPath)
+                    aLabel = [[NSFileManager defaultManager] 
displayNameAtPath:aPath];
+                bookmark = [[SKBookmark alloc] initFolderWithLabel:aLabel ?: 
@""];
                 if (aPath)
                     [bookmark insertBookmarksForPaths:[[NSFileManager 
defaultManager] contentsOfDirectoryAtPath:aPath error:NULL] 
relativeToPath:aPath atIndex:0];
                 break;
             }
-            case SKScriptingBookmarkTypeSeparator:
-                bookmark = [[SKBookmark alloc] initSeparator];
-                break;
             case SKScriptingBookmarkTypeSession:
             {
                 NSArray *setups = [[NSApp orderedDocuments] 
valueForKey:@"currentDocumentSetup"];
-                NSString *aLabel = [properties objectForKey:@"label"] ?: @"";
-                bookmark = [[SKBookmark alloc] initSessionWithSetups:setups 
label:aLabel];
+                bookmark = [[SKBookmark alloc] initSessionWithSetups:setups 
label:aLabel ?: @""];
                 break;
             }
+            case SKScriptingBookmarkTypeSeparator:
+                bookmark = [[SKBookmark alloc] initSeparator];
+                break;
             default:
                 [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
                 [[NSScriptCommand currentCommand] setScriptErrorString:@"New 
bookmark requires a supported bookmark type."];


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

------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to