Skip to content

Commit 06e4f7d

Browse files
committed
#2659: Scroll selected table into view when restoring a session.
1 parent 145ee33 commit 06e4f7d

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

Source/SPDatabaseDocument.m

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5056,59 +5056,57 @@ - (BOOL)setStateFromConnectionFile:(NSString *)path
50565056
}
50575057

50585058
/**
5059-
* Restore session from SPF file if given
5059+
* Restore the session from SPF file if given.
50605060
*/
50615061
- (void)restoreSession
50625062
{
50635063
@autoreleasepool {
50645064
// Check and set the table
50655065
NSArray *tables = [tablesListInstance tables];
50665066

5067-
BOOL isSelectedTableDefined = YES;
5068-
5069-
if([tables indexOfObject:[spfSession objectForKey:@"table"]] == NSNotFound) {
5070-
isSelectedTableDefined = NO;
5071-
}
5067+
NSUInteger tableIndex = [tables indexOfObject:[spfSession objectForKey:@"table"]];
50725068

50735069
// Restore toolbar setting
5074-
if([spfSession objectForKey:@"isToolbarVisible"]) {
5075-
[mainToolbar setVisible:[[spfSession objectForKey:@"isToolbarVisible"] boolValue]];
5070+
if ([spfSession objectForKey:@"isToolbarVisible"]) {
5071+
[[mainToolbar onMainThread] setVisible:[[spfSession objectForKey:@"isToolbarVisible"] boolValue]];
50765072
}
50775073

50785074
// Reset database view encoding if differs from default
5079-
if([spfSession objectForKey:@"connectionEncoding"] && ![[mySQLConnection encoding] isEqualToString:[spfSession objectForKey:@"connectionEncoding"]]) {
5075+
if ([spfSession objectForKey:@"connectionEncoding"] && ![[mySQLConnection encoding] isEqualToString:[spfSession objectForKey:@"connectionEncoding"]]) {
50805076
[self setConnectionEncoding:[spfSession objectForKey:@"connectionEncoding"] reloadingViews:YES];
50815077
}
50825078

5083-
if(isSelectedTableDefined) {
5079+
if (tableIndex != NSNotFound) {
50845080
// Set table content details for restore
5085-
if([spfSession objectForKey:@"contentSortCol"]) [tableContentInstance setSortColumnNameToRestore:[spfSession objectForKey:@"contentSortCol"] isAscending:[[spfSession objectForKey:@"contentSortColIsAsc"] boolValue]];
5086-
if([spfSession objectForKey:@"contentPageNumber"]) [tableContentInstance setPageToRestore:[[spfSession objectForKey:@"pageNumber"] integerValue]];
5087-
if([spfSession objectForKey:@"contentViewport"]) [tableContentInstance setViewportToRestore:NSRectFromString([spfSession objectForKey:@"contentViewport"])];
5088-
if([spfSession objectForKey:@"contentFilterV2"]) [tableContentInstance setFiltersToRestore:[spfSession objectForKey:@"contentFilterV2"]];
5081+
if ([spfSession objectForKey:@"contentSortCol"]) [tableContentInstance setSortColumnNameToRestore:[spfSession objectForKey:@"contentSortCol"] isAscending:[[spfSession objectForKey:@"contentSortColIsAsc"] boolValue]];
5082+
if ([spfSession objectForKey:@"contentPageNumber"]) [tableContentInstance setPageToRestore:[[spfSession objectForKey:@"pageNumber"] integerValue]];
5083+
if ([spfSession objectForKey:@"contentViewport"]) [tableContentInstance setViewportToRestore:NSRectFromString([spfSession objectForKey:@"contentViewport"])];
5084+
if ([spfSession objectForKey:@"contentFilterV2"]) [tableContentInstance setFiltersToRestore:[spfSession objectForKey:@"contentFilterV2"]];
50895085

50905086
// Select table
5091-
[tablesListInstance selectTableAtIndex:[NSNumber numberWithInteger:[tables indexOfObject:[spfSession objectForKey:@"table"]]]];
5087+
[[tablesListInstance onMainThread] selectTableAtIndex:@(tableIndex)];
50925088

50935089
// Restore table selection indexes
5094-
if([spfSession objectForKey:@"contentSelection"]) {
5090+
if ([spfSession objectForKey:@"contentSelection"]) {
50955091
[tableContentInstance setSelectionToRestore:[spfSession objectForKey:@"contentSelection"]];
50965092
}
50975093

5098-
[[tablesListInstance valueForKeyPath:@"tablesListView"] scrollRowToVisible:[tables indexOfObject:[spfSession objectForKey:@"selectedTable"]]];
5099-
5094+
// Scroll to table
5095+
#warning Private ivar accessed from outside (#2978)
5096+
[[[tablesListInstance valueForKeyPath:@"tablesListView"] onMainThread] scrollRowToVisible:tableIndex];
51005097
}
51015098

51025099
// update UI on main thread
51035100
SPMainQSync(^{
51045101
// Select view
51055102
NSString *view = [spfSession objectForKey:@"view"];
5106-
if([view isEqualToString:@"SP_VIEW_STRUCTURE"]) [self viewStructure:self];
5107-
else if([view isEqualToString:@"SP_VIEW_CONTENT"]) [self viewContent:self];
5108-
else if([view isEqualToString:@"SP_VIEW_CUSTOMQUERY"]) [self viewQuery:self];
5109-
else if([view isEqualToString:@"SP_VIEW_STATUS"]) [self viewStatus:self];
5110-
else if([view isEqualToString:@"SP_VIEW_RELATIONS"]) [self viewRelations:self];
5111-
else if([view isEqualToString:@"SP_VIEW_TRIGGERS"]) [self viewTriggers:self];
5103+
5104+
if ([view isEqualToString:@"SP_VIEW_STRUCTURE"]) [self viewStructure:self];
5105+
else if ([view isEqualToString:@"SP_VIEW_CONTENT"]) [self viewContent:self];
5106+
else if ([view isEqualToString:@"SP_VIEW_CUSTOMQUERY"]) [self viewQuery:self];
5107+
else if ([view isEqualToString:@"SP_VIEW_STATUS"]) [self viewStatus:self];
5108+
else if ([view isEqualToString:@"SP_VIEW_RELATIONS"]) [self viewRelations:self];
5109+
else if ([view isEqualToString:@"SP_VIEW_TRIGGERS"]) [self viewTriggers:self];
51125110

51135111
[self updateWindowTitle:self];
51145112
});

0 commit comments

Comments
 (0)