From 985d03cb9980bc92078af8c6a6815efdeefd1377 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 23 Apr 2009 10:12:39 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20menu=20item=20title=20logic=20fo?= =?UTF-8?q?r=20the=20gear=20menu=20and=20main=20menu=20according=20to=20ta?= =?UTF-8?q?ble=20types=20(table/view)=20=E2=80=A2=20moved=20code=20for=20v?= =?UTF-8?q?alidation=20of=20the=20gear=20menu=20items=20to=20validateMenuI?= =?UTF-8?q?tem:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TablesList.m | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/Source/TablesList.m b/Source/TablesList.m index 47dbc3c2..df22bb92 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -376,9 +376,7 @@ [tables insertObject:[copyTableNameField stringValue] atIndex:[tablesListView selectedRow]+1]; [tableTypes insertObject:[NSNumber numberWithInt:(isView)?SP_TABLETYPE_VIEW : SP_TABLETYPE_TABLE] atIndex:[tablesListView selectedRow]+1]; - [tablesListView reloadData]; [tablesListView selectRow:[tablesListView selectedRow]+1 byExtendingSelection:NO]; - [tablesListView scrollRowToVisible:[tablesListView selectedRow]]; [self updateTables:self]; [tablesListView scrollRowToVisible:[tablesListView selectedRow]]; @@ -709,6 +707,7 @@ */ - (void)tableViewSelectionDidChange:(NSNotification *)aNotification { + if ( [tablesListView numberOfSelectedRows] == 1 && [[self tableName] length] ) { // Reset the table information caches @@ -744,16 +743,32 @@ statusLoaded = NO; } - // To be able to disable duplicateTableMenuItem - [[duplicateTableMenuItem menu] setAutoenablesItems:NO]; - - // Set gear menu items Remove/Duplicate table/view according to the table types - [duplicateTableMenuItem setEnabled:YES]; + // Set gear menu items Remove/Duplicate table/view and mainMenu > Table items + // according to the table types if([[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_VIEW) { + // Change mainMenu > Table > ... according to table type + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:0] setTitle:NSLocalizedString(@"Copy Create View Syntax", @"copy create view syntax menu item")]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:1] setTitle:NSLocalizedString(@"Show Create View Syntax", @"show create view syntax menu item")]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:3] setTitle:NSLocalizedString(@"Check View", @"check view menu item")]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:4] setHidden:YES]; // repair + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:YES]; // analyse + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:7] setHidden:YES]; // optimize + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setTitle:NSLocalizedString(@"Flush View", @"flush view menu item")]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:YES]; // checksum + [removeTableMenuItem setTitle:NSLocalizedString(@"Remove view", @"remove view menu title")]; [duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate view", @"duplicate view menu title")]; } else { + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:0] setTitle:NSLocalizedString(@"Copy Create Table Syntax", @"copy create table syntax menu item")]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:1] setTitle:NSLocalizedString(@"Show Create Table Syntax", @"show create table syntax menu item")]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:3] setTitle:NSLocalizedString(@"Check Table", @"check table menu item")]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:4] setHidden:NO]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:NO]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:7] setHidden:NO]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setTitle:NSLocalizedString(@"Flush Table", @"flush table menu item")]; + [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:NO]; + [removeTableMenuItem setTitle:NSLocalizedString(@"Remove table", @"remove table menu title")]; [duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate table", @"duplicate table menu title")]; } @@ -769,13 +784,9 @@ contentLoaded = NO; statusLoaded = NO; - // To be able to disable duplicateTableMenuItem - [[duplicateTableMenuItem menu] setAutoenablesItems:NO]; - // Set gear menu items Remove/Duplicate table/view according to the table types NSIndexSet *indexes = [tablesListView selectedRowIndexes]; unsigned currentIndex = [indexes lastIndex]; - [duplicateTableMenuItem setEnabled:NO]; int tblTypesChecksum = 0; while (currentIndex != NSNotFound) { @@ -871,8 +882,11 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { // popup button below table list - if ([menuItem action] == @selector(copyTable:) || - [menuItem action] == @selector(removeTable:)) + if ([menuItem action] == @selector(copyTable:)) + { + return [tablesListView numberOfSelectedRows] == 1 && [[self tableName] length] && [tablesListView numberOfSelectedRows] > 0; + } + if ([menuItem action] == @selector(removeTable:)) { return [tablesListView numberOfSelectedRows] > 0; } -- cgit v1.2.3