Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ectly message appkit for bookmark reveal
  • Loading branch information...
commit a1a79be8d5801e856d635c3ab965850cc6075e59 1 parent 0ff7324
Zachary Schneirov authored

Showing 2 changed files with 32 additions and 34 deletions. Show diff stats Hide diff stats

  1. +15 6 BookmarksController.h
  2. +17 28 BookmarksController.m
21 BookmarksController.h
@@ -8,6 +8,7 @@
8 8
9 9 #import <Cocoa/Cocoa.h>
10 10
  11 +@class AppController;
11 12 @class NoteObject;
12 13
13 14 @interface NoteBookmark : NSObject {
@@ -56,10 +57,10 @@
56 57 NSMutableArray *bookmarks;
57 58
58 59 //for NoteObject <-> UUID lookups
59   - NSArray *notes;
  60 + id dataSource;
60 61
61 62 //for notifications
62   - id delegate, revealDelegate;
  63 + AppController *appController;
63 64 BOOL isRestoringSearch, isSelectingProgrammatically;
64 65
65 66 GlobalPrefs *prefsController;
@@ -77,7 +78,8 @@
77 78 - (id)initWithBookmarks:(NSArray*)array;
78 79 - (NSArray*)dictionaryReps;
79 80
80   -- (void)setNotes:(NSArray*)someNotes;
  81 +- (id)dataSource;
  82 +- (void)setDataSource:(id)aDataSource;
81 83 - (NoteObject*)noteWithUUIDBytes:(CFUUIDBytes)bytes;
82 84 - (void)removeBookmarkForNote:(NoteObject*)aNote;
83 85
@@ -101,9 +103,9 @@
101 103 - (BOOL)isVisible;
102 104
103 105 - (void)updateBookmarksUI;
104   -- (void)setRevealDelegate:(id)aDelegate;
105   -- (id)delegate;
106   -- (void)setDelegate:(id)aDelegate;
  106 +
  107 +- (AppController*)appController;
  108 +- (void)setAppController:(id)aDelegate;
107 109
108 110 @end
109 111
@@ -112,3 +114,10 @@
112 114 - (void)bookmarksController:(BookmarksController*)controller restoreNoteBookmark:(NoteBookmark*)aBookmark inBackground:(BOOL)inBG;
113 115
114 116 @end
  117 +
  118 +@interface NSObject (BookmarksControllerDataSource)
  119 +
  120 +- (NoteObject*)noteForUUIDBytes:(CFUUIDBytes*)bytes;
  121 +
  122 +@end
  123 +
45 BookmarksController.m
@@ -178,17 +178,18 @@ - (NSArray*)dictionaryReps {
178 178 return array;
179 179 }
180 180
181   -- (void)setNotes:(NSArray*)someNotes {
182   - [notes release];
183   - notes = [someNotes retain];
  181 +- (id)dataSource {
  182 + return dataSource;
  183 +}
  184 +- (void)setDataSource:(id)aDataSource {
  185 + dataSource = aDataSource;
184 186
185 187 [bookmarks makeObjectsPerformSelector:@selector(validateNoteObject)];
186 188 }
187 189
188 190 - (NoteObject*)noteWithUUIDBytes:(CFUUIDBytes)bytes {
189   - NSUInteger noteIndex = [notes indexOfNoteWithUUIDBytes:&bytes];
190   - if (noteIndex != NSNotFound) return [notes objectAtIndex:noteIndex];
191   - return nil;
  191 +
  192 + return [dataSource noteForUUIDBytes:&bytes];
192 193 }
193 194
194 195 - (void)removeBookmarkForNote:(NoteObject*)aNote {
@@ -272,7 +273,7 @@ - (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
272 273 SEL action = [menuItem action];
273 274 if (action == @selector(addBookmark:)) {
274 275
275   - return ([bookmarks count] < 27 && [delegate selectedNoteObject]);
  276 + return ([bookmarks count] < 27 && [appController selectedNoteObject]);
276 277 }
277 278
278 279 return YES;
@@ -290,7 +291,7 @@ - (BOOL)restoreNoteBookmark:(NoteBookmark*)bookmark inBackground:(BOOL)inBG{
290 291 isRestoringSearch = YES;
291 292
292 293 //BOOL inBG = ([[window currentEvent] modifierFlags] & NSCommandKeyMask) == 0;
293   - [revealDelegate bookmarksController:self restoreNoteBookmark:bookmark inBackground:inBG];
  294 + [appController bookmarksController:self restoreNoteBookmark:bookmark inBackground:inBG];
294 295 [self selectBookmarkInTableView:bookmark];
295 296
296 297 isRestoringSearch = NO;
@@ -326,7 +327,7 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu
326 327 }
327 328
328 329 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
329   - return notes ? [bookmarks count] : 0;
  330 + return dataSource ? [bookmarks count] : 0;
330 331 }
331 332
332 333 - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
@@ -488,14 +489,14 @@ - (void)clearAllBookmarks:(id)sender {
488 489
489 490 - (void)addBookmark:(id)sender {
490 491
491   - if (![delegate selectedNoteObject]) {
  492 + if (![appController selectedNoteObject]) {
492 493
493 494 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);
494 495
495 496 } else if ([bookmarks count] < 27) {
496   - NSString *newString = [[delegate fieldSearchString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  497 + NSString *newString = [[appController fieldSearchString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
497 498
498   - NoteBookmark *bookmark = [[NoteBookmark alloc] initWithNoteObject:[delegate selectedNoteObject] searchString:newString];
  499 + NoteBookmark *bookmark = [[NoteBookmark alloc] initWithNoteObject:[appController selectedNoteObject] searchString:newString];
499 500 if (bookmark) {
500 501
501 502 NSUInteger existingIndex = [bookmarks indexOfObject:bookmark];
@@ -528,23 +529,11 @@ - (void)removeBookmark:(id)sender {
528 529 }
529 530 }
530 531
531   -- (void)setRevealDelegate:(id)aDelegate {
532   - NSAssert([aDelegate respondsToSelector:@selector(bookmarksController:restoreNoteBookmark:inBackground:)], @"delegate must listen!");
533   -
534   - revealDelegate = aDelegate;
535   -}
536   -
537   -- (id)delegate {
538   - return delegate;
  532 +- (AppController*)appController {
  533 + return appController;
539 534 }
540   -
541   -- (void)setDelegate:(id)aDelegate {
542   - if ([aDelegate respondsToSelector:@selector(fieldSearchString)] &&
543   - [aDelegate respondsToSelector:@selector(selectedNoteObject)]) {
544   - delegate = aDelegate;
545   - } else {
546   - NSLog(@"Delegate %@ doesn't respond to our selectors!", aDelegate);
547   - }
  535 +- (void)setAppController:(id)aDelegate {
  536 + appController = aDelegate;
548 537 }
549 538
550 539 @end

0 comments on commit a1a79be

Please sign in to comment.
Something went wrong with that request. Please try again.