Revision: 6939
http://skim-app.svn.sourceforge.net/skim-app/?rev=6939&view=rev
Author: hofman
Date: 2010-12-06 18:42:36 +0000 (Mon, 06 Dec 2010)
Log Message:
-----------
move implementation of adding bookmarks for paths to SKBookmark class, so we
can use it from scripting when creating a folder with a file
Modified Paths:
--------------
trunk/SKBookmark.h
trunk/SKBookmark.m
trunk/SKBookmarkController.m
Modified: trunk/SKBookmark.h
===================================================================
--- trunk/SKBookmark.h 2010-12-06 15:49:25 UTC (rev 6938)
+++ trunk/SKBookmark.h 2010-12-06 18:42:36 UTC (rev 6939)
@@ -87,6 +87,8 @@
- (void)insertObject:(SKBookmark *)child inChildrenAtIndex:(NSUInteger)anIndex;
- (void)removeObjectFromChildrenAtIndex:(NSUInteger)anIndex;
+- (void)insertBookmarksForPaths:(NSArray *)paths relativeToPath:(NSString
*)basePath atIndex:(NSUInteger)anIndex;
+
@property (nonatomic, readonly) FourCharCode scriptingBookmarkType;
@property (nonatomic, readonly) NSURL *scriptingFile;
@property (nonatomic, readonly) SKBookmark *scriptingParent;
Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m 2010-12-06 15:49:25 UTC (rev 6938)
+++ trunk/SKBookmark.m 2010-12-06 18:42:36 UTC (rev 6939)
@@ -208,6 +208,8 @@
}
}
+- (void)insertBookmarksForPaths:(NSArray *)paths relativeToPath:(NSString
*)basePath atIndex:(NSUInteger)anIndex {}
+
- (FourCharCode)scriptingBookmarkType { return 0; }
- (NSURL *)scriptingFile {
@@ -598,8 +600,12 @@
}
case SKScriptingBookmarkTypeFolder:
{
- NSString *aLabel = [properties objectForKey:@"label"] ?: @"";
+ 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 (aPath)
+ [bookmark insertBookmarksForPaths:[[NSFileManager
defaultManager] contentsOfDirectoryAtPath:aPath error:NULL]
relativeToPath:aPath atIndex:0];
break;
}
case SKScriptingBookmarkTypeSeparator:
@@ -622,6 +628,34 @@
return [super newScriptingObjectOfClass:objectClass forValueForKey:key
withContentsValue:contentsValue properties:properties];
}
+- (void)insertBookmarksForPaths:(NSArray *)paths relativeToPath:(NSString
*)basePath atIndex:(NSUInteger)anIndex {
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSDocumentController *dc = [NSDocumentController sharedDocumentController];
+ NSUInteger insertIndex = anIndex;
+
+ 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];
+ Class docClass;
+ SKBookmark *bookmark;
+ if ([fileType isEqualToString:SKFolderDocumentType]) {
+ if (bookmark = [[SKBookmark alloc] initFolderWithLabel:[fm
displayNameAtPath:path]]) {
+ [bookmark insertBookmarksForPaths:[fm
contentsOfDirectoryAtPath:path error:NULL] relativeToPath:path atIndex:0];
+ if ([bookmark countOfChildren])
+ [self insertObject:bookmark
inChildrenAtIndex:insertIndex++];
+ [bookmark release];
+ }
+ } else if (docClass = [dc documentClassForType:fileType]) {
+ if (bookmark = [[SKBookmark alloc] initWithPath:path
pageIndex:([docClass isPDFDocument] ? 0 : NSNotFound) label:[fm
displayNameAtPath:path]]) {
+ [self insertObject:bookmark
inChildrenAtIndex:insertIndex++];
+ [bookmark release];
+ }
+ }
+ }
+ }
+}
+
@end
#pragma mark -
@@ -700,6 +734,8 @@
- (void)insertObject:(SKBookmark *)child inChildrenAtIndex:(NSUInteger)anIndex
{}
- (void)removeObjectFromChildrenAtIndex:(NSUInteger)anIndex {}
+- (void)insertBookmarksForPaths:(NSArray *)paths relativeToPath:(NSString
*)basePath atIndex:(NSUInteger)anIndex {}
+
- (NSArray *)entireContents { return nil; }
- (id)newScriptingObjectOfClass:(Class)objectClass forValueForKey:(NSString
*)key withContentsValue:(id)contentsValue properties:(NSDictionary *)properties
{
Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m 2010-12-06 15:49:25 UTC (rev 6938)
+++ trunk/SKBookmarkController.m 2010-12-06 18:42:36 UTC (rev 6939)
@@ -677,12 +677,15 @@
} else if ([type isEqualToString:NSFilenamesPboardType]) {
NSArray *paths = [pboard propertyListForType:NSFilenamesPboardType];
[self endEditing];
- NSUInteger count = [self addBookmarksForPaths:paths basePath:nil
toFolder:(item ?: bookmarkRoot) atIndex:anIndex];
- if (count > 0 && (item == nil || [outlineView isItemExpanded:item])) {
- NSRange range = NSMakeRange((item ? [outlineView rowForItem:item]
+ 1 : 0) + anIndex, count);
+ if (item == nil) item = bookmarkRoot;
+ NSUInteger oldCount = [item countOfChildren];
+ [item insertBookmarksForPaths:paths relativeToPath:nil
atIndex:anIndex];
+ NSUInteger newCount = [item countOfChildren];
+ if (newCount > oldCount && (item == nil || [outlineView
isItemExpanded:item])) {
+ NSRange range = NSMakeRange((item == bookmarkRoot ? 0 :
[outlineView rowForItem:item] + 1) + anIndex, newCount - oldCount);
[outlineView selectRowIndexes:[NSIndexSet
indexSetWithIndexesInRange:range] byExtendingSelection:NO];
}
- return count > 0;
+ return newCount > oldCount;
}
return NO;
}
@@ -751,19 +754,21 @@
}
- (void)tableView:(NSTableView *)tv pasteFromPasteboard:(NSPasteboard *)pboard
{
- NSUInteger count = 0;
+ NSUInteger oldCount = 0, newCount = 0;
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);
+ oldCount = [item countOfChildren];
+ [item insertBookmarksForPaths:paths relativeToPath:nil
atIndex:anIndex];
+ newCount = [item countOfChildren];
+ if (newCount > oldCount && (item == bookmarkRoot || [outlineView
isItemExpanded:item])) {
+ NSRange range = NSMakeRange((item == bookmarkRoot ? 0 :
[outlineView rowForItem:item] + 1) + anIndex, newCount - oldCount);
[outlineView selectRowIndexes:[NSIndexSet
indexSetWithIndexesInRange:range] byExtendingSelection:NO];
}
}
- if (count == 0)
+ if (newCount == oldCount)
NSBeep();
}
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