diff options
author | rowanbeentje <rowan@beent.je> | 2011-04-25 23:57:57 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2011-04-25 23:57:57 +0000 |
commit | 75e4e58eecf4ae1b8f25751b0bc7d457edcf57e8 (patch) | |
tree | 964b60108a9f41ba1adba08f82846911fd676ea8 | |
parent | 25268f100c5f1b90ed5944b0123748d8a152b040 (diff) | |
download | sequelpro-75e4e58eecf4ae1b8f25751b0bc7d457edcf57e8.tar.gz sequelpro-75e4e58eecf4ae1b8f25751b0bc7d457edcf57e8.tar.bz2 sequelpro-75e4e58eecf4ae1b8f25751b0bc7d457edcf57e8.zip |
- Add the ability to double-click in empty areas of the main tableviews to add new rows/records
-rw-r--r-- | Source/SPIndexesController.h | 4 | ||||
-rw-r--r-- | Source/SPIndexesController.m | 8 | ||||
-rw-r--r-- | Source/SPTableContent.m | 6 | ||||
-rw-r--r-- | Source/SPTableRelations.h | 4 | ||||
-rw-r--r-- | Source/SPTableRelations.m | 8 | ||||
-rw-r--r-- | Source/SPTableStructure.h | 6 | ||||
-rw-r--r-- | Source/SPTableStructure.m | 9 | ||||
-rw-r--r-- | Source/SPTableStructureDelegate.m | 1 | ||||
-rw-r--r-- | Source/SPTableTriggers.h | 4 | ||||
-rw-r--r-- | Source/SPTableTriggers.m | 8 | ||||
-rw-r--r-- | Source/SPTableView.h | 3 | ||||
-rw-r--r-- | Source/SPTableView.m | 45 |
12 files changed, 99 insertions, 7 deletions
diff --git a/Source/SPIndexesController.h b/Source/SPIndexesController.h index c56ff4eb..65cbb207 100644 --- a/Source/SPIndexesController.h +++ b/Source/SPIndexesController.h @@ -23,7 +23,7 @@ // // More info at <http://code.google.com/p/sequel-pro/> -@class SPDatabaseDocument, SPTablesList, SPTableData, SPTableStructure, MCPConnection, BWAnchoredButtonBar; +@class SPDatabaseDocument, SPTablesList, SPTableData, SPTableStructure, SPTableView, MCPConnection, BWAnchoredButtonBar; @interface SPIndexesController : NSWindowController { @@ -34,7 +34,7 @@ IBOutlet SPTableData *tableData; // Index table view - IBOutlet NSTableView *indexesTableView; + IBOutlet SPTableView *indexesTableView; IBOutlet NSButton *addIndexButton; IBOutlet NSButton *removeIndexButton; diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m index 9c0c03a6..989ec02c 100644 --- a/Source/SPIndexesController.m +++ b/Source/SPIndexesController.m @@ -31,6 +31,7 @@ #import <MCPKit/MCPKit.h> #import "SPDatabaseDocument.h" #import "SPTablesList.h" +#import "SPTableView.h" #import "SPDatabaseViewController.h" #import "SPTableStructure.h" @@ -111,6 +112,9 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; BOOL useMonospacedFont = NO; #endif + // Set the double-click action in blank areas of the table to create new rows + [indexesTableView setEmptyDoubleClickAction:@selector(addIndex:)]; + for (NSTableColumn *indexColumn in [indexesTableView tableColumns]) { [[indexColumn dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; @@ -134,6 +138,10 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; */ - (IBAction)addIndex:(id)sender { + + // Check whether table editing is permitted (necessary as some actions - eg table double-click - bypass validation) + if ([dbDocument isWorking] || [tablesList tableType] != SPTableTypeTable) return; + // Check whether a save of the current field row is required. if (![tableStructure saveRowOnDeselect]) return; diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index c9b8c145..ddc58670 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -163,6 +163,9 @@ [tableContentView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; #endif + // Set the double-click action in blank areas of the table to create new rows + [tableContentView setEmptyDoubleClickAction:@selector(addRow:)]; + // Load the pagination view, keeping references to the top-level objects for later release NSArray *paginationViewTopLevelObjects = nil; NSNib *nibLoader = [[NSNib alloc] initWithNibNamed:@"ContentPaginationView" bundle:[NSBundle mainBundle]]; @@ -1655,6 +1658,9 @@ NSMutableArray *newRow = [NSMutableArray array]; NSUInteger i; + // Check whether table editing is permitted (necessary as some actions - eg table double-click - bypass validation) + if ([tableDocumentInstance isWorking] || [tablesListInstance tableType] != SPTableTypeTable) return; + // Check whether a save of the current row is required. if ( ![self saveRowOnDeselect] ) return; diff --git a/Source/SPTableRelations.h b/Source/SPTableRelations.h index 3fbef811..aa270854 100644 --- a/Source/SPTableRelations.h +++ b/Source/SPTableRelations.h @@ -25,6 +25,8 @@ #import <MCPKit/MCPKit.h> +@class SPTableView; + @interface SPTableRelations : NSObject { IBOutlet id tableDocumentInstance; @@ -37,7 +39,7 @@ IBOutlet NSButton *removeRelationButton; IBOutlet NSButton *refreshRelationsButton; IBOutlet NSTextField *labelTextField; - IBOutlet NSTableView *relationsTableView; + IBOutlet SPTableView *relationsTableView; IBOutlet NSPanel *addRelationPanel; IBOutlet NSBox *addRelationTableBox; diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m index e62825c3..5160448f 100644 --- a/Source/SPTableRelations.m +++ b/Source/SPTableRelations.m @@ -27,6 +27,7 @@ #import "SPDatabaseDocument.h" #import "SPTablesList.h" #import "SPTableData.h" +#import "SPTableView.h" #import "SPAlertSheets.h" @interface SPTableRelations (PrivateAPI) @@ -61,6 +62,9 @@ // Set the table relation view's vertical gridlines if required [relationsTableView setGridStyleMask:([[NSUserDefaults standardUserDefaults] boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + // Set the double-click action in blank areas of the table to create new rows + [relationsTableView setEmptyDoubleClickAction:@selector(addRelation:)]; + // Set the strutcture and index view's font BOOL useMonospacedFont = [[NSUserDefaults standardUserDefaults] boolForKey:SPUseMonospacedFonts]; @@ -163,6 +167,10 @@ */ - (IBAction)addRelation:(id)sender { + + // Check whether table editing is permitted (necessary as some actions - eg table double-click - bypass validation) + if ([tableDocumentInstance isWorking] || [tablesListInstance tableType] != SPTableTypeTable) return; + // Set up the controls [addRelationTableBox setTitle:[NSString stringWithFormat:NSLocalizedString(@"Table: %@", @"Add Relation sheet title, showing table name"), [tablesListInstance tableName]]]; diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h index 81905410..40b665b2 100644 --- a/Source/SPTableStructure.h +++ b/Source/SPTableStructure.h @@ -25,7 +25,7 @@ #import <MCPKit/MCPKit.h> -@class SPDatabaseDocument, SPTableFieldValidation, SPTableData, SPDatabaseData, SPTablesList, SPIndexesController; +@class SPDatabaseDocument, SPTableFieldValidation, SPTableData, SPDatabaseData, SPTablesList, SPIndexesController, SPTableView; @interface SPTableStructure : NSObject { @@ -43,7 +43,7 @@ IBOutlet id resetAutoIncrementSheet; IBOutlet id resetAutoIncrementValue; IBOutlet id resetAutoIncrementLine; - IBOutlet id tableSourceView; + IBOutlet SPTableView *tableSourceView; IBOutlet id addFieldButton; IBOutlet id copyFieldButton; IBOutlet id removeFieldButton; @@ -54,7 +54,7 @@ IBOutlet id addIndexButton; IBOutlet id removeIndexButton; IBOutlet id refreshIndexesButton; - IBOutlet id indexesTableView; + IBOutlet SPTableView *indexesTableView; IBOutlet NSSplitView *tablesIndexesSplitView; IBOutlet NSButton *indexesShowButton; diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index 1af8bc62..ebbb9f7e 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -29,6 +29,7 @@ #import "SPTableInfo.h" #import "SPTablesList.h" #import "SPTableData.h" +#import "SPTableView.h" #import "SPDatabaseData.h" #import "SPSQLParser.h" #import "SPAlertSheets.h" @@ -83,6 +84,10 @@ // Set the structure and index view's vertical gridlines if required [tableSourceView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; #endif + + // Set the double-click action in blank areas of the table to create new rows + [tableSourceView setEmptyDoubleClickAction:@selector(addField:)]; + #ifndef SP_REFACTOR /* set font from prefs */ // Set the strutcture and index view's font [tableSourceView setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; @@ -474,6 +479,10 @@ */ - (IBAction)addField:(id)sender { + + // Check whether table editing is permitted (necessary as some actions - eg table double-click - bypass validation) + if ([tableDocumentInstance isWorking] || [tablesListInstance tableType] != SPTableTypeTable) return; + // Check whether a save of the current row is required. if ( ![self saveRowOnDeselect] ) return; diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m index e7f9d3be..ad061b62 100644 --- a/Source/SPTableStructureDelegate.m +++ b/Source/SPTableStructureDelegate.m @@ -28,6 +28,7 @@ #import "SPDatabaseData.h" #import "SPDatabaseViewController.h" #import "SPTableData.h" +#import "SPTableView.h" #import "SPTableFieldValidation.h" @implementation SPTableStructure (SPTableStructureDelegate) diff --git a/Source/SPTableTriggers.h b/Source/SPTableTriggers.h index 70eeeb2e..5cc8d59d 100644 --- a/Source/SPTableTriggers.h +++ b/Source/SPTableTriggers.h @@ -25,6 +25,8 @@ #import <MCPKit/MCPKit.h> +@class SPTableView; + @interface SPTableTriggers : NSObject { IBOutlet id tableDocumentInstance; @@ -36,7 +38,7 @@ IBOutlet NSButton *addTriggerButton; IBOutlet NSButton *removeTriggerButton; IBOutlet NSButton *refreshTriggersButton; - IBOutlet NSTableView *triggersTableView; + IBOutlet SPTableView *triggersTableView; IBOutlet NSPanel *addTriggerPanel; IBOutlet NSTextField *labelTextField; diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m index bc5fc4f6..742579d8 100644 --- a/Source/SPTableTriggers.m +++ b/Source/SPTableTriggers.m @@ -27,6 +27,7 @@ #import "SPDatabaseDocument.h" #import "SPTablesList.h" #import "SPTableData.h" +#import "SPTableView.h" #import "SPAlertSheets.h" #import "SPServerSupport.h" @@ -76,6 +77,9 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; // Set the table triggers view's vertical gridlines if required [triggersTableView setGridStyleMask:([[NSUserDefaults standardUserDefaults] boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; + // Set the double-click action in blank areas of the table to create new rows + [triggersTableView setEmptyDoubleClickAction:@selector(addTrigger:)]; + // Set the strutcture and index view's font BOOL useMonospacedFont = [[NSUserDefaults standardUserDefaults] boolForKey:SPUseMonospacedFonts]; @@ -263,6 +267,10 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; */ - (IBAction)addTrigger:(id)sender { + + // Check whether table editing is permitted (necessary as some actions - eg table double-click - bypass validation) + if ([tableDocumentInstance isWorking] || [tablesListInstance tableType] != SPTableTypeTable) return; + [NSApp beginSheet:addTriggerPanel modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self diff --git a/Source/SPTableView.h b/Source/SPTableView.h index e39df82f..11656e5b 100644 --- a/Source/SPTableView.h +++ b/Source/SPTableView.h @@ -25,8 +25,11 @@ @interface SPTableView : NSTableView { BOOL tabEditingDisabled; + SEL emptyDoubleClickAction; } @property (readwrite, assign) BOOL tabEditingDisabled; +- (void)setEmptyDoubleClickAction:(SEL)aSelector; + @end diff --git a/Source/SPTableView.m b/Source/SPTableView.m index d678fef3..9139bb79 100644 --- a/Source/SPTableView.m +++ b/Source/SPTableView.m @@ -34,10 +34,34 @@ @end +@interface SPTableView (PrivateAPI) + +- (void)_doubleClickAction; + +@end + + @implementation SPTableView @synthesize tabEditingDisabled; +- (id) init +{ + if ((self = [super init])) { + emptyDoubleClickAction = NULL; + } + return self; +} + +- (void) awakeFromNib +{ + [super setDoubleAction:@selector(_doubleClickAction)]; + if ([NSTableView instancesRespondToSelector:@selector(awakeFromNib)]) + [super awakeFromNib]; +} + +#pragma mark - + /** * Right-click at row will select that row before ordering out the contextual menu * if not more than one row is selected. @@ -193,4 +217,25 @@ } } +- (void)setEmptyDoubleClickAction:(SEL)aSelector +{ + emptyDoubleClickAction = aSelector; +} + +@end + + +@implementation SPTableView (PrivateAPI) + +/** + * On a double click, determine whether the action was in the empty area + * of the current table; if so, perform the assigned emptyDoubleClick action. + */ +- (void)_doubleClickAction +{ + if ([super clickedRow] == -1 && [super clickedColumn] == -1 && emptyDoubleClickAction) { + [[self delegate] performSelector:emptyDoubleClickAction]; + } +} + @end |