diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-01-04 12:59:51 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-01-04 12:59:51 +0000 |
commit | 313c5bc247548319dc1f93c9ece04ea4326d37e8 (patch) | |
tree | 3d2a0b62c92a60668dfd0020a88822ebed4a3dc2 /Source | |
parent | 25d72032f5f6296c69a5e44fb41ee9bc7942e8ca (diff) | |
download | sequelpro-313c5bc247548319dc1f93c9ece04ea4326d37e8.tar.gz sequelpro-313c5bc247548319dc1f93c9ece04ea4326d37e8.tar.bz2 sequelpro-313c5bc247548319dc1f93c9ece04ea4326d37e8.zip |
• remember scrollview port and selected row after editing in the Custom Query table view
- after reloading the entire data the table view port will be restored but this leads up to now to a "tiny jitter" (maybe fixable in the near future)
- the re-selection does NOT follow the actual edited row, e.g. if one changes a cell value whose column is used for sorting the actual edited row could appear somewhere
• if the editing in the Custom Query table view was invoked by pressing RETURN/ENTER one can go through the columns by pressing ESC but up to now that editing will be interrupted after the user pressed OK
- this behaviour is temporary and should be fixed in the near future by storing the new row data temporarily; after editing the last column AND if all columns have the same table origin the row data will be updated. To allow the row editing for columns which have different table origins could probably cause inconsistencies.
- further discussion is needed
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMCopyTable.m | 17 | ||||
-rw-r--r-- | Source/CustomQuery.h | 3 | ||||
-rw-r--r-- | Source/CustomQuery.m | 32 |
3 files changed, 42 insertions, 10 deletions
diff --git a/Source/CMCopyTable.m b/Source/CMCopyTable.m index 8893696d..64875cea 100644 --- a/Source/CMCopyTable.m +++ b/Source/CMCopyTable.m @@ -443,8 +443,23 @@ int MENU_EDIT_COPY_AS_SQL = 2002; } } } + if([[[[self delegate] class] description] isEqualToString:@"CustomQuery"]) { + id tableContentView = [[self delegate] valueForKeyPath:@"customQueryView"]; + if([tableContentView numberOfSelectedRows] == 1 && ([theEvent keyCode] == 36 || [theEvent keyCode] == 76)) { + + // TODO: this works until the user presses OK in the Field Editor Sheet!! + // in the future we should store the new row data temporarily and then + // after editing the last column update the db field by field (ask HansJB) + NSInteger colNum = [[tableContentView tableColumns] count]; + NSInteger i; + for(i=0; i<colNum; i++) { + [[self delegate] tableView:tableContentView shouldEditTableColumn:[[tableContentView tableColumns] objectAtIndex:i] row:[tableContentView selectedRow]]; + } + return; + } + } - [super keyDown:theEvent]; + [super keyDown:theEvent]; } @end diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index ba0e456d..121b4853 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -72,6 +72,7 @@ IBOutlet CMTextView *textView; IBOutlet CMCopyTable *customQueryView; + IBOutlet NSScrollView *customQueryScrollView; IBOutlet id errorText; IBOutlet id affectedRowsText; IBOutlet id valueSheet; @@ -126,6 +127,8 @@ NSInteger fullResultCount; NSArray *cqColumnDefinition; NSString *lastExecutedQuery; + NSInteger editedRow; + NSRect editedScrollViewRect; BOOL isWorking; BOOL tableReloadAfterEditing; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 71ed2ec4..ebcf1259 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -408,8 +408,10 @@ // Reset the current table view as necessary to avoid redraw and reload issues. // Restore the view position to the top left to be within the results for all datasets. - [customQueryView scrollRowToVisible:0]; - [customQueryView scrollColumnToVisible:0]; + if(editedRow == -1) { + [customQueryView scrollRowToVisible:0]; + [customQueryView scrollColumnToVisible:0]; + } // Remove all the columns if(!tableReloadAfterEditing) { @@ -576,7 +578,6 @@ if(!databaseWasChanged && [query isMatchedByRegex:@"(?i)\\b(use|drop\\s+database|drop\\s+schema)\\b\\s+."]) databaseWasChanged = YES; } - // If the query was cancelled, end all queries. if ([mySQLConnection queryCancelled]) break; } @@ -761,14 +762,20 @@ } } + [customQueryView reloadData]; + if(tableReloadAfterEditing) { - // scroll to last edited row after refreshing data - // TODO: should be improved - [customQueryView scrollRowToVisible:[customQueryView selectedRow]]; + // scroll to last edited row/view port after refreshing data + if(editedRow > -1) { + [customQueryView selectRowIndexes:[NSIndexSet indexSetWithIndex:editedRow] byExtendingSelection:NO]; + [[customQueryScrollView contentView] scrollToPoint:NSMakePoint(editedScrollViewRect.origin.x, editedScrollViewRect.origin.y)]; + [customQueryScrollView reflectScrolledClipView:[customQueryScrollView contentView]]; + editedRow = -1; + } else { + [customQueryView scrollRowToVisible:[customQueryView selectedRow]]; + } } - [customQueryView reloadData]; - // Init copyTable with necessary information for copying selected rows as SQL INSERT [customQueryView setTableInstance:self withTableData:fullResult withColumns:cqColumnDefinition withTableName:resultTableName withConnection:mySQLConnection]; @@ -1506,6 +1513,7 @@ // On success reload table data by executing the last query tableReloadAfterEditing = YES; + [self performQueries:[NSArray arrayWithObject:lastExecutedQuery] withCallback:NULL]; } else { @@ -1753,7 +1761,7 @@ /* * Double-click action on a field */ -- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex +- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { // Only allow editing if a task is not active @@ -1819,6 +1827,11 @@ SPFieldEditorController *fieldEditor = [[SPFieldEditorController alloc] init]; + + // Remember edited row for reselecting and setting the scroll view after reload + editedRow = rowIndex; + editedScrollViewRect = [customQueryScrollView documentVisibleRect]; + // Set max text length if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"] && [columnDefinition valueForKey:@"char_length"]) @@ -2844,6 +2857,7 @@ // init tableView's data source fullResultCount = 0; fullResult = [[NSMutableArray alloc] init]; + editedRow = -1; prefs = [NSUserDefaults standardUserDefaults]; } |