From 694e5a55fe9f2579fdef121e3da9d300ed372f89 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 14 Nov 2009 22:21:13 +0000 Subject: Updates to the 'use monospaced font' preference, making it a lot more consistent across all table views. Also includes live updating when the preference is changed as well as its implementation in the query console, process list and variables table views. --- Interfaces/English.lproj/Console.xib | 10 +-- Interfaces/English.lproj/DBView.xib | 46 +++++-------- Source/CustomQuery.m | 27 +++++--- Source/SPConstants.h | 3 + Source/SPConstants.m | 3 + Source/SPFieldEditorController.m | 21 +++--- Source/SPProcessListController.m | 28 +++++++- Source/SPQueryController.m | 21 +++++- Source/SPServerVariablesController.m | 28 +++++++- Source/SPTooltip.m | 2 +- Source/TableContent.m | 32 +++++---- Source/TableDocument.m | 24 ++----- Source/TableDump.m | 43 ++++-------- Source/TableSource.m | 126 ++++++++++++++--------------------- 14 files changed, 212 insertions(+), 202 deletions(-) diff --git a/Interfaces/English.lproj/Console.xib b/Interfaces/English.lproj/Console.xib index d84c24b5..1afdbc3b 100644 --- a/Interfaces/English.lproj/Console.xib +++ b/Interfaces/English.lproj/Console.xib @@ -12,8 +12,8 @@ YES + - YES @@ -534,7 +534,7 @@ - 4 + 1 YES 1 YES @@ -645,10 +645,6 @@ - - YES - SPConsoleShowTimestamps - YES @@ -1327,7 +1323,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{255, 481}, {283, 118}} + {{255, 376}, {283, 223}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 37e3ae2e..c5a4bfc4 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -23,7 +23,7 @@ YES - + YES @@ -871,7 +871,7 @@ source - + 256 YES @@ -1964,7 +1964,7 @@ 2 - 13 + 16 -222265344 @@ -2026,7 +2026,7 @@ - QSAAAEEgAABBcAAAQXAAAA + QSAAAEEgAABBkAAAQZAAAA @@ -2132,6 +2132,7 @@ {{10, 7}, {700, 544}} + Structure @@ -2926,7 +2927,7 @@ customQuery - + 256 YES @@ -2953,29 +2954,6 @@ 6418 - - YES - - YES - Apple HTML pasteboard type - Apple PDF pasteboard type - Apple PICT pasteboard type - Apple PNG pasteboard type - Apple URL pasteboard type - CorePasteboardFlavorType 0x6D6F6F76 - NSColor pasteboard type - NSFilenamesPboardType - NSStringPboardType - NeXT Encapsulated PostScript v1.2 pasteboard type - NeXT RTFD pasteboard type - NeXT Rich Text Format v1.0 pasteboard type - NeXT TIFF v4.0 pasteboard type - NeXT font pasteboard type - NeXT ruler pasteboard type - WebURLsWithTitlesPboardType - public.url - - {688, 14} @@ -3798,7 +3776,6 @@ {{10, 7}, {700, 544}} - Custom Query @@ -4843,14 +4820,14 @@ - + 134217731 YES YES YES - + @@ -24954,6 +24931,13 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + TableDocument + + IBProjectSource + Source/SPConnectionDelegate.h + + TableDocument NSDocument diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 14b8c191..f515f335 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -468,11 +468,7 @@ SPTextAndLinkCell *dataCell = [[[SPTextAndLinkCell alloc] initTextCell:@""] autorelease]; [dataCell setEditable:YES]; [dataCell setFormatter:[[SPDataCellFormatter new] autorelease]]; - if ( [prefs boolForKey:SPUseMonospacedFonts] ) { - [dataCell setFont:[NSFont fontWithName:@"Monaco" size:10]]; - } else { - [dataCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - } + [dataCell setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; [dataCell setLineBreakMode:NSLineBreakByTruncatingTail]; [theCol setDataCell:dataCell]; [[theCol headerCell] setStringValue:NSArrayObjectAtIndex(theColumns, i)]; @@ -2623,9 +2619,22 @@ */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + // Display table veiew vertical gridlines preference changed if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [customQueryView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } + // Use monospaced fonts preference changed + else if ([keyPath isEqualToString:SPUseMonospacedFonts]) { + + BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue]; + + for (NSTableColumn *column in [customQueryView tableColumns]) + { + [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + [customQueryView reloadData]; + } } /** @@ -2761,7 +2770,6 @@ for (i=6; i< [menu numberOfItems]; i++) [[menu itemAtIndex:i] setHidden:([[menu itemAtIndex:i] tag] != SP_FAVORITE_HEADER_MENUITEM_TAG && ![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", searchPattern]])]; - } - (IBAction)filterQueryHistory:(id)sender @@ -2771,19 +2779,17 @@ NSString *searchPattern = [queryHistorySearchField stringValue]; for (i=2; i< [menu numberOfItems]; i++) [[menu itemAtIndex:i] setHidden:(![[[menu itemAtIndex:i] title] isMatchedByRegex:[NSString stringWithFormat:@"(?i).*%@.*", searchPattern]])]; - } - (void)awakeFromNib { - // Set pre-defined menu tags [queryFavoritesSaveAsMenuItem setTag:SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG]; [queryFavoritesSaveAllMenuItem setTag:SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG]; // Set the structure and index view's vertical gridlines if required - [customQueryView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; - + [customQueryView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + // Add observers for document task activity [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDocumentTaskForTab:) @@ -2802,6 +2808,7 @@ [usedQuery release]; [fullResult release]; [favoritesManager release]; + if (helpHTMLTemplate) [helpHTMLTemplate release]; if (mySQLversion) [mySQLversion release]; if (sortField) [sortField release]; diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 3c40fc66..af884ac3 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -78,6 +78,9 @@ typedef enum { extern NSString *SPKillProcessQueryMode; extern NSString *SPKillProcessConnectionMode; +// Default monospaced font name +extern NSString *SPDefaultMonospacedFontName; + // Preference key constants // General Prefpane extern NSString *SPDefaultFavorite; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index 4cafc02e..e9a87ff7 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -29,6 +29,9 @@ NSString *SPKillProcessQueryMode = @"SPKillProcessQueryMode"; NSString *SPKillProcessConnectionMode = @"SPKillProcessConnectionMode"; +// Default monospaced font name +NSString *SPDefaultMonospacedFontName = @"Courier"; + // Preference key constants // General Prefpane NSString *SPDefaultFavorite = @"DefaultFavorite"; diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index 96631502..43bab67c 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -131,18 +131,15 @@ - (id)editWithObject:(id)data fieldName:(NSString*)fieldName usingEncoding:(NSStringEncoding)anEncoding isObjectBlob:(BOOL)isFieldBlob isEditable:(BOOL)isEditable withWindow:(NSWindow *)tableWindow { - - if ( ![prefs objectForKey:SPFieldEditorSheetFont] ) - if ( [prefs boolForKey:SPUseMonospacedFonts] ) { - [editTextView setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; - } else { - [editTextView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - // [prefs setObject:[NSArchiver archivedDataWithRootObject:[editTextView font]] forKey:@"FieldEditorSheetFont"]; - } - else + // If required, use monospaced fonts + if (![prefs objectForKey:SPFieldEditorSheetFont]) { + [editTextView setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + else { [editTextView setFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"FieldEditorSheetFont"]]]; + } - [hexTextView setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; + [hexTextView setFont:[NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]]]; [editSheetFieldName setStringValue:[NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Field", @"Field"), fieldName]]; @@ -153,7 +150,7 @@ [editTextView setHidden:YES]; [editTextScrollView setHidden:YES]; - if(!isEditable) { + if (!isEditable) { [editSheetOkButton setHidden:YES]; [editSheetCancelButton setHidden:YES]; [editSheetIsNotEditableCancelButton setHidden:NO]; @@ -180,7 +177,7 @@ [editSheetSegmentControl setHidden:(!isBlob)]; // Set window's min size since no segment and quicklook buttons are hidden - if(isBlob) { + if (isBlob) { [editSheet setFrameAutosaveName:@"SPFieldEditorBlobSheet"]; [editSheet setMinSize:NSMakeSize(560, 200)]; } else { diff --git a/Source/SPProcessListController.m b/Source/SPProcessListController.m index 864bccc3..5087ef2a 100644 --- a/Source/SPProcessListController.m +++ b/Source/SPProcessListController.m @@ -60,8 +60,21 @@ */ - (void)awakeFromNib { + NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; + // Set the process table view's vertical gridlines if required - [processListTableView setGridStyleMask:([[NSUserDefaults standardUserDefaults] boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + [processListTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + + // Set the strutcture and index view's font + BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts]; + + for (NSTableColumn *column in [processListTableView tableColumns]) + { + [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + // Register as an observer for the when the UseMonospacedFonts preference changes + [prefs addObserver:self forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL]; } #pragma mark - @@ -326,9 +339,22 @@ */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + // Display table veiew vertical gridlines preference changed if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [processListTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } + // Use monospaced fonts preference changed + else if ([keyPath isEqualToString:SPUseMonospacedFonts]) { + + BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue]; + + for (NSTableColumn *column in [processListTableView tableColumns]) + { + [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + [processListTableView reloadData]; + } } #pragma mark - diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index f951e582..891f4fb5 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -153,6 +153,13 @@ static SPQueryController *sharedQueryController = nil; // Set the process table view's vertical gridlines if required [consoleTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + // Set the strutcture and index view's font + BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts]; + + for (NSTableColumn *column in [consoleTableView tableColumns]) + { + [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } } #pragma mark - @@ -395,10 +402,22 @@ static SPQueryController *sharedQueryController = nil; if ([keyPath isEqualToString:SPConsoleEnableLogging]) { [loggingDisabledTextField setStringValue:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? @"" : @"Query logging is currently disabled"]; } - // Show/hide vertical grid lines in console table view + // Display table veiew vertical gridlines preference changed else if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [consoleTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } + // Use monospaced fonts preference changed + else if ([keyPath isEqualToString:SPUseMonospacedFonts]) { + + BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue]; + + for (NSTableColumn *column in [consoleTableView tableColumns]) + { + [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + [consoleTableView reloadData]; + } } /** diff --git a/Source/SPServerVariablesController.m b/Source/SPServerVariablesController.m index 17bb5ba0..3046c2dd 100644 --- a/Source/SPServerVariablesController.m +++ b/Source/SPServerVariablesController.m @@ -59,8 +59,21 @@ */ - (void)awakeFromNib { + NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; + // Set the process table view's vertical gridlines if required - [variablesTableView setGridStyleMask:([[NSUserDefaults standardUserDefaults] boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + [variablesTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + + // Set the strutcture and index view's font + BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts]; + + for (NSTableColumn *column in [variablesTableView tableColumns]) + { + [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + // Register as an observer for the when the UseMonospacedFonts preference changes + [prefs addObserver:self forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL]; } #pragma mark - @@ -199,9 +212,22 @@ */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + // Display table veiew vertical gridlines preference changed if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [variablesTableView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } + // Use monospaced fonts preference changed + else if ([keyPath isEqualToString:SPUseMonospacedFonts]) { + + BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue]; + + for (NSTableColumn *column in [variablesTableView tableColumns]) + { + [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + [variablesTableView reloadData]; + } } #pragma mark - diff --git a/Source/SPTooltip.m b/Source/SPTooltip.m index 9b321005..5a0bd954 100644 --- a/Source/SPTooltip.m +++ b/Source/SPTooltip.m @@ -31,7 +31,7 @@ // // [SPTooltip showWithObject:@"

Hello

I am a tooltip" ofType:@"html" // displayOptions:[NSDictionary dictionaryWithObjectsAndKeys: -// @"Monaco", @"fontname", +// SPDefaultMonospacedFontName, @"fontname", // @"#EEEEEE", @"backgroundcolor", // @"20", @"fontsize", // @"transparent", @"transparent", nil]]; diff --git a/Source/TableContent.m b/Source/TableContent.m index d479a3a3..552fbd41 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -119,11 +119,14 @@ return self; } +/** + * Initialise various interface controls + */ - (void)awakeFromNib { // Set the table content view's vertical gridlines if required [tableContentView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; - + // Add observers for document task activity [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDocumentTaskForTab:) @@ -319,11 +322,7 @@ } // Set the data cell font according to the preferences - if ( [prefs boolForKey:SPUseMonospacedFonts] ) { - [dataCell setFont:[NSFont fontWithName:@"Monaco" size:10]]; - } else { - [dataCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - } + [dataCell setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; // Assign the data cell [theCol setDataCell:dataCell]; @@ -1257,14 +1256,8 @@ [tableContentView setVerticalMotionCanBeginDrag:NO]; - if ( [prefs boolForKey:SPUseMonospacedFonts] ) { - [argumentField setFont:[NSFont fontWithName:@"Monaco" size:10]]; - [limitRowsField setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; - } else { - [limitRowsField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - [argumentField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - } [limitRowsStepper setEnabled:NO]; + if ( ![prefs boolForKey:SPLimitResults] ) { [limitRowsField setStringValue:@""]; } @@ -2878,9 +2871,22 @@ */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + // Display table veiew vertical gridlines preference changed if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } + // Use monospaced fonts preference changed + else if ([keyPath isEqualToString:SPUseMonospacedFonts]) { + + BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue]; + + for (NSTableColumn *column in [tableContentView tableColumns]) + { + [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + [tableContentView reloadData]; + } } /** diff --git a/Source/TableDocument.m b/Source/TableDocument.m index df856d33..69fc54d5 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -174,6 +174,12 @@ [prefs addObserver:tableRelationsInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL]; + // Register observers for the when the UseMonospacedFonts preference changes + [prefs addObserver:tableSourceInstance forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:tableContentInstance forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:customQueryInstance forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL]; + // Register observers for when the logging preference changes [prefs addObserver:[SPQueryController sharedQueryController] forKeyPath:SPConsoleEnableLogging options:NSKeyValueObservingOptionNew context:NULL]; @@ -3300,9 +3306,6 @@ [aController setShouldCascadeWindows:YES]; [super windowControllerDidLoadNib:aController]; - //NSEnumerator *theCols = [[variablesTableView tableColumns] objectEnumerator]; - //NSTableColumn *theCol; - //register for notifications [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPerformQuery:) name:@"SMySQLQueryWillBePerformed" object:self]; @@ -3310,21 +3313,6 @@ name:@"SMySQLQueryHasBeenPerformed" object:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:@"NSApplicationWillTerminateNotification" object:nil]; - - //set up interface - /*if ( [prefs boolForKey:SPUseMonospacedFonts] ) { - [[SPQueryController sharedQueryController] setConsoleFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; - - while ( (theCol = [theCols nextObject]) ) { - [[theCol dataCell] setFont:[NSFont fontWithName:@"Monaco" size:10]]; - } - } else { - [[SPQueryController sharedQueryController] setConsoleFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - - while ( (theCol = [theCols nextObject]) ) { - [[theCol dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - } - }*/ } // NSWindow delegate methods diff --git a/Source/TableDump.m b/Source/TableDump.m index 02e46cd7..90c27a42 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -2525,14 +2525,14 @@ [switchButton release]; if ( [prefs boolForKey:SPUseMonospacedFonts] ) { [[[exportDumpTableView tableColumnWithIdentifier:@"tables"] dataCell] - setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; + setFont:[NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]]]; [[[exportMultipleCSVTableView tableColumnWithIdentifier:@"tables"] dataCell] - setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; + setFont:[NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]]]; [[[exportMultipleXMLTableView tableColumnWithIdentifier:@"tables"] dataCell] - setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; + setFont:[NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]]]; [[[fieldMappingTableView tableColumnWithIdentifier:@"0"] dataCell] - setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; - [errorsView setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; + setFont:[NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]]]; + [errorsView setFont:[NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]]]; } else { [[[exportDumpTableView tableColumnWithIdentifier:@"tables"] dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; @@ -2544,7 +2544,6 @@ setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; [errorsView setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; } - // [self reloadTables:self]; } #pragma mark - @@ -2552,30 +2551,15 @@ - (int)numberOfRowsInTableView:(NSTableView *)aTableView; { - if ( aTableView == fieldMappingTableView ) { - return [fieldMappingTableColumnNames count]; - } else { - return [tables count]; - } + return (aTableView == fieldMappingTableView) ? [fieldMappingTableColumnNames count] : [tables count]; } -- (void)tableView:(NSTableView *)aTableView - willDisplayCell:(id)aCell - forTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex +- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { - if ( [[NSUserDefaults standardUserDefaults] boolForKey:SPUseMonospacedFonts] ) { - [aCell setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; - } - else - { - [aCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - } + [aCell setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; } -- (id)tableView:(NSTableView *)aTableView -objectValueForTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { id returnObject = nil; @@ -2603,15 +2587,12 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn return returnObject; } -- (void)tableView:(NSTableView *)aTableView - setObjectValue:(id)anObject - forTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex +- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { if ( aTableView == fieldMappingTableView ) { [fieldMappingArray replaceObjectAtIndex:rowIndex withObject:anObject]; - - } else { + } + else { [[tables objectAtIndex:rowIndex] replaceObjectAtIndex:0 withObject:anObject]; } } diff --git a/Source/TableSource.m b/Source/TableSource.m index 4d89ddbf..932d9cdd 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -216,28 +216,9 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab } else { [indexedColumnsField setNumberOfVisibleItems:10]; } - - // Reset font for field and index table - NSEnumerator *indexColumnsEnumerator = [[indexView tableColumns] objectEnumerator]; - NSEnumerator *fieldColumnsEnumerator = [[tableSourceView tableColumns] objectEnumerator]; - id indexColumn; - id fieldColumn; - BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts]; - - while ( (indexColumn = [indexColumnsEnumerator nextObject]) ) - if ( useMonospacedFont ) - [[indexColumn dataCell] setFont:[NSFont fontWithName:@"Monaco" size:10]]; - else - [[indexColumn dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - - while ( (fieldColumn = [fieldColumnsEnumerator nextObject]) ) - if ( useMonospacedFont ) - [[fieldColumn dataCell] setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; - else - [[fieldColumn dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - - [tableSourceView reloadData]; + [indexView reloadData]; + [tableSourceView reloadData]; // display and *then* tile to force scroll bars to be in the correct position [[tableSourceView enclosingScrollView] display]; @@ -246,8 +227,8 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab // Enable 'Duplicate field' if at least one field is specified // if no field is selected 'Duplicate field' will copy the last field // Enable 'Duplicate field' only for tables! - if([tablesListInstance tableType] == SP_TABLETYPE_TABLE) - [copyFieldButton setEnabled:enableInteraction && ([tableSourceView numberOfRows] > 0)]; + if ([tablesListInstance tableType] == SP_TABLETYPE_TABLE) + [copyFieldButton setEnabled:enableInteraction && ([tableSourceView numberOfRows] > 0)]; else [copyFieldButton setEnabled:NO]; @@ -255,9 +236,9 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; } -/* -reloads the table (performing a new mysql-query) -*/ +/** + * Reloads the table (performing a new mysql-query) + */ - (IBAction)reloadTable:(id)sender { [tableDataInstance resetAllData]; @@ -265,7 +246,6 @@ reloads the table (performing a new mysql-query) [self loadTable:selectedTable]; } - #pragma mark - #pragma mark Edit methods @@ -482,39 +462,15 @@ closes the keySheet #pragma mark - #pragma mark Additional methods -/* -sets the connection (received from TableDocument) and makes things that have to be done only once -*/ +/** + * Sets the connection (received from TableDocument) and makes things that have to be done only once + */ - (void)setConnection:(MCPConnection *)theConnection { - NSEnumerator *indexColumnsEnumerator = [[indexView tableColumns] objectEnumerator]; - NSEnumerator *fieldColumnsEnumerator = [[tableSourceView tableColumns] objectEnumerator]; - id indexColumn; - id fieldColumn; - mySQLConnection = theConnection; - //set up tableView + // Set up tableView [tableSourceView registerForDraggedTypes:[NSArray arrayWithObjects:@"SequelProPasteboard", nil]]; - - while ( (indexColumn = [indexColumnsEnumerator nextObject]) ) { - if ( [prefs boolForKey:SPUseMonospacedFonts] ) { - [[indexColumn dataCell] setFont:[NSFont fontWithName:@"Monaco" size:10]]; - } - else - { - [[indexColumn dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - } - } - while ( (fieldColumn = [fieldColumnsEnumerator nextObject]) ) { - if ( [prefs boolForKey:SPUseMonospacedFonts] ) { - [[fieldColumn dataCell] setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; - } - else - { - [[fieldColumn dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - } - } } /* @@ -822,10 +778,29 @@ fetches the result as an array with a dictionary for each row in it */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + // Display table veiew vertical gridlines preference changed if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) { [tableSourceView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; [indexView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; } + // Use monospaced fonts preference changed + else if ([keyPath isEqualToString:SPUseMonospacedFonts]) { + + BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue]; + + for (NSTableColumn *indexColumn in [indexView tableColumns]) + { + [[indexColumn dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + for (NSTableColumn *fieldColumn in [tableSourceView tableColumns]) + { + [[fieldColumn dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + [tableSourceView reloadData]; + [indexView reloadData]; + } } /** @@ -1057,26 +1032,12 @@ returns a dictionary containing enum/set field names as key and possible values return (aTableView == tableSourceView) ? [tableFields count] : [indexes count]; } -- (id)tableView:(NSTableView *)aTableView - objectValueForTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex -{ - id theRow, theValue; - - if ( aTableView == tableSourceView ) { - theRow = [tableFields objectAtIndex:rowIndex]; - } else { - theRow = [indexes objectAtIndex:rowIndex]; - } - theValue = [theRow objectForKey:[aTableColumn identifier]]; - - return theValue; +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex +{ + return [(aTableView == tableSourceView) ? [tableFields objectAtIndex:rowIndex] : [indexes objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]]; } -- (void)tableView:(NSTableView *)aTableView - setObjectValue:(id)anObject - forTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex +- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { // Make sure that the drag operation is for the right table view if (aTableView!=tableSourceView) return; @@ -1369,12 +1330,12 @@ would result in a position change. - (float)splitView:(NSSplitView *)sender constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)offset { - return proposedMax - 150; + return proposedMax - 150; } - (float)splitView:(NSSplitView *)sender constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset { - return proposedMin + 150; + return proposedMin + 150; } - (NSRect)splitView:(NSSplitView *)splitView additionalEffectiveRectOfDividerAtIndex:(int)dividerIndex @@ -1409,7 +1370,20 @@ would result in a position change. // Set the structure and index view's vertical gridlines if required [tableSourceView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; [indexView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; - + + // Set the strutcture and index view's font + BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts]; + + for (NSTableColumn *indexColumn in [indexView tableColumns]) + { + [[indexColumn dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + + for (NSTableColumn *fieldColumn in [tableSourceView tableColumns]) + { + [[fieldColumn dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + } + // Add observers for document task activity [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDocumentTaskForTab:) -- cgit v1.2.3