diff options
author | stuconnolly <stuart02@gmail.com> | 2013-02-21 22:00:31 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2013-02-21 22:00:31 +0000 |
commit | e708cef969bb833a35615f1b5bada42a0d464fcd (patch) | |
tree | ad8dee8ffb486f6ce371dd6650a2bcb7d1b40158 | |
parent | c0dc27bfb033fbd94013f593f3cf242a5777a252 (diff) | |
download | sequelpro-e708cef969bb833a35615f1b5bada42a0d464fcd.tar.gz sequelpro-e708cef969bb833a35615f1b5bada42a0d464fcd.tar.bz2 sequelpro-e708cef969bb833a35615f1b5bada42a0d464fcd.zip |
Move the table triggers controller delegate methods to their own category.
-rw-r--r-- | Source/SPTableTriggers.m | 64 | ||||
-rw-r--r-- | Source/SPTableTriggersDelegate.h | 35 | ||||
-rw-r--r-- | Source/SPTableTriggersDelegate.m | 102 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 18 |
4 files changed, 154 insertions, 65 deletions
diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m index 10099717..22374e23 100644 --- a/Source/SPTableTriggers.m +++ b/Source/SPTableTriggers.m @@ -340,58 +340,6 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; } #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 /** @@ -561,17 +509,6 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; } #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 diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 7ffc1841..37cabecc 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 1198F5B31174EDD500670590 /* SPDatabaseCopy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1198F5B21174EDD500670590 /* SPDatabaseCopy.m */; }; 11B55BFE1189E3B2009EF465 /* SPDatabaseAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 11B55BFD1189E3B2009EF465 /* SPDatabaseAction.m */; }; 11C211301180EC9A00758039 /* SPDatabaseRename.m in Sources */ = {isa = PBXBuildFile; fileRef = 11C2109D1180E70800758039 /* SPDatabaseRename.m */; }; + 17005CB316D6CF0000AF81F4 /* SPTableTriggersDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 17005CB216D6CF0000AF81F4 /* SPTableTriggersDelegate.m */; }; 171312CE109D23C700FB465F /* SPTableTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 171312CD109D23C700FB465F /* SPTableTextFieldCell.m */; }; 1713C740140D8AEF00CFD461 /* SPQueryDocumentsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1713C73F140D8AEF00CFD461 /* SPQueryDocumentsController.m */; }; 1713C75F140D8D5900CFD461 /* SPQueryConsoleDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 1713C75E140D8D5900CFD461 /* SPQueryConsoleDataSource.m */; }; @@ -596,6 +597,8 @@ 11C210DD1180E9B800758039 /* SPDatabaseRenameTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPDatabaseRenameTest.h; sourceTree = "<group>"; }; 11C210DE1180E9B800758039 /* SPDatabaseRenameTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDatabaseRenameTest.m; sourceTree = "<group>"; }; 11D44DEF118F5887002AA43C /* OCMock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCMock.framework; path = Frameworks/OCMock.framework; sourceTree = "<group>"; }; + 17005CB116D6CF0000AF81F4 /* SPTableTriggersDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableTriggersDelegate.h; sourceTree = "<group>"; }; + 17005CB216D6CF0000AF81F4 /* SPTableTriggersDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableTriggersDelegate.m; sourceTree = "<group>"; }; 17128B8A0FE6E0210035DD75 /* QLPreviewPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QLPreviewPanel.h; sourceTree = "<group>"; }; 1713122F109C7DF600FB465F /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; }; 171312CC109D23C700FB465F /* SPTableTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableTextFieldCell.h; sourceTree = "<group>"; }; @@ -1354,6 +1357,17 @@ name = "Database Actions"; sourceTree = "<group>"; }; + 17005CB016D6CEA400AF81F4 /* Table Triggers */ = { + isa = PBXGroup; + children = ( + 29FA88211114619E00D1AF3D /* SPTableTriggers.h */, + 29FA88221114619E00D1AF3D /* SPTableTriggers.m */, + 17005CB116D6CF0000AF81F4 /* SPTableTriggersDelegate.h */, + 17005CB216D6CF0000AF81F4 /* SPTableTriggersDelegate.m */, + ); + name = "Table Triggers"; + sourceTree = "<group>"; + }; 170DBD5815BEBE39007E95AB /* zlib */ = { isa = PBXGroup; children = ( @@ -1524,8 +1538,6 @@ 177E7A220FCB6A2E00E9E122 /* SPExtendedTableInfo.m */, 387BBBA60FBCB6CB00B31746 /* SPTableRelations.h */, 387BBBA70FBCB6CB00B31746 /* SPTableRelations.m */, - 29FA88211114619E00D1AF3D /* SPTableTriggers.h */, - 29FA88221114619E00D1AF3D /* SPTableTriggers.m */, 17E641500EF01EF6001BC333 /* SPDatabaseDocument.h */, 17E641510EF01EF6001BC333 /* SPDatabaseDocument.m */, 17D3DC1E1281816E002A163A /* SPDatabaseViewController.h */, @@ -1533,6 +1545,7 @@ 17D38FC2127B0C9500672B13 /* Connection View */, 17386E08151924E9002DC206 /* Table Content */, 17D38F691279E17D00672B13 /* Table Structure */, + 17005CB016D6CEA400AF81F4 /* Table Triggers */, 1792C28910AE1C7200ABE758 /* Controller Categories */, ); name = "Main View Controllers"; @@ -3223,6 +3236,7 @@ 58DFC91615CB3501003B4330 /* BGHUDButtonCell.m in Sources */, 171B374115DA654300EBC7AB /* SPTableContentFilter.m in Sources */, 5843E247162B555B00EAA6D1 /* SPThreadAdditions.m in Sources */, + 17005CB316D6CF0000AF81F4 /* SPTableTriggersDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |