From e708cef969bb833a35615f1b5bada42a0d464fcd Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Thu, 21 Feb 2013 22:00:31 +0000 Subject: Move the table triggers controller delegate methods to their own category. --- Source/SPTableTriggers.m | 64 +----------------------- Source/SPTableTriggersDelegate.h | 35 ++++++++++++++ Source/SPTableTriggersDelegate.m | 102 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 63 deletions(-) create mode 100644 Source/SPTableTriggersDelegate.h create mode 100644 Source/SPTableTriggersDelegate.m (limited to 'Source') diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m index 10099717..22374e23 100644 --- a/Source/SPTableTriggers.m +++ b/Source/SPTableTriggers.m @@ -339,58 +339,6 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; return value; } -#pragma mark - -#pragma mark Tableview delegate methods - -/** - * Called whenever the triggers table view selection changes. - */ -- (void)tableViewSelectionDidChange:(NSNotification *)notification -{ - [removeTriggerButton setEnabled:([triggersTableView numberOfSelectedRows] > 0)]; -} - -/** - * Alter the colour of cells displaying NULL values - */ -- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex -{ - if (![cell respondsToSelector:@selector(setTextColor:)]) { - return; - } - - id theValue = [[triggerData objectAtIndex:rowIndex] objectForKey:[tableColumn identifier]]; - - if ([theValue isNSNull]) { - [cell setTextColor:[NSColor lightGrayColor]]; - } else { - [cell setTextColor:[NSColor blackColor]]; - } -} - -/** - * Double-click action on table cells - for the time being, return NO to disable editing. - */ -- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex -{ - if ([tableDocumentInstance isWorking]) return NO; - - // Start Edit panel - if (((NSInteger)[triggerData count] > rowIndex) && [triggerData objectAtIndex:rowIndex]) { - [self _editTriggerAtIndex:rowIndex]; - } - - return NO; -} - -/** - * Disable row selection while the document is working. - */ -- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)rowIndex -{ - return (![tableDocumentInstance isWorking]); -} - #pragma mark - #pragma mark Task interaction @@ -560,17 +508,6 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; return data; } -#pragma mark - -#pragma mark Textfield delegate methods - -/** - * Toggles the enabled state of confirm add trigger button based on the editing of the trigger's name. - */ -- (void)controlTextDidChange:(NSNotification *)notification -{ - [self _toggleConfirmAddTriggerButtonEnabled]; -} - #pragma mark - #pragma mark Private API @@ -612,6 +549,7 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; [confirmAddTriggerButton setTitle:NSLocalizedString(@"Save", @"Save trigger button label")]; isEdit = YES; + [self _openTriggerSheet]; } diff --git a/Source/SPTableTriggersDelegate.h b/Source/SPTableTriggersDelegate.h new file mode 100644 index 00000000..c81ae72b --- /dev/null +++ b/Source/SPTableTriggersDelegate.h @@ -0,0 +1,35 @@ +// +// $Id$ +// +// SPTableTriggersDelegate.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 21, 2013. +// Copyright (c) 2013 Stuart Connolly. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +#import "SPTableTriggers.h" + +@interface SPTableTriggers (SPTableTriggersDelegate) + +@end diff --git a/Source/SPTableTriggersDelegate.m b/Source/SPTableTriggersDelegate.m new file mode 100644 index 00000000..9c752cc2 --- /dev/null +++ b/Source/SPTableTriggersDelegate.m @@ -0,0 +1,102 @@ +// +// $Id$ +// +// SPTableTriggersDelegate.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 21, 2013. +// Copyright (c) 2013 Stuart Connolly. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +#import "SPTableTriggersDelegate.h" +#import "SPDatabaseDocument.h" + +@interface SPTableTriggers () + +- (void)_editTriggerAtIndex:(NSInteger)index; +- (void)_toggleConfirmAddTriggerButtonEnabled; + +@end + +@implementation SPTableTriggers (SPTableTriggersDelegate) + +#pragma mark - +#pragma mark Tableview delegate methods + +/** + * Called whenever the triggers table view selection changes. + */ +- (void)tableViewSelectionDidChange:(NSNotification *)notification +{ + [removeTriggerButton setEnabled:([triggersTableView numberOfSelectedRows] > 0)]; +} + +/** + * Alter the colour of cells displaying NULL values + */ +- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex +{ + if (![cell respondsToSelector:@selector(setTextColor:)]) { + return; + } + + id value = [[triggerData objectAtIndex:rowIndex] objectForKey:[tableColumn identifier]]; + + [cell setTextColor:[value isNSNull] ? [NSColor lightGrayColor] : [NSColor blackColor]]; +} + +/** + * Double-click action on table cells - for the time being, return NO to disable editing. + */ +- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex +{ + if ([tableDocumentInstance isWorking]) return NO; + + // Start Edit panel + if (((NSInteger)[triggerData count] > rowIndex) && [triggerData objectAtIndex:rowIndex]) { + [self _editTriggerAtIndex:rowIndex]; + } + + return NO; +} + +/** + * Disable row selection while the document is working. + */ +- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)rowIndex +{ + return (![tableDocumentInstance isWorking]); +} + +#pragma mark - +#pragma mark Textfield delegate methods + +/** + * Toggles the enabled state of confirm add trigger button based on the editing of the trigger's name. + */ +- (void)controlTextDidChange:(NSNotification *)notification +{ + [self _toggleConfirmAddTriggerButtonEnabled]; +} + +@end -- cgit v1.2.3