From 4f1551950fb585328fe808f553122ff576063bab Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Thu, 17 Jan 2013 16:59:11 +0000 Subject: Small table info tidy up. --- Source/SPTableInfo.h | 1 - Source/SPTableInfo.m | 130 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 80 insertions(+), 51 deletions(-) diff --git a/Source/SPTableInfo.h b/Source/SPTableInfo.h index a6967c10..bcaad21f 100644 --- a/Source/SPTableInfo.h +++ b/Source/SPTableInfo.h @@ -39,7 +39,6 @@ IBOutlet id tableDocumentInstance; IBOutlet NSTableView *activitiesTable; - IBOutlet NSScrollView *tableInfoScrollView; NSMutableArray *info; diff --git a/Source/SPTableInfo.m b/Source/SPTableInfo.m index eabf45e7..3ccb1515 100644 --- a/Source/SPTableInfo.m +++ b/Source/SPTableInfo.m @@ -46,11 +46,15 @@ @implementation SPTableInfo +#pragma mark - +#pragma mark Initialisation + - (id)init { if ((self = [super init])) { info = [[NSMutableArray alloc] init]; activities = [[NSMutableArray alloc] init]; + _activitiesWillBeUpdated = NO; } @@ -59,7 +63,6 @@ - (void)awakeFromNib { - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableChanged:) name:SPTableChangedNotification @@ -80,15 +83,7 @@ [infoTable reloadData]; } -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [info release]; - [activities release]; - - [super dealloc]; -} +#pragma mark - /** * Remove an activity directly from the list since an update will be performer in the background @@ -96,25 +91,32 @@ */ - (void)removeActivity:(NSInteger)pid { - for(id cmd in activities) { - if([[cmd objectForKey:@"pid"] integerValue] == pid) { + for(id cmd in activities) + { + if ([[cmd objectForKey:@"pid"] integerValue] == pid) { [activities removeObject:cmd]; break; } } + [activitiesTable reloadData]; } - (void)updateActivities { NSMutableArray *acts = [NSMutableArray array]; + [acts removeAllObjects]; [acts addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"ACTIVITIES", @"header for activities pane"), @"name", nil]]; [acts addObjectsFromArray:[tableDocumentInstance runningActivities]]; [acts addObjectsFromArray:[[NSApp delegate] runningActivities]]; + _activitiesWillBeUpdated = YES; + [activities setArray:acts]; + _activitiesWillBeUpdated = NO; + [activitiesTable reloadData]; [infoTable deselectAll:nil]; [activitiesTable deselectAll:nil]; @@ -136,9 +138,11 @@ if (![tableListInstance tableName]) { [info addObject:NSLocalizedString(@"INFORMATION", @"header for blank info pane")]; + if ([[tableListInstance selectedTableItems] count]) { [info addObject:NSLocalizedString(@"multiple selection", @"multiple selection")]; } + [infoTable reloadData]; return; } @@ -194,7 +198,6 @@ } } - // Get PROC/FUNC information else if ([tableListInstance tableType] == SPTableTypeProc || [tableListInstance tableType] == SPTableTypeFunc) { @@ -298,59 +301,63 @@ if (![[tableStatus objectForKey:@"COLLATION_CONNECTION"] isNSNull]) { [info addObject:[NSString stringWithFormat:NSLocalizedString(@"collation connection: %@", @"collation connection: %@"), [tableStatus objectForKey:@"COLLATION_CONNECTION"]]]; } - } } } [infoTable reloadData]; - } #pragma mark - #pragma mark TableView datasource methods -- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView +- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { - if(aTableView == infoTable) { - return [info count]; - } else { - return [activities count]; - } + return (tableView == infoTable) ? [info count] : [activities count]; } -- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex { - if(aTableView == infoTable) { + if (tableView == infoTable) { return [info objectAtIndex:rowIndex]; - } else { - if(rowIndex == 0) - { + } + else { + if (rowIndex == 0) { SPTableTextFieldCell *c = [[[SPTableTextFieldCell alloc] initTextCell:NSLocalizedString(@"ACTIVITIES", @"header for activities pane")] autorelease]; - [aTableColumn setDataCell:c]; + + [tableColumn setDataCell:c]; + return NSLocalizedString(@"ACTIVITIES", @"header for activities pane"); } - else if(!_activitiesWillBeUpdated && rowIndex > 0 && rowIndex < (NSInteger)[activities count]) { + else if (!_activitiesWillBeUpdated && rowIndex > 0 && rowIndex < (NSInteger)[activities count]) { NSDictionary *dict = NSArrayObjectAtIndex(activities,rowIndex); SPActivityTextFieldCell *c = [[[SPActivityTextFieldCell alloc] init] autorelease]; + [c setActivityName:[[dict objectForKey:@"contextInfo"] objectForKey:@"name"]]; - if([dict objectForKey:@"type"] && [[dict objectForKey:@"type"] isEqualToString:@"bashcommand"]) { + + if ([dict objectForKey:@"type"] && [[dict objectForKey:@"type"] isEqualToString:@"bashcommand"]) { [c setContextInfo:[NSDictionary dictionaryWithObjectsAndKeys:[dict objectForKey:@"type"], @"type", [dict objectForKey:@"pid"], @"pid", nil]]; [c setActivityInfo:[NSString stringWithFormat:@"[%@] %@: %@", [[dict objectForKey:@"contextInfo"] objectForKey:@"scope"], NSLocalizedString(@"started", @"started"), [dict objectForKey:@"starttime"]]]; } else { [c setActivityInfo:@"..."]; } - [aTableColumn setDataCell:c]; + + [tableColumn setDataCell:c]; + return [dict objectForKey:@"name"]; - } else { + } + else { SPActivityTextFieldCell *c = [[[SPActivityTextFieldCell alloc] init] autorelease]; + [c setActivityName:@"..."]; [c setActivityInfo:@""]; - [aTableColumn setDataCell:c]; + [tableColumn setDataCell:c]; + return @"..."; } + return @""; } } @@ -362,23 +369,27 @@ - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex { - if(rowIndex == 0) return YES; - if(aTableView == infoTable) { + if (rowIndex == 0) return YES; + + if (aTableView == infoTable) { return NO; - } else { + } + else { return YES; } + return NO; } - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - if(rowIndex > 0) return NO; + if (rowIndex > 0) return NO; - if(![tableInfoScrollView isHidden]) { + if (![tableInfoScrollView isHidden]) { [tableDocumentInstance setActivityPaneHidden:[NSNumber numberWithInteger:0]]; [[NSApp mainWindow] makeFirstResponder:activitiesTable]; - } else { + } + else { [tableDocumentInstance setActivityPaneHidden:[NSNumber numberWithInteger:1]]; [[NSApp mainWindow] makeFirstResponder:infoTable]; } @@ -386,20 +397,28 @@ [infoTable deselectAll:nil]; [activitiesTable deselectAll:nil]; [self updateActivities]; + return NO; } - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex mouseLocation:(NSPoint)mouseLocation { - if(aTableView == activitiesTable) { - if(rowIndex == 0) return @""; - if(mouseLocation.x > rect->origin.x + rect->size.width - 30) + if (aTableView == activitiesTable) { + if (rowIndex == 0) return @""; + + if (mouseLocation.x > rect->origin.x + rect->size.width - 30) { return NSLocalizedString(@"Cancel", @"cancel"); + } + NSDictionary *dict = NSArrayObjectAtIndex(activities,rowIndex); - if([[dict objectForKey:@"contextInfo"] objectForKey:@"name"]) + + if ([[dict objectForKey:@"contextInfo"] objectForKey:@"name"]) { return [[dict objectForKey:@"contextInfo"] objectForKey:@"name"]; + } + return @""; } + return nil; } @@ -411,25 +430,24 @@ - (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - if(aTableView == infoTable) { - if ((rowIndex > 0) && [[aTableColumn identifier] isEqualToString:@"info"]) { + if (aTableView == infoTable) { + if (rowIndex > 0 && [[aTableColumn identifier] isEqualToString:@"info"]) { [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"table-property"]]; [(ImageAndTextCell*)aCell setIndentationLevel:1]; [(ImageAndTextCell*)aCell setDrawsBackground:NO]; - } else { + } + else { [(ImageAndTextCell*)aCell setImage:nil]; [(ImageAndTextCell*)aCell setIndentationLevel:0]; } } } -@end - -@implementation SPTableInfo (PrivateAPI) +#pragma mark - +#pragma mark Private API - (NSString *)_getUserDefinedDateStringFromMySQLDate:(NSString *)mysqlDate { - // Setup our data formatter NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; @@ -437,10 +455,22 @@ [dateFormatter setDateStyle:NSDateFormatterShortStyle]; [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; - // Convert our string date from the result to an NSDate. + // Convert our string date from the result to an NSDate NSDate *updateDate = [NSDate dateWithNaturalLanguageString:mysqlDate]; return [dateFormatter stringFromDate:updateDate]; } +#pragma mark - + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + [info release]; + [activities release]; + + [super dealloc]; +} + @end -- cgit v1.2.3