aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableContent.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/TableContent.m')
-rw-r--r--Source/TableContent.m81
1 files changed, 68 insertions, 13 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 78e47b9a..4710abef 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -221,7 +221,7 @@
}
// Update display if necessary
- [tableContentView performSelectorOnMainThread:@selector(displayIfNeeded) withObject:nil waitUntilDone:NO];
+ [[tableContentView onMainThread] setNeedsDisplay:YES];
// Init copyTable with necessary information for copying selected rows as SQL INSERT
[tableContentView setTableInstance:self withTableData:tableValues withColumns:dataColumns withTableName:selectedTable withConnection:mySQLConnection];
@@ -550,6 +550,9 @@
// If no table is selected, return
if (!selectedTable) return;
+ // Wrap the values load in an autorelease pool to ensure full and timely release
+ NSAutoreleasePool *loadPool = [[NSAutoreleasePool alloc] init];
+
NSMutableString *queryString;
NSString *queryStringBeforeLimit = nil;
NSString *filterString;
@@ -670,6 +673,8 @@
// Trigger a full reload if required
if (fullTableReloadRequired) [self reloadTable:self];
+
+ [loadPool drain];
}
/*
@@ -731,16 +736,16 @@
[tableDocumentInstance setTaskPercentage:(rowsProcessed*relativeTargetRowCount)];
} else if (rowsProcessed == targetRowCount) {
[tableDocumentInstance setTaskPercentage:100.0];
- [tableDocumentInstance performSelectorOnMainThread:@selector(setTaskProgressToIndeterminateAfterDelay:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:NO];
+ [[tableDocumentInstance onMainThread] setTaskProgressToIndeterminateAfterDelay:YES];
}
}
// Update the table view with new results every now and then
if (rowsProcessed > nextTableDisplayBoundary) {
if (rowsProcessed > tableRowsCount) tableRowsCount = rowsProcessed;
- [tableContentView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:NO];
+ [[tableContentView onMainThread] noteNumberOfRowsChanged];
if (!tableViewRedrawn) {
- [tableContentView performSelectorOnMainThread:@selector(displayIfNeeded) withObject:nil waitUntilDone:NO];
+ [[tableContentView onMainThread] setNeedsDisplay:YES];
tableViewRedrawn = YES;
}
nextTableDisplayBoundary *= 2;
@@ -1324,8 +1329,6 @@
//copy row
tempRow = [tableValues rowContentsAtIndex:[tableContentView selectedRow]];
- [tableValues insertRowContents:tempRow atIndex:[tableContentView selectedRow]+1];
- tableRowsCount++;
//if we don't show blobs, read data for this duplicate column from db
if ([prefs boolForKey:SPLoadBlobsAsNeeded]) {
@@ -1350,7 +1353,11 @@
[tempRow replaceObjectAtIndex:i withObject:[dbDataRow objectAtIndex:i]];
}
}
-
+
+ //insert the copied row
+ [tableValues insertRowContents:tempRow atIndex:[tableContentView selectedRow]+1];
+ tableRowsCount++;
+
//select row and go in edit mode
[tableContentView reloadData];
[tableContentView selectRowIndexes:[NSIndexSet indexSetWithIndex:[tableContentView selectedRow]+1] byExtendingSelection:NO];
@@ -1367,8 +1374,11 @@
- (IBAction)removeRow:(id)sender
{
// Check whether a save of the current row is required.
- if (![self saveRowOnDeselect])
- return;
+ //if (![self saveRowOnDeselect])
+ // return;
+
+ // cancel editing (maybe this is not the ideal method -- see xcode docs for that method)
+ [tableWindow endEditingFor:nil];
if (![tableContentView numberOfSelectedRows])
return;
@@ -1393,7 +1403,7 @@
NSString *contextInfo = @"removerow";
- if (([tableContentView numberOfSelectedRows] == [tableContentView numberOfRows]) && !isFiltered && !isLimited && !isInterruptedLoad) {
+ if (([tableContentView numberOfSelectedRows] == [tableContentView numberOfRows]) && !isFiltered && !isLimited && !isInterruptedLoad && !isEditingNewRow) {
contextInfo = @"removeallrows";
@@ -2158,6 +2168,14 @@
[tableContentView reloadData];
} else if ( [contextInfo isEqualToString:@"removeallrows"] ) {
if ( returnCode == NSAlertDefaultReturn ) {
+ //check if the user is currently editing a row
+ if (isEditingRow) {
+ //cancel the edit
+ isEditingRow = NO;
+ // in case the delete fails, make sure we at least stay in a somewhat consistent state
+ [tableValues replaceRowAtIndex:currentlyEditingRow withRowContents:oldRow];
+ currentlyEditingRow = -1;
+ }
[mySQLConnection queryString:[NSString stringWithFormat:@"DELETE FROM %@", [selectedTable backtickQuotedString]]];
if ( ![mySQLConnection queryErrored] ) {
@@ -2178,12 +2196,44 @@
}
} else if ( [contextInfo isEqualToString:@"removerow"] ) {
if ( returnCode == NSAlertDefaultReturn ) {
-
- errors = 0;
-
[selectedRows addIndexes:[tableContentView selectedRowIndexes]];
+
+ //check if the user is currently editing a row
+ if (isEditingRow) {
+ //make sure that only one row is selected. This should never happen
+ if ([selectedRows count]!=1) {
+ NSLog(@"Expected only one selected row, but found %d",[selectedRows count]);
+ }
+ // this code is pretty much taken from the escape key handler
+ if ( isEditingNewRow ) {
+ // since the user is currently editing a new row, we don't actually have to delete any rows from the database
+ // we just have to remove the row from the view (and the store)
+ isEditingRow = NO;
+ isEditingNewRow = NO;
+ tableRowsCount--;
+ [tableValues removeRowAtIndex:currentlyEditingRow];
+ currentlyEditingRow = -1;
+ [self updateCountText];
+ [tableContentView reloadData];
+
+ //deselect the row
+ [tableContentView selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO];
+
+ // we also don't have to reload the table, since no query went to the database
+ return;
+ } else {
+ //cancel the edit
+ isEditingRow = NO;
+ // in case the delete fails, make sure we at least stay in a somewhat consistent state
+ [tableValues replaceRowAtIndex:currentlyEditingRow withRowContents:oldRow];
+ currentlyEditingRow = -1;
+ }
+
+ }
[tableContentView selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO];
+ errors = 0;
+
// Disable updating of the Console Log window for large number of queries
// to speed the deletion
consoleUpdateStatus = [[SPQueryController sharedQueryController] allowConsoleUpdate];
@@ -2348,6 +2398,7 @@
if ( errors ) {
NSArray *message;
+ //TODO: The following three messages are NOT localisable!
if(errors < 0) {
message = [NSArray arrayWithObjects:NSLocalizedString(@"Warning", @"warning"),
[NSString stringWithFormat:NSLocalizedString(@"%ld row%@ more %@ removed! Please check the Console and inform the Sequel Pro team!", @"message of panel when more rows were deleted"), (long)(errors*-1), ((errors*-1)>1)?@"s":@"", (errors>1)?@"were":@"was"],
@@ -2379,6 +2430,9 @@
[tableContentView reloadData];
}
[tableContentView deselectAll:self];
+ } else {
+ // The user clicked cancel in the "sure you wanna delete" message
+ // restore editing or whatever
}
}
}
@@ -3186,6 +3240,7 @@
isEditingNewRow = NO;
tableRowsCount--;
[tableValues removeRowAtIndex:row];
+ [self updateCountText];
[tableContentView reloadData];
}
currentlyEditingRow = -1;