Revision: 6539
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6539&view=rev
Author:   hofman
Date:     2010-05-16 21:35:11 +0000 (Sun, 16 May 2010)

Log Message:
-----------
allow adding bookmarks by dropping files or folders on the bookmarks window

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

Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m        2010-05-16 17:52:39 UTC (rev 6538)
+++ trunk/SKBookmarkController.m        2010-05-16 21:35:11 UTC (rev 6539)
@@ -174,7 +174,7 @@
     
     [outlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelper]];
     
-    [outlineView registerForDraggedTypes:[NSArray 
arrayWithObjects:SKBookmarkRowsPboardType, nil]];
+    [outlineView registerForDraggedTypes:[NSArray 
arrayWithObjects:SKBookmarkRowsPboardType, NSFilenamesPboardType, nil]];
     
     [outlineView setDoubleAction:@selector(doubleClickBookmark:)];
 }
@@ -251,6 +251,33 @@
         [folder insertObject:bookmark inChildrenAtIndex:[folder 
countOfChildren]];
 }
 
+- (BOOL)addBookmarksForPaths:(NSArray *)paths basePath:(NSString *)basePath 
toFolder:(SKBookmark *)folder atIndex:(NSUInteger)anIndex {
+    BOOL rv = NO;
+    NSFileManager *fm = [NSFileManager defaultManager];
+    NSDocumentController *dc = [NSDocumentController sharedDocumentController];
+    
+    for (NSString *file in paths) {
+        if ([[file lastPathComponent] hasPrefix:@"."] == NO) {
+            NSString *path = [basePath stringByAppendingPathComponent:file] ?: 
file;
+            NSString *fileType = [dc typeForContentsOfURL:[NSURL 
fileURLWithPath:path] error:NULL];
+            SKBookmark *bookmark;
+            if (SKIsFolderDocumentType(fileType)) {
+                if (bookmark = [SKBookmark bookmarkFolderWithLabel:[fm 
displayNameAtPath:path]]) {
+                    [folder insertObject:bookmark inChildrenAtIndex:anIndex++];
+                    [self addBookmarksForPaths:[fm 
contentsOfDirectoryAtPath:path error:NULL] basePath:path toFolder:bookmark 
atIndex:0];
+                    rv = YES;
+                }
+            } else if ([dc documentClassForType:fileType] == [SKMainDocument 
class]) {
+                if (bookmark = [SKBookmark bookmarkWithPath:path pageIndex:0 
label:[fm displayNameAtPath:path]]) {
+                    [folder insertObject:bookmark inChildrenAtIndex:anIndex++];
+                    rv = YES;
+                }
+            }
+        }
+    }
+    return rv;
+}
+
 - (NSArray *)draggedBookmarks {
     return draggedBookmarks;
 }
@@ -619,9 +646,9 @@
 
 - (NSDragOperation)outlineView:(NSOutlineView *)ov validateDrop:(id 
<NSDraggingInfo>)info proposedItem:(id)item 
proposedChildIndex:(NSInteger)anIndex {
     NSPasteboard *pboard = [info draggingPasteboard];
-    NSString *type = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:SKBookmarkRowsPboardType, nil]];
+    NSString *type = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:SKBookmarkRowsPboardType, NSFilenamesPboardType, nil]];
     
-    if (type) {
+    if ([type isEqualToString:SKBookmarkRowsPboardType]) {
         if (anIndex == NSOutlineViewDropOnItemIndex) {
             if ([item bookmarkType] == SKBookmarkTypeFolder && [outlineView 
isItemExpanded:item]) {
                 [ov setDropItem:item dropChildIndex:0];
@@ -632,15 +659,17 @@
             }
         }
         return [item isDescendantOfArray:[self draggedBookmarks]] ? 
NSDragOperationNone : NSDragOperationMove;
+    } else if ([type isEqualToString:NSFilenamesPboardType]) {
+        return anIndex == NSOutlineViewDropOnItemIndex ? NSDragOperationNone : 
NSDragOperationEvery;
     }
     return NSDragOperationNone;
 }
 
 - (BOOL)outlineView:(NSOutlineView *)ov acceptDrop:(id <NSDraggingInfo>)info 
item:(id)item childIndex:(NSInteger)anIndex {
     NSPasteboard *pboard = [info draggingPasteboard];
-    NSString *type = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:SKBookmarkRowsPboardType, nil]];
+    NSString *type = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:SKBookmarkRowsPboardType, NSFilenamesPboardType, nil]];
     
-    if (type) {
+    if ([type isEqualToString:SKBookmarkRowsPboardType]) {
         if (item == nil) item = bookmarkRoot;
         
         [self endEditing];
@@ -657,6 +686,12 @@
             [(SKBookmark *)item insertObject:bookmark 
inChildrenAtIndex:anIndex++];
                }
         return YES;
+    } else if ([type isEqualToString:NSFilenamesPboardType]) {
+        if (item == nil) item = bookmarkRoot;
+        
+        NSArray *paths = [pboard propertyListForType:NSFilenamesPboardType];
+        [self endEditing];
+        return [self addBookmarksForPaths:paths basePath:nil toFolder:item 
atIndex:anIndex];
     }
     return NO;
 }


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

------------------------------------------------------------------------------

_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to