Navigation Menu

Skip to content

Commit

Permalink
Fix UI interaction from background thread when selecting a table that…
Browse files Browse the repository at this point in the history
… doesn't exist.
  • Loading branch information
stuconnolly committed Oct 7, 2018
1 parent b76667b commit 964d811
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Source/SPTableData.m
Expand Up @@ -471,12 +471,12 @@ - (NSDictionary *) informationForTable:(NSString *)tableName
tableName, [mySQLConnection lastErrorMessage]]; tableName, [mySQLConnection lastErrorMessage]];


// If the current table doesn't exist anymore reload table list // 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. // Release the table loading lock to allow reselection/reloading to requery the database.
pthread_mutex_unlock(&dataProcessingLock); pthread_mutex_unlock(&dataProcessingLock);


[[tableListInstance valueForKeyPath:@"tablesListView"] deselectAll:nil]; [tableListInstance deselectAllTables];
[tableListInstance updateTables:self]; [tableListInstance updateTables:self];
} }


Expand Down
2 changes: 2 additions & 0 deletions Source/SPTablesList.h
Expand Up @@ -143,6 +143,7 @@
- (void)selectTableAtIndex:(nullable NSNumber *)row; - (void)selectTableAtIndex:(nullable NSNumber *)row;
- (void)makeTableListFilterHaveFocus; - (void)makeTableListFilterHaveFocus;
- (void)makeTableListHaveFocus; - (void)makeTableListHaveFocus;
- (void)deselectAllTables;


// Getters // Getters
- (nonnull NSArray *)selectedTableNames; - (nonnull NSArray *)selectedTableNames;
Expand All @@ -161,6 +162,7 @@
- (nonnull NSArray *)allDatabaseNames; - (nonnull NSArray *)allDatabaseNames;
- (nonnull NSArray *)allSystemDatabaseNames; - (nonnull NSArray *)allSystemDatabaseNames;
- (nullable NSString *)selectedDatabase; - (nullable NSString *)selectedDatabase;

- (BOOL)hasViews; - (BOOL)hasViews;
- (BOOL)hasFunctions; - (BOOL)hasFunctions;
- (BOOL)hasProcedures; - (BOOL)hasProcedures;
Expand Down
46 changes: 30 additions & 16 deletions Source/SPTablesList.m
Expand Up @@ -166,7 +166,8 @@ - (IBAction)updateTables:(nullable id)sender
#endif #endif
tableListIsSelectable = YES; tableListIsSelectable = YES;
#ifndef SP_CODA #ifndef SP_CODA
[[tablesListView onMainThread] deselectAll:self]; [self deselectAllTables];

tableListIsSelectable = previousTableListIsSelectable; tableListIsSelectable = previousTableListIsSelectable;
#endif #endif
SPMainQSync(^{ SPMainQSync(^{
Expand Down Expand Up @@ -574,24 +575,24 @@ - (IBAction)copyTable:(id)sender


[[tableDocumentInstance parentWindow] endEditingFor:nil]; [[tableDocumentInstance parentWindow] endEditingFor:nil];


// Detect table type: table or view
NSInteger tblType = [[filteredTableTypes objectAtIndex:[tablesListView selectedRow]] integerValue]; NSInteger tblType = [[filteredTableTypes objectAtIndex:[tablesListView selectedRow]] integerValue];


switch (tblType){ switch (tblType)
{
case SPTableTypeTable: case SPTableTypeTable:
tableType = NSLocalizedString(@"table",@"table"); tableType = NSLocalizedString(@"table", @"table");
[copyTableContentSwitch setEnabled:YES]; [copyTableContentSwitch setEnabled:YES];
break; break;
case SPTableTypeView: case SPTableTypeView:
tableType = NSLocalizedString(@"view",@"view"); tableType = NSLocalizedString(@"view", @"view");
[copyTableContentSwitch setEnabled:NO]; [copyTableContentSwitch setEnabled:NO];
break; break;
case SPTableTypeProc: case SPTableTypeProc:
tableType = NSLocalizedString(@"procedure",@"procedure"); tableType = NSLocalizedString(@"procedure", @"procedure");
[copyTableContentSwitch setEnabled:NO]; [copyTableContentSwitch setEnabled:NO];
break; break;
case SPTableTypeFunc: case SPTableTypeFunc:
tableType = NSLocalizedString(@"function",@"function"); tableType = NSLocalizedString(@"function", @"function");
[copyTableContentSwitch setEnabled:NO]; [copyTableContentSwitch setEnabled:NO];
break; break;
} }
Expand Down Expand Up @@ -811,7 +812,6 @@ - (void)controlTextDidEndEditing:(NSNotification *)notification
#endif #endif
} }



/** /**
* Updates application state to match the current selection, including * Updates application state to match the current selection, including
* updating the interface selection if appropriate. * updating the interface selection if appropriate.
Expand Down Expand Up @@ -1167,6 +1167,11 @@ - (void)setSelectionState:(NSDictionary *)selectionDetails
#endif #endif
} }


- (void)deselectAllTables
{
[[tablesListView onMainThread] deselectAll:self];
}

#pragma mark - #pragma mark -
#pragma mark Getter methods #pragma mark Getter methods


Expand Down Expand Up @@ -1403,12 +1408,15 @@ - (BOOL)selectItemWithName:(NSString *)theName
#ifndef SP_CODA /* table list filtering */ #ifndef SP_CODA /* table list filtering */
if (!isTableListFiltered) { if (!isTableListFiltered) {
[tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO]; [tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
} else { }
else {
NSInteger filteredIndex = [filteredTables indexOfObject:[tables objectAtIndex:itemIndex]]; NSInteger filteredIndex = [filteredTables indexOfObject:[tables objectAtIndex:itemIndex]];

if (filteredIndex != NSNotFound) { if (filteredIndex != NSNotFound) {
[tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:filteredIndex] byExtendingSelection:NO]; [tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:filteredIndex] byExtendingSelection:NO];
} else { }
[tablesListView deselectAll:nil]; else {
[self deselectAllTables];
#endif #endif
if (selectedTableName) [selectedTableName release]; if (selectedTableName) [selectedTableName release];


Expand Down Expand Up @@ -1458,10 +1466,14 @@ - (BOOL)selectItemsWithNames:(NSArray *)theNames


if (!isTableListFiltered) { if (!isTableListFiltered) {
[tablesListView selectRowIndexes:selectionIndexSet byExtendingSelection:NO]; [tablesListView selectRowIndexes:selectionIndexSet byExtendingSelection:NO];
} else { }
[tablesListView deselectAll:nil]; else {
[self deselectAllTables];

[listFilterField setStringValue:@""]; [listFilterField setStringValue:@""];

[self updateFilter:self]; [self updateFilter:self];

[tablesListView selectRowIndexes:selectionIndexSet byExtendingSelection:NO]; [tablesListView selectRowIndexes:selectionIndexSet byExtendingSelection:NO];
} }


Expand Down Expand Up @@ -1987,11 +1999,12 @@ - (void) makeTableListHaveFocus
/** /**
* Update the filter search. * Update the filter search.
*/ */
- (IBAction) updateFilter:(id)sender - (IBAction)updateFilter:(id)sender
{ {
// Don't try and maintain selections of multiple rows through filtering // Don't try and maintain selections of multiple rows through filtering
if ([tablesListView numberOfSelectedRows] > 1) { if ([tablesListView numberOfSelectedRows] > 1) {
[tablesListView deselectAll:self]; [self deselectAllTables];

if (selectedTableName) SPClear(selectedTableName); if (selectedTableName) SPClear(selectedTableName);
} }


Expand Down Expand Up @@ -2291,7 +2304,8 @@ - (void)_removeTable:(BOOL)force
} }


[tablesListView reloadData]; [tablesListView reloadData];
[tablesListView deselectAll:self];
[self deselectAllTables];


#ifndef SP_CODA #ifndef SP_CODA
[tableDocumentInstance updateWindowTitle:self]; [tableDocumentInstance updateWindowTitle:self];
Expand Down

0 comments on commit 964d811

Please sign in to comment.