Revision: 2926
http://skim-app.svn.sourceforge.net/skim-app/?rev=2926&view=rev
Author: hofman
Date: 2007-09-15 09:41:19 -0700 (Sat, 15 Sep 2007)
Log Message:
-----------
Save bookmarks as binary. Add some string constants.
Modified Paths:
--------------
trunk/SKBookmarkController.h
trunk/SKBookmarkController.m
trunk/SKStringConstants.h
trunk/SKStringConstants.m
Modified: trunk/SKBookmarkController.h
===================================================================
--- trunk/SKBookmarkController.h 2007-09-15 12:52:53 UTC (rev 2925)
+++ trunk/SKBookmarkController.h 2007-09-15 16:41:19 UTC (rev 2926)
@@ -61,7 +61,7 @@
- (void)removeObjectFromBookmarksAtIndex:(unsigned)index;
- (void)addBookmarkForPath:(NSString *)path pageIndex:(unsigned)pageIndex
label:(NSString *)label;
-- (void)saveBookmarks;
+- (void)handleApplicationWillTerminateNotification:(NSNotification
*)notification;
- (void)handleBookmarkChangedNotification:(NSNotification *)notification;
- (void)handleBookmarkWillBeRemovedNotification:(NSNotification *)notification;
- (NSString *)bookmarksFilePath;
Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m 2007-09-15 12:52:53 UTC (rev 2925)
+++ trunk/SKBookmarkController.m 2007-09-15 16:41:19 UTC (rev 2926)
@@ -48,6 +48,7 @@
#import "SKTextWithIconCell.h"
#import "SKToolbarItem.h"
#import "NSImage_SKExtensions.h"
+#import "SKStringConstants.h"
static NSString *SKBookmarkRowsPboardType = @"SKBookmarkRowsPboardType";
@@ -56,6 +57,9 @@
static NSString *SKBookmarksNewSeparatorToolbarItemIdentifier =
@"SKBookmarksNewSeparatorToolbarItemIdentifier";
static NSString *SKBookmarksDeleteToolbarItemIdentifier =
@"SKBookmarksDeleteToolbarItemIdentifier";
+#define BOOKMARKS_KEY @"bookmarks"
+#define RECENT_DOCUMENTS_KEY @"recentDocuments"
+
@implementation SKBookmarkController
static unsigned int maxRecentDocumentsCount = 0;
@@ -81,7 +85,7 @@
NSData *data = [NSData dataWithContentsOfFile:[self
bookmarksFilePath]];
if (data) {
NSString *error = nil;
- NSPropertyListFormat format = NSPropertyListXMLFormat_v1_0;
+ NSPropertyListFormat format = NSPropertyListBinaryFormat_v1_0;
id plist = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable
format:&format
@@ -91,8 +95,8 @@
NSLog(@"Error deserializing: %@", error);
[error release];
} else if ([plist isKindOfClass:[NSDictionary class]]) {
- [recentDocuments addObjectsFromArray:[plist
objectForKey:@"recentDocuments"]];
- NSEnumerator *dictEnum = [[plist objectForKey:@"bookmarks"]
objectEnumerator];
+ [recentDocuments addObjectsFromArray:[plist
objectForKey:RECENT_DOCUMENTS_KEY]];
+ NSEnumerator *dictEnum = [[plist objectForKey:BOOKMARKS_KEY]
objectEnumerator];
NSDictionary *dict;
while (dict = [dictEnum nextObject]) {
@@ -104,6 +108,10 @@
}
[[NSNotificationCenter defaultCenter] addObserver:self
+
selector:@selector(handleApplicationWillTerminateNotification:)
+
name:NSApplicationWillTerminateNotification
+ object:NSApp];
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleBookmarkChangedNotification:)
name:SKBookmarkChangedNotification
object:nil];
@@ -116,6 +124,7 @@
}
- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[bookmarks release];
[recentDocuments release];
[draggedBookmarks release];
@@ -132,7 +141,7 @@
[self setWindowFrameAutosaveName:@"SKBookmarksWindow"];
[statusBar retain];
- if ([[NSUserDefaults standardUserDefaults]
boolForKey:@"SKShowBookmarkStatusBar"] == NO)
+ if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKShowBookmarkStatusBarKey] == NO)
[self toggleStatusBar:nil];
SKTypeSelectHelper *typeSelectHelper = [[[SKTypeSelectHelper alloc] init]
autorelease];
@@ -282,8 +291,6 @@
[recentDocuments insertObject:bm atIndex:0];
if ([recentDocuments count] > maxRecentDocumentsCount)
[recentDocuments removeLastObject];
-
- [self saveBookmarks];
}
- (unsigned int)pageIndexForRecentDocumentAtPath:(NSString *)path {
@@ -301,30 +308,6 @@
return [setups count] ? setups : nil;
}
-- (void)saveBookmarks {
- NSDictionary *bookmarksDictionary = [NSDictionary
dictionaryWithObjectsAndKeys:[bookmarks valueForKey:@"dictionaryValue"],
@"bookmarks", recentDocuments, @"recentDocuments", nil];
- NSString *error = nil;
- NSPropertyListFormat format = NSPropertyListXMLFormat_v1_0;
- NSData *data = [NSPropertyListSerialization
dataFromPropertyList:bookmarksDictionary format:format errorDescription:&error];
-
- if (error) {
- NSLog(@"Error deserializing: %@", error);
- [error release];
- } else {
- [data writeToFile:[self bookmarksFilePath] atomically:YES];
- }
-}
-
-- (void)handleBookmarkWillBeRemovedNotification:(NSNotification *)notification
{
- if ([outlineView editedRow] && [[self window]
makeFirstResponder:outlineView] == NO)
- [[self window] endEditingFor:nil];
-}
-
-- (void)handleBookmarkChangedNotification:(NSNotification *)notification {
- [self saveBookmarks];
- [outlineView reloadData];
-}
-
- (NSString *)bookmarksFilePath {
static NSString *bookmarksPath = nil;
@@ -433,7 +416,7 @@
- (IBAction)toggleStatusBar:(id)sender {
[statusBar toggleBelowView:[outlineView enclosingScrollView] offset:1.0];
- [[NSUserDefaults standardUserDefaults] setBool:[statusBar isVisible]
forKey:@"SKShowBookmarkStatusBar"];
+ [[NSUserDefaults standardUserDefaults] setBool:[statusBar isVisible]
forKey:SKShowBookmarkStatusBarKey];
}
#pragma mark Undo support
@@ -448,6 +431,31 @@
return [self undoManager];
}
+#pragma mark Notification handlers
+
+- (void)handleApplicationWillTerminateNotification:(NSNotification
*)notification {
+ NSDictionary *bookmarksDictionary = [NSDictionary
dictionaryWithObjectsAndKeys:[bookmarks valueForKey:@"dictionaryValue"],
BOOKMARKS_KEY, recentDocuments, RECENT_DOCUMENTS_KEY, nil];
+ NSString *error = nil;
+ NSPropertyListFormat format = NSPropertyListBinaryFormat_v1_0;
+ NSData *data = [NSPropertyListSerialization
dataFromPropertyList:bookmarksDictionary format:format errorDescription:&error];
+
+ if (error) {
+ NSLog(@"Error deserializing: %@", error);
+ [error release];
+ } else {
+ [data writeToFile:[self bookmarksFilePath] atomically:YES];
+ }
+}
+
+- (void)handleBookmarkWillBeRemovedNotification:(NSNotification *)notification
{
+ if ([outlineView editedRow] && [[self window]
makeFirstResponder:outlineView] == NO)
+ [[self window] endEditingFor:nil];
+}
+
+- (void)handleBookmarkChangedNotification:(NSNotification *)notification {
+ [outlineView reloadData];
+}
+
#pragma mark NSOutlineView datasource methods
- (int)outlineView:(NSOutlineView *)ov numberOfChildrenOfItem:(id)item {
Modified: trunk/SKStringConstants.h
===================================================================
--- trunk/SKStringConstants.h 2007-09-15 12:52:53 UTC (rev 2925)
+++ trunk/SKStringConstants.h 2007-09-15 16:41:19 UTC (rev 2926)
@@ -97,6 +97,7 @@
extern NSString *SKDefaultPDFDisplaySettingsKey;
extern NSString *SKDefaultFullScreenPDFDisplaySettingsKey;
extern NSString *SKShowStatusBarKey;
+extern NSString *SKShowBookmarkStatusBarKey;
extern NSString *SKEnableAppleRemoteKey;
extern NSString *SKAppleRemoteSwitchIndicationTimeoutKey;
extern NSString *SKReadMissingNotesFromSkimFileOptionKey;
Modified: trunk/SKStringConstants.m
===================================================================
--- trunk/SKStringConstants.m 2007-09-15 12:52:53 UTC (rev 2925)
+++ trunk/SKStringConstants.m 2007-09-15 16:41:19 UTC (rev 2926)
@@ -98,6 +98,7 @@
NSString *SKDefaultPDFDisplaySettingsKey = @"SKDefaultPDFDisplaySettings";
NSString *SKDefaultFullScreenPDFDisplaySettingsKey =
@"SKDefaultFullScreenPDFDisplaySettings";
NSString *SKShowStatusBarKey = @"SKShowStatusBar";
+NSString *SKShowBookmarkStatusBarKey = @"SKShowBookmarkStatusBar";
NSString *SKEnableAppleRemoteKey = @"SKEnableAppleRemote";
NSString *SKAppleRemoteSwitchIndicationTimeoutKey =
@"SKAppleRemoteSwitchIndicationTimeout";
NSString *SKReadMissingNotesFromSkimFileOptionKey =
@"SKReadMissingNotesFromSkimFileOption";
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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit