Permalink
Browse files

call to notationcontroller (dataSource) for note UUID resolution; dir…

…ectly message appkit for bookmark reveal
  • Loading branch information...
1 parent 0ff7324 commit a1a79be8d5801e856d635c3ab965850cc6075e59 Zachary Schneirov committed Feb 8, 2010
Showing with 32 additions and 34 deletions.
  1. +15 −6 BookmarksController.h
  2. +17 −28 BookmarksController.m
View
21 BookmarksController.h
@@ -8,6 +8,7 @@
#import <Cocoa/Cocoa.h>
+@class AppController;
@class NoteObject;
@interface NoteBookmark : NSObject {
@@ -56,10 +57,10 @@
NSMutableArray *bookmarks;
//for NoteObject <-> UUID lookups
- NSArray *notes;
+ id dataSource;
//for notifications
- id delegate, revealDelegate;
+ AppController *appController;
BOOL isRestoringSearch, isSelectingProgrammatically;
GlobalPrefs *prefsController;
@@ -77,7 +78,8 @@
- (id)initWithBookmarks:(NSArray*)array;
- (NSArray*)dictionaryReps;
-- (void)setNotes:(NSArray*)someNotes;
+- (id)dataSource;
+- (void)setDataSource:(id)aDataSource;
- (NoteObject*)noteWithUUIDBytes:(CFUUIDBytes)bytes;
- (void)removeBookmarkForNote:(NoteObject*)aNote;
@@ -101,9 +103,9 @@
- (BOOL)isVisible;
- (void)updateBookmarksUI;
-- (void)setRevealDelegate:(id)aDelegate;
-- (id)delegate;
-- (void)setDelegate:(id)aDelegate;
+
+- (AppController*)appController;
+- (void)setAppController:(id)aDelegate;
@end
@@ -112,3 +114,10 @@
- (void)bookmarksController:(BookmarksController*)controller restoreNoteBookmark:(NoteBookmark*)aBookmark inBackground:(BOOL)inBG;
@end
+
+@interface NSObject (BookmarksControllerDataSource)
+
+- (NoteObject*)noteForUUIDBytes:(CFUUIDBytes*)bytes;
+
+@end
+
View
45 BookmarksController.m
@@ -178,17 +178,18 @@ - (NSArray*)dictionaryReps {
return array;
}
-- (void)setNotes:(NSArray*)someNotes {
- [notes release];
- notes = [someNotes retain];
+- (id)dataSource {
+ return dataSource;
+}
+- (void)setDataSource:(id)aDataSource {
+ dataSource = aDataSource;
[bookmarks makeObjectsPerformSelector:@selector(validateNoteObject)];
}
- (NoteObject*)noteWithUUIDBytes:(CFUUIDBytes)bytes {
- NSUInteger noteIndex = [notes indexOfNoteWithUUIDBytes:&bytes];
- if (noteIndex != NSNotFound) return [notes objectAtIndex:noteIndex];
- return nil;
+
+ return [dataSource noteForUUIDBytes:&bytes];
}
- (void)removeBookmarkForNote:(NoteObject*)aNote {
@@ -272,7 +273,7 @@ - (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
SEL action = [menuItem action];
if (action == @selector(addBookmark:)) {
- return ([bookmarks count] < 27 && [delegate selectedNoteObject]);
+ return ([bookmarks count] < 27 && [appController selectedNoteObject]);
}
return YES;
@@ -290,7 +291,7 @@ - (BOOL)restoreNoteBookmark:(NoteBookmark*)bookmark inBackground:(BOOL)inBG{
isRestoringSearch = YES;
//BOOL inBG = ([[window currentEvent] modifierFlags] & NSCommandKeyMask) == 0;
- [revealDelegate bookmarksController:self restoreNoteBookmark:bookmark inBackground:inBG];
+ [appController bookmarksController:self restoreNoteBookmark:bookmark inBackground:inBG];
[self selectBookmarkInTableView:bookmark];
isRestoringSearch = NO;
@@ -326,7 +327,7 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
- return notes ? [bookmarks count] : 0;
+ return dataSource ? [bookmarks count] : 0;
}
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
@@ -488,14 +489,14 @@ - (void)clearAllBookmarks:(id)sender {
- (void)addBookmark:(id)sender {
- if (![delegate selectedNoteObject]) {
+ if (![appController selectedNoteObject]) {
NSRunAlertPanel(NSLocalizedString(@"No note selected.",@"alert title when bookmarking no note"), NSLocalizedString(@"You must select a note before it can be added as a bookmark.",nil), NSLocalizedString(@"OK",nil), nil, NULL);
} else if ([bookmarks count] < 27) {
- NSString *newString = [[delegate fieldSearchString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ NSString *newString = [[appController fieldSearchString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
- NoteBookmark *bookmark = [[NoteBookmark alloc] initWithNoteObject:[delegate selectedNoteObject] searchString:newString];
+ NoteBookmark *bookmark = [[NoteBookmark alloc] initWithNoteObject:[appController selectedNoteObject] searchString:newString];
if (bookmark) {
NSUInteger existingIndex = [bookmarks indexOfObject:bookmark];
@@ -528,23 +529,11 @@ - (void)removeBookmark:(id)sender {
}
}
-- (void)setRevealDelegate:(id)aDelegate {
- NSAssert([aDelegate respondsToSelector:@selector(bookmarksController:restoreNoteBookmark:inBackground:)], @"delegate must listen!");
-
- revealDelegate = aDelegate;
-}
-
-- (id)delegate {
- return delegate;
+- (AppController*)appController {
+ return appController;
}
-
-- (void)setDelegate:(id)aDelegate {
- if ([aDelegate respondsToSelector:@selector(fieldSearchString)] &&
- [aDelegate respondsToSelector:@selector(selectedNoteObject)]) {
- delegate = aDelegate;
- } else {
- NSLog(@"Delegate %@ doesn't respond to our selectors!", aDelegate);
- }
+- (void)setAppController:(id)aDelegate {
+ appController = aDelegate;
}
@end

0 comments on commit a1a79be

Please sign in to comment.