Permalink
Browse files

track last scroll offset from selected row or top

  • Loading branch information...
1 parent d030c56 commit c402448254a867e408a49c09228c1695d9f0edf8 Zachary Schneirov committed Feb 8, 2010
Showing with 21 additions and 8 deletions.
  1. +3 −1 GlobalPrefs.h
  2. +18 −7 GlobalPrefs.m
View
@@ -17,6 +17,7 @@ extern NSString *NotePreviewString;
extern NSString *NVPTFPboardType;
+@class NotesTableView;
@class BookmarksController;
@class NotationPrefs;
@class PTKeyCombo;
@@ -120,9 +121,10 @@ extern NSString *NVPTFPboardType;
- (NSString*)lastSelectedPreferencesPane;
- (void)setLastSelectedPreferencesPane:(NSString*)pane sender:(id)sender;
+- (double)scrollOffsetOfLastSelectedNote;
- (CFUUIDBytes)UUIDBytesOfLastSelectedNote;
- (NSString*)lastSearchString;
-- (void)setLastSearchString:(NSString*)string selectedNote:(id<SynchronizedNote>)aNote sender:(id)sender;
+- (void)setLastSearchString:(NSString*)string selectedNote:(id<SynchronizedNote>)aNote scrollOffsetForTableView:(NotesTableView*)tv sender:(id)sender;
- (void)saveCurrentBookmarksFromSender:(id)sender;
- (BookmarksController*)bookmarksController;
View
@@ -11,6 +11,8 @@
#import "NotationPrefs.h"
#import "BookmarksController.h"
#import "AttributedPlainText.h"
+#import "FastListDataSource.h"
+#import "NotesTableView.h"
#import "PTHotKey.h"
#import "PTKeyCombo.h"
#import "PTHotKeyCenter.h"
@@ -42,6 +44,7 @@
static NSString *AppActivationKeyCodeKey = @"AppActivationKeyCode";
static NSString *AppActivationModifiersKey = @"AppActivationModifiers";
static NSString *BookmarksKey = @"Bookmarks";
+static NSString *LastScrollOffsetKey = @"LastScrollOffset";
static NSString *LastSearchStringKey = @"LastSearchString";
static NSString *LastSelectedNoteUUIDBytesKey = @"LastSelectedNoteUUIDBytes";
static NSString *LastSelectedPreferencesPaneKey = @"LastSelectedPrefsPane";
@@ -95,20 +98,21 @@ - (id)init {
[NSNumber numberWithBool:NO], DrawFocusRingKey,
[NSNumber numberWithBool:YES], MakeURLsClickableKey,
[NSNumber numberWithBool:YES], TableColumnsHaveBodyPreviewKey,
+ [NSNumber numberWithDouble:0.0], LastScrollOffsetKey,
@"General", LastSelectedPreferencesPaneKey,
[NSArchiver archivedDataWithRootObject:
- [NSFont fontWithName:@"Helvetica" size:12.0f]], NoteBodyFontKey,
+ [NSFont fontWithName:@"Helvetica" size:12.0f]], NoteBodyFontKey,
//[NSArchiver archivedDataWithRootObject:
// [NSColor colorWithCalibratedRed:0.9340 green:0.91415775 blue:0.81043575 alpha:1.0f]], SearchTermHighlightColorKey,
[NSArchiver archivedDataWithRootObject:
- [NSColor colorWithCalibratedRed:0.945 green:0.702 blue:0.702 alpha:1.0f]], SearchTermHighlightColorKey,
+ [NSColor colorWithCalibratedRed:0.945 green:0.702 blue:0.702 alpha:1.0f]], SearchTermHighlightColorKey,
- [NSNumber numberWithFloat:[NSFont smallSystemFontSize]], TableFontSizeKey,
- [NSArray arrayWithObjects:NoteTitleColumnString, NoteDateCreatedColumnString, nil], TableColumnsVisibleKey,
- NoteDateCreatedColumnString, TableSortColumnKey,
- [NSNumber numberWithBool:YES], TableIsReverseSortedKey, nil]];
+ [NSNumber numberWithFloat:[NSFont smallSystemFontSize]], TableFontSizeKey,
+ [NSArray arrayWithObjects:NoteTitleColumnString, NoteDateCreatedColumnString, nil], TableColumnsVisibleKey,
+ NoteDateCreatedColumnString, TableSortColumnKey,
+ [NSNumber numberWithBool:YES], TableIsReverseSortedKey, nil]];
autoCompleteSearches = [defaults boolForKey:AutoCompleteSearchesKey];
}
@@ -574,7 +578,7 @@ - (void)setLastSelectedPreferencesPane:(NSString*)pane sender:(id)sender {
SEND_CALLBACKS();
}
-- (void)setLastSearchString:(NSString*)string selectedNote:(id<SynchronizedNote>)aNote sender:(id)sender {
+- (void)setLastSearchString:(NSString*)string selectedNote:(id<SynchronizedNote>)aNote scrollOffsetForTableView:(NotesTableView*)tv sender:(id)sender {
NSMutableString *stringMinusBreak = [[string mutableCopy] autorelease];
[stringMinusBreak replaceOccurrencesOfString:@"\n" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [stringMinusBreak length])];
@@ -587,6 +591,9 @@ - (void)setLastSearchString:(NSString*)string selectedNote:(id<SynchronizedNote>
[defaults setObject:uuidString forKey:LastSelectedNoteUUIDBytesKey];
+ double offset = [tv distanceFromRow:[(FastListDataSource*)[tv dataSource] indexOfObjectIdenticalTo:aNote] forVisibleArea:[tv visibleRect]];
+ [defaults setDouble:offset forKey:LastScrollOffsetKey];
+
SEND_CALLBACKS();
}
@@ -603,6 +610,10 @@ - (CFUUIDBytes)UUIDBytesOfLastSelectedNote {
return bytes;
}
+- (double)scrollOffsetOfLastSelectedNote {
+ return [defaults doubleForKey:LastScrollOffsetKey];
+}
+
- (void)saveCurrentBookmarksFromSender:(id)sender {
//run this during quit and when saved searches change?
NSArray *bookmarks = [bookmarksController dictionaryReps];

0 comments on commit c402448

Please sign in to comment.