From 5f1b37e21c113101b2d72124f6dbd22b77a4fddc Mon Sep 17 00:00:00 2001 From: Stuart Connolly Date: Tue, 28 Mar 2017 23:15:10 +0100 Subject: Move table relations delegate methods into their own catrgory to be consistent with other controllers. --- Source/SPTableRelations.h | 6 +-- Source/SPTableRelations.m | 56 +---------------------- Source/SPTableRelationsDelegate.h | 35 +++++++++++++++ Source/SPTableRelationsDelegate.m | 87 ++++++++++++++++++++++++++++++++++++ sequel-pro.xcodeproj/project.pbxproj | 18 +++++++- 5 files changed, 143 insertions(+), 59 deletions(-) create mode 100644 Source/SPTableRelationsDelegate.h create mode 100644 Source/SPTableRelationsDelegate.m diff --git a/Source/SPTableRelations.h b/Source/SPTableRelations.h index 1ab7f1b7..6fa2bd57 100644 --- a/Source/SPTableRelations.h +++ b/Source/SPTableRelations.h @@ -34,7 +34,7 @@ @class SPTablesList; @class SPTableData; -@interface SPTableRelations : NSObject +@interface SPTableRelations : NSObject { IBOutlet SPDatabaseDocument *tableDocumentInstance; IBOutlet SPTablesList *tablesListInstance; @@ -85,8 +85,8 @@ - (void)tableSelectionChanged:(NSNotification *)notification; // Task interaction -- (void)startDocumentTaskForTab:(NSNotification *)aNotification; -- (void)endDocumentTaskForTab:(NSNotification *)aNotification; +- (void)startDocumentTaskForTab:(NSNotification *)notification; +- (void)endDocumentTaskForTab:(NSNotification *)notification; // Other - (NSArray *)relationDataForPrinting; diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m index 64a7b98b..20059fbb 100644 --- a/Source/SPTableRelations.m +++ b/Source/SPTableRelations.m @@ -372,27 +372,6 @@ static NSString *SPRelationOnDeleteKey = @"on_delete"; [self _refreshRelationDataForcingCacheRefresh:NO]; } -#pragma mark - -#pragma mark TextField delegate methods - -- (void)controlTextDidChange:(NSNotification *)notification -{ - // Make sure the user does not enter a taken name, using the quickly-generated incomplete list - if ([notification object] == constraintName) { - NSString *userValue = [[constraintName stringValue] lowercaseString]; - - // Make field red and disable add button - if ([takenConstraintNames containsObject:userValue]) { - [constraintName setTextColor:[NSColor redColor]]; - [confirmAddRelationButton setEnabled:NO]; - } - else { - [constraintName setTextColor:[NSColor controlTextColor]]; - [confirmAddRelationButton setEnabled:YES]; - } - } -} - #pragma mark - #pragma mark Tableview datasource methods @@ -412,45 +391,14 @@ static NSString *SPRelationOnDeleteKey = @"on_delete"; return data; } -#pragma mark - -#pragma mark Tableview delegate methods - -/** - * Called whenever the relations table view selection changes. - */ -- (void)tableViewSelectionDidChange:(NSNotification *)notification -{ - [removeRelationButton setEnabled:([relationsTableView numberOfSelectedRows] > 0)]; -} - -/* - * 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; - - 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 /** * Disable all content interactive elements during an ongoing task. */ -- (void)startDocumentTaskForTab:(NSNotification *)aNotification +- (void)startDocumentTaskForTab:(NSNotification *)notification { - // Only proceed if this view is selected. if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableRelations]) return; @@ -462,7 +410,7 @@ static NSString *SPRelationOnDeleteKey = @"on_delete"; /** * Enable all content interactive elements after an ongoing task. */ -- (void)endDocumentTaskForTab:(NSNotification *)aNotification +- (void)endDocumentTaskForTab:(NSNotification *)notification { // Only proceed if this view is selected. if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableRelations]) return; diff --git a/Source/SPTableRelationsDelegate.h b/Source/SPTableRelationsDelegate.h new file mode 100644 index 00000000..79b1e914 --- /dev/null +++ b/Source/SPTableRelationsDelegate.h @@ -0,0 +1,35 @@ +// +// SPTableRelationsDelegate.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on March 28, 2017. +// Copyright (c) 2017 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. +// +// More info at + +#import "SPTableRelations.h" + +@interface SPTableRelations (SPTableRelationsDelegate) + +@end diff --git a/Source/SPTableRelationsDelegate.m b/Source/SPTableRelationsDelegate.m new file mode 100644 index 00000000..bf083318 --- /dev/null +++ b/Source/SPTableRelationsDelegate.m @@ -0,0 +1,87 @@ +// +// SPTableRelationsDelegate.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on March 28, 2017. +// Copyright (c) 2017 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. +// +// More info at + +#import "SPTableRelationsDelegate.h" +#import "SPDatabaseDocument.h" + +@implementation SPTableRelations (SPTableRelationsDelegate) + +#pragma mark - +#pragma mark TextField delegate methods + +- (void)controlTextDidChange:(NSNotification *)notification +{ + // Make sure the user does not enter a taken name, using the quickly-generated incomplete list + if ([notification object] == constraintName) { + NSString *userValue = [[constraintName stringValue] lowercaseString]; + + // Make field red and disable add button + if ([takenConstraintNames containsObject:userValue]) { + [constraintName setTextColor:[NSColor redColor]]; + [confirmAddRelationButton setEnabled:NO]; + } + else { + [constraintName setTextColor:[NSColor controlTextColor]]; + [confirmAddRelationButton setEnabled:YES]; + } + } +} + +#pragma mark - +#pragma mark Tableview delegate methods + +/** + * Called whenever the relations table view selection changes. + */ +- (void)tableViewSelectionDidChange:(NSNotification *)notification +{ + [removeRelationButton setEnabled:([relationsTableView numberOfSelectedRows] > 0)]; +} + +/* + * 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; + + return NO; +} + +/** + * Disable row selection while the document is working. + */ +- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)rowIndex +{ + return ![tableDocumentInstance isWorking]; +} + +@end diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 1169e406..d7194ef7 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 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 */; }; + 171156551E8B0F96002E6363 /* SPTableRelationsDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 171156541E8B0F96002E6363 /* SPTableRelationsDelegate.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 */; }; @@ -673,6 +674,8 @@ 11D44DEF118F5887002AA43C /* OCMock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCMock.framework; path = Frameworks/OCMock.framework; sourceTree = ""; }; 17005CB116D6CF0000AF81F4 /* SPTableTriggersDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableTriggersDelegate.h; sourceTree = ""; }; 17005CB216D6CF0000AF81F4 /* SPTableTriggersDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableTriggersDelegate.m; sourceTree = ""; }; + 171156531E8B0F96002E6363 /* SPTableRelationsDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableRelationsDelegate.h; sourceTree = ""; }; + 171156541E8B0F96002E6363 /* SPTableRelationsDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableRelationsDelegate.m; sourceTree = ""; }; 1713122F109C7DF600FB465F /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = ""; }; 171312CC109D23C700FB465F /* SPTableTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableTextFieldCell.h; sourceTree = ""; }; 171312CD109D23C700FB465F /* SPTableTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableTextFieldCell.m; sourceTree = ""; }; @@ -1495,6 +1498,17 @@ name = "Table Triggers"; sourceTree = ""; }; + 171156501E8B0F40002E6363 /* Table Relations */ = { + isa = PBXGroup; + children = ( + 387BBBA60FBCB6CB00B31746 /* SPTableRelations.h */, + 387BBBA70FBCB6CB00B31746 /* SPTableRelations.m */, + 171156531E8B0F96002E6363 /* SPTableRelationsDelegate.h */, + 171156541E8B0F96002E6363 /* SPTableRelationsDelegate.m */, + ); + name = "Table Relations"; + sourceTree = ""; + }; 171312CF109D23CA00FB465F /* Cells */ = { isa = PBXGroup; children = ( @@ -1655,8 +1669,6 @@ 17E641490EF01EF6001BC333 /* SPCustomQuery.m */, 177E7A210FCB6A2E00E9E122 /* SPExtendedTableInfo.h */, 177E7A220FCB6A2E00E9E122 /* SPExtendedTableInfo.m */, - 387BBBA60FBCB6CB00B31746 /* SPTableRelations.h */, - 387BBBA70FBCB6CB00B31746 /* SPTableRelations.m */, 17E641500EF01EF6001BC333 /* SPDatabaseDocument.h */, 17E641510EF01EF6001BC333 /* SPDatabaseDocument.m */, 17D3DC1E1281816E002A163A /* SPDatabaseViewController.h */, @@ -1665,6 +1677,7 @@ 17386E08151924E9002DC206 /* Table Content */, 17D38F691279E17D00672B13 /* Table Structure */, 17005CB016D6CEA400AF81F4 /* Table Triggers */, + 171156501E8B0F40002E6363 /* Table Relations */, 1792C28910AE1C7200ABE758 /* Controller Categories */, ); name = "Main View Controllers"; @@ -3450,6 +3463,7 @@ 17D3C671128AD8160047709F /* SPSingleton.m in Sources */, 17D3C6D3128B1C900047709F /* SPFavoritesOutlineView.m in Sources */, 50D3C3521A77135F00B5429C /* SPParserUtils.c in Sources */, + 171156551E8B0F96002E6363 /* SPTableRelationsDelegate.m in Sources */, BC68BFC7128D4EAE004907D9 /* SPBundleEditorController.m in Sources */, BC1944D01297291800A236CD /* SPBundleCommandTextView.m in Sources */, BC77C5E4129AA69E009AD832 /* SPBundleHTMLOutputController.m in Sources */, -- cgit v1.2.3