Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fix a case of "background thread updating UI" (may affect some cras…
…hes when importing CSVs)
  • Loading branch information
dmoagx committed Apr 22, 2017
1 parent dfab0cd commit bed1cff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Source/SPAppController.m
Expand Up @@ -770,7 +770,7 @@ - (void)handleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEvent
}
else {
NSBeep();
NSLog(@"Error in sequelpro URL scheme");
NSLog(@"Error in sequelpro URL scheme for URL <%@>",url);
}
}

Expand Down
43 changes: 22 additions & 21 deletions Source/SPDataImport.m
Expand Up @@ -1213,29 +1213,30 @@ - (void)importCSVFile:(NSString *)filename
document:tableDocumentInstance
notificationName:@"Import Finished"];

SPMainQSync(^{
if(importIntoNewTable) {

if(importIntoNewTable) {

// Select the new table

// Update current database tables
[[tablesListInstance onMainThread] updateTables:self];

// Re-query the structure of all databases in the background
[[tableDocumentInstance databaseStructureRetrieval] queryDbStructureInBackgroundWithUserInfo:@{@"forceUpdate" : @YES}];

// Select the new table
[tablesListInstance selectItemWithName:selectedTableTarget];

} else {

// If import was done into a new table or the table selected for import is also selected in the content view,
// update the content view - on the main thread to avoid crashes.
if ([tablesListInstance tableName] && [selectedTableTarget isEqualToString:[tablesListInstance tableName]]) {
[tableDocumentInstance setContentRequiresReload:YES];
// Select the new table
// Update current database tables
[tablesListInstance updateTables:self];
// Re-query the structure of all databases in the background
[[tableDocumentInstance databaseStructureRetrieval] queryDbStructureInBackgroundWithUserInfo:@{@"forceUpdate" : @YES}];
// Select the new table
[tablesListInstance selectItemWithName:selectedTableTarget];
} else {
// If import was done into a new table or the table selected for import is also selected in the content view,
// update the content view - on the main thread to avoid crashes.
if ([tablesListInstance tableName] && [selectedTableTarget isEqualToString:[tablesListInstance tableName]]) {
[tableDocumentInstance setContentRequiresReload:YES];
}

}

}
});

}

Expand Down
16 changes: 9 additions & 7 deletions Source/SPTableContent.m
Expand Up @@ -2541,13 +2541,15 @@ - (void)clickLinkArrowTask:(SPTextAndLinkCell *)theArrowCell
@"filterValue": targetFilterValue,
@"filterComparison": SPBoxNil(filterComparison)
};
[self setFiltersToRestore:filterSettings];

// Attempt to switch to the target table
if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) {
NSBeep();
[self setFiltersToRestore:nil];
}
SPMainQSync(^{
[self setFiltersToRestore:filterSettings];

// Attempt to switch to the target table
if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) {
NSBeep();
[self setFiltersToRestore:nil];
}
});
}

#ifndef SP_CODA
Expand Down
4 changes: 3 additions & 1 deletion Source/SPTablesList.m
Expand Up @@ -1370,6 +1370,8 @@ - (BOOL)hasNonTableObjects
/**
* Select an item using the provided name; returns YES if the
* supplied name could be selected, or NO if not.
*
* MUST BE CALLED ON THE UI THREAD!
*/
- (BOOL)selectItemWithName:(NSString *)theName
{
Expand Down Expand Up @@ -1418,7 +1420,7 @@ - (BOOL)selectItemWithName:(NSString *)theName
}
}

[[tablesListView onMainThread] scrollRowToVisible:[tablesListView selectedRow]];
[tablesListView scrollRowToVisible:[tablesListView selectedRow]];
#endif

return YES;
Expand Down

0 comments on commit bed1cff

Please sign in to comment.