diff options
Diffstat (limited to 'Source/SPTableTriggers.m')
-rw-r--r-- | Source/SPTableTriggers.m | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m index dde516a8..c202e9c9 100644 --- a/Source/SPTableTriggers.m +++ b/Source/SPTableTriggers.m @@ -77,12 +77,7 @@ selector:@selector(triggerStatementTextDidChange:) name:NSTextStorageDidProcessEditingNotification object:[triggerStatementTextView textStorage]]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(tableSelectionChanged:) - name:SPTableChangedNotification - object:tableDocumentInstance]; - + // Add observers for document task activity [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDocumentTaskForTab:) @@ -94,6 +89,46 @@ object:tableDocumentInstance]; } +/** + * Called whenever the user selects the triggers tab for the first time, + * or switches between tables with the triggers tab active. + */ +- (void)loadTriggers +{ + BOOL enableInteraction = ((![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableTriggers]) || (![tableDocumentInstance isWorking])); + + // Disable all interface elements by default + [addTriggerButton setEnabled:NO]; + [refreshTriggersButton setEnabled:NO]; + [triggersTableView setEnabled:NO]; + [labelTextField setStringValue:@""]; + + // Show a warning if the version of MySQL is too low to support triggers + if ([connection serverMajorVersion] < 5 + || ([connection serverMajorVersion] == 5 + && [connection serverMinorVersion] == 0 + && [connection serverReleaseVersion] < 2)) + { + [labelTextField setStringValue:NSLocalizedString(@"This version of MySQL does not support triggers. Support for triggers was added in MySQL 5.0.2", @"triggers not supported label")]; + return; + } + + // If no item is selected, or the item selected is not a table, return. + if (![tablesListInstance tableName] || [tablesListInstance tableType] != SPTableTypeTable) + return; + + // Update the text label + [labelTextField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Triggers for table: %@", @"triggers for table label"), [tablesListInstance tableName]]]; + + // Enable interface elements + [addTriggerButton setEnabled:enableInteraction]; + [refreshTriggersButton setEnabled:enableInteraction]; + [triggersTableView setEnabled:YES]; + + // Ensure trigger data is loaded + [self _refreshTriggerDataForcingCacheRefresh:NO]; +} + #pragma mark - #pragma mark IB action methods @@ -185,49 +220,6 @@ [self _refreshTriggerDataForcingCacheRefresh:YES]; } -/** - * Called whenever the user selects a different table. - */ -- (void)tableSelectionChanged:(NSNotification *)notification -{ - BOOL enableInteraction = ((![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableTriggers]) || (![tableDocumentInstance isWorking])); - - // To begin enable all interface elements - [addTriggerButton setEnabled:enableInteraction]; - [refreshTriggersButton setEnabled:enableInteraction]; - [triggersTableView setEnabled:YES]; - - if (([connection serverMajorVersion] >= 5) && - ([connection serverMinorVersion] >= 0) && - ([connection serverReleaseVersion] >= 2)) { - - // Update the text label - [labelTextField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Triggers for table: %@", @"triggers for table label"), [tablesListInstance tableName]]]; - - [addTriggerButton setEnabled:enableInteraction]; - [refreshTriggersButton setEnabled:enableInteraction]; - [triggersTableView setEnabled:YES]; - - [self _refreshTriggerDataForcingCacheRefresh:NO]; - } - else { - [addTriggerButton setEnabled:NO]; - [refreshTriggersButton setEnabled:NO]; - [triggersTableView setEnabled:NO]; - - [labelTextField setStringValue:NSLocalizedString(@"This version of MySQL does not support triggers. Support for triggers was added in MySQL 5.0.2", @"triggers not supported label")]; - } - - // If a proc or function is selected disable everything. - if (([tablesListInstance tableType] == SPTableTypeProc) || ([tablesListInstance tableType] == SPTableTypeFunc)) { - [addTriggerButton setEnabled:NO]; - [refreshTriggersButton setEnabled:NO]; - [triggersTableView setEnabled:NO]; - - [labelTextField setStringValue:@""]; - } -} - #pragma mark - #pragma mark Tableview datasource methods @@ -479,7 +471,10 @@ if ([tablesListInstance tableType] == SPTableTypeTable) { - if (clearAllCaches) [tableDataInstance updateInformationForCurrentTable]; + if (clearAllCaches) { + [tableDataInstance resetAllData]; + [tableDataInstance updateTriggersForCurrentTable]; + } NSArray *triggers = [tableDataInstance triggers]; |