Skip to content

Commit

Permalink
even more accurate note-preview-condition testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Schneirov committed Jan 23, 2010
1 parent af9a3c2 commit 48ee410
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
3 changes: 2 additions & 1 deletion NotesTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ typedef struct _ViewLocationContext {
- (BOOL)objectIsSelected:(id)obj;

- (void)setShouldUseSecondaryHighlightColor:(BOOL)value;
- (void)setTitleDereferencorIsActiveStyle:(BOOL)activeStyle;
- (void)_setTitleDereferencorState:(BOOL)activeStyle;
- (void)updateTitleDereferencorState;

- (void)reloadDataIfNotEditing;

Expand Down
49 changes: 34 additions & 15 deletions NotesTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "NSString_NV.h"

#define STATUS_STRING_FONT_SIZE 16.0f
#define SET_DUAL_HIGHLIGHTS 0

@implementation NotesTableView

Expand Down Expand Up @@ -134,11 +135,11 @@ - (void)awakeFromNib {

NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center addObserver:self selector:@selector(windowDidBecomeKey:)
name:NSWindowDidBecomeKeyNotification object:[self window]];
[center addObserver:self selector:@selector(windowDidBecomeMain:)
name:NSWindowDidBecomeMainNotification object:[self window]];

[center addObserver:self selector:@selector(windowDidResignKey:)
name:NSWindowDidResignKeyNotification object:[self window]];
[center addObserver:self selector:@selector(windowDidResignMain:)
name:NSWindowDidResignMainNotification object:[self window]];

outletObjectAwoke(self);
}
Expand Down Expand Up @@ -171,23 +172,28 @@ - (void)paste:(id)sender {
[[NSApp delegate] addNotesFromPasteboard:[NSPasteboard generalPasteboard]];
}

- (void)setTitleDereferencorIsActiveStyle:(BOOL)activeStyle {
- (void)_setTitleDereferencorState:(BOOL)activeStyle {
NoteAttributeColumn *col = [self noteAttributeColumnForIdentifier:NoteTitleColumnString];

#if SET_DUAL_HIGHLIGHTS
activeStyle = YES;
#endif
[col setDereferencingFunction: [globalPrefs tableColumnsShowPreview] ?
(activeStyle ? properlyHighlightingTableTitleOfNote : tableTitleOfNote) : titleOfNote2];

}

- (void)updateTitleDereferencorState {
NSWindow *win = [self window];
[self _setTitleDereferencorState: [win isMainWindow] && ([win firstResponder] == self || [self currentEditor]) ];
}

- (BOOL)becomeFirstResponder {
[self setTitleDereferencorIsActiveStyle:YES];
[self updateTitleDereferencorState];

return [super becomeFirstResponder];
}

- (BOOL)resignFirstResponder {
[self setTitleDereferencorIsActiveStyle:NO];

- (BOOL)resignFirstResponder {
[self _setTitleDereferencorState:NO];
return [super resignFirstResponder];
}

Expand Down Expand Up @@ -582,14 +588,16 @@ - (BOOL)objectIsSelected:(id)obj {
}


- (void)windowDidBecomeKey:(NSNotification *)aNotification {
- (void)windowDidBecomeMain:(NSNotification *)aNotification {
[self setShouldUseSecondaryHighlightColor:hadHighlightInForeground];
[self updateTitleDereferencorState];
}

- (void)windowDidResignKey:(NSNotification *)aNotification {
- (void)windowDidResignMain:(NSNotification *)aNotification {
BOOL highlightBefore = shouldUseSecondaryHighlightColor;
[self setShouldUseSecondaryHighlightColor:YES];
hadHighlightInForeground = highlightBefore;
[self updateTitleDereferencorState];
}

- (void)setShouldUseSecondaryHighlightColor:(BOOL)value {
Expand Down Expand Up @@ -832,7 +840,7 @@ - (void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSE
[super editColumn:columnIndex row:rowIndex withEvent:theEvent select:flag];

//become/resignFirstResponder can't handle the field-editor case for row-highlighting style, so do it here:
[self setTitleDereferencorIsActiveStyle:YES];
[self updateTitleDereferencorState];

//this is way easier and faster than a custom formatter! just change the title while we're editing!
if ([self columnWithIdentifier:NoteTitleColumnString] == columnIndex) {
Expand All @@ -841,10 +849,21 @@ - (void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSE

NSTextView *editor = (NSTextView*)[self currentEditor];
[editor setString:titleOfNote(note)];
[editor setSelectedRange:NSMakeRange(0, [titleOfNote(note) length])];
if (flag) [editor setSelectedRange:NSMakeRange(0, [titleOfNote(note) length])];
}
}

- (void)textDidEndEditing:(NSNotification *)aNotification {
[super textDidEndEditing:aNotification];
[self updateTitleDereferencorState];
}

- (BOOL)abortEditing {
BOOL result = [super abortEditing];
[self updateTitleDereferencorState];
return result;
}

- (void)cancelOperation:(id)sender {
[self abortEditing];
[[NSApp delegate] cancelOperation:sender];
Expand Down

0 comments on commit 48ee410

Please sign in to comment.