Permalink
Browse files

Move some badly misplaced KVO code

  • Loading branch information...
dmoagx committed May 6, 2018
1 parent 2252b66 commit 0e5c6589049f9df0fdda70c2e1c0ab6267066412
Showing with 37 additions and 22 deletions.
  1. +0 −8 Source/SPDatabaseDocument.m
  2. +37 −14 Source/SPTableContent.m
@@ -6395,7 +6395,6 @@ - (void)_addPreferenceObservers
// Register observers for when the DisplayTableViewVerticalGridlines preference changes
[prefs addObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:tableContentInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:customQueryInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:tableRelationsInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
@@ -6404,9 +6403,6 @@ - (void)_addPreferenceObservers
[prefs addObserver:tableSourceInstance forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:tableContentInstance forKeyPath:SPGlobalResultTableFont options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:tableContentInstance forKeyPath:SPDisplayBinaryDataAsHex options:NSKeyValueObservingOptionNew context:NULL];
// Register observers for when the logging preference changes
[prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:SPConsoleEnableLogging options:NSKeyValueObservingOptionNew context:NULL];
@@ -6424,13 +6420,9 @@ - (void)_removePreferenceObservers
[prefs removeObserver:tableSourceInstance forKeyPath:SPUseMonospacedFonts];
[prefs removeObserver:tableContentInstance forKeyPath:SPGlobalResultTableFont];
[prefs removeObserver:tableContentInstance forKeyPath:SPDisplayBinaryDataAsHex];
[prefs removeObserver:customQueryInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableRelationsInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableContentInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:[SPQueryController sharedQueryController] forKeyPath:SPUseMonospacedFonts];
[prefs removeObserver:[SPQueryController sharedQueryController] forKeyPath:SPConsoleEnableLogging];
@@ -65,6 +65,12 @@
#import <SPMySQL/SPMySQL.h>
#include <stdlib.h>
/**
* This is the unique KVO context of code that resides in THIS class.
* Do not try to give it to other classes, ESPECIALLY NOT child classes!
*/
static void *TableContentKVOContext = &TableContentKVOContext;
#ifndef SP_CODA
static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOperator";
#endif
@@ -287,6 +293,10 @@ - (void)awakeFromNib
// filterTableDefaultOperator = [[self escapeFilterTableDefaultOperator:nil] retain];
#endif
[prefs addObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:TableContentKVOContext];
[prefs addObserver:self forKeyPath:SPGlobalResultTableFont options:NSKeyValueObservingOptionNew context:TableContentKVOContext];
[prefs addObserver:self forKeyPath:SPDisplayBinaryDataAsHex options:NSKeyValueObservingOptionNew context:TableContentKVOContext];
// Add observers for document task activity
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(startDocumentTaskForTab:)
@@ -4197,22 +4207,28 @@ - (void)documentWillClose:(NSNotification *)notification
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
#ifndef SP_CODA /* observe pref changes */
// Display table veiew vertical gridlines preference changed
if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) {
[tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
[filterTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
}
// Table font preference changed
else if ([keyPath isEqualToString:SPGlobalResultTableFont]) {
NSFont *tableFont = [NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]];
// a parent class (or cocoa) can also use KVO, so we need to watch out to only catch those KVO messages we requested
if(context == TableContentKVOContext) {
// Display table veiew vertical gridlines preference changed
if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) {
[tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
[filterTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
}
// Table font preference changed
else if ([keyPath isEqualToString:SPGlobalResultTableFont]) {
NSFont *tableFont = [NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]];
[tableContentView setRowHeight:2.0f + NSSizeToCGSize([@"{ǞṶḹÜ∑zgyf" sizeWithAttributes:@{NSFontAttributeName : tableFont}]).height];
[tableContentView setFont:tableFont];
[tableContentView reloadData];
[tableContentView setRowHeight:2.0f + NSSizeToCGSize([@"{ǞṶḹÜ∑zgyf" sizeWithAttributes:@{NSFontAttributeName : tableFont}]).height];
[tableContentView setFont:tableFont];
[tableContentView reloadData];
}
// Display binary data as Hex
else if ([keyPath isEqualToString:SPDisplayBinaryDataAsHex] && [tableContentView numberOfRows] > 0) {
[tableContentView reloadData];
}
}
// Display binary data as Hex
else if ([keyPath isEqualToString:SPDisplayBinaryDataAsHex] && [tableContentView numberOfRows] > 0) {
[tableContentView reloadData];
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
#endif
}
@@ -5461,6 +5477,13 @@ - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
if(_mainNibLoaded) {
//TODO this should be changed to the variant with …context: after 10.6 support is removed!
[prefs removeObserver:self forKeyPath:SPGlobalResultTableFont];
[prefs removeObserver:self forKeyPath:SPDisplayBinaryDataAsHex];
[prefs removeObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines];
}
// Cancel previous performSelector: requests on ourselves and the table view
// to prevent crashes for deferred actions
[NSObject cancelPreviousPerformRequestsWithTarget:self];

0 comments on commit 0e5c658

Please sign in to comment.