aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-10-19 19:40:37 +0000
committerstuconnolly <stuart02@gmail.com>2010-10-19 19:40:37 +0000
commit68e90d59bbb8660751e9fb74cd6553c4b32bcfa5 (patch)
tree18289bc6324d25b93f96ffe84b2d92d7e2f10dd8 /Source
parentda8b958902b41f733b2c346836a1c5bdab3abc70 (diff)
downloadsequelpro-68e90d59bbb8660751e9fb74cd6553c4b32bcfa5.tar.gz
sequelpro-68e90d59bbb8660751e9fb74cd6553c4b32bcfa5.tar.bz2
sequelpro-68e90d59bbb8660751e9fb74cd6553c4b32bcfa5.zip
Add a 'Edit Trigger' menu item to the trigger's table view context menu.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPTableTriggers.h2
-rw-r--r--Source/SPTableTriggers.m186
2 files changed, 108 insertions, 80 deletions
diff --git a/Source/SPTableTriggers.h b/Source/SPTableTriggers.h
index b2a754ce..b7bd61fd 100644
--- a/Source/SPTableTriggers.h
+++ b/Source/SPTableTriggers.h
@@ -23,7 +23,6 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
-#import <Cocoa/Cocoa.h>
#import <MCPKit/MCPKit.h>
@interface SPTableTriggers : NSObject
@@ -68,6 +67,7 @@
// IB action methods
- (IBAction)addTrigger:(id)sender;
+- (IBAction)editTrigger:(id)sender;
- (IBAction)removeTrigger:(id)sender;
- (IBAction)closeTriggerSheet:(id)sender;
- (IBAction)confirmAddTrigger:(id)sender;
diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m
index 86f0aa53..a934f450 100644
--- a/Source/SPTableTriggers.m
+++ b/Source/SPTableTriggers.m
@@ -34,6 +34,7 @@
@interface SPTableTriggers (PrivateAPI)
+- (void)_editTriggerAtIndex:(NSInteger)index;
- (void)_toggleConfirmAddTriggerButtonEnabled;
- (void)_refreshTriggerDataForcingCacheRefresh:(BOOL)clearAllCaches;
@@ -43,6 +44,9 @@
@synthesize connection;
+#pragma mark -
+#pragma mark Initialization
+
/**
* init
*/
@@ -275,6 +279,14 @@
}
/**
+ * Edits the selected trigger.
+ */
+- (IBAction)editTrigger:(id)sender
+{
+ [self _editTriggerAtIndex:[triggersTableView selectedRow]];
+}
+
+/**
* Trigger a refresh of the displayed triggers via the interface.
*/
- (IBAction)refreshTriggers:(id)sender
@@ -309,54 +321,13 @@
/**
* Double-click action on table cells - for the time being, return NO to disable editing.
*/
-- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
if ([tableDocumentInstance isWorking]) return NO;
// Start Edit panel
- if (([triggerData count] > rowIndex) && ([triggerData objectAtIndex:rowIndex] != NSNotFound))
- {
- NSDictionary *trigger = [triggerData objectAtIndex:rowIndex];
-
- // Cache the original trigger's name and statement in the event that the editing process fails and
- // we need to recreate it.
- editTriggerName = [trigger objectForKey:@"trigger"];
- editTriggerStatement = [trigger objectForKey:@"statement"];
- editTriggerTableName = [trigger objectForKey:@"table"];
- editTriggerEvent = [trigger objectForKey:@"event"];
- editTriggerActionTime = [trigger objectForKey:@"timing"];
-
- [triggerNameTextField setStringValue:editTriggerName];
- [triggerStatementTextView setString:editTriggerStatement];
-
- // 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:@"timing"] uppercaseString]]) {
- [triggerActionTimePopUpButton selectItemAtIndex:i];
- break;
- }
- }
-
- // 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:@"event"] uppercaseString]]) {
- [triggerEventPopUpButton selectItemAtIndex:i];
- break;
- }
- }
-
- // Change button label from Add to Edit
- [confirmAddTriggerButton setTitle:NSLocalizedString(@"Save", @"Save trigger button label")];
-
- isEdit = YES;
-
- [NSApp beginSheet:addTriggerPanel
- modalForWindow:[tableDocumentInstance parentWindow]
- modalDelegate:self
- didEndSelector:nil
- contextInfo:nil];
+ if (([triggerData count] > rowIndex) && ([triggerData objectAtIndex:rowIndex] != NSNotFound)) {
+ [self _editTriggerAtIndex:rowIndex];
}
return NO;
@@ -365,7 +336,7 @@
/**
* Disable row selection while the document is working.
*/
-- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
+- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)rowIndex
{
return (![tableDocumentInstance isWorking]);
}
@@ -472,25 +443,22 @@
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
+ SEL action = [menuItem action];
+
// Remove row
- if ([menuItem action] == @selector(removeTrigger:)) {
+ if (action == @selector(removeTrigger:)) {
[menuItem setTitle:([triggersTableView numberOfSelectedRows] > 1) ? NSLocalizedString(@"Delete Triggers", @"delete triggers menu item") : NSLocalizedString(@"Delete Trigger", @"delete trigger menu item")];
return ([triggersTableView numberOfSelectedRows] > 0);
}
+ else if (action == @selector(editTrigger:)) {
+ return ([triggersTableView numberOfSelectedRows] == 1);
+ }
return YES;
}
/**
- * Toggles the enabled state of confirm add trigger button based on the editing of the trigger's name.
- */
-- (void)controlTextDidChange:(NSNotification *)notification
-{
- [self _toggleConfirmAddTriggerButtonEnabled];
-}
-
-/**
* Toggles the enabled state of confirm add trigger button based on the editing of the trigger's statement.
*/
- (void)triggerStatementTextDidChange:(NSNotification *)notification
@@ -542,23 +510,68 @@
}
#pragma mark -
+#pragma mark Textfield delegate methods
/**
- * Dealloc.
+ * Toggles the enabled state of confirm add trigger button based on the editing of the trigger's name.
*/
-- (void)dealloc
+- (void)controlTextDidChange:(NSNotification *)notification
{
- [triggerData release], triggerData = nil;
-
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:SPUseMonospacedFonts];
-
- [super dealloc];
+ [self _toggleConfirmAddTriggerButtonEnabled];
}
-@end
+#pragma mark -
+#pragma mark Private API
-@implementation SPTableTriggers (PrivateAPI)
+/**
+ * Presents the edit sheet for the trigger at the supplied index.
+ *
+ * @param index The index of the trigger to edit
+ */
+- (void)_editTriggerAtIndex:(NSInteger)index
+{
+ NSDictionary *trigger = [triggerData objectAtIndex:index];
+
+ // Cache the original trigger's name and statement in the event that the editing process fails and
+ // we need to recreate it.
+ editTriggerName = [trigger objectForKey:@"trigger"];
+ editTriggerStatement = [trigger objectForKey:@"statement"];
+ editTriggerTableName = [trigger objectForKey:@"table"];
+ editTriggerEvent = [trigger objectForKey:@"event"];
+ editTriggerActionTime = [trigger objectForKey:@"timing"];
+
+ [triggerNameTextField setStringValue:editTriggerName];
+ [triggerStatementTextView setString:editTriggerStatement];
+
+ // 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:@"timing"] uppercaseString]]) {
+ [triggerActionTimePopUpButton selectItemAtIndex:i];
+ break;
+ }
+ }
+
+ // 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:@"event"] uppercaseString]]) {
+ [triggerEventPopUpButton selectItemAtIndex:i];
+ break;
+ }
+ }
+
+ // Change button label from Add to Edit
+ [confirmAddTriggerButton setTitle:NSLocalizedString(@"Save", @"Save trigger button label")];
+
+ isEdit = YES;
+
+ [NSApp beginSheet:addTriggerPanel
+ modalForWindow:[tableDocumentInstance parentWindow]
+ modalDelegate:self
+ didEndSelector:nil
+ contextInfo:nil];
+}
/**
* Enables or disables the confirm add trigger button based on the values of the trigger's name
@@ -575,33 +588,48 @@
- (void)_refreshTriggerDataForcingCacheRefresh:(BOOL)clearAllCaches
{
[triggerData removeAllObjects];
-
+
if ([tablesListInstance tableType] == SPTableTypeTable) {
-
+
if (clearAllCaches) {
[tableDataInstance resetAllData];
[tableDataInstance updateTriggersForCurrentTable];
}
-
+
NSArray *triggers = ([[tableDocumentInstance serverSupport] supportsTriggers]) ? [tableDataInstance triggers] : nil;
-
+
for (NSDictionary *trigger in triggers)
{
[triggerData addObject:[NSDictionary dictionaryWithObjectsAndKeys:
- [trigger objectForKey:@"Table"], @"table",
- [trigger objectForKey:@"Trigger"], @"trigger",
- [trigger objectForKey:@"Event"], @"event",
- [trigger objectForKey:@"Timing"], @"timing",
- [trigger objectForKey:@"Statement"], @"statement",
- [trigger objectForKey:@"Definer"], @"definer",
- [trigger objectForKey:@"Created"], @"created",
- [trigger objectForKey:@"sql_mode"], @"sql_mode",
- nil]];
-
+ [trigger objectForKey:@"Table"], @"table",
+ [trigger objectForKey:@"Trigger"], @"trigger",
+ [trigger objectForKey:@"Event"], @"event",
+ [trigger objectForKey:@"Timing"], @"timing",
+ [trigger objectForKey:@"Statement"], @"statement",
+ [trigger objectForKey:@"Definer"], @"definer",
+ [trigger objectForKey:@"Created"], @"created",
+ [trigger objectForKey:@"sql_mode"], @"sql_mode",
+ nil]];
+
}
}
-
+
[triggersTableView reloadData];
}
+#pragma mark -
+
+/**
+ * Dealloc.
+ */
+- (void)dealloc
+{
+ [triggerData release], triggerData = nil;
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:SPUseMonospacedFonts];
+
+ [super dealloc];
+}
+
@end