Permalink
Browse files

trigger bookmark reveal and launch-restore from AppController instead…

… NotationController setDelegate
  • Loading branch information...
1 parent 205d8ba commit 0ff7324d519895eda5759945317f56cef5d77629 Zachary Schneirov committed Feb 8, 2010
Showing with 55 additions and 31 deletions.
  1. +4 −0 AppController.h
  2. +46 −7 AppController.m
  3. +0 −1 NotationController.h
  4. +5 −23 NotationController.m
View
@@ -69,12 +69,16 @@ void outletObjectAwoke(id sender);
- (IBAction)fieldAction:(id)sender;
- (NoteObject*)createNoteIfNecessary;
+- (void)searchForString:(NSString*)string;
+- (NSUInteger)_revealNote:(NoteObject*)note options:(NSUInteger)opts;
- (BOOL)displayContentsForNoteAtIndex:(int)noteIndex;
- (void)processChangedSelectionForTable:(NSTableView*)table;
- (void)setEmptyViewState:(BOOL)state;
- (void)_setCurrentNote:(NoteObject*)aNote;
- (NoteObject*)selectedNoteObject;
+- (void)restoreListStateUsingPreferences;
+
- (IBAction)syncWaitQuit:(id)sender;
- (void)setTableAllowsMultipleSelection;
View
@@ -132,7 +132,7 @@ void outletObjectAwoke(id sender) {
}
- (void)runDelayedUIActionsAfterLaunch {
- [[prefsController bookmarksController] setDelegate:self];
+ [[prefsController bookmarksController] setAppController:self];
[[prefsController bookmarksController] restoreWindowFromSave];
[[prefsController bookmarksController] updateBookmarksUI];
[self updateNoteMenus];
@@ -265,13 +265,21 @@ - (void)setNotationController:(NotationController*)newNotation {
if (oldNotation) {
[notesTableView abortEditing];
- [prefsController setLastSearchString:[self fieldSearchString] selectedNote:currentNote sender:self];
+ [prefsController setLastSearchString:[self fieldSearchString] selectedNote:currentNote
+ scrollOffsetForTableView:notesTableView sender:self];
//if we already had a notation, appController should already be bookmarksController's delegate
[[prefsController bookmarksController] performSelector:@selector(updateBookmarksUI) withObject:nil afterDelay:0.0];
}
[notationController setSortColumn:[notesTableView noteAttributeColumnForIdentifier:[prefsController sortedTableColumnKey]]];
[notesTableView setDataSource:[notationController notesListDataSource]];
[notationController setDelegate:self];
+
+ //allow resolution of UUIDs to NoteObjects from saved searches
+ [[prefsController bookmarksController] setDataSource:notationController];
+
+ //update the list using the new notation and saved settings
+ [self restoreListStateUsingPreferences];
+
//window's undomanager could be referencing actions from the old notation object
[[window undoManager] removeAllActions];
[notationController setUndoManager:[window undoManager]];
@@ -1195,15 +1203,30 @@ - (NoteObject*)createNoteIfNecessary {
return currentNote;
}
-- (void)notation:(NotationController*)notation revealNote:(NoteObject*)note options:(NSUInteger)opts {
+- (void)restoreListStateUsingPreferences {
+ //to be invoked after loading a notationcontroller
+
+ NSString *searchString = [prefsController lastSearchString];
+ if (searchString)
+ [self searchForString:searchString];
+ else
+ [notationController refilterNotes];
+
+ CFUUIDBytes bytes = [prefsController UUIDBytesOfLastSelectedNote];
+ NSUInteger idx = [self _revealNote:[notationController noteForUUIDBytes:&bytes] options:NVDoNotChangeScrollPosition];
+ //scroll using saved scrollbar position
+ [notesTableView scrollRowToVisible:NSNotFound == idx ? 0 : idx withVerticalOffset:[prefsController scrollOffsetOfLastSelectedNote]];
+}
+
+- (NSUInteger)_revealNote:(NoteObject*)note options:(NSUInteger)opts {
if (note) {
- NSUInteger selectedNoteIndex = [notation indexInFilteredListForNoteIdenticalTo:note];
+ NSUInteger selectedNoteIndex = [notationController indexInFilteredListForNoteIdenticalTo:note];
if (selectedNoteIndex == NSNotFound) {
NSLog(@"Note was not visible--showing all notes and trying again");
[self cancelOperation:nil];
- selectedNoteIndex = [notation indexInFilteredListForNoteIdenticalTo:note];
+ selectedNoteIndex = [notationController indexInFilteredListForNoteIdenticalTo:note];
}
if (selectedNoteIndex != NSNotFound) {
@@ -1218,11 +1241,17 @@ - (void)notation:(NotationController*)notation revealNote:(NoteObject*)note opti
if ((opts & NVOrderFrontWindow) && ![window isKeyWindow]) {
[window makeKeyAndOrderFront:nil];
}
+ return selectedNoteIndex;
} else {
[notesTableView deselectAll:self];
+ return NSNotFound;
}
}
+- (void)notation:(NotationController*)notation revealNote:(NoteObject*)note options:(NSUInteger)opts {
+ [self _revealNote:note options:opts];
+}
+
- (void)notation:(NotationController*)notation revealNotes:(NSArray*)notes {
NSIndexSet *indexes = [notation indexesOfNotes:notes];
@@ -1237,7 +1266,7 @@ - (void)notation:(NotationController*)notation revealNotes:(NSArray*)notes {
}
}
-- (void)notation:(NotationController*)notation wantsToSearchForString:(NSString*)string {
+- (void)searchForString:(NSString*)string {
if (string) {
@@ -1253,6 +1282,14 @@ - (void)notation:(NotationController*)notation wantsToSearchForString:(NSString*
}
}
+- (void)bookmarksController:(BookmarksController*)controller restoreNoteBookmark:(NoteBookmark*)aBookmark inBackground:(BOOL)inBG {
+ if (aBookmark) {
+ [self searchForString:[aBookmark searchString]];
+ [self _revealNote:[aBookmark noteObject] options:!inBG ? NVOrderFrontWindow : 0];
+ }
+}
+
+
- (void)splitView:(RBSplitView*)sender wasResizedFrom:(CGFloat)oldDimension to:(CGFloat)newDimension {
if (sender == splitView) {
[sender adjustSubviewsExcepting:[splitView subviewAtPosition:0]];
@@ -1422,7 +1459,9 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification {
[currentNote updateContentCacheCStringIfNecessary];
- [prefsController setLastSearchString:[self fieldSearchString] selectedNote:currentNote sender:self];
+ [prefsController setLastSearchString:[self fieldSearchString] selectedNote:currentNote
+ scrollOffsetForTableView:notesTableView sender:self];
+
[prefsController saveCurrentBookmarksFromSender:self];
}
View
@@ -184,7 +184,6 @@ enum { NVDefaultReveal = 0, NVDoNotChangeScrollPosition = 1, NVOrderFrontWindow
- (BOOL)notationListShouldChange:(NotationController*)someNotation;
- (void)notationListMightChange:(NotationController*)someNotation;
- (void)notationListDidChange:(NotationController*)someNotation;
-- (void)notation:(NotationController*)notation wantsToSearchForString:(NSString*)string;
- (void)notation:(NotationController*)notation revealNote:(NoteObject*)note options:(NSUInteger)opts;
- (void)notation:(NotationController*)notation revealNotes:(NSArray*)notes;
View
@@ -163,18 +163,6 @@ - (void)setDelegate:(id)theDelegate {
delegate = theDelegate;
- //show the new delegate our notes one way or another
-
- NSString *searchString = [prefsController lastSearchString];
- if (searchString)
- [delegate notation:self wantsToSearchForString:searchString];
- else
- [self refilterNotes];
-
- CFUUIDBytes bytes = [prefsController UUIDBytesOfLastSelectedNote];
- NSUInteger noteIndex = [allNotes indexOfNoteWithUUIDBytes:&bytes];
- if (noteIndex != NSNotFound)
- [delegate notation:self revealNote:[allNotes objectAtIndex:noteIndex] options:NVDoNotChangeScrollPosition];
}
- (void)upgradeDatabaseIfNecessary {
@@ -319,11 +307,6 @@ - (OSStatus)_readAndInitializeSerializedNotes {
if (!(deletedNotes = [[frozenNotation deletedNotes] retain]))
deletedNotes = [[NSMutableSet alloc] init];
- //allow resolution of UUIDs to NoteObjects from saved searches
- BookmarksController *ssController = [prefsController bookmarksController];
- [ssController setNotes:allNotes];
- [ssController setRevealDelegate:self];
-
[prefsController setNotationPrefs:notationPrefs sender:self];
if(notesData)
@@ -1441,12 +1424,11 @@ - (void)restyleAllNotes {
}
//used by BookmarksController
-- (void)bookmarksController:(BookmarksController*)controller restoreNoteBookmark:(NoteBookmark*)aBookmark inBackground:(BOOL)inBG {
- if (aBookmark) {
- [delegate notation:self wantsToSearchForString:[aBookmark searchString]];
- [delegate notation:self revealNote:[aBookmark noteObject] options: !inBG ? NVOrderFrontWindow : 0 ];
- //if selectedNote is non-nil, should focus be moved to data entry field?, probably not; it can be dangerous to accidentally overwrite text
- }
+
+- (NoteObject*)noteForUUIDBytes:(CFUUIDBytes*)bytes {
+ NSUInteger noteIndex = [allNotes indexOfNoteWithUUIDBytes:bytes];
+ if (noteIndex != NSNotFound) return [allNotes objectAtIndex:noteIndex];
+ return nil;
}
//re-searching for all notes each time a label is added or removed is unnecessary, I think

0 comments on commit 0ff7324

Please sign in to comment.