From aa3dca31f0509f304df0399b9b7e06a51739bc97 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 25 Mar 2009 01:30:03 +0000 Subject: - Refactor custom query results redrawing code and reset view position to avoid out-of-range assertions when switching from a larger dataset to a smaller dataset; this fixes Issue #189 --- Source/CustomQuery.m | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'Source/CustomQuery.m') diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index a955bec3..e8c7af53 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -278,6 +278,17 @@ sets the tableView columns corresponding to the mysql-result // Notify listeners that a query has started [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self]; + // Reset the current table view as necessary to avoid redraw and reload issues. + // Restore the view position to the top left to be within the results for all datasets. + [customQueryView scrollRowToVisible:0]; + [customQueryView scrollColumnToVisible:0]; + + // Remove all the columns + theColumns = [customQueryView tableColumns]; + while ([theColumns count]) { + [customQueryView removeTableColumn:[theColumns objectAtIndex:0]]; + } + // Perform the supplied queries in series for ( i = 0 ; i < [queries count] ; i++ ) { @@ -373,25 +384,16 @@ sets the tableView columns corresponding to the mysql-result } } - + + + // If no results were returned, redraw the empty table and post notifications before returning. if ( !theResult || ![theResult numOfRows] ) { -//no rows in result - //free tableView - theColumns = [customQueryView tableColumns]; - while ([theColumns count]) { - [customQueryView removeTableColumn:[theColumns objectAtIndex:0]]; - } -// theCol = [[NSTableColumn alloc] initWithIdentifier:@""]; -// [[theCol headerCell] setStringValue:@""]; -// [customQueryView addTableColumn:theCol]; -// [customQueryView sizeLastColumnToFit]; [customQueryView reloadData]; -// [theCol release]; - //query finished + // Notify any listeners that the query has completed [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self]; - // Query finished Growl notification + // Perform the Growl notification for query completion [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Query Finished" description:[NSString stringWithFormat:NSLocalizedString(@"%@",@"description for query finished growl notification"), [errorText stringValue]] notificationName:@"Query Finished"]; @@ -399,16 +401,8 @@ sets the tableView columns corresponding to the mysql-result return; } -//set columns -//remove all columns - theColumns = [customQueryView tableColumns]; -// i=0; - while ([theColumns count]) { - [customQueryView removeTableColumn:[theColumns objectAtIndex:0]]; -// i++; - } -//add columns, corresponding to the query result + // Otherwise add columns corresponding to the query result theColumns = [theResult fetchFieldNames]; for ( i = 0 ; i < [theResult numOfFields] ; i++) { theCol = [[NSTableColumn alloc] initWithIdentifier:[NSNumber numberWithInt:i]]; -- cgit v1.2.3