From eb72b9122f57fa31c86229c3c698d90853dcb4ec Mon Sep 17 00:00:00 2001 From: avenjamin Date: Wed, 7 May 2008 04:02:13 +0000 Subject: Changed the tables list, custom cell to handle image+text+indentation, added table information (commented out until bug resolved) --- TableContent.m | 910 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 455 insertions(+), 455 deletions(-) (limited to 'TableContent.m') diff --git a/TableContent.m b/TableContent.m index 7bab5e3a..86ca54ce 100644 --- a/TableContent.m +++ b/TableContent.m @@ -51,17 +51,17 @@ - (void)loadTable:(NSString *)aTable /* -loads aTable, put it in an array, update the tableViewColumns and reload the tableView -*/ + loads aTable, put it in an array, update the tableViewColumns and reload the tableView + */ { int i; NSNumber *colWidth; NSArray *theColumns; NSTableColumn *theCol; -// NSNumberFormatter *numberFormatter; + // NSNumberFormatter *numberFormatter; NSString *query; CMMCPResult *queryResult; - + selectedTable = aTable; [tableContentView deselectAll:self]; if ( isEditingRow ) @@ -69,7 +69,7 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab //query started [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self]; - + [limitRowsField setStringValue:@"1"]; //reset keys @@ -79,24 +79,24 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [tableContentView scrollRowToVisible:0]; [tableContentView scrollColumnToVisible:0]; - + if ( [aTable isEqualToString:@""] || !aTable ) { -//no table selected - //free tableView + //no table selected + //free tableView theColumns = [tableContentView tableColumns]; while ([theColumns count]) { [tableContentView removeTableColumn:[theColumns objectAtIndex:0]]; } -// theCol = [[NSTableColumn alloc] initWithIdentifier:@""]; -// [[theCol headerCell] setStringValue:@""]; -// [tableContentView addTableColumn:theCol]; -// [tableContentView sizeLastColumnToFit]; + // theCol = [[NSTableColumn alloc] initWithIdentifier:@""]; + // [[theCol headerCell] setStringValue:@""]; + // [tableContentView addTableColumn:theCol]; + // [tableContentView sizeLastColumnToFit]; [fullResult removeAllObjects]; [filteredResult removeAllObjects]; [tableContentView reloadData]; -// [theCol release]; - - //disable filter options + // [theCol release]; + + //disable filter options [fieldField setEnabled:NO]; [fieldField removeAllItems]; [fieldField addItemWithTitle:NSLocalizedString(@"field", @"popup menuitem for field (showing only if disabled)")]; @@ -107,11 +107,11 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [argumentField setStringValue:@""]; [filterButton setEnabled:NO]; areShowingAllRows = YES; - - //disable limit fields + + //disable limit fields if ( [prefs boolForKey:@"limitRows"] ) { [limitRowsText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Limited to %d rows starting with row", @"text showing the number of rows the result is limited to"), - [prefs integerForKey:@"limitRowsValue"]]]; + [prefs integerForKey:@"limitRowsValue"]]]; } else { [limitRowsField setStringValue:@""]; [limitRowsText setStringValue:NSLocalizedString(@"No limit", @"text showing that the result isn't limited")]; @@ -119,58 +119,58 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [limitRowsField setEnabled:NO]; [limitRowsButton setEnabled:NO]; [limitRowsStepper setEnabled:NO]; - - //disable buttons + + //disable buttons [addButton setEnabled:NO]; [copyButton setEnabled:NO]; [removeButton setEnabled:NO]; - + [countText setStringValue:@""]; - + //query finished [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self]; - + return; } - -//make a fast query to get fieldNames and fieldTypes (used in fieldListForQuery method) + + //make a fast query to get fieldNames and fieldTypes (used in fieldListForQuery method) queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT * FROM `%@` LIMIT 0", selectedTable]]; fieldTypes = [[queryResult fetchTypesAsArray] retain]; fieldNames = [[queryResult fetchFieldNames] retain]; - -//perform query and load result in array (each row as a dictionary) -// queryResult = [mySQLConnection queryString:[@"SELECT * FROM " stringByAppendingString:selectedTable]]; + + //perform query and load result in array (each row as a dictionary) + // queryResult = [mySQLConnection queryString:[@"SELECT * FROM " stringByAppendingString:selectedTable]]; query = [NSString stringWithFormat:@"SELECT %@ FROM `%@`", [self fieldListForQuery], selectedTable]; if ( [prefs boolForKey:@"limitRows"] ) { if ( [limitRowsField intValue] <= 0 ) { [limitRowsField setStringValue:@"1"]; } query = [query stringByAppendingString: - [NSString stringWithFormat:@" LIMIT %d,%d", - [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; + [NSString stringWithFormat:@" LIMIT %d,%d", + [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; } -// [queryResult release]; + // [queryResult release]; queryResult = [mySQLConnection queryString:query]; -// [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; + // [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; [fullResult setArray:[self fetchResultAsArray:queryResult]]; [filteredResult setArray:fullResult]; -// fieldTypes = [[queryResult fetchTypesAsArray] retain]; -// fieldNames = [[queryResult fetchFieldNames] retain]; - -//set count text + // fieldTypes = [[queryResult fetchTypesAsArray] retain]; + // fieldNames = [[queryResult fetchFieldNames] retain]; + + //set count text numRows = [self getNumberOfRows]; [countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows in table", @"text showing how many rows are in the result"), numRows]]; - -//clear sorting + + //clear sorting sortField = nil; isDesc = NO; - + if ( queryResult == nil ) { NSLog(@"Loading table %@ failed, query string was: %@", aTable, query); return; } - -//enable and initialize filter fields (with tags for position of menu item and field position) + + //enable and initialize filter fields (with tags for position of menu item and field position) [fieldField setEnabled:YES]; [fieldField removeAllItems]; [fieldField addItemsWithTitles:fieldNames]; @@ -183,14 +183,14 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [argumentField setStringValue:@""]; [filterButton setEnabled:YES]; areShowingAllRows = YES; - -//enable or disable limit fields + + //enable or disable limit fields if ( [prefs boolForKey:@"limitRows"] ) { [limitRowsField setEnabled:YES]; [limitRowsButton setEnabled:YES]; [limitRowsStepper setEnabled:YES]; [limitRowsText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Limited to %d rows starting with row", @"text showing the number of rows the result is limited to"), - [prefs integerForKey:@"limitRowsValue"]]]; + [prefs integerForKey:@"limitRowsValue"]]]; } else { [limitRowsField setEnabled:NO]; [limitRowsButton setEnabled:NO]; @@ -198,13 +198,13 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [limitRowsField setStringValue:@""]; [limitRowsText setStringValue:NSLocalizedString(@"No limit", @"text showing that the result isn't limited")]; } - -//enable buttons + + //enable buttons [addButton setEnabled:YES]; [copyButton setEnabled:YES]; [removeButton setEnabled:YES]; - -//set columns + + //set columns //remove all columns from table theColumns = [tableContentView tableColumns]; i=0; @@ -212,17 +212,17 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [tableContentView removeTableColumn:[theColumns objectAtIndex:0]]; i++; } - + //add columns, corresponding to the query result theColumns = fieldNames; for ( i = 0 ; i < [theColumns count] ; i++ ) { theCol = [[NSTableColumn alloc] initWithIdentifier:[theColumns objectAtIndex:i]]; [theCol setEditable:YES]; if ( [theCol respondsToSelector:@selector(setResizingMask:)] ) { - // os 10.4 + // os 10.4 [theCol setResizingMask:NSTableColumnUserResizingMask]; } else { - // os pre-10.4 + // os pre-10.4 [theCol setResizable:YES]; } NSComboBoxCell *dataCell; @@ -239,57 +239,57 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab dataCell = [[[NSTextFieldCell alloc] initTextCell:@""] autorelease]; } [dataCell setEditable:YES]; -// [[theCol dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; + // [[theCol dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; if ( [prefs boolForKey:@"useMonospacedFonts"] ) { -// [[theCol dataCell] setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; + // [[theCol dataCell] setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]]; [dataCell setFont:[NSFont fontWithName:@"Monaco" size:10]]; } else { [dataCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; } if ( [dataCell respondsToSelector:@selector(setLineBreakMode:)] ) { - // os 10.4 + // os 10.4 [dataCell setLineBreakMode:NSLineBreakByTruncatingTail]; } [theCol setDataCell:dataCell]; //set date and number formatters -/* - if ([[fieldTypes objectAtIndex:i] isEqualToString:@"timestamp"]) { - [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] - initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:YES]]; - } - if ([[fieldTypes objectAtIndex:i] isEqualToString:@"datetime"]) { - [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:YES]]; - } - if ([[fieldTypes objectAtIndex:i] isEqualToString:@"date"]) { - [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d" allowNaturalLanguage:YES]]; - } - if ([[fieldTypes objectAtIndex:i] isEqualToString:@"time"]) { - [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%H:%M:%S" allowNaturalLanguage:YES]]; - } - if ([[fieldTypes objectAtIndex:i] isEqualToString:@"year"]) { - [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y" allowNaturalLanguage:YES]]; - } - if ([[fieldTypes objectAtIndex:i] isEqualToString:@"tiny"] || [[fieldTypes objectAtIndex:i] isEqualToString:@"short"] - || [[fieldTypes objectAtIndex:i] isEqualToString:@"long"] || [[fieldTypes objectAtIndex:i] isEqualToString:@"int24"] - || [[fieldTypes objectAtIndex:i] isEqualToString:@"longlong"] ) { - numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; - [numberFormatter setFormat:@"0"]; - [numberFormatter setAttributedStringForNil:[[NSAttributedString alloc] initWithString:[prefs stringForKey:@"nullValue"]]]; - [numberFormatter setAllowsFloats:NO]; - [[theCol dataCell] setFormatter:numberFormatter]; - } - if ( [[fieldTypes objectAtIndex:i] isEqualToString:@"decimal"] || [[fieldTypes objectAtIndex:i] isEqualToString:@"float"] - || [[fieldTypes objectAtIndex:i] isEqualToString:@"double"] ) { - numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; - //here we should allow any number of decimal values (after the comma) - //problem with float-numbers like 2.13231e+08 - //double numbers doesn't have all decimal values - //-> bugs in the framework? - [numberFormatter setFormat:@"0.####################"]; - [numberFormatter setAttributedStringForNil:[[NSAttributedString alloc] initWithString:[prefs stringForKey:@"nullValue"]]]; - [[theCol dataCell] setFormatter:numberFormatter]; - } -*/ + /* + if ([[fieldTypes objectAtIndex:i] isEqualToString:@"timestamp"]) { + [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] + initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:YES]]; + } + if ([[fieldTypes objectAtIndex:i] isEqualToString:@"datetime"]) { + [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:YES]]; + } + if ([[fieldTypes objectAtIndex:i] isEqualToString:@"date"]) { + [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d" allowNaturalLanguage:YES]]; + } + if ([[fieldTypes objectAtIndex:i] isEqualToString:@"time"]) { + [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%H:%M:%S" allowNaturalLanguage:YES]]; + } + if ([[fieldTypes objectAtIndex:i] isEqualToString:@"year"]) { + [[theCol dataCell] setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y" allowNaturalLanguage:YES]]; + } + if ([[fieldTypes objectAtIndex:i] isEqualToString:@"tiny"] || [[fieldTypes objectAtIndex:i] isEqualToString:@"short"] + || [[fieldTypes objectAtIndex:i] isEqualToString:@"long"] || [[fieldTypes objectAtIndex:i] isEqualToString:@"int24"] + || [[fieldTypes objectAtIndex:i] isEqualToString:@"longlong"] ) { + numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + [numberFormatter setFormat:@"0"]; + [numberFormatter setAttributedStringForNil:[[NSAttributedString alloc] initWithString:[prefs stringForKey:@"nullValue"]]]; + [numberFormatter setAllowsFloats:NO]; + [[theCol dataCell] setFormatter:numberFormatter]; + } + if ( [[fieldTypes objectAtIndex:i] isEqualToString:@"decimal"] || [[fieldTypes objectAtIndex:i] isEqualToString:@"float"] + || [[fieldTypes objectAtIndex:i] isEqualToString:@"double"] ) { + numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + //here we should allow any number of decimal values (after the comma) + //problem with float-numbers like 2.13231e+08 + //double numbers doesn't have all decimal values + //-> bugs in the framework? + [numberFormatter setFormat:@"0.####################"]; + [numberFormatter setAttributedStringForNil:[[NSAttributedString alloc] initWithString:[prefs stringForKey:@"nullValue"]]]; + [[theCol dataCell] setFormatter:numberFormatter]; + } + */ [[theCol headerCell] setStringValue:[theColumns objectAtIndex:i]]; // set width of column to saved value if exists colWidth = [[[[prefs objectForKey:@"tableColumnWidths"] objectForKey:[NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]]] objectForKey:[tablesListInstance table]] objectForKey:[theColumns objectAtIndex:i]]; @@ -299,15 +299,15 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab [tableContentView addTableColumn:theCol]; [theCol release]; } - -// [tableContentView sizeLastColumnToFit]; + + // [tableContentView sizeLastColumnToFit]; //tries to fix problem with last row (otherwise to small) //sets last column to width of the first if smaller than 30 //problem not fixed for resizing window -// if ( [[tableContentView tableColumnWithIdentifier:[theColumns objectAtIndex:[theColumns count]-1]] width] < 30 ) -// [[tableContentView tableColumnWithIdentifier:[theColumns objectAtIndex:[theColumns count]-1]] -// setWidth:[[tableContentView tableColumnWithIdentifier:[theColumns objectAtIndex:0]] width]]; - + // if ( [[tableContentView tableColumnWithIdentifier:[theColumns objectAtIndex:[theColumns count]-1]] width] < 30 ) + // [[tableContentView tableColumnWithIdentifier:[theColumns objectAtIndex:[theColumns count]-1]] + // setWidth:[[tableContentView tableColumnWithIdentifier:[theColumns objectAtIndex:0]] width]]; + [tableContentView reloadData]; //query finished @@ -316,30 +316,30 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab - (IBAction)reloadTable:(id)sender /* -reloads the table (performing a new mysql-query) -*/ + reloads the table (performing a new mysql-query) + */ { [self loadTable:selectedTable]; } - (IBAction)reloadTableValues:(id)sender /* -reload the table values without reconfiguring the tableView (with filter and limit if set) -*/ + reload the table values without reconfiguring the tableView (with filter and limit if set) + */ { NSString *queryString; CMMCPResult *queryResult; - + //query started [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self]; - -//enable or disable limit fields + + //enable or disable limit fields if ( [prefs boolForKey:@"limitRows"] ) { [limitRowsField setEnabled:YES]; [limitRowsButton setEnabled:YES]; [limitRowsStepper setEnabled:YES]; [limitRowsText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Limited to %d rows starting with row", @"text showing the number of rows the result is limited to"), - [prefs integerForKey:@"limitRowsValue"]]]; + [prefs integerForKey:@"limitRowsValue"]]]; } else { [limitRowsField setEnabled:NO]; [limitRowsButton setEnabled:NO]; @@ -347,12 +347,12 @@ reload the table values without reconfiguring the tableView (with filter and lim [limitRowsText setStringValue:NSLocalizedString(@"No limit", @"text showing that the result isn't limited")]; [limitRowsField setStringValue:@""]; } - -// queryString = [@"SELECT * FROM " stringByAppendingString:selectedTable]; + + // queryString = [@"SELECT * FROM " stringByAppendingString:selectedTable]; queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@`", [self fieldListForQuery], selectedTable]; if ( sortField ) { queryString = [NSString stringWithFormat:@"%@ ORDER BY `%@`", queryString, sortField]; -// queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]]; + // queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]]; if ( isDesc ) queryString = [queryString stringByAppendingString:@" DESC"]; } @@ -361,12 +361,12 @@ reload the table values without reconfiguring the tableView (with filter and lim [limitRowsField setStringValue:@"1"]; } queryString = [queryString stringByAppendingString: - [NSString stringWithFormat:@" LIMIT %d,%d", - [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; + [NSString stringWithFormat:@" LIMIT %d,%d", + [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; [limitRowsField selectText:self]; } queryResult = [mySQLConnection queryString:queryString]; -// [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; + // [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; [fullResult setArray:[self fetchResultAsArray:queryResult]]; numRows = [self getNumberOfRows]; if ( !areShowingAllRows ) { @@ -377,7 +377,7 @@ reload the table values without reconfiguring the tableView (with filter and lim [countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows in table", @"text showing how many rows are in the result"), numRows]]; } [tableContentView reloadData]; - + //query finished [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self]; } @@ -493,12 +493,12 @@ reload the table values without reconfiguring the tableView (with filter and lim } [argument setString:[mySQLConnection prepareString:argument]]; queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@` WHERE `%@` %@ \"%@\"", - [self fieldListForQuery], selectedTable, [fieldField titleOfSelectedItem], - compareOperator, argument]; + [self fieldListForQuery], selectedTable, [fieldField titleOfSelectedItem], + compareOperator, argument]; } else { queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@` WHERE `%@` %@ %@", - [self fieldListForQuery], selectedTable, [fieldField titleOfSelectedItem], - compareOperator, argument]; + [self fieldListForQuery], selectedTable, [fieldField titleOfSelectedItem], + compareOperator, argument]; } if ( sortField ) { // queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]]; @@ -511,8 +511,8 @@ reload the table values without reconfiguring the tableView (with filter and lim [limitRowsField setStringValue:@"1"]; } queryString = [queryString stringByAppendingString: - [NSString stringWithFormat:@" LIMIT %d,%d", - [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; + [NSString stringWithFormat:@" LIMIT %d,%d", + [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; } } else { NSLog(@"ERROR: unknown compare type %@", compareType); @@ -540,7 +540,7 @@ reload the table values without reconfiguring the tableView (with filter and lim [filteredResult setArray:fullResult]; [tableContentView reloadData]; areShowingAllRows = YES; - + [countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows in table", @"text showing how many rows are in the result"), numRows]]; } @@ -548,22 +548,22 @@ reload the table values without reconfiguring the tableView (with filter and lim //edit methods - (IBAction)addRow:(id)sender /* -adds an empty row to the table-array and goes into edit mode -*/ + adds an empty row to the table-array and goes into edit mode + */ { NSMutableDictionary *newRow = [NSMutableDictionary dictionary]; int i; - + if ( ![self selectionShouldChangeInTableView:nil] ) return; - + for ( i = 0 ; i < [fieldNames count] ; i++ ) { -// [newRow setObject:[prefs stringForKey:@"nullValue"] forKey:[fieldNames objectAtIndex:i]]; + // [newRow setObject:[prefs stringForKey:@"nullValue"] forKey:[fieldNames objectAtIndex:i]]; [newRow setObject:[tableSourceInstance defaultValueForField:[fieldNames objectAtIndex:i]] - forKey:[fieldNames objectAtIndex:i]]; + forKey:[fieldNames objectAtIndex:i]]; } [filteredResult addObject:newRow]; - + isEditingRow = YES; isEditingNewRow = YES; [tableContentView reloadData]; @@ -574,14 +574,14 @@ adds an empty row to the table-array and goes into edit mode - (IBAction)copyRow:(id)sender /* -copies a row of the table-array and goes into edit mode -*/ + copies a row of the table-array and goes into edit mode + */ { NSMutableDictionary *tempRow; CMMCPResult *queryResult; NSDictionary *row; int i; - + if ( ![self selectionShouldChangeInTableView:nil] ) return; if ( [tableContentView numberOfSelectedRows] < 1 ) @@ -590,7 +590,7 @@ copies a row of the table-array and goes into edit mode NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"You can only copy single rows.", @"message of panel when trying to copy multiple rows")); return; } - + //copy row tempRow = [NSMutableDictionary dictionaryWithDictionary:[filteredResult objectAtIndex:[tableContentView selectedRow]]]; [filteredResult insertObject:tempRow atIndex:[tableContentView selectedRow]+1]; @@ -614,30 +614,30 @@ copies a row of the table-array and goes into edit mode - (IBAction)removeRow:(id)sender /* -asks user if he really wants to delete the selected rows -*/ + asks user if he really wants to delete the selected rows + */ { if ( ![self selectionShouldChangeInTableView:nil] ) return; if ( ![tableContentView numberOfSelectedRows] ) return; -/* - if ( ([tableContentView numberOfSelectedRows] == [self numberOfRowsInTableView:tableContentView]) && - areShowingAllRows && - (![prefs boolForKey:@"limitRows"] || ([tableContentView numberOfSelectedRows] < [prefs integerForKey:@"limitRowsValue"])) ) { -*/ + /* + if ( ([tableContentView numberOfSelectedRows] == [self numberOfRowsInTableView:tableContentView]) && + areShowingAllRows && + (![prefs boolForKey:@"limitRows"] || ([tableContentView numberOfSelectedRows] < [prefs integerForKey:@"limitRowsValue"])) ) { + */ if ( ([tableContentView numberOfSelectedRows] == [tableContentView numberOfRows]) && - (([prefs boolForKey:@"limitRows"] && [tableContentView numberOfSelectedRows] == [self fetchNumberOfRows]) || - (![prefs boolForKey:@"limitRows"] && [tableContentView numberOfSelectedRows] == [self getNumberOfRows])) ) { + (([prefs boolForKey:@"limitRows"] && [tableContentView numberOfSelectedRows] == [self fetchNumberOfRows]) || + (![prefs boolForKey:@"limitRows"] && [tableContentView numberOfSelectedRows] == [self getNumberOfRows])) ) { NSBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"Delete", @"delete button"), NSLocalizedString(@"Cancel", @"cancel button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), - nil, @"removeallrows", NSLocalizedString(@"Do you really want to delete all rows?", @"message of panel asking for confirmation for deleting all rows")); + nil, @"removeallrows", NSLocalizedString(@"Do you really want to delete all rows?", @"message of panel asking for confirmation for deleting all rows")); } else if ( [tableContentView numberOfSelectedRows] == 1 ) { NSBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"Delete", @"delete button"), NSLocalizedString(@"Cancel", @"cancel button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), - nil, @"removerow", NSLocalizedString(@"Do you really want to delete the selected row?", @"message of panel asking for confirmation for deleting the selected row")); + nil, @"removerow", NSLocalizedString(@"Do you really want to delete the selected row?", @"message of panel asking for confirmation for deleting the selected row")); } else { NSBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"Delete", @"delete button"), NSLocalizedString(@"Cancel", @"cancel button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), - nil, @"removerow", - [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete the selected %d rows?", @"message of panel asking for confirmation for deleting the selected rows"), [tableContentView numberOfSelectedRows]]); + nil, @"removerow", + [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete the selected %d rows?", @"message of panel asking for confirmation for deleting the selected rows"), [tableContentView numberOfSelectedRows]]); } } @@ -650,24 +650,24 @@ asks user if he really wants to delete the selected rows - (IBAction)openEditSheet:(id)sender /* -loads a file into the editSheet -*/ + loads a file into the editSheet + */ { NSOpenPanel *panel = [NSOpenPanel openPanel]; if ( [panel runModal] == NSOKButton ) { NSString *fileName = [panel filename]; - + // free old data if ( editData != nil ) { [editData release]; } - + // load new data/images editData = [[NSData alloc] initWithContentsOfFile:fileName]; NSImage *image = [[[NSImage alloc] initByReferencingFile:fileName] autorelease]; NSString *contents = [[NSString stringWithContentsOfFile:fileName] autorelease]; - + // set the image preview, string contents and hex representation [editImage setImage:image]; [editTextView setString:contents]; @@ -680,31 +680,31 @@ loads a file into the editSheet saves a file containing the content of the editSheet */ { - NSSavePanel *panel = [NSSavePanel savePanel]; - - if ( [panel runModal] == NSOKButton ) { - NSString *fileName = [panel filename]; + NSSavePanel *panel = [NSSavePanel savePanel]; + + if ( [panel runModal] == NSOKButton ) { + NSString *fileName = [panel filename]; NSString *data; - - if ( [editData isKindOfClass:[NSData class]] ) { + + if ( [editData isKindOfClass:[NSData class]] ) { data = editData; - } else { + } else { data = [editData description]; - } + } if ( [editData respondsToSelector:@selector(writeToFile:atomically:encoding:error:)] ) { - // mac os 10.4 or later + // mac os 10.4 or later [editData writeToFile:fileName atomically:YES encoding:[CMMCPConnection encodingForMySQLEncoding:[(NSString *)[tableDocumentInstance encoding] cString]] error:NULL]; } else { - // mac os pre 10.4 + // mac os pre 10.4 [editData writeToFile:fileName atomically:YES]; } - } + } } - (IBAction)dropImage:(id)sender /* -invoked when user drag&drops image on imageView -*/ + invoked when user drag&drops image on imageView + */ { // load new data/images if (nil != editData) @@ -713,7 +713,7 @@ invoked when user drag&drops image on imageView } editData = [[[NSData alloc] initWithContentsOfFile:[sender draggedFilePath]] retain]; NSString *contents = [NSString stringWithContentsOfFile:[sender draggedFilePath]]; - + // set the string contents and hex representation [editTextView setString:contents]; [hexTextView setString:[self dataToHex:editData]]; @@ -721,8 +721,8 @@ invoked when user drag&drops image on imageView - (void)textDidChange:(NSNotification *)notification /* -invoked when the user changes the string in the editSheet -*/ + invoked when the user changes the string in the editSheet + */ { // clear the image and hex (since i doubt someone can "type" a gif) [editImage setImage:nil]; @@ -739,8 +739,8 @@ invoked when the user changes the string in the editSheet - (NSString *)dataToHex:(NSData *)data /* -returns the hex representation of the given data -*/ + returns the hex representation of the given data + */ { unsigned i; unsigned totalLength = [data length]; @@ -827,8 +827,8 @@ returns the hex representation of the given data //getter methods - (NSArray *)currentResult /* -returns the current result (as shown in table content view) as array, the first object containing the field names as array, the following objects containing the rows as array -*/ + returns the current result (as shown in table content view) as array, the first object containing the field names as array, the following objects containing the rows as array + */ { NSArray *tableColumns; NSEnumerator *enumerator; @@ -844,7 +844,7 @@ returns the current result (as shown in table content view) as array, the first tableColumns = [tableContentView tableColumns]; enumerator = [tableColumns objectEnumerator]; - + //set field names as first line while ( (tableColumn = [enumerator nextObject]) ) { [tempRow addObject:[[tableColumn headerCell] stringValue]]; @@ -867,13 +867,13 @@ returns the current result (as shown in table content view) as array, the first //additional methods - (void)setConnection:(CMMCPConnection *)theConnection /* -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 + */ { mySQLConnection = theConnection; [tableContentView setVerticalMotionCanBeginDrag:NO]; - + prefs = [[NSUserDefaults standardUserDefaults] retain]; if ( [prefs boolForKey:@"useMonospacedFonts"] ) { [argumentField setFont:[NSFont fontWithName:@"Monaco" size:10]]; @@ -886,7 +886,7 @@ sets the connection (received from TableDocument) and makes things that have to [limitRowsStepper setEnabled:NO]; if ( [prefs boolForKey:@"limitRows"] ) { [limitRowsText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Limited to %d rows starting with row", @"text showing the number of rows the result is limited to"), - [prefs integerForKey:@"limitRowsValue"]]]; + [prefs integerForKey:@"limitRowsValue"]]]; } else { [limitRowsText setStringValue:NSLocalizedString(@"No limit", @"text showing that the result isn't limited")]; [limitRowsField setStringValue:@""]; @@ -895,8 +895,8 @@ sets the connection (received from TableDocument) and makes things that have to - (IBAction)setCompareTypes:(id)sender /* -sets the compare types for the filter and the appropriate formatter for the textField -*/ + sets the compare types for the filter and the appropriate formatter for the textField + */ { NSArray *stringFields = [NSArray arrayWithObjects:@"varstring", @"string", @"tinyblob", @"blob", @"mediumblob", @"longblob", @"set", @"enum", nil]; NSArray *stringTypes = [NSArray arrayWithObjects:NSLocalizedString(@"is", @"popup menuitem for field IS value"), NSLocalizedString(@"is not", @"popup menuitem for field IS NOT value"), NSLocalizedString(@"contains", @"popup menuitem for field CONTAINS value"), NSLocalizedString(@"contains not", @"popup menuitem for field CONTAINS NOT value"), @"IN", nil]; @@ -905,61 +905,61 @@ sets the compare types for the filter and the appropriate formatter for the text NSArray *dateFields = [NSArray arrayWithObjects:@"timestamp", @"date", @"time", @"datetime", @"year", nil]; NSArray *dateTypes = [NSArray arrayWithObjects:NSLocalizedString(@"is", @"popup menuitem for field IS value"), NSLocalizedString(@"is not", @"popup menuitem for field IS NOT value"), NSLocalizedString(@"older than", @"popup menuitem for field OLDER THAN value"), NSLocalizedString(@"younger than", @"popup menuitem for field YOUNGER THAN value"), NSLocalizedString(@"older than or equal to", @"popup menuitem for field OLDER THAN OR EQUAL TO value"), NSLocalizedString(@"younger than or equal to", @"popup menuitem for field YOUNGER THAN OR EQUAL TO value"), nil]; NSString *fieldType = [NSString stringWithString:[fieldTypes objectAtIndex:[[fieldField selectedItem] tag]]]; -// NSNumberFormatter *numberFormatter; + // NSNumberFormatter *numberFormatter; int i; - -// numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; -// [numberFormatter setFormat:@"0.####################"]; - + + // numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + // [numberFormatter setFormat:@"0.####################"]; + [compareField removeAllItems]; -// [argumentField setStringValue:@""]; + // [argumentField setStringValue:@""]; -//why do we get "string" for enum fields? (error in framework?) + //why do we get "string" for enum fields? (error in framework?) if ( [stringFields containsObject:fieldType] ) { [compareField addItemsWithTitles:stringTypes]; compareType = @"string"; -// [argumentField setFormatter:nil]; + // [argumentField setFormatter:nil]; } else if ( [numberFields containsObject:fieldType] ) { [compareField addItemsWithTitles:numberTypes]; compareType = @"number"; -// [argumentField setFormatter:numberFormatter]; + // [argumentField setFormatter:numberFormatter]; } else if ( [dateFields containsObject:fieldType] ) { [compareField addItemsWithTitles:dateTypes]; compareType = @"date"; -/* - if ([fieldType isEqualToString:@"timestamp"]) { - [argumentField setFormatter:[[NSDateFormatter alloc] - initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:YES]]; - } - if ([fieldType isEqualToString:@"datetime"]) { - [argumentField setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:YES]]; - } - if ([fieldType isEqualToString:@"date"]) { - [argumentField setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d" allowNaturalLanguage:YES]]; - } - if ([fieldType isEqualToString:@"time"]) { - [argumentField setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%H:%M:%S" allowNaturalLanguage:YES]]; - } - if ([fieldType isEqualToString:@"year"]) { - [argumentField setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y" allowNaturalLanguage:YES]]; - } -*/ + /* + if ([fieldType isEqualToString:@"timestamp"]) { + [argumentField setFormatter:[[NSDateFormatter alloc] + initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:YES]]; + } + if ([fieldType isEqualToString:@"datetime"]) { + [argumentField setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:YES]]; + } + if ([fieldType isEqualToString:@"date"]) { + [argumentField setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d" allowNaturalLanguage:YES]]; + } + if ([fieldType isEqualToString:@"time"]) { + [argumentField setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%H:%M:%S" allowNaturalLanguage:YES]]; + } + if ([fieldType isEqualToString:@"year"]) { + [argumentField setFormatter:[[NSDateFormatter alloc] initWithDateFormat:@"%Y" allowNaturalLanguage:YES]]; + } + */ } else { NSLog(@"ERROR: unknown type for comparision: %@", fieldType); } - + for ( i = 0 ; i < [compareField numberOfItems] ; i++ ) { [[compareField itemAtIndex:i] setTag:i]; } - -// set focus on argumentField + + // set focus on argumentField [argumentField selectText:self]; } - (IBAction)stepLimitRows:(id)sender /* -steps the start row up or down (+/- limitRowsValue) -*/ + steps the start row up or down (+/- limitRowsValue) + */ { if ( [limitRowsStepper intValue] > 0 ) { [limitRowsField setIntValue:[limitRowsField intValue]+[prefs integerForKey:@"limitRowsValue"]]; @@ -975,8 +975,8 @@ steps the start row up or down (+/- limitRowsValue) - (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult /* -fetches the result as an array with a dictionary for each row in it -*/ + fetches the result as an array with a dictionary for each row in it + */ { NSMutableArray *tempResult = [NSMutableArray array]; NSDictionary *tempRow; @@ -984,7 +984,7 @@ fetches the result as an array with a dictionary for each row in it NSEnumerator *enumerator; id key; int i,j; - + for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { [theResult dataSeek:i]; tempRow = [theResult fetchRowAsDictionary]; @@ -992,13 +992,13 @@ fetches the result as an array with a dictionary for each row in it while ( key = [enumerator nextObject] ) { if ( [[tempRow objectForKey:key] isMemberOfClass:[NSNull class]] ) { [modifiedRow setObject:[prefs stringForKey:@"nullValue"] forKey:key]; -/* -//NSData objects now decoded in tableView:objectValueForTableColumn:row -//object in result remains a NSData object - } else if ( [[tempRow objectForKey:key] isKindOfClass:[NSData class]] ) { - [modifiedRow setObject:[[NSString alloc] initWithData:[tempRow objectForKey:key] encoding:[mySQLConnection encoding]] - forKey:key]; -*/ + /* + //NSData objects now decoded in tableView:objectValueForTableColumn:row + //object in result remains a NSData object + } else if ( [[tempRow objectForKey:key] isKindOfClass:[NSData class]] ) { + [modifiedRow setObject:[[NSString alloc] initWithData:[tempRow objectForKey:key] encoding:[mySQLConnection encoding]] + forKey:key]; + */ } else { [modifiedRow setObject:[tempRow objectForKey:key] forKey:key]; } @@ -1018,10 +1018,10 @@ fetches the result as an array with a dictionary for each row in it - (BOOL)addRowToDB /* -tries to write row to mysql-db -returns YES if row written to db, otherwies NO -returns YES if no row is beeing edited and nothing has to be written to db -*/ + tries to write row to mysql-db + returns YES if row written to db, otherwies NO + returns YES if no row is beeing edited and nothing has to be written to db + */ { int rowIndex = [tableContentView selectedRow]; NSMutableArray *fieldValues = [[NSMutableArray alloc] init]; @@ -1037,30 +1037,30 @@ returns YES if no row is beeing edited and nothing has to be written to db [fieldValues release]; return YES; } - -//get field values + + //get field values for ( i=0 ; i < [fieldNames count] ; i++) { rowObject = [[filteredResult objectAtIndex:rowIndex] objectForKey:[fieldNames objectAtIndex:i]]; -//convert the object to a string (here we can add special treatment for date-, number- and data-fields) + //convert the object to a string (here we can add special treatment for date-, number- and data-fields) if ( [[rowObject description] isEqualToString:[prefs stringForKey:@"nullValue"]] || - ([rowObject isMemberOfClass:[NSConstantString class]] && [[rowObject description] isEqualToString:@""]) ) { - //NULL when user entered the nullValue string defined in the prefs or when a number field isn't set - // problem: when a number isn't set, sequel-pro enters 0 - // -> second if argument isn't necessary! + ([rowObject isMemberOfClass:[NSConstantString class]] && [[rowObject description] isEqualToString:@""]) ) { + //NULL when user entered the nullValue string defined in the prefs or when a number field isn't set + // problem: when a number isn't set, sequel-pro enters 0 + // -> second if argument isn't necessary! [rowValue setString:@"NULL"]; } else { if ( [rowObject isKindOfClass:[NSCalendarDate class]] ) { -// [rowValue setString:[NSString stringWithFormat:@"\"%@\"", [mySQLConnection prepareString:[rowObject description]]]]; + // [rowValue setString:[NSString stringWithFormat:@"\"%@\"", [mySQLConnection prepareString:[rowObject description]]]]; [rowValue setString:[NSString stringWithFormat:@"'%@'", [mySQLConnection prepareString:[rowObject description]]]]; } else if ( [rowObject isKindOfClass:[NSNumber class]] ) { [rowValue setString:[rowObject stringValue]]; } else if ( [rowObject isKindOfClass:[NSData class]] ) { - //problem: if a blob field is edited, it becomes a string and is not more prepared as binary data - // but probably blob fields are corrupted before, when they decoded in the tableView method -// [rowValue setString:[NSString stringWithFormat:@"\"%@\"", [mySQLConnection prepareBinaryData:rowObject]]]; + //problem: if a blob field is edited, it becomes a string and is not more prepared as binary data + // but probably blob fields are corrupted before, when they decoded in the tableView method + // [rowValue setString:[NSString stringWithFormat:@"\"%@\"", [mySQLConnection prepareBinaryData:rowObject]]]; [rowValue setString:[NSString stringWithFormat:@"'%@'", [mySQLConnection prepareBinaryData:rowObject]]]; } else { -// [rowValue setString:[NSString stringWithFormat:@"\"%@\"", [mySQLConnection prepareString:[rowObject description]]]]; + // [rowValue setString:[NSString stringWithFormat:@"\"%@\"", [mySQLConnection prepareString:[rowObject description]]]]; if ( [[rowObject description] isEqualToString:@"CURRENT_TIMESTAMP"] ) { [rowValue setString:@"CURRENT_TIMESTAMP"]; } else { @@ -1068,47 +1068,47 @@ returns YES if no row is beeing edited and nothing has to be written to db } } } -//escape special characters -> now escaped by framework -/* - for ( j = 0 ; j < [rowValue length] ; j++ ) { - if ( [rowValue characterAtIndex:j] == '\\' ) { - [rowValue insertString:@"\\" atIndex:j]; - j++; - } else if ( [rowValue characterAtIndex:j] == '"' ) { - [rowValue insertString:@"\\" atIndex:j]; - j++; - } - } -*/ + //escape special characters -> now escaped by framework + /* + for ( j = 0 ; j < [rowValue length] ; j++ ) { + if ( [rowValue characterAtIndex:j] == '\\' ) { + [rowValue insertString:@"\\" atIndex:j]; + j++; + } else if ( [rowValue characterAtIndex:j] == '"' ) { + [rowValue insertString:@"\\" atIndex:j]; + j++; + } + } + */ [fieldValues addObject:[NSString stringWithString:rowValue]]; } - + if ( isEditingNewRow ) { -//INSERT syntax + //INSERT syntax queryString = [NSString stringWithFormat:@"INSERT INTO `%@` (`%@`) VALUES (%@)", - selectedTable, [fieldNames componentsJoinedByString:@"`,`"], [fieldValues componentsJoinedByString:@","]]; + selectedTable, [fieldNames componentsJoinedByString:@"`,`"], [fieldValues componentsJoinedByString:@","]]; } else { -//UPDATE syntax + //UPDATE syntax queryString = [NSMutableString stringWithFormat:@"UPDATE `%@` SET ", selectedTable]; for ( i = 0 ; i < [fieldNames count] ; i++ ) { if ( i > 0 ) { [queryString appendString:@", "]; } [queryString appendString:[NSString stringWithFormat:@"`%@`=%@", - [fieldNames objectAtIndex:i], [fieldValues objectAtIndex:i]]]; + [fieldNames objectAtIndex:i], [fieldValues objectAtIndex:i]]]; } [fieldValues release]; [queryString appendString:[NSString stringWithFormat:@" WHERE %@", [self argumentForRow:-2]]]; } [mySQLConnection queryString:queryString]; - -//NSLog( @"%@", queryString ); - + + //NSLog( @"%@", queryString ); + if ( ![mySQLConnection affectedRows] ) { -//no rows changed + //no rows changed if ( [prefs boolForKey:@"showError"] ) { NSBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db")); + NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db")); } else { NSBeep(); } @@ -1118,38 +1118,38 @@ returns YES if no row is beeing edited and nothing has to be written to db [tableDocumentInstance showErrorInConsole:[NSString stringWithFormat:NSLocalizedString(@"/* WARNING %@ No rows have been affected */\n", @"warning shown in the console when no rows have been affected after writing to the db"), currentTime]]; return YES; } else if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { -//added new row with success + //added new row with success isEditingRow = NO; if ( isEditingNewRow ) { if ( [prefs boolForKey:@"reloadAfterAdding"] ) { [self reloadTableValues:self]; -// if ( sortField ) + // if ( sortField ) [tableContentView deselectAll:self]; } else { - //set insertId for fields with auto_increment + //set insertId for fields with auto_increment queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM `%@`", selectedTable]]; for ( i = 0 ; i < [queryResult numOfRows] ; i++ ) { [queryResult dataSeek:i]; rowObject = [queryResult fetchRowAsDictionary]; if ( [[rowObject objectForKey:@"Extra"] isEqualToString:@"auto_increment"] ) { [[filteredResult objectAtIndex:rowIndex] setObject:[NSNumber numberWithLong:[mySQLConnection insertId]] - forKey:[rowObject objectForKey:@"Field"]]; + forKey:[rowObject objectForKey:@"Field"]]; } } [fullResult addObject:[filteredResult objectAtIndex:rowIndex]]; } isEditingNewRow = NO; } else { -//updated row with success + //updated row with success if ( [prefs boolForKey:@"reloadAfterEditing"] ) { [self reloadTableValues:self]; -// if ( sortField ) + // if ( sortField ) [tableContentView deselectAll:self]; } else { -// query = [@"SELECT * FROM " stringByAppendingString:selectedTable]; + // query = [@"SELECT * FROM " stringByAppendingString:selectedTable]; query = [NSString stringWithFormat:@"SELECT %@ FROM `%@`", [self fieldListForQuery], selectedTable]; if ( sortField ) { -// query = [query stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]]; + // query = [query stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]]; query = [NSString stringWithFormat:@"%@ ORDER BY `%@`", query, sortField]; if ( isDesc ) query = [query stringByAppendingString:@" DESC"]; @@ -1159,29 +1159,29 @@ returns YES if no row is beeing edited and nothing has to be written to db [limitRowsField setStringValue:@"1"]; } query = [query stringByAppendingString: - [NSString stringWithFormat:@" LIMIT %d,%d", - [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; + [NSString stringWithFormat:@" LIMIT %d,%d", + [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; } queryResult = [mySQLConnection queryString:query]; -// [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; + // [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; [fullResult setArray:[self fetchResultAsArray:queryResult]]; } } return YES; } else { -//error in mysql-query + //error in mysql-query NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), NSLocalizedString(@"Cancel", @"cancel button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addrow", - [NSString stringWithFormat:NSLocalizedString(@"Couldn't write row.\nMySQL said: %@", @"message of panel when error while adding row to db"), [mySQLConnection getLastErrorMessage]]); + [NSString stringWithFormat:NSLocalizedString(@"Couldn't write row.\nMySQL said: %@", @"message of panel when error while adding row to db"), [mySQLConnection getLastErrorMessage]]); return NO; } } - (NSString *)argumentForRow:(int)row /* -returns the WHERE argument to identify a row -if row is -2, it uses the oldRow -if there is one, it uses the primary key, otherwise uses all fields as argument and sets LIMIT to 1 -*/ + returns the WHERE argument to identify a row + if row is -2, it uses the oldRow + if there is one, it uses the primary key, otherwise uses all fields as argument and sets LIMIT to 1 + */ { CMMCPResult *theResult; NSDictionary *theRow; @@ -1196,18 +1196,18 @@ if there is one, it uses the primary key, otherwise uses all fields as argument if ( row == -1 ) return @""; - -//get primary key if there is one -/* - theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW INDEX FROM `%@`", selectedTable]]; - for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { - [theResult dataSeek:i]; - theRow = [theResult fetchRowAsDictionary]; - if ( [[theRow objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"] ) { - [keys addObject:[theRow objectForKey:@"Column_name"]]; - } - } -*/ + + //get primary key if there is one + /* + theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW INDEX FROM `%@`", selectedTable]]; + for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { + [theResult dataSeek:i]; + theRow = [theResult fetchRowAsDictionary]; + if ( [[theRow objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"] ) { + [keys addObject:[theRow objectForKey:@"Column_name"]]; + } + } + */ if ( !keys ) { setLimit = NO; keys = [[NSMutableArray alloc] init]; @@ -1222,8 +1222,8 @@ if there is one, it uses the primary key, otherwise uses all fields as argument } if ( ![keys count] ) { -//if there is no primary key, take all fields as argument -//here we have a problem when dontShowBlob == YES (we don't have the right values to use in the WHERE statement) + //if there is no primary key, take all fields as argument + //here we have a problem when dontShowBlob == YES (we don't have the right values to use in the WHERE statement) [keys setArray:fieldNames]; setLimit = YES; enumerator = [fieldTypes objectEnumerator]; @@ -1234,7 +1234,7 @@ if there is one, it uses the primary key, otherwise uses all fields as argument } if ( [prefs boolForKey:@"dontShowBlob"] && blob ) { NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - NSLocalizedString(@"You can't hide blob and text fields when working with tables without index.", @"message of panel when trying to edit tables without index and with hidden blob/text fields")); + NSLocalizedString(@"You can't hide blob and text fields when working with tables without index.", @"message of panel when trying to edit tables without index and with hidden blob/text fields")); [keys removeAllObjects]; [tableContentView deselectAll:self]; return @""; @@ -1244,10 +1244,10 @@ if there is one, it uses the primary key, otherwise uses all fields as argument if ( i ) [argument appendString:@" AND "]; if ( row >= 0 ) { - //use selected row + //use selected row tempValue = [[filteredResult objectAtIndex:row] objectForKey:[keys objectAtIndex:i]]; } else { - //use oldRow + //use oldRow tempValue = [oldRow objectForKey:[keys objectAtIndex:i]]; } if ( [tempValue isKindOfClass:[NSData class]] ) { @@ -1269,12 +1269,12 @@ if there is one, it uses the primary key, otherwise uses all fields as argument [value setString:[mySQLConnection prepareString:value]]; for ( j = 0 ; j < [value length] ; j++ ) { if ( [value characterAtIndex:j] == '%' || - [value characterAtIndex:j] == '_' ) { + [value characterAtIndex:j] == '_' ) { [value insertString:@"\\" atIndex:j]; j++; } } -// [value setString:[NSString stringWithFormat:@"\"%@\"", value]]; + // [value setString:[NSString stringWithFormat:@"\"%@\"", value]]; [value setString:[NSString stringWithFormat:@"'%@'", value]]; } if ( [value isEqualToString:@"NULL"] ) { @@ -1294,12 +1294,12 @@ if there is one, it uses the primary key, otherwise uses all fields as argument - (BOOL)isBlobOrText:(NSString *)fieldType /* -returns YES if fieldType is some kind of blob or text. afaik the type of this fields is always blob, but better we test it... -it would be nice to know if it is blob or text, but mysql doesn't want to tell it... -*/ + returns YES if fieldType is some kind of blob or text. afaik the type of this fields is always blob, but better we test it... + it would be nice to know if it is blob or text, but mysql doesn't want to tell it... + */ { if ( [fieldType isEqualToString:@"tinyblob"] || [fieldType isEqualToString:@"blob"] || - [fieldType isEqualToString:@"mediumblob"] || [fieldType isEqualToString:@"longblob"] ) { + [fieldType isEqualToString:@"mediumblob"] || [fieldType isEqualToString:@"longblob"] ) { return YES; } else { return NO; @@ -1308,13 +1308,13 @@ it would be nice to know if it is blob or text, but mysql doesn't want to tell i - (NSString *)fieldListForQuery /* -returns * if dontShowBlob == NO -returns a comma-separated list of all fields which aren't of type blob or text if dontShowBlob == YES -*/ + returns * if dontShowBlob == NO + returns a comma-separated list of all fields which aren't of type blob or text if dontShowBlob == YES + */ { int i; NSMutableArray *fields = [NSMutableArray array]; - + if ( [prefs boolForKey:@"dontShowBlob"] ) { for ( i = 0 ; i < [fieldTypes count] ; i++ ) { if ( ![self isBlobOrText:[fieldTypes objectAtIndex:i]] ) { @@ -1333,9 +1333,9 @@ returns a comma-separated list of all fields which aren't of type blob or text i - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo /* -if contextInfo == addrow: remain in edit-mode if user hits OK, otherwise cancel editing -if contextInfo == removerow: removes row if user hits OK -*/ + if contextInfo == addrow: remain in edit-mode if user hits OK, otherwise cancel editing + if contextInfo == removerow: removes row if user hits OK + */ { NSEnumerator *enumerator = [tableContentView selectedRowEnumerator]; NSNumber *index; @@ -1344,17 +1344,17 @@ if contextInfo == removerow: removes row if user hits OK NSString *queryString; CMMCPResult *queryResult; int i, errors; - + [sheet orderOut:self]; - + if ( [contextInfo isEqualToString:@"addrow"] ) { if ( returnCode == NSAlertDefaultReturn ) { - //problem: reenter edit mode doesn't function + //problem: reenter edit mode doesn't function [tableContentView editColumn:0 row:[tableContentView selectedRow] withEvent:nil select:YES]; } else { if ( !isEditingNewRow ) { [filteredResult replaceObjectAtIndex:[tableContentView selectedRow] - withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]]; + withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]]; isEditingRow = NO; } else { [filteredResult removeObjectAtIndex:[tableContentView selectedRow]]; @@ -1365,44 +1365,44 @@ if contextInfo == removerow: removes row if user hits OK [tableContentView reloadData]; } else if ( [contextInfo isEqualToString:@"removeallrows"] ) { if ( returnCode == NSAlertDefaultReturn ) { -/* - if ( ([tableContentView numberOfSelectedRows] == [self numberOfRowsInTableView:tableContentView]) && - areShowingAllRows && - ([tableContentView numberOfSelectedRows] < [prefs integerForKey:@"limitRowsValue"]) ) { -*/ + /* + if ( ([tableContentView numberOfSelectedRows] == [self numberOfRowsInTableView:tableContentView]) && + areShowingAllRows && + ([tableContentView numberOfSelectedRows] < [prefs integerForKey:@"limitRowsValue"]) ) { + */ [mySQLConnection queryString:[NSString stringWithFormat:@"DELETE FROM `%@`", selectedTable]]; if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { [self reloadTable:self]; } else { NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"Couldn't remove rows.\nMySQL said: %@", @"message of panel when field cannot be removed"), - [mySQLConnection getLastErrorMessage]]); + [NSString stringWithFormat:NSLocalizedString(@"Couldn't remove rows.\nMySQL said: %@", @"message of panel when field cannot be removed"), + [mySQLConnection getLastErrorMessage]]); } } } else if ( [contextInfo isEqualToString:@"removerow"] ) { if ( returnCode == NSAlertDefaultReturn ) { errors = 0; - + while ( (index = [enumerator nextObject]) ) { [mySQLConnection queryString:[NSString stringWithFormat:@"DELETE FROM `%@` WHERE %@", - selectedTable, [self argumentForRow:[index intValue]]]]; + selectedTable, [self argumentForRow:[index intValue]]]]; if ( ![mySQLConnection affectedRows] ) { - //no rows deleted + //no rows deleted errors++; } else if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - //rows deleted with success + //rows deleted with success [tempArray addObject:index]; } else { - //error in mysql-query + //error in mysql-query errors++; } } - + if ( errors ) { NSBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"%d rows have not been removed. Reload the table to be sure that the rows exist and use a primary key for your table.", @"message of panel when not all selected fields have been deleted"), errors]); } - - //do deleting (after enumerating) + + //do deleting (after enumerating) if ( [prefs boolForKey:@"reloadAfterRemoving"] ) { [self reloadTableValues:self]; } else { @@ -1413,10 +1413,10 @@ if contextInfo == removerow: removes row if user hits OK [filteredResult setArray:tempResult]; numRows = [self getNumberOfRows]; if ( !areShowingAllRows ) { -// queryString = [@"SELECT * FROM " stringByAppendingString:selectedTable]; + // queryString = [@"SELECT * FROM " stringByAppendingString:selectedTable]; queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@`", [self fieldListForQuery], selectedTable]; if ( sortField ) { -// queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]]; + // queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]]; queryString = [NSString stringWithFormat:@"%@ ORDER BY `%@`", queryString, sortField]; if ( isDesc ) queryString = [queryString stringByAppendingString:@" DESC"]; @@ -1426,15 +1426,15 @@ if contextInfo == removerow: removes row if user hits OK [limitRowsField setStringValue:@"1"]; } queryString = [queryString stringByAppendingString: - [NSString stringWithFormat:@" LIMIT %d,%d", - [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; + [NSString stringWithFormat:@" LIMIT %d,%d", + [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; } queryResult = [mySQLConnection queryString:queryString]; -// [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; + // [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; [fullResult setArray:[self fetchResultAsArray:queryResult]]; [tableContentView reloadData]; [countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows of %d selected", @"text showing how many rows are in the filtered result"), - [filteredResult count], numRows]]; + [filteredResult count], numRows]]; } else { [fullResult setArray:filteredResult]; [tableContentView reloadData]; @@ -1448,9 +1448,9 @@ if contextInfo == removerow: removes row if user hits OK - (int)getNumberOfRows /* -returns the number of rows in the selected table -queries the number from mysql if enabled in prefs and result is limited, otherwise just return the fullResult count -*/ + returns the number of rows in the selected table + queries the number from mysql if enabled in prefs and result is limited, otherwise just return the fullResult count + */ { if ( [prefs boolForKey:@"limitRows"] && [prefs boolForKey:@"fetchRowCount"] ) { numRows = [self fetchNumberOfRows]; @@ -1462,8 +1462,8 @@ queries the number from mysql if enabled in prefs and result is limited, otherwi - (int)fetchNumberOfRows /* -fetches the number of rows in the selected table using a "SELECT COUNT(*)" query and return it -*/ + fetches the number of rows in the selected table using a "SELECT COUNT(*)" query and return it + */ { return [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(*) FROM `%@`", selectedTable]] fetchRowAsArray] objectAtIndex:0] intValue]; } @@ -1476,30 +1476,30 @@ fetches the number of rows in the selected table using a "SELECT COUNT(*)" query } - (id)tableView:(NSTableView *)aTableView - objectValueForTableColumn:(NSTableColumn *)aTableColumn +objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { id theRow, theValue; theRow = [filteredResult objectAtIndex:rowIndex]; theValue = [theRow objectForKey:[aTableColumn identifier]]; - + if ( [theValue isKindOfClass:[NSData class]] ) { theValue = [[NSString alloc] initWithData:theValue encoding:[mySQLConnection encoding]]; //show only first 50 characters to speed up interface (but return everything when this method is used to return the current result) -// if ( ([theValue length] > 100) && aTableView ) { + // if ( ([theValue length] > 100) && aTableView ) { } if ( ([(NSString *)theValue length] > 100) && aTableView ) { theValue = [NSString stringWithFormat:@"%@(...)", [theValue substringToIndex:100]]; } - + return theValue; } - (void)tableView:(NSTableView *)aTableView - setObjectValue:(id)anObject - forTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex + setObjectValue:(id)anObject + forTableColumn:(NSTableColumn *)aTableColumn + row:(int)rowIndex { if ( !isEditingRow ) { [oldRow setDictionary:[filteredResult objectAtIndex:rowIndex]]; @@ -1515,29 +1515,29 @@ fetches the number of rows in the selected table using a "SELECT COUNT(*)" query //tableView delegate methods - (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)tableColumn /* -sorts the tableView by the clicked column -if clicked twice, order is descending -*/ + sorts the tableView by the clicked column + if clicked twice, order is descending + */ { NSString *queryString; NSImage *upSortImage; NSImage *downSortImage; CMMCPResult *queryResult; - + if ( [selectedTable isEqualToString:@""] || !selectedTable ) return; if ( ![self selectionShouldChangeInTableView:nil] ) return; - -//query started + + //query started [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self]; - + upSortImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sort-up" ofType:@"tiff"]]; [upSortImage autorelease]; downSortImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sort-down" ofType:@"tiff"]]; [downSortImage autorelease]; - -//sets order descending if a header is clicked twice + + //sets order descending if a header is clicked twice if ( [[tableColumn identifier] isEqualTo:sortField] ) { if ( isDesc ) { isDesc = NO; @@ -1549,10 +1549,10 @@ if clicked twice, order is descending [tableContentView setIndicatorImage:nil inTableColumn:[tableContentView tableColumnWithIdentifier:sortField]]; } sortField = [tableColumn identifier]; - -//make queryString and perform query + + //make queryString and perform query queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@` ORDER BY `%@`", [self fieldListForQuery], - selectedTable, sortField]; + selectedTable, sortField]; if ( isDesc ) queryString = [queryString stringByAppendingString:@" DESC"]; if ( [prefs boolForKey:@"limitRows"] ) { @@ -1560,34 +1560,34 @@ if clicked twice, order is descending [limitRowsField setStringValue:@"1"]; } queryString = [queryString stringByAppendingString: - [NSString stringWithFormat:@" LIMIT %d,%d", - [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; + [NSString stringWithFormat:@" LIMIT %d,%d", + [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; } queryResult = [mySQLConnection queryString:queryString]; - -// [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; + + // [fullResult setArray:[[self fetchResultAsArray:queryResult] retain]]; [fullResult setArray:[self fetchResultAsArray:queryResult]]; - + if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"Couldn't sort table. MySQL said: %@", @"message of panel when sorting of table failed"), [mySQLConnection getLastErrorMessage]]); + [NSString stringWithFormat:NSLocalizedString(@"Couldn't sort table. MySQL said: %@", @"message of panel when sorting of table failed"), [mySQLConnection getLastErrorMessage]]); return; } - -//sets highlight and indicatorImage + + //sets highlight and indicatorImage [tableContentView setHighlightedTableColumn:tableColumn]; if ( isDesc ) { [tableContentView setIndicatorImage:downSortImage inTableColumn:tableColumn]; } else { [tableContentView setIndicatorImage:upSortImage inTableColumn:tableColumn]; } - -//query finished + + //query finished [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self]; - -//if filter is activated filters the result, otherwise shows fullResult + + //if filter is activated filters the result, otherwise shows fullResult if ( !areShowingAllRows ) { - [self filterTable:self]; + [self filterTable:self]; } else { [filteredResult setArray:fullResult]; [tableContentView reloadData]; @@ -1619,41 +1619,41 @@ if clicked twice, order is descending saves the new column size in the preferences */ { - // sometimes the column has no identifier. I can't figure out what is causing it, so we just skip over this item - if (![[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier]) - return; - + // sometimes the column has no identifier. I can't figure out what is causing it, so we just skip over this item + if (![[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier]) + return; + NSMutableDictionary *tableColumnWidths; NSString *database = [NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]]; NSString *table = (NSString *)[tablesListInstance table]; - - // get tableColumnWidths object + + // get tableColumnWidths object if ( [prefs objectForKey:@"tableColumnWidths"] != nil ) { - tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:@"tableColumnWidths"]]; - } else { - tableColumnWidths = [NSMutableDictionary dictionary]; - } - // get database object + tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:@"tableColumnWidths"]]; + } else { + tableColumnWidths = [NSMutableDictionary dictionary]; + } + // get database object if ( [tableColumnWidths objectForKey:database] == nil ) { [tableColumnWidths setObject:[NSMutableDictionary dictionary] forKey:database]; } else { [tableColumnWidths setObject:[[tableColumnWidths objectForKey:database] mutableCopy] forKey:database]; } - // get table object + // get table object if ( [[tableColumnWidths objectForKey:database] objectForKey:table] == nil ) { [[tableColumnWidths objectForKey:database] setObject:[NSMutableDictionary dictionary] forKey:table]; } else { [[tableColumnWidths objectForKey:database] setObject:[[[tableColumnWidths objectForKey:database] objectForKey:table] mutableCopy] forKey:table]; } - // save column size + // save column size [[[tableColumnWidths objectForKey:database] objectForKey:table] setObject:[NSNumber numberWithFloat:[[[aNotification userInfo] objectForKey:@"NSTableColumn"] width]] forKey:[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier]]; [prefs setObject:tableColumnWidths forKey:@"tableColumnWidths"]; } - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex /* -opens sheet if multipleLineEditingButton is clicked or field is a hidden blob or text field -*/ + opens sheet if multipleLineEditingButton is clicked or field is a hidden blob or text field + */ { NSEnumerator *enumerator; id type; @@ -1666,11 +1666,11 @@ opens sheet if multipleLineEditingButton is clicked or field is a hidden blob or CMMCPResult *tempResult; id theValue; BOOL columnIsBlob = NO; -// int i; -// NSArray *columns = [aTableView tableColumns]; - + // int i; + // NSArray *columns = [aTableView tableColumns]; + if ( [prefs boolForKey:@"dontShowBlob"] && !isEditingRow ) { - //get all row values if dontShowBlob == YES and table contains blob or text field and isEditingRow = NO + //get all row values if dontShowBlob == YES and table contains blob or text field and isEditingRow = NO enumerator = [fieldTypes objectEnumerator]; while ( (type = [enumerator nextObject]) ) { if ( [self isBlobOrText:type] ) { @@ -1680,11 +1680,11 @@ opens sheet if multipleLineEditingButton is clicked or field is a hidden blob or if ( blob ) { query = [NSString stringWithFormat:@"SELECT * FROM `%@` WHERE %@", - selectedTable, [self argumentForRow:[tableContentView selectedRow]]]; + selectedTable, [self argumentForRow:[tableContentView selectedRow]]]; tempResult = [mySQLConnection queryString:query]; if ( ![tempResult numOfRows] ) { NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - NSLocalizedString(@"Couldn't load the row. Reload the table to be sure that the row exists and use a primary key for your table.", @"message of panel when loading of row failed")); + NSLocalizedString(@"Couldn't load the row. Reload the table to be sure that the row exists and use a primary key for your table.", @"message of panel when loading of row failed")); return NO; } tempRow = [tempResult fetchRowAsDictionary]; @@ -1697,26 +1697,26 @@ opens sheet if multipleLineEditingButton is clicked or field is a hidden blob or } } [filteredResult replaceObjectAtIndex:rowIndex - withObject:[NSMutableDictionary dictionaryWithDictionary:modifiedRow]]; + withObject:[NSMutableDictionary dictionaryWithDictionary:modifiedRow]]; [tableContentView reloadData]; } } - -/* - // find the column we're trying to edit - for ( i = 0; i < [columns count]; i++ ) { - if ( [columns objectAtIndex:i] == aTableColumn ) { - // this flag will let us determine if we should "force" multi-line edit. - columnIsBlob = [self isBlobOrText:[fieldTypes objectAtIndex:i]]; - break; - } - } -*/ + + /* + // find the column we're trying to edit + for ( i = 0; i < [columns count]; i++ ) { + if ( [columns objectAtIndex:i] == aTableColumn ) { + // this flag will let us determine if we should "force" multi-line edit. + columnIsBlob = [self isBlobOrText:[fieldTypes objectAtIndex:i]]; + break; + } + } + */ //is the column a blob field -> if YES force sheet editing if ( [self isBlobOrText:[fieldTypes objectAtIndex:[fieldNames indexOfObject:[aTableColumn identifier]]]] ) { columnIsBlob = YES; } - + if ( [multipleLineEditingButton state] == NSOnState || columnIsBlob ) { theValue = [[filteredResult objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]]; NSImage *image = nil; @@ -1725,12 +1725,12 @@ opens sheet if multipleLineEditingButton is clicked or field is a hidden blob or if ( [theValue isKindOfClass:[NSData class]] ) { image = [[NSImage alloc] initWithData:theValue]; [hexTextView setString:[self dataToHex:theValue]]; -/* - // update displayed font to monospace - NSFont *font = [NSFont fontWithName:@"Courier" size:12.0f]; - NSRange hexRange = { 0, [[hexTextView string] length] - 1 }; - [hexTextView setFont:font range:hexRange]; -*/ + /* + // update displayed font to monospace + NSFont *font = [NSFont fontWithName:@"Courier" size:12.0f]; + NSRange hexRange = { 0, [[hexTextView string] length] - 1 }; + [hexTextView setFont:font range:hexRange]; + */ theValue = [[NSString alloc] initWithData:theValue encoding:[mySQLConnection encoding]]; } else { [hexTextView setString:@""]; @@ -1740,24 +1740,24 @@ opens sheet if multipleLineEditingButton is clicked or field is a hidden blob or [editImage setImage:image]; [editTextView setString:theValue]; [editTextView setSelectedRange:NSMakeRange(0,[[editTextView string] length])]; -//different sheets for date (with up/down arrows), number and text + //different sheets for date (with up/down arrows), number and text [NSApp beginSheet:editSheet - modalForWindow:tableWindow modalDelegate:self - didEndSelector:nil contextInfo:nil]; + modalForWindow:tableWindow modalDelegate:self + didEndSelector:nil contextInfo:nil]; code = [NSApp runModalForWindow:editSheet]; - + [NSApp endSheet:editSheet]; [editSheet orderOut:nil]; - - if ( code ) { + + if ( code ) { if ( !isEditingRow ) { [oldRow setDictionary:[filteredResult objectAtIndex:rowIndex]]; isEditingRow = YES; } - + [[filteredResult objectAtIndex:rowIndex] setObject:[editData copy] - forKey:[aTableColumn identifier]]; - + forKey:[aTableColumn identifier]]; + // clean up [editImage setImage:nil]; [editTextView setString:@""]; @@ -1775,8 +1775,8 @@ opens sheet if multipleLineEditingButton is clicked or field is a hidden blob or - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard /* -enable drag from tableview -*/ + enable drag from tableview + */ { if ( tableView == tableContentView ) { @@ -1785,8 +1785,8 @@ enable drag from tableview if ( nil != tmp ) { [pboard declareTypes:[NSArray arrayWithObjects: NSTabularTextPboardType, - NSStringPboardType, nil] - owner:nil]; + NSStringPboardType, nil] + owner:nil]; [pboard setString:tmp forType:NSStringPboardType]; [pboard setString:tmp forType:NSTabularTextPboardType]; @@ -1798,42 +1798,42 @@ enable drag from tableview - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command /* -traps enter and esc an make/cancel editing without entering next row -*/ + traps enter and esc an make/cancel editing without entering next row + */ { int row, column, i; - + row = [tableContentView editedRow]; column = [tableContentView editedColumn]; - - if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] || - [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) //trap enter and tab - { + + if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] || + [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) //trap enter and tab + { //save current line [[control window] makeFirstResponder:control]; if ( column == ( [tableContentView numberOfColumns] - 1 ) ) { [self addRowToDB]; -/* - if ( [self addRowToDB] && - ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) && - !(sortField && ([prefs boolForKey:@"reloadAfterAdding"] || [prefs boolForKey:@"reloadAfterEditing"])) ) { -//get in edit-mode of next row if user hit tab (and result isn't sorted and reloaded) - if ( row < ([tableContentView numberOfRows] - 1) ) { - [tableContentView selectRow:row+1 byExtendingSelection:NO]; - [tableContentView editColumn:0 row:row+1 withEvent:nil select:YES]; - } else { - [tableContentView selectRow:0 byExtendingSelection:NO]; - [tableContentView editColumn:0 row:0 withEvent:nil select:YES]; - } - } -*/ + /* + if ( [self addRowToDB] && + ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) && + !(sortField && ([prefs boolForKey:@"reloadAfterAdding"] || [prefs boolForKey:@"reloadAfterEditing"])) ) { + //get in edit-mode of next row if user hit tab (and result isn't sorted and reloaded) + if ( row < ([tableContentView numberOfRows] - 1) ) { + [tableContentView selectRow:row+1 byExtendingSelection:NO]; + [tableContentView editColumn:0 row:row+1 withEvent:nil select:YES]; + } else { + [tableContentView selectRow:0 byExtendingSelection:NO]; + [tableContentView editColumn:0 row:0 withEvent:nil select:YES]; + } + } + */ } else { - //check if next column is a blob column + //check if next column is a blob column i = 1; while ( [self isBlobOrText:[fieldTypes objectAtIndex:[fieldNames indexOfObject:[[[tableContentView tableColumns] objectAtIndex:column+i] identifier]]]] ) { i++; if ( (column+i) >= [tableContentView numberOfColumns] ) { - //there is no other column after the blob column + //there is no other column after the blob column [self addRowToDB]; return TRUE; } @@ -1842,10 +1842,10 @@ traps enter and esc an make/cancel editing without entering next row [tableContentView editColumn:column+i row:row withEvent:nil select:YES]; } return TRUE; - } - else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] || - [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) //trap esc - { + } + else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] || + [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) //trap esc + { //abort editing [control abortEditing]; if ( isEditingRow && !isEditingNewRow ) { @@ -1858,23 +1858,23 @@ traps enter and esc an make/cancel editing without entering next row [tableContentView reloadData]; } return TRUE; - } - else - { - return FALSE; - } + } + else + { + return FALSE; + } } //textView delegate methods - (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector /* -traps enter and return key and closes editSheet instead of inserting a linebreak when user hits return -*/ + traps enter and return key and closes editSheet instead of inserting a linebreak when user hits return + */ { if ( aTextView == editTextView ) { if ( [aTextView methodForSelector:aSelector] == [aTextView methodForSelector:@selector(insertNewline:)] && - [[[NSApp currentEvent] characters] isEqualToString:@"\003"] ) + [[[NSApp currentEvent] characters] isEqualToString:@"\003"] ) { [NSApp stopModalWithCode:1]; return YES; @@ -1890,8 +1890,8 @@ traps enter and return key and closes editSheet instead of inserting a linebreak - (void)dealloc { -// NSLog(@"TableContent dealloc"); - + // NSLog(@"TableContent dealloc"); + [editData release]; [fullResult release]; [filteredResult release]; -- cgit v1.2.3