From c3dbdaa772c2fe53cd0ac60e91d83df724483aa1 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Fri, 24 Jul 2009 00:10:17 +0000 Subject: - For custom query result columns which map to SQL fields, check the column width memory to set column widths - Save custom query result columns back to the master column width store for columns witch map to SQL fields --- Source/CustomQuery.h | 2 +- Source/CustomQuery.m | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) (limited to 'Source') diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index fe2865ab..618bd0d0 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -35,6 +35,7 @@ @interface CustomQuery : NSObject { + IBOutlet id tableDocumentInstance; IBOutlet id tableWindow; IBOutlet id queryFavoritesButton; IBOutlet id queryHistoryButton; @@ -98,7 +99,6 @@ BOOL queryIsTableSorter; BOOL isDesc; NSNumber *sortField; - BOOL tempAlertWasShown; // a temp value for nightly builts } diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index f5742df4..bf15ff30 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -674,7 +674,8 @@ if(!tableReloadAfterEditing) { for ( i = 0 ; i < [theResult numOfFields] ; i++) { - theCol = [[NSTableColumn alloc] initWithIdentifier:[NSArrayObjectAtIndex(cqColumnDefinition,i) objectForKey:@"datacolumnindex"]]; + NSDictionary *columnDefinition = NSArrayObjectAtIndex(cqColumnDefinition,i); + theCol = [[NSTableColumn alloc] initWithIdentifier:[columnDefinition objectForKey:@"datacolumnindex"]]; [theCol setResizingMask:NSTableColumnUserResizingMask]; [theCol setEditable:YES]; SPTextAndLinkCell *dataCell = [[[SPTextAndLinkCell alloc] initTextCell:@""] autorelease]; @@ -689,6 +690,14 @@ [theCol setDataCell:dataCell]; [[theCol headerCell] setStringValue:NSArrayObjectAtIndex(theColumns, i)]; + // Set the width of this column to saved value if exists and maps to a real column + if ([columnDefinition objectForKey:@"org_name"] && [[columnDefinition objectForKey:@"org_name"] length]) { + NSNumber *colWidth = [[[[prefs objectForKey:@"tableColumnWidths"] objectForKey:[NSString stringWithFormat:@"%@@%@", [columnDefinition objectForKey:@"db"], [tableDocumentInstance host]]] objectForKey:[columnDefinition objectForKey:@"org_table"]] objectForKey:[columnDefinition objectForKey:@"org_name"]]; + if ( colWidth ) { + [theCol setWidth:[colWidth floatValue]]; + } + } + [customQueryView addTableColumn:theCol]; [theCol release]; } @@ -1117,7 +1126,6 @@ } hasBackgroundAttribute = NO; - tempAlertWasShown = NO; //temp for nightly builds // Set up the interface // Bind backgroundColor @@ -1649,6 +1657,55 @@ } } +/** + * Saves the new column size in the preferences for columns which map to fields + */ +- (void)tableViewColumnDidResize:(NSNotification *)aNotification +{ + // Abort if still loading the table + if (![cqColumnDefinition count]) return; +NSLog(@"start"); + // Retrieve the original index of the column from the identifier + int columnIndex = [[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier] intValue]; + NSDictionary *columnDefinition = NSArrayObjectAtIndex(cqColumnDefinition, columnIndex); + NSLog(@"1"); + // Don't save if the column doesn't map to an underlying SQL field + if (![columnDefinition objectForKey:@"org_name"] || ![[columnDefinition objectForKey:@"org_name"] length]) + return; + NSLog(@"2"); + + NSMutableDictionary *tableColumnWidths; + NSString *host_db = [NSString stringWithFormat:@"%@@%@", [columnDefinition objectForKey:@"db"], [tableDocumentInstance host]]; + NSString *table = [columnDefinition objectForKey:@"org_table"]; + NSString *col = [columnDefinition objectForKey:@"org_name"]; + + // Retrieve or instantiate the tableColumnWidths object + if ([prefs objectForKey:@"tableColumnWidths"] != nil) { + tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:@"tableColumnWidths"]]; + } else { + tableColumnWidths = [NSMutableDictionary dictionary]; + } + + // Edit or create database object + if ([tableColumnWidths objectForKey:host_db] == nil) { + [tableColumnWidths setObject:[NSMutableDictionary dictionary] forKey:host_db]; + } else { + [tableColumnWidths setObject:[NSMutableDictionary dictionaryWithDictionary:[tableColumnWidths objectForKey:host_db]] forKey:host_db]; + } + + // Edit or create table object + if ([[tableColumnWidths objectForKey:host_db] objectForKey:table] == nil) { + [[tableColumnWidths objectForKey:host_db] setObject:[NSMutableDictionary dictionary] forKey:table]; + } else { + [[tableColumnWidths objectForKey:host_db] setObject:[NSMutableDictionary dictionaryWithDictionary:[[tableColumnWidths objectForKey:host_db] objectForKey:table]] forKey:table]; + } + + // Save the column size + [[[tableColumnWidths objectForKey:host_db] objectForKey:table] setObject:[NSNumber numberWithFloat:[[[aNotification userInfo] objectForKey:@"NSTableColumn"] width]] forKey:col]; + [prefs setObject:tableColumnWidths forKey:@"tableColumnWidths"]; +} + + #pragma mark - #pragma mark TextView delegate methods -- cgit v1.2.3