Revision: 6934
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6934&view=rev
Author:   hofman
Date:     2010-12-05 12:25:39 +0000 (Sun, 05 Dec 2010)

Log Message:
-----------
only create new scripting bookmarks in folders

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

Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m  2010-12-05 10:45:27 UTC (rev 6933)
+++ trunk/SKBookmark.m  2010-12-05 12:25:39 UTC (rev 6934)
@@ -235,62 +235,9 @@
 
 - (id)newScriptingObjectOfClass:(Class)objectClass forValueForKey:(NSString 
*)key withContentsValue:(id)contentsValue properties:(NSDictionary *)properties 
{
     if ([key isEqualToString:@"bookmarks"]) {
-        SKBookmark *bookmark = nil;
-        FourCharCode type = [[properties 
objectForKey:@"scriptingBookmarkType"] unsignedIntValue];
-        if (type == 0) {
-            if (contentsValue || [properties objectForKey:@"scriptingFile"])
-                type = SKScriptingBookmarkTypeBookmark;
-            else if ([properties objectForKey:@"label"])
-                type = SKScriptingBookmarkTypeFolder;
-        }
-        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];
-                    [[NSScriptCommand currentCommand] 
setScriptErrorString:@"New file bookmark requires a file."];
-                } else if ([[NSFileManager defaultManager] 
fileExistsAtPath:aPath] == NO) {
-                    [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
-                    [[NSScriptCommand currentCommand] 
setScriptErrorString:@"New file bookmark requires an existing file."];
-                } else if (docClass = [[NSDocumentController 
sharedDocumentController] documentClassForContentsOfURL:aURL]) {
-                    NSUInteger aPageNumber = [[properties 
objectForKey:@"pageNumber"] unsignedIntegerValue];
-                    if (aPageNumber > 0)
-                        aPageNumber--;
-                    else
-                        aPageNumber = [docClass isPDFDocument] ? 0 : 
NSNotFound;
-                    bookmark = [[SKBookmark alloc] initWithPath:aPath 
pageIndex:aPageNumber label:aLabel];
-                } else {
-                    [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
-                    [[NSScriptCommand currentCommand] 
setScriptErrorString:@"Unsupported file type for new bookmark."];
-                }
-                break;
-            }
-            case SKScriptingBookmarkTypeFolder:
-            {
-                NSString *aLabel = [properties objectForKey:@"label"] ?: @"";
-                bookmark = [[SKBookmark alloc] initFolderWithLabel:aLabel];
-                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];
-                break;
-            }
-            default:
-                [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
-                [[NSScriptCommand currentCommand] setScriptErrorString:@"New 
bookmark requires a supported bookmark type."];
-                break;
-        }
-        return bookmark;
+        [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+        [[NSScriptCommand currentCommand] setScriptErrorString:@"Invalid 
container for new bookmark."];
+        return nil;
     }
     return [super newScriptingObjectOfClass:objectClass forValueForKey:key 
withContentsValue:contentsValue properties:properties];
 }
@@ -613,6 +560,68 @@
     return contents;
 }
 
+- (id)newScriptingObjectOfClass:(Class)objectClass forValueForKey:(NSString 
*)key withContentsValue:(id)contentsValue properties:(NSDictionary *)properties 
{
+    if ([key isEqualToString:@"bookmarks"]) {
+        SKBookmark *bookmark = nil;
+        FourCharCode type = [[properties 
objectForKey:@"scriptingBookmarkType"] unsignedIntValue];
+        if (type == 0) {
+            if (contentsValue || [properties objectForKey:@"scriptingFile"])
+                type = SKScriptingBookmarkTypeBookmark;
+            else if ([properties objectForKey:@"label"])
+                type = SKScriptingBookmarkTypeFolder;
+        }
+        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];
+                    [[NSScriptCommand currentCommand] 
setScriptErrorString:@"New file bookmark requires a file."];
+                } else if ([[NSFileManager defaultManager] 
fileExistsAtPath:aPath] == NO) {
+                    [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
+                    [[NSScriptCommand currentCommand] 
setScriptErrorString:@"New file bookmark requires an existing file."];
+                } else if (docClass = [[NSDocumentController 
sharedDocumentController] documentClassForContentsOfURL:aURL]) {
+                    NSUInteger aPageNumber = [[properties 
objectForKey:@"pageNumber"] unsignedIntegerValue];
+                    if (aPageNumber > 0)
+                        aPageNumber--;
+                    else
+                        aPageNumber = [docClass isPDFDocument] ? 0 : 
NSNotFound;
+                    bookmark = [[SKBookmark alloc] initWithPath:aPath 
pageIndex:aPageNumber label:aLabel];
+                } else {
+                    [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
+                    [[NSScriptCommand currentCommand] 
setScriptErrorString:@"Unsupported file type for new bookmark."];
+                }
+                break;
+            }
+            case SKScriptingBookmarkTypeFolder:
+            {
+                NSString *aLabel = [properties objectForKey:@"label"] ?: @"";
+                bookmark = [[SKBookmark alloc] initFolderWithLabel:aLabel];
+                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];
+                break;
+            }
+            default:
+                [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSArgumentsWrongScriptError];
+                [[NSScriptCommand currentCommand] setScriptErrorString:@"New 
bookmark requires a supported bookmark type."];
+                break;
+        }
+        return bookmark;
+    }
+    return [super newScriptingObjectOfClass:objectClass forValueForKey:key 
withContentsValue:contentsValue properties:properties];
+}
+
 @end
 
 #pragma mark -
@@ -693,6 +702,15 @@
 
 - (NSArray *)entireContents { return nil; }
 
+- (id)newScriptingObjectOfClass:(Class)objectClass forValueForKey:(NSString 
*)key withContentsValue:(id)contentsValue properties:(NSDictionary *)properties 
{
+    if ([key isEqualToString:@"bookmarks"]) {
+        [[NSScriptCommand currentCommand] 
setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+        [[NSScriptCommand currentCommand] setScriptErrorString:@"Invalid 
container for new bookmark."];
+        return nil;
+    }
+    return [super newScriptingObjectOfClass:objectClass forValueForKey:key 
withContentsValue:contentsValue properties:properties];
+}
+
 @end
 
 #pragma mark -


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