aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPDatabaseDocument.m112
1 files changed, 63 insertions, 49 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 6511eb4e..4558e70f 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -3543,20 +3543,22 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
+ SEL action = [menuItem action];
+
if ([menuItem menu] == chooseDatabaseButton) {
return (_isConnected && databaseListIsSelectable);
}
if (!_isConnected || _isWorkingLevel) {
- return ([menuItem action] == @selector(newWindow:) ||
- [menuItem action] == @selector(terminate:) ||
- [menuItem action] == @selector(closeTab:));
+ return (action == @selector(newWindow:) ||
+ action == @selector(terminate:) ||
+ action == @selector(closeTab:));
}
#ifndef SP_CODA
- if ([menuItem action] == @selector(openCurrentConnectionInNewWindow:))
+ if (action == @selector(openCurrentConnectionInNewWindow:))
{
- if([self isUntitled]) {
+ if ([self isUntitled]) {
[menuItem setTitle:NSLocalizedString(@"Open in New Window", @"menu item open in new window")];
return NO;
}
@@ -3568,12 +3570,12 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
#endif
// Data export
- if ([menuItem action] == @selector(export:)) {
+ if (action == @selector(export:)) {
return (([self database] != nil) && ([[tablesListInstance tables] count] > 1));
}
// Selected tables data export
- if ([menuItem action] == @selector(exportSelectedTablesAs:)) {
+ if (action == @selector(exportSelectedTablesAs:)) {
NSInteger tag = [menuItem tag];
NSInteger type = [tablesListInstance tableType];
@@ -3600,44 +3602,56 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
}
}
- //can only be enabled on mysql 4.1+
- if([menuItem action] == @selector(alterDatabase:)) {
+ // Can only be enabled on mysql 4.1+
+ if (action == @selector(alterDatabase:)) {
return (([self database] != nil) && [serverSupport supportsPost41CharacterSetHandling]);
}
+
+ // Table specific actions
+ if (action == @selector(viewStructure:) ||
+ action == @selector(viewContent:) ||
+ action == @selector(viewRelations:) ||
+ action == @selector(viewStatus:) ||
+ action == @selector(viewTriggers:))
+ {
+ return [self database] != nil && [[[tablesListInstance valueForKeyPath:@"tablesListView"] selectedRowIndexes] count];
+
+ }
- if ([menuItem action] == @selector(import:) ||
- [menuItem action] == @selector(removeDatabase:) ||
- [menuItem action] == @selector(copyDatabase:) ||
- [menuItem action] == @selector(renameDatabase:) ||
- [menuItem action] == @selector(openDatabaseInNewTab:) ||
- [menuItem action] == @selector(refreshTables:))
+ // Database specific actions
+ if (action == @selector(import:) ||
+ action == @selector(removeDatabase:) ||
+ action == @selector(copyDatabase:) ||
+ action == @selector(renameDatabase:) ||
+ action == @selector(openDatabaseInNewTab:) ||
+ action == @selector(refreshTables:))
{
- return ([self database] != nil);
+ return [self database] != nil;
}
- if ([menuItem action] == @selector(importFromClipboard:))
- {
+ if (action == @selector(importFromClipboard:)){
return [self database] && [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObjects:NSStringPboardType, nil]];
-
}
// Change "Save Query/Queries" menu item title dynamically
// and disable it if no query in the editor
- if ([menuItem action] == @selector(saveConnectionSheet:) && [menuItem tag] == 0) {
- if([customQueryInstance numberOfQueries] < 1) {
+ if (action == @selector(saveConnectionSheet:) && [menuItem tag] == 0) {
+ if ([customQueryInstance numberOfQueries] < 1) {
[menuItem setTitle:NSLocalizedString(@"Save Query…", @"Save Query…")];
+
return NO;
}
- else if([customQueryInstance numberOfQueries] == 1)
- [menuItem setTitle:NSLocalizedString(@"Save Query…", @"Save Query…")];
- else
- [menuItem setTitle:NSLocalizedString(@"Save Queries…", @"Save Queries…")];
+ else {
+ [menuItem setTitle:[customQueryInstance numberOfQueries] == 1 ?
+ NSLocalizedString(@"Save Query…", @"Save Query…") :
+ NSLocalizedString(@"Save Queries…", @"Save Queries…")];
+ }
return YES;
}
#ifndef SP_CODA
- if ([menuItem action] == @selector(printDocument:)) {
+ if (action == @selector(printDocument:)) {
return (([self database] != nil && [[tablesListInstance valueForKeyPath:@"tablesListView"] numberOfSelectedRows] == 1) ||
// If Custom Query Tab is active the textView will handle printDocument by itself
// if it is first responder; otherwise allow to print the Query Result table even
@@ -3646,72 +3660,72 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
}
#endif
- if ([menuItem action] == @selector(chooseEncoding:)) {
+ if (action == @selector(chooseEncoding:)) {
return [self supportsEncoding];
}
- if ([menuItem action] == @selector(analyzeTable:) ||
- [menuItem action] == @selector(optimizeTable:) ||
- [menuItem action] == @selector(repairTable:) ||
- [menuItem action] == @selector(flushTable:) ||
- [menuItem action] == @selector(checkTable:) ||
- [menuItem action] == @selector(checksumTable:) ||
- [menuItem action] == @selector(showCreateTableSyntax:) ||
- [menuItem action] == @selector(copyCreateTableSyntax:))
+ // Table actions and view switching
+ if (action == @selector(analyzeTable:) ||
+ action == @selector(optimizeTable:) ||
+ action == @selector(repairTable:) ||
+ action == @selector(flushTable:) ||
+ action == @selector(checkTable:) ||
+ action == @selector(checksumTable:) ||
+ action == @selector(showCreateTableSyntax:) ||
+ action == @selector(copyCreateTableSyntax:))
{
return [[[tablesListInstance valueForKeyPath:@"tablesListView"] selectedRowIndexes] count];
}
#ifndef SP_CODA
- if ([menuItem action] == @selector(addConnectionToFavorites:)) {
+ if (action == @selector(addConnectionToFavorites:)) {
return ![connectionController selectedFavorite] || [connectionController isEditingConnection];
}
// Backward in history menu item
- if (([menuItem action] == @selector(backForwardInHistory:)) && ([menuItem tag] == 0)) {
+ if ((action == @selector(backForwardInHistory:)) && ([menuItem tag] == 0)) {
return (([[spHistoryControllerInstance history] count]) && ([spHistoryControllerInstance historyPosition] > 0));
}
// Forward in history menu item
- if (([menuItem action] == @selector(backForwardInHistory:)) && ([menuItem tag] == 1)) {
+ if ((action == @selector(backForwardInHistory:)) && ([menuItem tag] == 1)) {
return (([[spHistoryControllerInstance history] count]) && (([spHistoryControllerInstance historyPosition] + 1) < [[spHistoryControllerInstance history] count]));
}
#endif
// Show/hide console
- if ([menuItem action] == @selector(toggleConsole:)) {
+ if (action == @selector(toggleConsole:)) {
[menuItem setTitle:([[[SPQueryController sharedQueryController] window] isVisible] && [[[NSApp keyWindow] windowController] isKindOfClass:[SPQueryController class]]) ? NSLocalizedString(@"Hide Console", @"hide console") : NSLocalizedString(@"Show Console", @"show console")];
}
// Clear console
- if ([menuItem action] == @selector(clearConsole:)) {
+ if (action == @selector(clearConsole:)) {
return ([[SPQueryController sharedQueryController] consoleMessageCount] > 0);
}
// Show/hide console
- if ([menuItem action] == @selector(toggleNavigator:)) {
+ if (action == @selector(toggleNavigator:)) {
[menuItem setTitle:([[[SPNavigatorController sharedNavigatorController] window] isVisible]) ? NSLocalizedString(@"Hide Navigator", @"hide navigator") : NSLocalizedString(@"Show Navigator", @"show navigator")];
}
// Focus on table content filter
- if ([menuItem action] == @selector(focusOnTableContentFilter:) || [menuItem action] == @selector(showFilterTable:)) {
+ if (action == @selector(focusOnTableContentFilter:) || [menuItem action] == @selector(showFilterTable:)) {
return ([self table] != nil && [[self table] isNotEqualTo:@""]);
}
// Focus on table list or filter resp.
- if ([menuItem action] == @selector(makeTableListFilterHaveFocus:)) {
+ if (action == @selector(makeTableListFilterHaveFocus:)) {
- if([[tablesListInstance valueForKeyPath:@"tables"] count] > 20)
- [menuItem setTitle:NSLocalizedString(@"Filter Tables", @"filter tables menu item")];
- else
- [menuItem setTitle:NSLocalizedString(@"Change Focus to Table List", @"change focus to table list menu item")];
+ [menuItem setTitle:[[tablesListInstance valueForKeyPath:@"tables"] count] > 20 ?
+ NSLocalizedString(@"Filter Tables", @"filter tables menu item") :
+ NSLocalizedString(@"Change Focus to Table List", @"change focus to table list menu item")];
- return ([[tablesListInstance valueForKeyPath:@"tables"] count] > 1);
+ return [[tablesListInstance valueForKeyPath:@"tables"] count] > 1;
}
// If validation for the sort favorites tableview items reaches here then the preferences window isn't
// open return NO.
- if (([menuItem action] == @selector(sortFavorites:)) || ([menuItem action] == @selector(reverseSortFavorites:))) {
+ if ((action == @selector(sortFavorites:)) || ([menuItem action] == @selector(reverseSortFavorites:))) {
return NO;
}