Skip to content

Commit bed1cff

Browse files
committed
* Fix a case of "background thread updating UI" (may affect some crashes when importing CSVs)
1 parent dfab0cd commit bed1cff

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

Source/SPAppController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ - (void)handleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEvent
770770
}
771771
else {
772772
NSBeep();
773-
NSLog(@"Error in sequelpro URL scheme");
773+
NSLog(@"Error in sequelpro URL scheme for URL <%@>",url);
774774
}
775775
}
776776

Source/SPDataImport.m

+22-21
Original file line numberDiff line numberDiff line change
@@ -1213,29 +1213,30 @@ - (void)importCSVFile:(NSString *)filename
12131213
document:tableDocumentInstance
12141214
notificationName:@"Import Finished"];
12151215

1216+
SPMainQSync(^{
1217+
if(importIntoNewTable) {
12161218

1217-
if(importIntoNewTable) {
1218-
1219-
// Select the new table
1220-
1221-
// Update current database tables
1222-
[[tablesListInstance onMainThread] updateTables:self];
1223-
1224-
// Re-query the structure of all databases in the background
1225-
[[tableDocumentInstance databaseStructureRetrieval] queryDbStructureInBackgroundWithUserInfo:@{@"forceUpdate" : @YES}];
1226-
1227-
// Select the new table
1228-
[tablesListInstance selectItemWithName:selectedTableTarget];
1229-
1230-
} else {
1231-
1232-
// If import was done into a new table or the table selected for import is also selected in the content view,
1233-
// update the content view - on the main thread to avoid crashes.
1234-
if ([tablesListInstance tableName] && [selectedTableTarget isEqualToString:[tablesListInstance tableName]]) {
1235-
[tableDocumentInstance setContentRequiresReload:YES];
1219+
// Select the new table
1220+
1221+
// Update current database tables
1222+
[tablesListInstance updateTables:self];
1223+
1224+
// Re-query the structure of all databases in the background
1225+
[[tableDocumentInstance databaseStructureRetrieval] queryDbStructureInBackgroundWithUserInfo:@{@"forceUpdate" : @YES}];
1226+
1227+
// Select the new table
1228+
[tablesListInstance selectItemWithName:selectedTableTarget];
1229+
1230+
} else {
1231+
1232+
// If import was done into a new table or the table selected for import is also selected in the content view,
1233+
// update the content view - on the main thread to avoid crashes.
1234+
if ([tablesListInstance tableName] && [selectedTableTarget isEqualToString:[tablesListInstance tableName]]) {
1235+
[tableDocumentInstance setContentRequiresReload:YES];
1236+
}
1237+
12361238
}
1237-
1238-
}
1239+
});
12391240

12401241
}
12411242

Source/SPTableContent.m

+9-7
Original file line numberDiff line numberDiff line change
@@ -2541,13 +2541,15 @@ - (void)clickLinkArrowTask:(SPTextAndLinkCell *)theArrowCell
25412541
@"filterValue": targetFilterValue,
25422542
@"filterComparison": SPBoxNil(filterComparison)
25432543
};
2544-
[self setFiltersToRestore:filterSettings];
2545-
2546-
// Attempt to switch to the target table
2547-
if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) {
2548-
NSBeep();
2549-
[self setFiltersToRestore:nil];
2550-
}
2544+
SPMainQSync(^{
2545+
[self setFiltersToRestore:filterSettings];
2546+
2547+
// Attempt to switch to the target table
2548+
if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) {
2549+
NSBeep();
2550+
[self setFiltersToRestore:nil];
2551+
}
2552+
});
25512553
}
25522554

25532555
#ifndef SP_CODA

Source/SPTablesList.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,8 @@ - (BOOL)hasNonTableObjects
13701370
/**
13711371
* Select an item using the provided name; returns YES if the
13721372
* supplied name could be selected, or NO if not.
1373+
*
1374+
* MUST BE CALLED ON THE UI THREAD!
13731375
*/
13741376
- (BOOL)selectItemWithName:(NSString *)theName
13751377
{
@@ -1418,7 +1420,7 @@ - (BOOL)selectItemWithName:(NSString *)theName
14181420
}
14191421
}
14201422

1421-
[[tablesListView onMainThread] scrollRowToVisible:[tablesListView selectedRow]];
1423+
[tablesListView scrollRowToVisible:[tablesListView selectedRow]];
14221424
#endif
14231425

14241426
return YES;

0 commit comments

Comments
 (0)