Permalink
Browse files

Fix Edit Trigger sheet no working correctly in many localized versions (

  • Loading branch information...
dmoagx committed Oct 15, 2015
1 parent 2aca7fa commit ce97183958fd81e2f7cd5c1218f9e529009ddddb
Showing with 57 additions and 22 deletions.
  1. +3 −0 Interfaces/English.lproj/DBView.xib
  2. +54 −22 Source/SPTableTriggers.m
@@ -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>
@@ -47,6 +47,20 @@
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 @@ - (IBAction)confirmAddTrigger:(id)sender
}
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 @@ - (void)_editTriggerAtIndex:(NSInteger)index
[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 @@ - (void)dealloc
}
@end
#pragma mark -
SPTriggerActionTimeTag TagForActionTime(NSString *mysql)
{
NSString *uc = [mysql uppercaseString];
if([uc isEqualToString:@"BEFORE"]) return SPTriggerActionTimeBeforeTag;
if([uc isEqualToString:@"AFTER"]) return SPTriggerActionTimeAfterTag;
SPLog(@"Unknown trigger action time: %@",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;
SPLog(@"Unknown trigger event: %@",uc);
return -1;
}

0 comments on commit ce97183

Please sign in to comment.