diff options
author | rowanbeentje <rowan@beent.je> | 2010-03-29 22:56:24 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2010-03-29 22:56:24 +0000 |
commit | 2424d968ad5e6d9516b15fead3edf26d0183c450 (patch) | |
tree | 1fc3227a6d8b6cb7daf4ab3450828b073033ff68 /Source | |
parent | d4d1243d665aee61cde560468d72bb0ecfee3bd8 (diff) | |
download | sequelpro-2424d968ad5e6d9516b15fead3edf26d0183c450.tar.gz sequelpro-2424d968ad5e6d9516b15fead3edf26d0183c450.tar.bz2 sequelpro-2424d968ad5e6d9516b15fead3edf26d0183c450.zip |
- Ensure Copy [with Column Names]/Copy As SQL are disabled on the trigger and relations views. This fixes the copy parts of http://log.sequelpro.com/view/53
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMCopyTable.h | 1 | ||||
-rw-r--r-- | Source/CMCopyTable.m | 43 |
2 files changed, 32 insertions, 12 deletions
diff --git a/Source/CMCopyTable.h b/Source/CMCopyTable.h index 03fc53cb..6baa2527 100644 --- a/Source/CMCopyTable.h +++ b/Source/CMCopyTable.h @@ -114,5 +114,6 @@ @end +extern NSInteger MENU_EDIT_COPY; extern NSInteger MENU_EDIT_COPY_WITH_COLUMN; extern NSInteger MENU_EDIT_COPY_AS_SQL; diff --git a/Source/CMCopyTable.m b/Source/CMCopyTable.m index dc9cc770..9c12b358 100644 --- a/Source/CMCopyTable.m +++ b/Source/CMCopyTable.m @@ -28,13 +28,16 @@ #import "SPArrayAdditions.h" #import "SPStringAdditions.h" #import "TableContent.h" +#import "SPTableTriggers.h" +#import "SPTableRelations.h" #import "CustomQuery.h" #import "SPNotLoaded.h" #import "SPConstants.h" #import "SPDataStorage.h" -NSInteger MENU_EDIT_COPY_WITH_COLUMN = 2001; -NSInteger MENU_EDIT_COPY_AS_SQL = 2002; +NSInteger MENU_EDIT_COPY = 2001; +NSInteger MENU_EDIT_COPY_WITH_COLUMN = 2002; +NSInteger MENU_EDIT_COPY_AS_SQL = 2003; @implementation CMCopyTable @@ -75,19 +78,35 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2002; return NSDragOperationCopy; } -//only have the copy menu item enabled when row(s) are selected +/** + * Only have the copy menu item enabled when row(s) are selected in + * supported tables. + */ - (BOOL)validateMenuItem:(NSMenuItem*)anItem -{ - if ( [[anItem title] isEqualToString:@"Copy"] - || [anItem tag] == MENU_EDIT_COPY_WITH_COLUMN ) - { - return ([self selectedRow] > -1); +{ + NSInteger menuItemTag = [anItem tag]; + + // Don't validate anything other than the copy commands + if (menuItemTag != MENU_EDIT_COPY && menuItemTag != MENU_EDIT_COPY_WITH_COLUMN && menuItemTag != MENU_EDIT_COPY_AS_SQL) { + return YES; } - if ( [anItem tag] == MENU_EDIT_COPY_AS_SQL ) - { - return (columnDefinitions != nil && [self selectedRow] > -1); + + // Don't enable menus for relations or triggers - no action to take yet + if ([[self delegate] isKindOfClass:[SPTableRelations class]] || [[self delegate] isKindOfClass:[SPTableTriggers class]]) { + return NO; + } + + // Enable the Copy [with column names] commands if a row is selected + if (menuItemTag == MENU_EDIT_COPY || menuItemTag == MENU_EDIT_COPY_WITH_COLUMN) { + return ([self numberOfSelectedRows] > 0); } - return YES; + + // Enable the Copy as SQL commands if rows are selected and column definitions are available + if (menuItemTag == MENU_EDIT_COPY_AS_SQL) { + return (columnDefinitions != nil && [self numberOfSelectedRows] > 0); + } + + return NO; } //get selected rows a string of newline separated lines of tab separated fields |