From 313c5bc247548319dc1f93c9ece04ea4326d37e8 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 4 Jan 2010 12:59:51 +0000 Subject: =?UTF-8?q?=E2=80=A2=20remember=20scrollview=20port=20and=20select?= =?UTF-8?q?ed=20row=20after=20editing=20in=20the=20Custom=20Query=20table?= =?UTF-8?q?=20view=20-=20after=20reloading=20the=20entire=20data=20the=20t?= =?UTF-8?q?able=20view=20port=20will=20be=20restored=20but=20this=20leads?= =?UTF-8?q?=20up=20to=20now=20to=20a=20"tiny=20jitter"=20(maybe=20fixable?= =?UTF-8?q?=20in=20the=20near=20future)=20-=20the=20re-selection=20does=20?= =?UTF-8?q?NOT=20follow=20the=20actual=20edited=20row,=20e.g.=20if=20one?= =?UTF-8?q?=20changes=20a=20cell=20value=20whose=20column=20is=20used=20fo?= =?UTF-8?q?r=20sorting=20the=20actual=20edited=20row=20could=20appear=20so?= =?UTF-8?q?mewhere=20=E2=80=A2=20if=20the=20editing=20in=20the=20Custom=20?= =?UTF-8?q?Query=20table=20view=20was=20invoked=20by=20pressing=20RETURN/E?= =?UTF-8?q?NTER=20one=20can=20go=20through=20the=20columns=20by=20pressing?= =?UTF-8?q?=20ESC=20but=20up=20to=20now=20that=20editing=20will=20be=20int?= =?UTF-8?q?errupted=20after=20the=20user=20pressed=20OK=20-=20this=20behav?= =?UTF-8?q?iour=20is=20temporary=20and=20should=20be=20fixed=20in=20the=20?= =?UTF-8?q?near=20future=20by=20storing=20the=20new=20row=20data=20tempora?= =?UTF-8?q?rily;=20after=20editing=20the=20last=20column=20AND=20if=20all?= =?UTF-8?q?=20columns=20have=20the=20same=20table=20origin=20the=20row=20d?= =?UTF-8?q?ata=20will=20be=20updated.=20To=20allow=20the=20row=20editing?= =?UTF-8?q?=20for=20columns=20which=20have=20different=20table=20origins?= =?UTF-8?q?=20could=20probably=20cause=20inconsistencies.=20-=20further=20?= =?UTF-8?q?discussion=20is=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.m | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'Source/CustomQuery.m') 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]; } -- cgit v1.2.3