diff options
-rw-r--r-- | Interfaces/English.lproj/DBView.xib | 3 | ||||
-rw-r--r-- | Source/SPTableTriggers.m | 76 |
2 files changed, 57 insertions, 22 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index ad7a8129..2c1747be 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -9118,6 +9118,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <reference key="NSOnImage" ref="803427867"/> <reference key="NSMixedImage" ref="245717585"/> <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">1</int> <reference key="NSTarget" ref="556116646"/> </object> </array> @@ -9174,6 +9175,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <reference key="NSOnImage" ref="803427867"/> <reference key="NSMixedImage" ref="245717585"/> <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">1</int> <reference key="NSTarget" ref="468443756"/> </object> <object class="NSMenuItem" id="766167700"> @@ -9185,6 +9187,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <reference key="NSOnImage" ref="803427867"/> <reference key="NSMixedImage" ref="245717585"/> <string key="NSAction">_popUpItemAction:</string> + <int key="NSTag">2</int> <reference key="NSTarget" ref="468443756"/> </object> </array> diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m index 179e509e..dbe64751 100644 --- a/Source/SPTableTriggers.m +++ b/Source/SPTableTriggers.m @@ -47,6 +47,20 @@ static const NSString *SPTriggerDefiner = @"TriggerDefiner"; static const NSString *SPTriggerCreated = @"TriggerCreated"; static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; +typedef NS_ENUM(NSInteger, SPTriggerActionTimeTag) { + SPTriggerActionTimeBeforeTag = 0, + SPTriggerActionTimeAfterTag = 1 +}; + +typedef NS_ENUM(NSInteger, SPTriggerEventTag) { + SPTriggerEventInsertTag = 0, + SPTriggerEventUpdateTag = 1, + SPTriggerEventDeleteTag = 2 +}; + +static SPTriggerActionTimeTag TagForActionTime(NSString *mysql); +static SPTriggerEventTag TagForEvent(NSString *mysql); + @interface SPTableTriggers () - (void)_editTriggerAtIndex:(NSInteger)index; @@ -208,18 +222,29 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; } NSString *triggerName = [triggerNameTextField stringValue]; - NSString *triggerActionTime = ([triggerActionTimePopUpButton indexOfSelectedItem]) ? @"AFTER" : @"BEFORE"; - NSString *triggerEvent = @""; - switch ([triggerEventPopUpButton indexOfSelectedItem]) + NSString *triggerActionTime = @""; + switch ([triggerActionTimePopUpButton selectedTag]) + { + case SPTriggerActionTimeBeforeTag: + triggerActionTime = @"BEFORE"; + break; + + case SPTriggerActionTimeAfterTag: + triggerActionTime = @"AFTER"; + break; + } + + NSString *triggerEvent = @""; + switch ([triggerEventPopUpButton selectedTag]) { - case 0: + case SPTriggerEventInsertTag: triggerEvent = @"INSERT"; break; - case 1: + case SPTriggerEventUpdateTag: triggerEvent = @"UPDATE"; break; - case 2: + case SPTriggerEventDeleteTag: triggerEvent = @"DELETE"; break; } @@ -531,23 +556,9 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; [triggerNameTextField setStringValue:[trigger objectForKey:SPTriggerName]]; [triggerStatementTextView setString:[trigger objectForKey:SPTriggerStatement]]; - // Timin title is different then what we have saved in the database (case difference) - for (NSUInteger i = 0; i < [[triggerActionTimePopUpButton itemArray] count]; i++) - { - if ([[[triggerActionTimePopUpButton itemTitleAtIndex:i] uppercaseString] isEqualToString:[[trigger objectForKey:SPTriggerActionTime] uppercaseString]]) { - [triggerActionTimePopUpButton selectItemAtIndex:i]; - break; - } - } + [triggerActionTimePopUpButton selectItemWithTag:TagForActionTime([trigger objectForKey:SPTriggerActionTime])]; - // Event title is different then what we have saved in the database (case difference) - for (NSUInteger i = 0; i < [[triggerEventPopUpButton itemArray] count]; i++) - { - if ([[[triggerEventPopUpButton itemTitleAtIndex:i] uppercaseString] isEqualToString:[[trigger objectForKey:SPTriggerEvent] uppercaseString]]) { - [triggerEventPopUpButton selectItemAtIndex:i]; - break; - } - } + [triggerEventPopUpButton selectItemWithTag:TagForEvent([trigger objectForKey:SPTriggerEvent])]; // Change button label from Add to Edit [confirmAddTriggerButton setTitle:NSLocalizedString(@"Save", @"Save trigger button label")]; @@ -642,3 +653,24 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; } @end + +#pragma mark - + +SPTriggerActionTimeTag TagForActionTime(NSString *mysql) +{ + NSString *uc = [mysql uppercaseString]; + if([uc isEqualToString:@"BEFORE"]) return SPTriggerActionTimeBeforeTag; + if([uc isEqualToString:@"AFTER"]) return SPTriggerActionTimeAfterTag; + NSLog(@"%s Unknown trigger action time: %@",__FUNCTION__,uc); + return -1; +} + +SPTriggerEventTag TagForEvent(NSString *mysql) +{ + NSString *uc = [mysql uppercaseString]; + if([uc isEqualToString:@"INSERT"]) return SPTriggerEventInsertTag; + if([uc isEqualToString:@"UPDATE"]) return SPTriggerEventUpdateTag; + if([uc isEqualToString:@"DELETE"]) return SPTriggerEventDeleteTag; + NSLog(@"%s Unknown trigger event: %@",__FUNCTION__,uc); + return -1; +} |