Skip to content

Commit

Permalink
Move table relations delegate methods into their own catrgory to be c…
Browse files Browse the repository at this point in the history
…onsistent with other controllers.
  • Loading branch information
stuconnolly committed Mar 28, 2017
1 parent dbcea5c commit 5f1b37e
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 59 deletions.
6 changes: 3 additions & 3 deletions Source/SPTableRelations.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@class SPTablesList;
@class SPTableData;

@interface SPTableRelations : NSObject
@interface SPTableRelations : NSObject <NSTableViewDelegate, NSTableViewDataSource>
{
IBOutlet SPDatabaseDocument *tableDocumentInstance;
IBOutlet SPTablesList *tablesListInstance;
Expand Down Expand Up @@ -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;
Expand Down
56 changes: 2 additions & 54 deletions Source/SPTableRelations.m
Original file line number Diff line number Diff line change
Expand Up @@ -372,27 +372,6 @@ - (void)tableSelectionChanged:(NSNotification *)notification
[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

Expand All @@ -412,45 +391,14 @@ - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColum
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;

Expand All @@ -462,7 +410,7 @@ - (void)startDocumentTaskForTab:(NSNotification *)aNotification
/**
* 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;
Expand Down
35 changes: 35 additions & 0 deletions Source/SPTableRelationsDelegate.h
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/sequelpro/sequelpro>

#import "SPTableRelations.h"

@interface SPTableRelations (SPTableRelationsDelegate)

@end
87 changes: 87 additions & 0 deletions Source/SPTableRelationsDelegate.m
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/sequelpro/sequelpro>

#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
18 changes: 16 additions & 2 deletions sequel-pro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -673,6 +674,8 @@
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>"; };
171156531E8B0F96002E6363 /* SPTableRelationsDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableRelationsDelegate.h; sourceTree = "<group>"; };
171156541E8B0F96002E6363 /* SPTableRelationsDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableRelationsDelegate.m; 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>"; };
171312CD109D23C700FB465F /* SPTableTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableTextFieldCell.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1495,6 +1498,17 @@
name = "Table Triggers";
sourceTree = "<group>";
};
171156501E8B0F40002E6363 /* Table Relations */ = {
isa = PBXGroup;
children = (
387BBBA60FBCB6CB00B31746 /* SPTableRelations.h */,
387BBBA70FBCB6CB00B31746 /* SPTableRelations.m */,
171156531E8B0F96002E6363 /* SPTableRelationsDelegate.h */,
171156541E8B0F96002E6363 /* SPTableRelationsDelegate.m */,
);
name = "Table Relations";
sourceTree = "<group>";
};
171312CF109D23CA00FB465F /* Cells */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -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 */,
Expand All @@ -1665,6 +1677,7 @@
17386E08151924E9002DC206 /* Table Content */,
17D38F691279E17D00672B13 /* Table Structure */,
17005CB016D6CEA400AF81F4 /* Table Triggers */,
171156501E8B0F40002E6363 /* Table Relations */,
1792C28910AE1C7200ABE758 /* Controller Categories */,
);
name = "Main View Controllers";
Expand Down Expand Up @@ -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 */,
Expand Down

0 comments on commit 5f1b37e

Please sign in to comment.