aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/TableContent.m72
-rw-r--r--Source/TableSource.m61
2 files changed, 114 insertions, 19 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m
index a7dfef7d..134e5234 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -267,10 +267,10 @@
[limitRowsText setStringValue:NSLocalizedString(@"No limit", @"text showing that the result isn't limited")];
}
- // Enable the table buttons
+ // set the state of the table buttons
[addButton setEnabled:YES];
- [copyButton setEnabled:YES];
- [removeButton setEnabled:YES];
+ [copyButton setEnabled:NO];
+ [removeButton setEnabled:NO];
// Perform the data query and store the result as an array containing a dictionary per result row
query = [NSString stringWithFormat:@"SELECT %@ FROM %@", [self fieldListForQuery], [selectedTable backtickQuotedString]];
@@ -1153,7 +1153,7 @@
if ( [prefs boolForKey:@"dontShowBlob"] ) {
for ( j = 0 ; j < [columns count] ; j++ ) {
if ( [tableDataInstance columnIsBlobOrText:[[columns objectAtIndex:j] objectForKey:@"name"] ] ) {
- [modifiedRow setObject:NSLocalizedString(@"- blob or text -", @"value shown for hidden blob and text fields") forKey:[[columns objectAtIndex:j] objectForKey:@"name"]];
+ [modifiedRow setObject:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields") forKey:[[columns objectAtIndex:j] objectForKey:@"name"]];
}
}
}
@@ -1673,10 +1673,10 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
id theRow, theValue;
-
+
theRow = [filteredResult objectAtIndex:rowIndex];
theValue = [theRow objectForKey:[aTableColumn identifier]];
-
+
// Convert data objects to their string representation in the current encoding, falling back to ascii
if ( [theValue isKindOfClass:[NSData class]] ) {
NSString *dataRepresentation = [[NSString alloc] initWithData:theValue encoding:[mySQLConnection encoding]];
@@ -1686,8 +1686,59 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
else theValue = [NSString stringWithString:dataRepresentation];
if (dataRepresentation) [dataRepresentation release];
}
-
- return theValue;
+ return theValue;
+}
+
+- (void)tableView: (CMCopyTable *)aTableView
+ willDisplayCell: (id)cell
+ forTableColumn: (NSTableColumn*)aTableColumn
+ row: (int)row
+/*
+ * This function changes the text color of
+ * text/blob fields which are not yet loaded to gray
+ */
+{
+ // Check if loading of text/blob fields is disabled
+ // If not, all text fields are loaded and we don't have to make them gray
+ if ([prefs boolForKey:@"dontShowBlob"])
+ {
+ // Make sure that the cell actually responds to setTextColor:
+ // In the future, we might use different cells for the table view
+ // that don't support this selector
+ if ([cell respondsToSelector:@selector(setTextColor:)])
+ {
+ NSArray *columns = [tableDataInstance columns];
+ NSArray *columnNames = [tableDataInstance columnNames];
+ NSString *columnTypeGrouping;
+ NSUInteger indexOfColumn;
+
+ // We have to find the index of the current column
+ // Make sure we find it, otherwise return (We might decide in the future
+ // to add a column to the TableView that doesn't correspond to a column
+ // of the Mysql table...)
+ indexOfColumn = [columnNames indexOfObject:[aTableColumn identifier]];
+ if (indexOfColumn == NSNotFound) return;
+
+ // Test if the current column is a text or a blob field
+ columnTypeGrouping = [[columns objectAtIndex:indexOfColumn] objectForKey:@"typegrouping"];
+ if ([columnTypeGrouping isEqualToString:@"textdata"] || [columnTypeGrouping isEqualToString:@"blobdata"]) {
+
+ // now check if the field has been loaded already or not
+ if ([[cell stringValue] isEqualToString:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")])
+ {
+ // change the text color of the cell to gray
+ [cell setTextColor: [NSColor grayColor]];
+ }
+ else
+ {
+ // Change the text color back to black
+ // This is necessary because NSTableView reuses
+ // the NSCell to draw further rows in the column
+ [cell setTextColor: [NSColor blackColor]];
+ }
+ }
+ }
+ }
}
- (void)tableView:(NSTableView *)aTableView
@@ -1799,9 +1850,14 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
if ( isEditingRow && [tableContentView selectedRow] != currentlyEditingRow && ![self saveRowOnDeselect] ) return;
// Update the row selection count
+ // and update the status of the delete/duplicate buttons
if ( [tableContentView numberOfSelectedRows] > 0 ) {
+ [copyButton setEnabled:YES];
+ [removeButton setEnabled:YES];
[countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d of %d rows selected", @"Text showing how many rows are selected"), [tableContentView numberOfSelectedRows], [tableContentView numberOfRows]]];
} else {
+ [copyButton setEnabled:NO];
+ [removeButton setEnabled:NO];
[countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows", @"Text showing how many rows are in the result"), [tableContentView numberOfRows]]];
}
}
diff --git a/Source/TableSource.m b/Source/TableSource.m
index b9fd59e6..692fa98e 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -50,6 +50,7 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab
selectedTable = aTable;
[tableSourceView deselectAll:self];
+ [indexView deselectAll:self];
if ( isEditingRow )
return;
@@ -181,10 +182,12 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab
// If a view is selected, disable the buttons; otherwise enable.
BOOL editingEnabled = ([tablesListInstance tableType] == SP_TABLETYPE_TABLE);
[addFieldButton setEnabled:editingEnabled];
- [copyFieldButton setEnabled:editingEnabled];
- [removeFieldButton setEnabled:editingEnabled];
[addIndexButton setEnabled:editingEnabled];
- [removeIndexButton setEnabled:editingEnabled];
+
+ //the following three buttons will only be enabled if a row field/index is selected!
+ [copyFieldButton setEnabled:NO];
+ [removeFieldButton setEnabled:NO];
+ [removeIndexButton setEnabled:NO];
//add columns to indexedColumnsField
[indexedColumnsField removeAllItems];
@@ -861,6 +864,9 @@ returns a dictionary containing enum/set field names as key and possible values
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
+ //make sure that the drag operation is for the right table view
+ if (aTableView!=tableSourceView) return;
+
if ( !isEditingRow ) {
[oldRow setDictionary:[tableFields objectAtIndex:rowIndex]];
isEditingRow = YES;
@@ -878,6 +884,10 @@ Begin a drag and drop operation from the table - copy a single dragged row to th
*/
- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard
{
+ //make sure that the drag operation is started from the right table view
+ if (tableView!=tableSourceView) return NO;
+
+
int originalRow;
NSArray *pboardTypes;
@@ -905,6 +915,9 @@ would result in a position change.
- (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row
proposedDropOperation:(NSTableViewDropOperation)operation
{
+ //make sure that the drag operation is for the right table view
+ if (tableView!=tableSourceView) return NO;
+
NSArray *pboardTypes = [[info draggingPasteboard] types];
int originalRow;
@@ -929,6 +942,9 @@ would result in a position change.
*/
- (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)destinationRowIndex dropOperation:(NSTableViewDropOperation)operation
{
+ //make sure that the drag operation is for the right table view
+ if (tableView!=tableSourceView) return NO;
+
int originalRowIndex;
NSMutableString *queryString;
NSDictionary *originalRow;
@@ -1010,13 +1026,32 @@ would result in a position change.
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
-
- // Check our notification object is our table fields view
- if ([aNotification object] != tableSourceView)
- return;
-
- // If we are editing a row, attempt to save that row - if saving failed, reselect the edit row.
- if ( isEditingRow && [tableSourceView selectedRow] != currentlyEditingRow && ![self saveRowOnDeselect] ) return;
+ //check for which table view the selection changed
+ if ([aNotification object] == tableSourceView) {
+ // If we are editing a row, attempt to save that row - if saving failed, reselect the edit row.
+ if ( isEditingRow && [tableSourceView selectedRow] != currentlyEditingRow ) {
+ [self saveRowOnDeselect];
+ }
+
+ // check if there is currently a field selected
+ // and change button state accordingly
+ if ([tableSourceView numberOfSelectedRows] > 0 && [tablesListInstance tableType] == SP_TABLETYPE_TABLE) {
+ [removeFieldButton setEnabled:YES];
+ [copyFieldButton setEnabled:YES];
+ } else {
+ [removeFieldButton setEnabled:NO];
+ [copyFieldButton setEnabled:NO];
+ }
+ }
+ else if ([aNotification object] == indexView) {
+ // check if there is currently an index selected
+ // and change button state accordingly
+ if ([indexView numberOfSelectedRows] > 0 && [tablesListInstance tableType] == SP_TABLETYPE_TABLE) {
+ [removeIndexButton setEnabled:YES];
+ } else {
+ [removeIndexButton setEnabled:NO];
+ }
+ }
}
/*
@@ -1080,7 +1115,11 @@ traps enter and esc and make/cancel editing without entering next row
* Modify cell display by disabling table cells when a view is selected, meaning structure/index
* is uneditable.
*/
-- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
+- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
+
+ //make sure that the message is from the right table view
+ if (tableView!=tableSourceView) return NO;
+
[aCell setEnabled:([tablesListInstance tableType] == SP_TABLETYPE_TABLE)];
}