diff options
-rw-r--r-- | Source/SPDatabaseDocument.m | 8 | ||||
-rw-r--r-- | Source/SPTableContent.m | 51 |
2 files changed, 37 insertions, 22 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index ad7a2614..0ed51ce0 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -6395,7 +6395,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; // 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 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; [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 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; [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]; diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 507aca80..5353b653 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -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 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper // 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 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper - (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 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper { [[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]; |