Revision: 6725
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6725&view=rev
Author:   hofman
Date:     2010-08-23 09:58:06 +0000 (Mon, 23 Aug 2010)

Log Message:
-----------
support paste of filenames in bookmarks outlineview

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

Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m        2010-08-23 09:40:31 UTC (rev 6724)
+++ trunk/SKBookmarkController.m        2010-08-23 09:58:06 UTC (rev 6725)
@@ -350,6 +350,26 @@
     return bookmarksPath;
 }
 
+- (void)getInsertionFolder:(SKBookmark **)bookmarkPtr childIndex:(NSUInteger 
*)indexPtr {
+    NSInteger rowIndex = [[outlineView selectedRowIndexes] lastIndex];
+    SKBookmark *item = bookmarkRoot;
+    NSUInteger idx = [bookmarkRoot countOfChildren];
+    
+    if (rowIndex != NSNotFound) {
+        SKBookmark *selectedItem = [outlineView itemAtRow:rowIndex];
+        if ([outlineView isItemExpanded:selectedItem]) {
+            item = selectedItem;
+            idx = [item countOfChildren];
+        } else {
+            item = [selectedItem parent];
+            idx = [[item children] indexOfObject:selectedItem] + 1;
+        }
+    }
+    
+    *bookmarkPtr = item;
+    *indexPtr = idx;
+}
+
 - (void)openFileBookmark:(SKBookmark *)bookmark {
     id document = nil;
     NSError *error = nil;
@@ -394,20 +414,10 @@
 
 - (IBAction)insertBookmarkFolder:(id)sender {
     SKBookmark *folder = [SKBookmark 
bookmarkFolderWithLabel:NSLocalizedString(@"Folder", @"default folder name")];
-    NSInteger rowIndex = [[outlineView selectedRowIndexes] lastIndex];
-    SKBookmark *item = bookmarkRoot;
-    NSUInteger idx = [bookmarkRoot countOfChildren];
+    SKBookmark *item = nil;
+    NSUInteger idx = 0;
     
-    if (rowIndex != NSNotFound) {
-        SKBookmark *selectedItem = [outlineView itemAtRow:rowIndex];
-        if ([outlineView isItemExpanded:selectedItem]) {
-            item = selectedItem;
-            idx = [item countOfChildren];
-        } else {
-            item = [selectedItem parent];
-            idx = [[item children] indexOfObject:selectedItem] + 1;
-        }
-    }
+    [self getInsertionFolder:&item childIndex:&idx];
     [item insertObject:folder inChildrenAtIndex:idx];
     
     NSInteger row = [outlineView rowForItem:folder];
@@ -417,20 +427,10 @@
 
 - (IBAction)insertBookmarkSeparator:(id)sender {
     SKBookmark *separator = [SKBookmark bookmarkSeparator];
-    NSInteger rowIndex = [[outlineView selectedRowIndexes] lastIndex];
-    SKBookmark *item = bookmarkRoot;
-    NSUInteger idx = [bookmarkRoot countOfChildren];
+    SKBookmark *item = nil;
+    NSUInteger idx = 0;
     
-    if (rowIndex != NSNotFound) {
-        SKBookmark *selectedItem = [outlineView itemAtRow:rowIndex];
-        if ([outlineView isItemExpanded:selectedItem]) {
-            item = selectedItem;
-            idx = [item countOfChildren];
-        } else {
-            item = [selectedItem parent];
-            idx = [[item children] indexOfObject:selectedItem] + 1;
-        }
-    }
+    [self getInsertionFolder:&item childIndex:&idx];
     [item insertObject:separator inChildrenAtIndex:idx];
     
     NSInteger row = [outlineView rowForItem:separator];
@@ -749,6 +749,28 @@
     return [items count] > 0;
 }
 
+- (void)outlineViewPaste:(NSOutlineView *)ov {
+    NSUInteger count = 0;
+    NSPasteboard *pboard = [NSPasteboard generalPasteboard];
+    if ([pboard availableTypeFromArray:[NSArray 
arrayWithObjects:NSFilenamesPboardType, nil]]) {
+        NSArray *paths = [pboard propertyListForType:NSFilenamesPboardType];
+        SKBookmark *item = nil;
+        NSUInteger anIndex = 0;
+        [self getInsertionFolder:&item childIndex:&anIndex];
+        count = [self addBookmarksForPaths:paths basePath:nil toFolder:item 
atIndex:anIndex];
+        if (count > 0 && (item == bookmarkRoot || [outlineView 
isItemExpanded:item])) {
+            NSRange range = NSMakeRange((item == bookmarkRoot ? 0 : 
[outlineView rowForItem:item] + 1) + anIndex, count);
+            [outlineView selectRowIndexes:[NSIndexSet 
indexSetWithIndexesInRange:range] byExtendingSelection:NO];
+        }
+    }
+    if (count == 0)
+        NSBeep();
+}
+
+- (BOOL)outlineViewCanPaste:(NSOutlineView *)ov {
+    return nil != [[NSPasteboard generalPasteboard] 
availableTypeFromArray:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
+}
+
 - (NSArray *)outlineView:(NSOutlineView *)ov 
typeSelectHelperSelectionItems:(SKTypeSelectHelper *)typeSelectHelper {
     NSInteger i, count = [outlineView numberOfRows];
     NSMutableArray *labels = [NSMutableArray arrayWithCapacity:count];

Modified: trunk/SKOutlineView.h
===================================================================
--- trunk/SKOutlineView.h       2010-08-23 09:40:31 UTC (rev 6724)
+++ trunk/SKOutlineView.h       2010-08-23 09:58:06 UTC (rev 6725)
@@ -48,11 +48,12 @@
 + (BOOL)usesDefaultFontSize;
 
 @property (nonatomic, readonly) NSArray *selectedItems;
-...@property (nonatomic, readonly) BOOL canDelete, canCopy;
+...@property (nonatomic, readonly) BOOL canDelete, canCopy, canPaste;
 @property (nonatomic, retain) SKTypeSelectHelper *typeSelectHelper;
 
 - (void)delete:(id)sender;
 - (void)copy:(id)sender;
+- (void)paste:(id)sender;
 
 - (void)scrollToBeginningOfDocument:(id)sender;
 - (void)scrollToEndOfDocument:(id)sender;
@@ -76,6 +77,9 @@
 - (void)outlineView:(NSOutlineView *)anOutlineView copyItems:(NSArray *)items;
 - (BOOL)outlineView:(NSOutlineView *)anOutlineView canCopyItems:(NSArray 
*)items;
 
+- (void)outlineViewPaste:(NSOutlineView *)anOutlineView;
+- (BOOL)outlineViewCanPaste:(NSOutlineView *)anOutlineView;
+
 - (NSArray *)outlineView:(NSOutlineView *)anOutlineView 
typeSelectHelperSelectionItems:(SKTypeSelectHelper *)aTypeSelectHelper;
 - (void)outlineView:(NSOutlineView *)anOutlineView 
typeSelectHelper:(SKTypeSelectHelper *)aTypeSelectHelper 
didFailToFindMatchForSearchString:(NSString *)searchString;
 - (void)outlineView:(NSOutlineView *)anOutlineView 
typeSelectHelper:(SKTypeSelectHelper *)aTypeSelectHelper 
updateSearchString:(NSString *)searchString;

Modified: trunk/SKOutlineView.m
===================================================================
--- trunk/SKOutlineView.m       2010-08-23 09:40:31 UTC (rev 6724)
+++ trunk/SKOutlineView.m       2010-08-23 09:58:06 UTC (rev 6725)
@@ -51,7 +51,7 @@
 @implementation SKOutlineView
 
 @synthesize typeSelectHelper;
-...@dynamic selectedItems, canDelete, canCopy;
+...@dynamic selectedItems, canDelete, canCopy, canPaste;
 
 + (BOOL)usesDefaultFontSize { return NO; }
 
@@ -192,11 +192,30 @@
         NSBeep();
 }
 
+- (BOOL)canPaste {
+    if ([[self delegate] respondsToSelector:@selector(outlineViewPaste:)]) {
+        if ([[self delegate] 
respondsToSelector:@selector(outlineViewCanPaste:)])
+            return [[self delegate] outlineViewCanPaste:self];
+        else
+            return YES;
+    }
+    return NO;
+}
+
+- (void)paste:(id)sender {
+    if ([self canPaste])
+        [[self delegate] outlineViewPaste:self];
+    else
+        NSBeep();
+}
+
 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
     if ([menuItem action] == @selector(delete:))
         return [self canDelete];
     else if ([menuItem action] == @selector(copy:))
         return [self canCopy];
+    else if ([menuItem action] == @selector(paste:))
+        return [self canPaste];
     else if ([menuItem action] == @selector(selectAll:))
         return [self allowsMultipleSelection];
     else if ([menuItem action] == @selector(deselectAll:))


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

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to