Revision: 6732
http://skim-app.svn.sourceforge.net/skim-app/?rev=6732&view=rev
Author: hofman
Date: 2010-08-25 09:45:42 +0000 (Wed, 25 Aug 2010)
Log Message:
-----------
scripting support for bookmarks
Modified Paths:
--------------
trunk/SKApplicationController.m
trunk/SKBookmark.h
trunk/SKBookmark.m
trunk/Skim.sdef
Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m 2010-08-24 18:23:22 UTC (rev 6731)
+++ trunk/SKApplicationController.m 2010-08-25 09:45:42 UTC (rev 6732)
@@ -452,11 +452,35 @@
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
{
static NSSet *applicationScriptingKeys = nil;
if (applicationScriptingKeys == nil)
- applicationScriptingKeys = [[NSSet alloc]
initWithObjects:@"defaultPdfViewSettings", @"defaultFullScreenPdfViewSettings",
@"backgroundColor", @"fullScreenBackgroundColor", @"pageBackgroundColor",
+ applicationScriptingKeys = [[NSSet alloc]
initWithObjects:@"bookmarks",
+ @"defaultPdfViewSettings", @"defaultFullScreenPdfViewSettings",
@"backgroundColor", @"fullScreenBackgroundColor", @"pageBackgroundColor",
@"defaultNoteColors", @"defaultLineWidths", @"defaultLineStyles",
@"defaultDashPatterns", @"defaultStartLineStyle", @"defaultEndLineStyle",
@"defaultFontNames", @"defaultFontSizes", @"defaultTextNoteFontColor",
@"defaultIconType", nil];
return [applicationScriptingKeys containsObject:key];
}
+- (id)newScriptingObjectOfClass:(Class)objectClass forValueForKey:(NSString
*)key withContentsValue:(id)contentsValue properties:(NSDictionary *)properties
{
+ if ([key isEqualToString:@"bookmarks"])
+ return [[[SKBookmarkController sharedBookmarkController] bookmarkRoot]
newScriptingObjectOfClass:objectClass forValueForKey:key
withContentsValue:contentsValue properties:properties];
+ else
+ return [super newScriptingObjectOfClass:objectClass forValueForKey:key
withContentsValue:contentsValue properties:properties];
+}
+
+- (NSArray *)bookmarks {
+ return [[[SKBookmarkController sharedBookmarkController] bookmarkRoot]
bookmarks];
+}
+
+- (void)insertInBookmarks:(SKBookmark *)bookmark {
+ [[[SKBookmarkController sharedBookmarkController] bookmarkRoot]
insertInBookmarks:bookmark];
+}
+
+- (void)insertObject:(SKBookmark *)bookmark
inBookmarksAtIndex:(NSUInteger)anIndex {
+ [[[SKBookmarkController sharedBookmarkController] bookmarkRoot]
insertObject:bookmark inBookmarksAtIndex:anIndex];
+}
+
+- (void)removeObjectFromBookmarksAtIndex:(NSUInteger)anIndex {
+ [[[SKBookmarkController sharedBookmarkController] bookmarkRoot]
removeObjectFromBookmarksAtIndex:anIndex];
+}
+
- (NSDictionary *)defaultPdfViewSettings {
return SKScriptingPDFViewSettingsFromPDFViewSettings([[NSUserDefaults
standardUserDefaults] dictionaryForKey:SKDefaultPDFDisplaySettingsKey]);
}
Modified: trunk/SKBookmark.h
===================================================================
--- trunk/SKBookmark.h 2010-08-24 18:23:22 UTC (rev 6731)
+++ trunk/SKBookmark.h 2010-08-25 09:45:42 UTC (rev 6732)
@@ -46,6 +46,13 @@
};
typedef NSInteger SKBookmarkType;
+enum {
+ SKScriptingBookmarkTypeBookmark = 'BmFl',
+ SKScriptingBookmarkTypeFolder = 'BmFd',
+ SKScriptingBookmarkTypeSession = 'BmSs',
+ SKScriptingBookmarkTypeSeparator = 'BmSp'
+};
+
@interface SKBookmark : NSObject {
SKBookmark *parent;
}
@@ -82,6 +89,15 @@
- (void)insertObject:(SKBookmark *)child inChildrenAtIndex:(NSUInteger)anIndex;
- (void)removeObjectFromChildrenAtIndex:(NSUInteger)anIndex;
+...@property (nonatomic, readonly) FourCharCode scriptingBookmarkType;
+...@property (nonatomic, readonly) NSURL *scriptingFile;
+...@property (nonatomic, readonly) SKBookmark *scriptingParent;
+
+- (NSArray *)bookmarks;
+- (void)insertInBookmarks:(SKBookmark *)bookmark;
+- (void)insertObject:(SKBookmark *)bookmark
inBookmarksAtIndex:(NSUInteger)anIndex;
+- (void)removeObjectFromBookmarksAtIndex:(NSUInteger)anIndex;
+
- (BOOL)isDescendantOf:(SKBookmark *)bookmark;
- (BOOL)isDescendantOfArray:(NSArray *)bookmarks;
Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m 2010-08-24 18:23:22 UTC (rev 6731)
+++ trunk/SKBookmark.m 2010-08-25 09:45:42 UTC (rev 6732)
@@ -39,6 +39,7 @@
#import "SKBookmark.h"
#import "BDAlias.h"
#import "NSImage_SKExtensions.h"
+#import "SKBookmarkController.h"
#define BOOKMARK_STRING @"bookmark"
#define SESSION_STRING @"session"
@@ -87,7 +88,7 @@
@implementation SKBookmark
@synthesize parent;
-...@dynamic properties, bookmarkType, label, icon, path, pageIndex, pageNumber;
+...@dynamic properties, bookmarkType, label, icon, path, pageIndex,
pageNumber, scriptingBookmarkType, scriptingFile, scriptingParent;
static SKPlaceholderBookmark *defaultPlaceholderBookmark = nil;
static Class SKBookmarkClass = Nil;
@@ -193,9 +194,98 @@
- (NSArray *)children { return nil; }
- (NSUInteger)countOfChildren { return 0; }
- (SKBookmark *)objectInChildrenAtIndex:(NSUInteger)anIndex { return nil; }
+- (void)insertInChildren:(SKBookmark *)child {}
- (void)insertObject:(SKBookmark *)child inChildrenAtIndex:(NSUInteger)anIndex
{}
- (void)removeObjectFromChildrenAtIndex:(NSUInteger)anIndex {}
+- (id)objectSpecifier {
+ NSUInteger idx = [[parent children] indexOfObjectIdenticalTo:self];
+ if (idx != NSNotFound) {
+ NSScriptObjectSpecifier *containerRef = nil;
+ NSScriptClassDescription *containerClassDescription = nil;
+ if ([parent parent]) {
+ containerRef = [parent objectSpecifier];
+ containerClassDescription = [containerRef keyClassDescription];
+ } else {
+ containerClassDescription = [NSScriptClassDescription
classDescriptionForClass:[NSApp class]];
+ }
+ return [[[NSIndexSpecifier allocWithZone:[self zone]]
initWithContainerClassDescription:containerClassDescription
containerSpecifier:containerRef key:@"bookmarks" index:idx] autorelease];
+ } else {
+ return nil;
+ }
+}
+
+- (FourCharCode)scriptingBookmarkType { return 0; }
+
+- (NSURL *)scriptingFile {
+ NSString *path = [self path];
+ return path ? [NSURL fileURLWithPath:path] : nil;
+}
+
+- (SKBookmark *)scriptingParent {
+ return [parent parent] == nil ? nil : parent;
+};
+
+- (NSArray *)bookmarks {
+ return [self children];
+}
+
+- (void)insertInBookmarks:(SKBookmark *)bookmark {
+ return [self insertObject:bookmark inChildrenAtIndex:[self
countOfChildren]];
+}
+
+- (void)insertObject:(SKBookmark *)bookmark
inBookmarksAtIndex:(NSUInteger)anIndex {
+ [self insertObject:bookmark inChildrenAtIndex:anIndex];
+}
+
+- (void)removeObjectFromBookmarksAtIndex:(NSUInteger)anIndex {
+ [self removeObjectFromChildrenAtIndex:anIndex];
+}
+
+- (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 && [contentsValue isKindOfClass:[NSURL class]])
+ type = SKScriptingBookmarkTypeBookmark;
+ switch (type) {
+ case SKScriptingBookmarkTypeBookmark:
+ {
+ NSString *aPath = [[properties objectForKey:@"scriptingFile"]
path];
+ if (aPath == nil && [contentsValue isKindOfClass:[NSURL
class]])
+ aPath = [contentsValue path];
+ NSString *aLabel = [properties objectForKey:@"label"] ?:
[aPath lastPathComponent] ?: @"";
+ if (aPath == nil) {
+ [[NSScriptCommand currentCommand]
setScriptErrorNumber:NSArgumentsWrongScriptError];
+ [[NSScriptCommand currentCommand]
setScriptErrorString:@"New file bookmark requires a path."];
+ } else if ([[NSFileManager defaultManager]
fileExistsAtPath:aPath] == NO) {
+ [[NSScriptCommand currentCommand]
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
+ [[NSScriptCommand currentCommand]
setScriptErrorString:@"New file bookmark requires an existing path."];
+ } else {
+ NSUInteger aPageNumber = [[properties
objectForKey:@"pageNumber"] unsignedIntegerValue];
+ bookmark = [[SKBookmark alloc] initWithPath:aPath
pageIndex:(aPageNumber > 0 ? aPageNumber - 1 : 0) label:aLabel];
+ }
+ break;
+ }
+ case SKScriptingBookmarkTypeFolder:
+ {
+ NSString *aLabel = [properties objectForKey:@"label"] ?: @"";
+ bookmark = [[SKBookmark alloc] initFolderWithLabel:aLabel];
+ break;
+ }
+ case SKScriptingBookmarkTypeSeparator:
+ bookmark = [[SKBookmark alloc] initSeparator];
+ break;
+ default:
+ [[NSScriptCommand currentCommand]
setScriptErrorNumber:NSArgumentsWrongScriptError];
+ [[NSScriptCommand currentCommand] setScriptErrorString:@"New
bookmark require a supported bookmark type."];
+ break;
+ }
+ return bookmark;
+ }
+ return [super newScriptingObjectOfClass:objectClass forValueForKey:key
withContentsValue:contentsValue properties:properties];
+}
+
- (BOOL)isDescendantOf:(SKBookmark *)bookmark {
if (self == bookmark)
return YES;
@@ -395,6 +485,10 @@
}
}
+- (FourCharCode)scriptingBookmarkType {
+ return SKScriptingBookmarkTypeBookmark;
+}
+
@end
#pragma mark -
@@ -455,6 +549,10 @@
return [children objectAtIndex:anIndex];
}
+- (void)insertInChildren:(SKBookmark *)child {
+ [self insertObject:child inChildrenAtIndex:[children count]];
+}
+
- (void)insertObject:(SKBookmark *)child inChildrenAtIndex:(NSUInteger)anIndex
{
[children insertObject:child atIndex:anIndex];
[child setParent:self];
@@ -465,6 +563,10 @@
[children removeObjectAtIndex:anIndex];
}
+- (FourCharCode)scriptingBookmarkType {
+ return SKScriptingBookmarkTypeFolder;
+}
+
@end
#pragma mark -
@@ -536,7 +638,14 @@
- (NSImage *)icon {
return [NSImage imageNamed:NSImageNameMultipleDocuments];
}
+- (FourCharCode)scriptingBookmarkType {
+ return SKScriptingBookmarkTypeSession;
+}
+- (NSArray *)bookmarks { return nil; }
+- (void)insertObject:(SKBookmark *)bookmark
inBookmarksAtIndex:(NSUInteger)anIndex {}
+- (void)removeObjectFromBookmarksAtIndex:(NSUInteger)anIndex {}
+
@end
#pragma mark -
@@ -555,4 +664,8 @@
return SKBookmarkTypeSeparator;
}
+- (FourCharCode)scriptingBookmarkType {
+ return SKScriptingBookmarkTypeSeparator;
+}
+
@end
Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef 2010-08-24 18:23:22 UTC (rev 6731)
+++ trunk/Skim.sdef 2010-08-25 09:45:42 UTC (rev 6732)
@@ -776,6 +776,10 @@
<class-extension extends="application"
description="Skim's top level scripting object.">
<cocoa class="SKApplication"/>
+ <element type="bookmark"
+ description="The top level bookmarks.">
+ <cocoa key="bookmarks"/>
+ </element>
<element type="TeX line" access="r" hidden="yes"
description="Lines in a TeX source file.">
<cocoa key="lines"/>
@@ -1124,6 +1128,35 @@
</responds-to>
</class>
+ <class name="bookmark" plural="bookmarks" code="Bkmk"
+ description="A bookmark.">
+ <cocoa class="SKBookmark"/>
+ <element type="bookmark"
+ description="The children of the bookmark.">
+ <cocoa key="bookmarks"/>
+ </element>
+ <property name="name" code="pnam" type="text"
+ description="The name for the bookmark.">
+ <cocoa key="label"/>
+ </property>
+ <property name="type" code="rtyp" type="bookmark type" access="r"
+ description="The bookmark type.">
+ <cocoa key="scriptingBookmarkType"/>
+ </property>
+ <contents name="file" code="file" type="file" access="r"
+ description="The file for the bookmark.">
+ <cocoa key="scriptingFile"/>
+ </contents>
+ <property name="page index" code="PIdx" type="integer"
+ description="The page index for the bookmark.">
+ <cocoa key="pageNumber"/>
+ </property>
+ <property name="parent" code="Parn" type="bookmark" access="r"
+ description="The parent for the bookmark.">
+ <cocoa key="scriptingParent"/>
+ </property>
+ </class>
+
<class name="point list" plural="point lists" code="PtLi"
description="A list of points.">
<cocoa class="NSArray"/>
@@ -1553,6 +1586,17 @@
description="Display pages side-by-side vertically
continuously."/>
</enumeration>
+ <enumeration name="bookmark type" code="BmkE">
+ <enumerator name="file bookmark" code="BmFl"
+ description="File bookmark."/>
+ <enumerator name="folder bookmark" code="BmFd"
+ description="Bookmark folder."/>
+ <enumerator name="session bookmark" code="BmSs"
+ description="Session bookmark."/>
+ <enumerator name="separator bookmark" code="BmSp"
+ description="Bookmark separator."/>
+ </enumeration>
+
</suite>
</dictionary>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit