Permalink
Browse files

Fix UI interaction from background thread when selecting a table that…

… doesn't exist.
  • Loading branch information...
stuconnolly committed Oct 7, 2018
1 parent b76667b commit 964d811075d98420203889d2a2a076fb3241d1d5
Showing with 34 additions and 18 deletions.
  1. +2 −2 Source/SPTableData.m
  2. +2 −0 Source/SPTablesList.h
  3. +30 −16 Source/SPTablesList.m
View
@@ -471,12 +471,12 @@ - (NSDictionary *) informationForTable:(NSString *)tableName
tableName, [mySQLConnection lastErrorMessage]];
// If the current table doesn't exist anymore reload table list
if([mySQLConnection lastErrorID] == 1146) {
if ([mySQLConnection lastErrorID] == 1146) {
// Release the table loading lock to allow reselection/reloading to requery the database.
pthread_mutex_unlock(&dataProcessingLock);
[[tableListInstance valueForKeyPath:@"tablesListView"] deselectAll:nil];
[tableListInstance deselectAllTables];
[tableListInstance updateTables:self];
}
View
@@ -143,6 +143,7 @@
- (void)selectTableAtIndex:(nullable NSNumber *)row;
- (void)makeTableListFilterHaveFocus;
- (void)makeTableListHaveFocus;
- (void)deselectAllTables;
// Getters
- (nonnull NSArray *)selectedTableNames;
@@ -161,6 +162,7 @@
- (nonnull NSArray *)allDatabaseNames;
- (nonnull NSArray *)allSystemDatabaseNames;
- (nullable NSString *)selectedDatabase;
- (BOOL)hasViews;
- (BOOL)hasFunctions;
- (BOOL)hasProcedures;
View
@@ -166,7 +166,8 @@ - (IBAction)updateTables:(nullable id)sender
#endif
tableListIsSelectable = YES;
#ifndef SP_CODA
[[tablesListView onMainThread] deselectAll:self];
[self deselectAllTables];
tableListIsSelectable = previousTableListIsSelectable;
#endif
SPMainQSync(^{
@@ -574,24 +575,24 @@ - (IBAction)copyTable:(id)sender
[[tableDocumentInstance parentWindow] endEditingFor:nil];
// Detect table type: table or view
NSInteger tblType = [[filteredTableTypes objectAtIndex:[tablesListView selectedRow]] integerValue];
switch (tblType){
switch (tblType)
{
case SPTableTypeTable:
tableType = NSLocalizedString(@"table",@"table");
tableType = NSLocalizedString(@"table", @"table");
[copyTableContentSwitch setEnabled:YES];
break;
case SPTableTypeView:
tableType = NSLocalizedString(@"view",@"view");
tableType = NSLocalizedString(@"view", @"view");
[copyTableContentSwitch setEnabled:NO];
break;
case SPTableTypeProc:
tableType = NSLocalizedString(@"procedure",@"procedure");
tableType = NSLocalizedString(@"procedure", @"procedure");
[copyTableContentSwitch setEnabled:NO];
break;
case SPTableTypeFunc:
tableType = NSLocalizedString(@"function",@"function");
tableType = NSLocalizedString(@"function", @"function");
[copyTableContentSwitch setEnabled:NO];
break;
}
@@ -811,7 +812,6 @@ - (void)controlTextDidEndEditing:(NSNotification *)notification
#endif
}
/**
* Updates application state to match the current selection, including
* updating the interface selection if appropriate.
@@ -1167,6 +1167,11 @@ - (void)setSelectionState:(NSDictionary *)selectionDetails
#endif
}
- (void)deselectAllTables
{
[[tablesListView onMainThread] deselectAll:self];
}
#pragma mark -
#pragma mark Getter methods
@@ -1403,12 +1408,15 @@ - (BOOL)selectItemWithName:(NSString *)theName
#ifndef SP_CODA /* table list filtering */
if (!isTableListFiltered) {
[tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
} else {
}
else {
NSInteger filteredIndex = [filteredTables indexOfObject:[tables objectAtIndex:itemIndex]];
if (filteredIndex != NSNotFound) {
[tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:filteredIndex] byExtendingSelection:NO];
} else {
[tablesListView deselectAll:nil];
}
else {
[self deselectAllTables];
#endif
if (selectedTableName) [selectedTableName release];
@@ -1458,10 +1466,14 @@ - (BOOL)selectItemsWithNames:(NSArray *)theNames
if (!isTableListFiltered) {
[tablesListView selectRowIndexes:selectionIndexSet byExtendingSelection:NO];
} else {
[tablesListView deselectAll:nil];
}
else {
[self deselectAllTables];
[listFilterField setStringValue:@""];
[self updateFilter:self];
[tablesListView selectRowIndexes:selectionIndexSet byExtendingSelection:NO];
}
@@ -1987,11 +1999,12 @@ - (void) makeTableListHaveFocus
/**
* Update the filter search.
*/
- (IBAction) updateFilter:(id)sender
- (IBAction)updateFilter:(id)sender
{
// Don't try and maintain selections of multiple rows through filtering
if ([tablesListView numberOfSelectedRows] > 1) {
[tablesListView deselectAll:self];
[self deselectAllTables];
if (selectedTableName) SPClear(selectedTableName);
}
@@ -2291,7 +2304,8 @@ - (void)_removeTable:(BOOL)force
}
[tablesListView reloadData];
[tablesListView deselectAll:self];
[self deselectAllTables];
#ifndef SP_CODA
[tableDocumentInstance updateWindowTitle:self];

0 comments on commit 964d811

Please sign in to comment.