Permalink
Browse files

#2659: Scroll selected table into view when restoring a session.

  • Loading branch information...
stuconnolly committed Oct 28, 2018
1 parent 145ee33 commit 06e4f7d6f6e8078e8dbf9415bf64eeac87127172
Showing with 22 additions and 24 deletions.
  1. +22 −24 Source/SPDatabaseDocument.m
@@ -5056,59 +5056,57 @@ - (BOOL)setStateFromConnectionFile:(NSString *)path
}
/**
* Restore session from SPF file if given
* Restore the session from SPF file if given.
*/
- (void)restoreSession
{
@autoreleasepool {
// Check and set the table
NSArray *tables = [tablesListInstance tables];
BOOL isSelectedTableDefined = YES;
if([tables indexOfObject:[spfSession objectForKey:@"table"]] == NSNotFound) {
isSelectedTableDefined = NO;
}
NSUInteger tableIndex = [tables indexOfObject:[spfSession objectForKey:@"table"]];
// Restore toolbar setting
if([spfSession objectForKey:@"isToolbarVisible"]) {
[mainToolbar setVisible:[[spfSession objectForKey:@"isToolbarVisible"] boolValue]];
if ([spfSession objectForKey:@"isToolbarVisible"]) {
[[mainToolbar onMainThread] setVisible:[[spfSession objectForKey:@"isToolbarVisible"] boolValue]];
}
// Reset database view encoding if differs from default
if([spfSession objectForKey:@"connectionEncoding"] && ![[mySQLConnection encoding] isEqualToString:[spfSession objectForKey:@"connectionEncoding"]]) {
if ([spfSession objectForKey:@"connectionEncoding"] && ![[mySQLConnection encoding] isEqualToString:[spfSession objectForKey:@"connectionEncoding"]]) {
[self setConnectionEncoding:[spfSession objectForKey:@"connectionEncoding"] reloadingViews:YES];
}
if(isSelectedTableDefined) {
if (tableIndex != NSNotFound) {
// Set table content details for restore
if([spfSession objectForKey:@"contentSortCol"]) [tableContentInstance setSortColumnNameToRestore:[spfSession objectForKey:@"contentSortCol"] isAscending:[[spfSession objectForKey:@"contentSortColIsAsc"] boolValue]];
if([spfSession objectForKey:@"contentPageNumber"]) [tableContentInstance setPageToRestore:[[spfSession objectForKey:@"pageNumber"] integerValue]];
if([spfSession objectForKey:@"contentViewport"]) [tableContentInstance setViewportToRestore:NSRectFromString([spfSession objectForKey:@"contentViewport"])];
if([spfSession objectForKey:@"contentFilterV2"]) [tableContentInstance setFiltersToRestore:[spfSession objectForKey:@"contentFilterV2"]];
if ([spfSession objectForKey:@"contentSortCol"]) [tableContentInstance setSortColumnNameToRestore:[spfSession objectForKey:@"contentSortCol"] isAscending:[[spfSession objectForKey:@"contentSortColIsAsc"] boolValue]];
if ([spfSession objectForKey:@"contentPageNumber"]) [tableContentInstance setPageToRestore:[[spfSession objectForKey:@"pageNumber"] integerValue]];
if ([spfSession objectForKey:@"contentViewport"]) [tableContentInstance setViewportToRestore:NSRectFromString([spfSession objectForKey:@"contentViewport"])];
if ([spfSession objectForKey:@"contentFilterV2"]) [tableContentInstance setFiltersToRestore:[spfSession objectForKey:@"contentFilterV2"]];
// Select table
[tablesListInstance selectTableAtIndex:[NSNumber numberWithInteger:[tables indexOfObject:[spfSession objectForKey:@"table"]]]];
[[tablesListInstance onMainThread] selectTableAtIndex:@(tableIndex)];
// Restore table selection indexes
if([spfSession objectForKey:@"contentSelection"]) {
if ([spfSession objectForKey:@"contentSelection"]) {
[tableContentInstance setSelectionToRestore:[spfSession objectForKey:@"contentSelection"]];
}
[[tablesListInstance valueForKeyPath:@"tablesListView"] scrollRowToVisible:[tables indexOfObject:[spfSession objectForKey:@"selectedTable"]]];
// Scroll to table
#warning Private ivar accessed from outside (#2978)
[[[tablesListInstance valueForKeyPath:@"tablesListView"] onMainThread] scrollRowToVisible:tableIndex];
}
// update UI on main thread
SPMainQSync(^{
// Select view
NSString *view = [spfSession objectForKey:@"view"];
if([view isEqualToString:@"SP_VIEW_STRUCTURE"]) [self viewStructure:self];
else if([view isEqualToString:@"SP_VIEW_CONTENT"]) [self viewContent:self];
else if([view isEqualToString:@"SP_VIEW_CUSTOMQUERY"]) [self viewQuery:self];
else if([view isEqualToString:@"SP_VIEW_STATUS"]) [self viewStatus:self];
else if([view isEqualToString:@"SP_VIEW_RELATIONS"]) [self viewRelations:self];
else if([view isEqualToString:@"SP_VIEW_TRIGGERS"]) [self viewTriggers:self];
if ([view isEqualToString:@"SP_VIEW_STRUCTURE"]) [self viewStructure:self];
else if ([view isEqualToString:@"SP_VIEW_CONTENT"]) [self viewContent:self];
else if ([view isEqualToString:@"SP_VIEW_CUSTOMQUERY"]) [self viewQuery:self];
else if ([view isEqualToString:@"SP_VIEW_STATUS"]) [self viewStatus:self];
else if ([view isEqualToString:@"SP_VIEW_RELATIONS"]) [self viewRelations:self];
else if ([view isEqualToString:@"SP_VIEW_TRIGGERS"]) [self viewTriggers:self];
[self updateWindowTitle:self];
});

0 comments on commit 06e4f7d

Please sign in to comment.