Revision: 10948
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=10948&view=rev
Author:   hofman
Date:     2007-08-19 15:17:43 -0700 (Sun, 19 Aug 2007)

Log Message:
-----------
Use custom data objects for bookmarks and validate edits.

Modified Paths:
--------------
    trunk/bibdesk/BDSKBookmarkController.h
    trunk/bibdesk/BDSKBookmarkController.m
    trunk/bibdesk/BDSKTextImportController.m
    trunk/bibdesk/BDSKWebGroupViewController.m
    trunk/bibdesk/English.lproj/BookmarksWindow.nib/classes.nib
    trunk/bibdesk/English.lproj/BookmarksWindow.nib/keyedobjects.nib
    trunk/bibdesk/French.lproj/BookmarksWindow.nib/keyedobjects.nib

Modified: trunk/bibdesk/BDSKBookmarkController.h
===================================================================
--- trunk/bibdesk/BDSKBookmarkController.h      2007-08-19 15:57:13 UTC (rev 
10947)
+++ trunk/bibdesk/BDSKBookmarkController.h      2007-08-19 22:17:43 UTC (rev 
10948)
@@ -22,8 +22,29 @@
 - (void)insertObject:(id)obj inBookmarksAtIndex:(unsigned)index;
 - (void)removeObjectFromBookmarksAtIndex:(unsigned)index;
 
-- (void)addBookmarkWithURLString:(NSString *)URLString title:(NSString *)title;
+- (void)addBookmarkWithUrlString:(NSString *)urlString name:(NSString *)name;
 
 - (void)handleApplicationWillTerminateNotification:(NSNotification 
*)notification;
 
 @end
+
+
[EMAIL PROTECTED] BDSKBookmark : NSObject {
+    NSString *urlString;
+    NSString *name;
+}
+
+- (id)initWithUrlString:(NSString *)aUrlString name:(NSString *)aName;
+- (id)initWithDictionary:(NSDictionary *)dictionary;
+
+- (NSDictionary *)dictionaryValue;
+
+- (NSURL *)URL;
+
+- (NSString *)urlString;
+- (void)setUrlString:(NSString *)newUrlString;
+
+- (NSString *)name;
+- (void)setName:(NSString *)newName;
+
[EMAIL PROTECTED]

Modified: trunk/bibdesk/BDSKBookmarkController.m
===================================================================
--- trunk/bibdesk/BDSKBookmarkController.m      2007-08-19 15:57:13 UTC (rev 
10947)
+++ trunk/bibdesk/BDSKBookmarkController.m      2007-08-19 22:17:43 UTC (rev 
10948)
@@ -13,7 +13,7 @@
 @implementation BDSKBookmarkController
 
 + (id)sharedBookmarkController {
-    id sharedBookmarkController = nil;
+    static id sharedBookmarkController = nil;
     if (sharedBookmarkController == nil) {
         sharedBookmarkController = [[self alloc] init];
     }
@@ -28,10 +28,12 @@
                NSString *bookmarksPath = [applicationSupportPath 
stringByAppendingPathComponent:@"Bookmarks.plist"];
                if ([[NSFileManager defaultManager] 
fileExistsAtPath:bookmarksPath]) {
                        NSEnumerator *bEnum = [[NSArray 
arrayWithContentsOfFile:bookmarksPath] objectEnumerator];
-                       NSDictionary *bm;
+                       NSDictionary *dict;
                        
-                       while(bm = [bEnum nextObject]){
-                               [bookmarks addObject:[[bm mutableCopy] 
autorelease]];
+                       while(dict = [bEnum nextObject]){
+                BDSKBookmark *bookmark = [[BDSKBookmark alloc] 
initWithDictionary:dict];
+                               [bookmarks addObject:bookmark];
+                [bookmark release];
                        }
             
             [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleApplicationWillTerminateNotification:) 
name:NSApplicationWillTerminateNotification object:nil];
@@ -78,15 +80,15 @@
     [bookmarks removeObjectAtIndex:index];
 }
 
-- (void)addBookmarkWithURLString:(NSString *)URLString title:(NSString *)title 
{
-    NSMutableDictionary *bookmark = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:
-                                    URLString, @"URLString", title, @"Title", 
nil];
+- (void)addBookmarkWithUrlString:(NSString *)urlString name:(NSString *)name {
+    BDSKBookmark *bookmark = [[BDSKBookmark alloc] initWithUrlString:urlString 
name:name];
     [[self mutableArrayValueForKey:@"bookmarks"] addObject:bookmark];
+    [bookmark release];
 }
 
 - (void)handleApplicationWillTerminateNotification:(NSNotification 
*)notification {
        NSString *error = nil;
-       NSData *data = [NSPropertyListSerialization 
dataFromPropertyList:bookmarks
+       NSData *data = [NSPropertyListSerialization 
dataFromPropertyList:[bookmarks valueForKey:@"dictionaryValue"]
                                                                                
                                          format:NSPropertyListXMLFormat_v1_0 
                                                                                
                        errorDescription:&error];
        if (error) {
@@ -101,3 +103,89 @@
 }
 
 @end
+
+
[EMAIL PROTECTED] BDSKBookmark
+
+- (id)initWithUrlString:(NSString *)aUrlString name:(NSString *)aName {
+    if (self = [super init]) {
+        urlString = [aUrlString copy];
+        name = [aName copy];
+    }
+    return self;
+}
+
+- (id)init {
+    return [self initWithUrlString:@"http://"; name:NSLocalizedString(@"New 
Boookmark", @"Default name for boookmark")];
+}
+
+- (id)initWithDictionary:(NSDictionary *)dictionary {
+    return [self initWithUrlString:[dictionary objectForKey:@"URLString"] 
name:[dictionary objectForKey:@"Title"]];
+}
+
+- (void)dealloc {
+    [urlString release];
+    [name release];
+    [super dealloc];
+}
+
+- (NSDictionary *)dictionaryValue {
+    return [NSDictionary dictionaryWithObjectsAndKeys:urlString, @"URLString", 
name, @"Title", nil];
+}
+
+- (NSURL *)URL {
+    return [NSURL URLWithString:[self urlString]];
+}
+
+- (NSString *)urlString {
+    return [[urlString retain] autorelease];
+}
+
+- (void)setUrlString:(NSString *)newUrlString {
+    if (urlString != newUrlString) {
+        [urlString release];
+        urlString = [newUrlString retain];
+    }
+}
+
+- (BOOL)validateUrlString:(id *)value error:(NSError **)error {
+    NSString *string = *value;
+    if (string == nil || [NSURL URLWithString:string] == nil) {
+        if (error) {
+            NSString *description = NSLocalizedString(@"Invalid URL.", @"Error 
description");
+            NSString *reason = [NSString 
stringWithFormat:NSLocalizedString(@"\"[EMAIL PROTECTED]" is not a valid URL.", 
@"Error reason"), string];
+            NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:description, NSLocalizedDescriptionKey, reason, 
NSLocalizedFailureReasonErrorKey, nil];
+            *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 
userInfo:userInfo];
+        }
+        return NO;
+    }
+    return YES;
+}
+
+- (NSString *)name {
+    return [[name retain] autorelease];
+}
+
+- (void)setName:(NSString *)newName {
+    if (name != newName) {
+        [name release];
+        name = [newName retain];
+    }
+}
+
+- (BOOL)validateName:(id *)value error:(NSError **)error {log_method();
+    NSArray *names = [[[BDSKBookmarkController sharedBookmarkController] 
bookmarks] valueForKey:@"name"];
+    NSString *string = *value;
+    if ([NSString isEmptyString:string] || ([name isEqualToString:string] == 
NO && [names containsObject:string])) {
+        if (error) {
+            NSString *description = NSLocalizedString(@"Invalid name.", 
@"Error description");
+            NSString *reason = [NSString 
stringWithFormat:NSLocalizedString(@"The bookmark \"[EMAIL PROTECTED]" already 
exists or is empty.", @"Error reason"), string];
+            NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:description, NSLocalizedDescriptionKey, reason, 
NSLocalizedFailureReasonErrorKey, nil];
+            *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 
userInfo:userInfo];
+        }
+        return NO;
+    }
+    return YES;
+}
+
[EMAIL PROTECTED]

Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m    2007-08-19 15:57:13 UTC (rev 
10947)
+++ trunk/bibdesk/BDSKTextImportController.m    2007-08-19 22:17:43 UTC (rev 
10948)
@@ -210,8 +210,8 @@
        [bookmarkPopUpButton removeAllItems];
        [bookmarkPopUpButton 
addItemWithTitle:NSLocalizedString(@"Bookmarks",@"Menu item title for Bookmarks 
popup")];
        for (i = 0; i < count; i++) {
-        NSDictionary *bm = [bookmarks objectAtIndex:i];
-               [bookmarkPopUpButton addItemWithTitle:[bm 
objectForKey:@"Title"]];
+        BDSKBookmark *bm = [bookmarks objectAtIndex:i];
+               [bookmarkPopUpButton addItemWithTitle:[bm name]];
         [[bookmarkPopUpButton itemAtIndex:i + 1] setTag:i];
        }
        
@@ -339,12 +339,12 @@
 
 - (IBAction)importFromWebAction:(id)sender{
        NSEnumerator *bEnum = [[[BDSKBookmarkController 
sharedBookmarkController] bookmarks] objectEnumerator];
-       NSDictionary *bm;
+       BDSKBookmark *bm;
        
        [bookmarkPopUpButton removeAllItems];
        [bookmarkPopUpButton addItemWithTitle:NSLocalizedString(@"Bookmarks", 
@"Menu item title for Bookmarks popup")];
        while (bm = [bEnum nextObject]) {
-               [bookmarkPopUpButton addItemWithTitle:[bm 
objectForKey:@"Title"]];
+               [bookmarkPopUpButton addItemWithTitle:[bm name]];
        }
        
        [NSApp beginSheet:urlSheet
@@ -375,7 +375,7 @@
 
 - (IBAction)chooseBookmarkAction:(id)sender{
        int index = [[bookmarkPopUpButton selectedItem] tag];
-       NSString *URLString = [[[BDSKBookmarkController 
sharedBookmarkController] objectInBookmarksAtIndex:index] 
objectForKey:@"URLString"];
+       NSString *URLString = [[[BDSKBookmarkController 
sharedBookmarkController] objectInBookmarksAtIndex:index] urlString];
        [urlTextField setStringValue:URLString];
     
        [urlSheet orderOut:sender];
@@ -383,7 +383,7 @@
 }
 
 - (IBAction)dismissAddBookmarkSheet:(id)sender{
-    NSArray *bookmarkNames = [[[BDSKBookmarkController 
sharedBookmarkController] bookmarks] valueForKey:@"Title"];
+    NSArray *bookmarkNames = [[[BDSKBookmarkController 
sharedBookmarkController] bookmarks] valueForKey:@"name"];
     if ([sender tag] == NSOKButton && [bookmarkNames 
containsObject:[bookmarkField stringValue]]) {
         NSAlert *alert = [NSAlert 
alertWithMessageText:NSLocalizedString(@"Duplicate Bookmark Name", @"Message in 
alert dialog") 
                                          
defaultButton:NSLocalizedString(@"OK", @"Button title")
@@ -999,7 +999,7 @@
 - (void)addBookmarkSheetDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode 
contextInfo:(void *)contextInfo{
     NSString *URLString = (NSString *)contextInfo;
        if (returnCode == NSOKButton) {
-        [[BDSKBookmarkController sharedBookmarkController] 
addBookmarkWithURLString:URLString title:[bookmarkField stringValue]];
+        [[BDSKBookmarkController sharedBookmarkController] 
addBookmarkWithUrlString:URLString name:[bookmarkField stringValue]];
        }
        [URLString release]; //the contextInfo was retained
 }

Modified: trunk/bibdesk/BDSKWebGroupViewController.m
===================================================================
--- trunk/bibdesk/BDSKWebGroupViewController.m  2007-08-19 15:57:13 UTC (rev 
10947)
+++ trunk/bibdesk/BDSKWebGroupViewController.m  2007-08-19 22:17:43 UTC (rev 
10948)
@@ -78,7 +78,7 @@
     [stopOrReloadButton setImagePosition:NSImageOnly];
     [stopOrReloadButton setImage:[NSImage imageNamed:@"reload_small"]];
        [urlComboBox removeAllItems];
-    [urlComboBox addItemsWithObjectValues:[[[BDSKBookmarkController 
sharedBookmarkController] bookmarks] valueForKey:@"URLString"]];
+    [urlComboBox addItemsWithObjectValues:[[[BDSKBookmarkController 
sharedBookmarkController] bookmarks] valueForKey:@"urlString"]];
     [[urlComboBox cell] setPlaceholderString:NSLocalizedString(@"URL", @"Web 
group URL field placeholder")];
 }
 

Modified: trunk/bibdesk/English.lproj/BookmarksWindow.nib/classes.nib
===================================================================
--- trunk/bibdesk/English.lproj/BookmarksWindow.nib/classes.nib 2007-08-19 
15:57:13 UTC (rev 10947)
+++ trunk/bibdesk/English.lproj/BookmarksWindow.nib/classes.nib 2007-08-19 
22:17:43 UTC (rev 10948)
@@ -13,6 +13,7 @@
             OUTLETS = {delegate = id; textCell = id; }; 
             SUPERCLASS = BDSKGradientView; 
         }, 
+        {CLASS = BDSKURLStringFormatter; LANGUAGE = ObjC; SUPERCLASS = 
NSFormatter; }, 
         {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
         {CLASS = NSObject; LANGUAGE = ObjC; }
     ); 

Modified: trunk/bibdesk/English.lproj/BookmarksWindow.nib/keyedobjects.nib
===================================================================
(Binary files differ)

Modified: trunk/bibdesk/French.lproj/BookmarksWindow.nib/keyedobjects.nib
===================================================================
(Binary files differ)


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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to