|
65 | 65 | #import <SPMySQL/SPMySQL.h>
|
66 | 66 | #include <stdlib.h>
|
67 | 67 |
|
| 68 | +/** |
| 69 | + * This is the unique KVO context of code that resides in THIS class. |
| 70 | + * Do not try to give it to other classes, ESPECIALLY NOT child classes! |
| 71 | + */ |
| 72 | +static void *TableContentKVOContext = &TableContentKVOContext; |
| 73 | + |
68 | 74 | #ifndef SP_CODA
|
69 | 75 | static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOperator";
|
70 | 76 | #endif
|
@@ -287,6 +293,10 @@ - (void)awakeFromNib
|
287 | 293 | // filterTableDefaultOperator = [[self escapeFilterTableDefaultOperator:nil] retain];
|
288 | 294 | #endif
|
289 | 295 |
|
| 296 | + [prefs addObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:TableContentKVOContext]; |
| 297 | + [prefs addObserver:self forKeyPath:SPGlobalResultTableFont options:NSKeyValueObservingOptionNew context:TableContentKVOContext]; |
| 298 | + [prefs addObserver:self forKeyPath:SPDisplayBinaryDataAsHex options:NSKeyValueObservingOptionNew context:TableContentKVOContext]; |
| 299 | + |
290 | 300 | // Add observers for document task activity
|
291 | 301 | [[NSNotificationCenter defaultCenter] addObserver:self
|
292 | 302 | selector:@selector(startDocumentTaskForTab:)
|
@@ -4197,22 +4207,28 @@ - (void)documentWillClose:(NSNotification *)notification
|
4197 | 4207 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
4198 | 4208 | {
|
4199 | 4209 | #ifndef SP_CODA /* observe pref changes */
|
4200 |
| - // Display table veiew vertical gridlines preference changed |
4201 |
| - if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { |
4202 |
| - [tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; |
4203 |
| - [filterTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; |
4204 |
| - } |
4205 |
| - // Table font preference changed |
4206 |
| - else if ([keyPath isEqualToString:SPGlobalResultTableFont]) { |
4207 |
| - NSFont *tableFont = [NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]; |
| 4210 | + // a parent class (or cocoa) can also use KVO, so we need to watch out to only catch those KVO messages we requested |
| 4211 | + if(context == TableContentKVOContext) { |
| 4212 | + // Display table veiew vertical gridlines preference changed |
| 4213 | + if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { |
| 4214 | + [tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; |
| 4215 | + [filterTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; |
| 4216 | + } |
| 4217 | + // Table font preference changed |
| 4218 | + else if ([keyPath isEqualToString:SPGlobalResultTableFont]) { |
| 4219 | + NSFont *tableFont = [NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]; |
4208 | 4220 |
|
4209 |
| - [tableContentView setRowHeight:2.0f + NSSizeToCGSize([@"{ǞṶḹÜ∑zgyf" sizeWithAttributes:@{NSFontAttributeName : tableFont}]).height]; |
4210 |
| - [tableContentView setFont:tableFont]; |
4211 |
| - [tableContentView reloadData]; |
| 4221 | + [tableContentView setRowHeight:2.0f + NSSizeToCGSize([@"{ǞṶḹÜ∑zgyf" sizeWithAttributes:@{NSFontAttributeName : tableFont}]).height]; |
| 4222 | + [tableContentView setFont:tableFont]; |
| 4223 | + [tableContentView reloadData]; |
| 4224 | + } |
| 4225 | + // Display binary data as Hex |
| 4226 | + else if ([keyPath isEqualToString:SPDisplayBinaryDataAsHex] && [tableContentView numberOfRows] > 0) { |
| 4227 | + [tableContentView reloadData]; |
| 4228 | + } |
4212 | 4229 | }
|
4213 |
| - // Display binary data as Hex |
4214 |
| - else if ([keyPath isEqualToString:SPDisplayBinaryDataAsHex] && [tableContentView numberOfRows] > 0) { |
4215 |
| - [tableContentView reloadData]; |
| 4230 | + else { |
| 4231 | + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; |
4216 | 4232 | }
|
4217 | 4233 | #endif
|
4218 | 4234 | }
|
@@ -5461,6 +5477,13 @@ - (void)dealloc
|
5461 | 5477 | {
|
5462 | 5478 | [[NSNotificationCenter defaultCenter] removeObserver:self];
|
5463 | 5479 |
|
| 5480 | + if(_mainNibLoaded) { |
| 5481 | + //TODO this should be changed to the variant with …context: after 10.6 support is removed! |
| 5482 | + [prefs removeObserver:self forKeyPath:SPGlobalResultTableFont]; |
| 5483 | + [prefs removeObserver:self forKeyPath:SPDisplayBinaryDataAsHex]; |
| 5484 | + [prefs removeObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines]; |
| 5485 | + } |
| 5486 | + |
5464 | 5487 | // Cancel previous performSelector: requests on ourselves and the table view
|
5465 | 5488 | // to prevent crashes for deferred actions
|
5466 | 5489 | [NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
0 commit comments