diff options
author | abhibeckert <abhi@abhibeckert.com> | 2008-04-20 11:09:57 +0000 |
---|---|---|
committer | abhibeckert <abhi@abhibeckert.com> | 2008-04-20 11:09:57 +0000 |
commit | 0261432e0704f5afe4067e7288d7845c6c8bb82f (patch) | |
tree | 4ee93fa9779fa84d13fbf977996937a44b37bae4 | |
parent | 385af2eacdcceb9160d787539380d921919f3d99 (diff) | |
download | sequelpro-0261432e0704f5afe4067e7288d7845c6c8bb82f.tar.gz sequelpro-0261432e0704f5afe4067e7288d7845c6c8bb82f.tar.bz2 sequelpro-0261432e0704f5afe4067e7288d7845c6c8bb82f.zip |
refactor encoding system
refactor menu validation
move database action buttons into a new "Database" menu
pretty up the table select view and it's action buttons
-rw-r--r-- | English.lproj/DBView.nib/classes.nib | 8 | ||||
-rw-r--r-- | English.lproj/DBView.nib/info.nib | 1 | ||||
-rw-r--r-- | English.lproj/DBView.nib/keyedobjects.nib | bin | 168350 -> 154190 bytes | |||
-rw-r--r-- | English.lproj/MainMenu.nib/classes.nib | 14 | ||||
-rw-r--r-- | English.lproj/MainMenu.nib/info.nib | 4 | ||||
-rw-r--r-- | English.lproj/MainMenu.nib/keyedobjects.nib | bin | 50276 -> 56712 bytes | |||
-rw-r--r-- | TableContent.m | 2 | ||||
-rw-r--r-- | TableDocument.h | 14 | ||||
-rw-r--r-- | TableDocument.m | 372 | ||||
-rw-r--r-- | TableDump.m | 4 | ||||
-rw-r--r-- | TablesList.m | 200 |
11 files changed, 326 insertions, 293 deletions
diff --git a/English.lproj/DBView.nib/classes.nib b/English.lproj/DBView.nib/classes.nib index 7991a45c..bfc58dc7 100644 --- a/English.lproj/DBView.nib/classes.nib +++ b/English.lproj/DBView.nib/classes.nib @@ -478,8 +478,14 @@ <string>id</string> <key>export</key> <string>id</string> + <key>exportMultipleTables</key> + <string>id</string> + <key>exportTable</key> + <string>id</string> <key>import</key> <string>id</string> + <key>importCSV</key> + <string>id</string> <key>removeDatabase</key> <string>id</string> <key>setDatabases</key> @@ -503,8 +509,6 @@ <dict> <key>chooseDatabaseButton</key> <string>id</string> - <key>chooseEncodingButton</key> - <string>id</string> <key>chooseTableOperationButton</key> <string>id</string> <key>connectProgressBar</key> diff --git a/English.lproj/DBView.nib/info.nib b/English.lproj/DBView.nib/info.nib index b1d2945b..e7b8303d 100644 --- a/English.lproj/DBView.nib/info.nib +++ b/English.lproj/DBView.nib/info.nib @@ -11,6 +11,7 @@ <key>IBOpenObjects</key> <array> <integer>2268</integer> + <integer>675</integer> </array> <key>IBSystem Version</key> <string>9C7010</string> diff --git a/English.lproj/DBView.nib/keyedobjects.nib b/English.lproj/DBView.nib/keyedobjects.nib Binary files differindex 88cb1cf1..71093888 100644 --- a/English.lproj/DBView.nib/keyedobjects.nib +++ b/English.lproj/DBView.nib/keyedobjects.nib diff --git a/English.lproj/MainMenu.nib/classes.nib b/English.lproj/MainMenu.nib/classes.nib index f58a97d2..3166ed1b 100644 --- a/English.lproj/MainMenu.nib/classes.nib +++ b/English.lproj/MainMenu.nib/classes.nib @@ -15,10 +15,24 @@ <dict> <key>ACTIONS</key> <dict> + <key>addDatabase</key> + <string>id</string> + <key>chooseEncoding</key> + <string>id</string> <key>export</key> <string>id</string> + <key>exportMultipleTables</key> + <string>id</string> + <key>exportTable</key> + <string>id</string> <key>import</key> <string>id</string> + <key>importCSV</key> + <string>id</string> + <key>removeDatabase</key> + <string>id</string> + <key>setDatabases</key> + <string>id</string> <key>viewContent</key> <string>id</string> <key>viewQuery</key> diff --git a/English.lproj/MainMenu.nib/info.nib b/English.lproj/MainMenu.nib/info.nib index 928e8da9..29e47bf2 100644 --- a/English.lproj/MainMenu.nib/info.nib +++ b/English.lproj/MainMenu.nib/info.nib @@ -9,7 +9,9 @@ <key>IBOldestOS</key> <integer>5</integer> <key>IBOpenObjects</key> - <array/> + <array> + <integer>401</integer> + </array> <key>IBSystem Version</key> <string>9C7010</string> <key>targetFramework</key> diff --git a/English.lproj/MainMenu.nib/keyedobjects.nib b/English.lproj/MainMenu.nib/keyedobjects.nib Binary files differindex c896d03b..e95a3bd5 100644 --- a/English.lproj/MainMenu.nib/keyedobjects.nib +++ b/English.lproj/MainMenu.nib/keyedobjects.nib diff --git a/TableContent.m b/TableContent.m index 9b2e3b27..f26f12b7 100644 --- a/TableContent.m +++ b/TableContent.m @@ -678,7 +678,7 @@ saves a file containing the content of the editSheet } if ( [editData respondsToSelector:@selector(writeToFile:atomically:encoding:error:)] ) { // mac os 10.4 or later - [editData writeToFile:fileName atomically:YES encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance getSelectedEncoding] cString]] error:errorStr]; + [editData writeToFile:fileName atomically:YES encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance encoding] cString]] error:errorStr]; } else { // mac os pre 10.4 [editData writeToFile:fileName atomically:YES]; diff --git a/TableDocument.h b/TableDocument.h index 64081d92..f0d1ba19 100644 --- a/TableDocument.h +++ b/TableDocument.h @@ -63,7 +63,6 @@ IBOutlet id consoleTextView; IBOutlet id variablesTableView; IBOutlet id createTableSyntaxView; - IBOutlet id chooseEncodingButton; IBOutlet id chooseTableOperationButton; IBOutlet NSTabView *tableTabView; @@ -75,6 +74,10 @@ NSString *selectedFavorite; NSString *mySQLVersion; NSUserDefaults *prefs; + + NSMenu *selectEncodingMenu; + BOOL _supportsEncoding; + NSString *_encoding; } //start sheet @@ -114,9 +117,11 @@ //encoding methods - (void)setEncoding:(NSString *)encoding; - (void)detectEncoding; -- (NSString *)getSelectedEncoding; - (IBAction)chooseEncoding:(id)sender; - (BOOL)supportsEncoding; +- (void)updateEncodingMenuWithSelectedEncoding:(NSString *)encoding; +- (NSString *)encodingNameFromMySQLEncoding:(NSString *)mysqlEncoding; +- (NSString *)mysqlEncodingFromDisplayEncoding:(NSString *)encodingName; //other methods - (NSString *)host; @@ -141,9 +146,12 @@ - (void)tunnelStatusChanged:(NSNotification *)notification; //menu methods +- (BOOL)validateMenuItem:(NSMenuItem *)anItem; - (IBAction)import:(id)sender; +- (IBAction)importCSV:(id)sender; - (IBAction)export:(id)sender; -- (BOOL)validateMenuItem:(NSMenuItem *)anItem; +- (IBAction)exportTable:(id)sender; +- (IBAction)exportMultipleTables:(id)sender; - (IBAction)viewStructure:(id)sender; - (IBAction)viewContent:(id)sender; - (IBAction)viewQuery:(id)sender; diff --git a/TableDocument.m b/TableDocument.m index 9623bdb2..feb2c11d 100644 --- a/TableDocument.m +++ b/TableDocument.m @@ -35,9 +35,23 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum @implementation TableDocument +- (id)init +{ + if (![super init]) + return nil; + + _encoding = [@"utf8" retain];; + + return self; +} + - (void)awakeFromNib { + // register selection did change handler for favorites controller (used in connect sheet) [favoritesController addObserver:self forKeyPath:@"selectionIndex" options:NSKeyValueChangeInsertion context:TableDocumentFavoritesControllerSelectionIndexDidChange]; + + // find the Database -> Database Encoding menu (it's not in our nib, so we can't use interface builder) + selectEncodingMenu = [[[[[NSApp mainMenu] itemWithTag:1] submenu] itemWithTag:1] submenu]; } - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -51,7 +65,6 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum } - //start sheet - (IBAction)connectToDB:(id)sender @@ -60,9 +73,8 @@ tries to connect to the db alert-sheets when no success */ { - CMMCPResult *theResult; - NSString *encoding; - int code; + CMMCPResult *theResult; + int code; id version; [self setFavorites]; @@ -80,12 +92,11 @@ alert-sheets when no success //register as delegate [mySQLConnection setDelegate:self]; // set encoding - encoding = [prefs objectForKey:@"encoding"]; - if ( [encoding isEqualToString:@"Autodetect"] ) { + NSString *encodingName = [prefs objectForKey:@"encoding"]; + if ( [encodingName isEqualToString:@"Autodetect"] ) { [self detectEncoding]; } else { - [chooseEncodingButton selectItemWithTitle:encoding]; - [self setEncoding:[self getSelectedEncoding]]; + [self setEncoding:[self mysqlEncodingFromDisplayEncoding:encodingName]]; } // get selected db if ( ![[databaseField stringValue] isEqualToString:@""] ) @@ -214,6 +225,16 @@ reused when user hits the close button of the variablseSheet or of the createTab - (NSArray *)favorites { + // if no favorites, load from user defaults + if (!favorites) { + favorites = [[NSArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"favorites"]]; + } + + // if no favorites in user defaults, load empty ones + if (!favorites) { + favorites = [[NSArray array] retain]; + } + return favorites; } @@ -541,156 +562,157 @@ reused when user hits the close button of the variablseSheet or of the createTab } } +#pragma mark Encoding Methods -//encoding methods /** - * set the encoding for the database + * Set the encoding for the database connection */ -- (void)setEncoding:(NSString *)encoding +- (void)setEncoding:(NSString *)mysqlEncoding { // set encoding of connection and client - [mySQLConnection queryString:[NSString stringWithFormat:@"SET NAMES '%@'", encoding]]; + [mySQLConnection queryString:[NSString stringWithFormat:@"SET NAMES '%@'", mysqlEncoding]]; if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - [mySQLConnection setEncoding:[CMMCPConnection encodingForMySQLEncoding:[encoding cString]]]; + [mySQLConnection setEncoding:[CMMCPConnection encodingForMySQLEncoding:[mysqlEncoding cString]]]; + [_encoding autorelease]; + _encoding = [mysqlEncoding retain]; } else { [self detectEncoding]; } - + + // update the selected menu item + [self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:mysqlEncoding]]; + + // reload stuff [tableSourceInstance reloadTable:self]; [tableContentInstance reloadTable:self]; [tableStatusInstance reloadTable:self]; } /** - * autodetects the connection encoding and sets the encoding dropdown + * returns the current mysql encoding for this object + */ +- (NSString *)encoding +{ + return _encoding; +} + +/** + * updates the currently selected item in the encoding menu + * + * @param NSString *encoding - the title of the menu item which will be selected + */ +- (void)updateEncodingMenuWithSelectedEncoding:(NSString *)encoding +{ + NSEnumerator *dbEncodingMenuEn = [[selectEncodingMenu itemArray] objectEnumerator]; + id menuItem; + int correctStateForMenuItem; + while (menuItem = [dbEncodingMenuEn nextObject]) { + correctStateForMenuItem = [[menuItem title] isEqualToString:encoding] ? NSOnState : NSOffState; + + if ([menuItem state] == correctStateForMenuItem) // don't re-apply state incase it causes performance issues + continue; + + [menuItem setState:correctStateForMenuItem]; + } +} + +/** + * Returns the display name for a mysql encoding + */ +- (NSString *)encodingNameFromMySQLEncoding:(NSString *)mysqlEncoding +{ + NSDictionary *translationMap = [NSDictionary dictionaryWithObjectsAndKeys: + @"UCS-2 Unicode (ucs2)", @"ucs2", + @"UTF-8 Unicode (utf8)", @"utf8", + @"US ASCII (ascii)", @"ascii", + @"ISO Latin 1 (latin1)", @"latin1", + @"Mac Roman (macroman)", @"macroman", + @"Windows Latin 2 (cp1250)", @"cp1250", + @"ISO Latin 2 (latin2)", @"latin2", + @"Windows Arabic (cp1256)", @"cp1256", + @"ISO Greek (greek)", @"greek", + @"ISO Hebrew (hebrew)", @"hebrew", + @"ISO Turkish (latin5)", @"latin5", + @"Windows Baltic (cp1257)", @"cp1257", + @"Windows Cyrillic (cp1251)", @"cp1251", + @"Big5 Traditional Chinese (big5)", @"big5", + @"Shift-JIS Japanese (sjis)", @"sjis", + @"EUC-JP Japanese (ujis)", @"ujis", + nil]; + NSString *encodingName = [translationMap valueForKey:mysqlEncoding]; + + if (!encodingName) + return [NSString stringWithFormat:@"Unknown Encoding (%@)", mysqlEncoding, nil]; + + return encodingName; +} + +/** + * Returns the mysql encoding for an encoding string that is displayed to the user + */ +- (NSString *)mysqlEncodingFromDisplayEncoding:(NSString *)encodingName +{ + NSDictionary *translationMap = [NSDictionary dictionaryWithObjectsAndKeys: + @"ucs2", @"UCS-2 Unicode (ucs2)", + @"utf8", @"UTF-8 Unicode (utf8)", + @"ascii", @"US ASCII (ascii)", + @"latin1", @"ISO Latin 1 (latin1)", + @"macroman", @"Mac Roman (macroman)", + @"cp1250", @"Windows Latin 2 (cp1250)", + @"latin2", @"ISO Latin 2 (latin2)", + @"cp1256", @"Windows Arabic (cp1256)", + @"greek", @"ISO Greek (greek)", + @"hebrew", @"ISO Hebrew (hebrew)", + @"latin5", @"ISO Turkish (latin5)", + @"cp1257", @"Windows Baltic (cp1257)", + @"cp1251", @"Windows Cyrillic (cp1251)", + @"big5", @"Big5 Traditional Chinese (big5)", + @"sjis", @"Shift-JIS Japanese (sjis)", + @"ujis", @"EUC-JP Japanese (ujis)", + nil]; + NSString *mysqlEncoding = [translationMap valueForKey:encodingName]; + + if (!mysqlEncoding) + return @"utf8"; + + return mysqlEncoding; +} + +/** + * Autodetect the connection encoding and select the relevant encoding menu item in Database -> Database Encoding */ - (void)detectEncoding { - id mysqlEncoding; - // mysql > 4.0 - mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set_connection'"] fetchRowAsDictionary] objectForKey:@"Value"]; + id mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set_connection'"] fetchRowAsDictionary] objectForKey:@"Value"]; + _supportsEncoding = (mysqlEncoding != nil); + if ( [mysqlEncoding isKindOfClass:[NSData class]] ) { // MySQL 4.1.14 returns the mysql variables as nsdata mysqlEncoding = [mySQLConnection stringWithText:mysqlEncoding]; } if ( !mysqlEncoding ) { // mysql 4.0 or older -> only default character set possible, cannot choose others using "set names xy" mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] fetchRowAsDictionary] objectForKey:@"Value"]; - [chooseEncodingButton setEnabled:NO]; } - if ( !mysqlEncoding ) { // older version? -> set encoding to mysql default encoding latin1, chooseEncodingButton is already disabled + if ( !mysqlEncoding ) { // older version? -> set encoding to mysql default encoding latin1 NSLog(@"error: no character encoding found, mysql version is %@", [self mySQLVersion]); mysqlEncoding = @"latin1"; } [mySQLConnection setEncoding:[CMMCPConnection encodingForMySQLEncoding:[mysqlEncoding cString]]]; - - if ( [mysqlEncoding isEqualToString:@"ucs2"] ) { - [chooseEncodingButton selectItemWithTitle:@"UCS-2 Unicode (ucs2)"]; - } else if ( [mysqlEncoding isEqualToString:@"utf8"] ) { - [chooseEncodingButton selectItemWithTitle:@"UTF-8 Unicode (utf8)"]; - } else if ( [mysqlEncoding isEqualToString:@"ascii"] ) { - [chooseEncodingButton selectItemWithTitle:@"US ASCII (ascii)"]; - } else if ( [mysqlEncoding isEqualToString:@"latin1"] ) { - [chooseEncodingButton selectItemWithTitle:@"ISO Latin 1 (latin1)"]; - } else if ( [mysqlEncoding isEqualToString:@"macroman"] ) { - [chooseEncodingButton selectItemWithTitle:@"Mac Roman (macroman)"]; - } else if ( [mysqlEncoding isEqualToString:@"cp1250"] ) { - [chooseEncodingButton selectItemWithTitle:@"Windows Latin 2 (cp1250)"]; - } else if ( [mysqlEncoding isEqualToString:@"latin2"] ) { - [chooseEncodingButton selectItemWithTitle:@"ISO Latin 2 (latin2)"]; - } else if ( [mysqlEncoding isEqualToString:@"cp1256"] ) { - [chooseEncodingButton selectItemWithTitle:@"Windows Arabic (cp1256)"]; - } else if ( [mysqlEncoding isEqualToString:@"greek"] ) { - [chooseEncodingButton selectItemWithTitle:@"ISO Greek (greek)"]; - } else if ( [mysqlEncoding isEqualToString:@"hebrew"] ) { - [chooseEncodingButton selectItemWithTitle:@"ISO Hebrew (hebrew)"]; - } else if ( [mysqlEncoding isEqualToString:@"latin5"] ) { - [chooseEncodingButton selectItemWithTitle:@"ISO Turkish (latin5)"]; - } else if ( [mysqlEncoding isEqualToString:@"cp1257"] ) { - [chooseEncodingButton selectItemWithTitle:@"Windows Baltic (cp1257)"]; - } else if ( [mysqlEncoding isEqualToString:@"cp1251"] ) { - [chooseEncodingButton selectItemWithTitle:@"Windows Cyrillic (cp1251)"]; - } else if ( [mysqlEncoding isEqualToString:@"big5"] ) { - [chooseEncodingButton selectItemWithTitle:@"Big5 Traditional Chinese (big5)"]; - } else if ( [mysqlEncoding isEqualToString:@"sjis"] ) { - [chooseEncodingButton selectItemWithTitle:@"Shift-JIS Japanese (sjis)"]; - } else if ( [mysqlEncoding isEqualToString:@"ujis"] ) { - [chooseEncodingButton selectItemWithTitle:@"EUC-JP Japanese (ujis)"]; - } else { - NSLog(@"unsupported encoding %@! falling back to utf8.", mysqlEncoding); - [chooseEncodingButton selectItemWithTitle:@"UTF-8 Unicode (utf8)"]; - [self setEncoding:[self getSelectedEncoding]]; - } -} - -/** - * gets the selected mysql encoding - */ -- (NSString *)getSelectedEncoding -{ - NSString *mysqlEncoding; - NSString *encoding = [chooseEncodingButton titleOfSelectedItem]; - - // unicode - if ( [encoding isEqualToString:@"UCS-2 Unicode (ucs2)"] ) { - mysqlEncoding = @"ucs2"; - } else if ( [encoding isEqualToString:@"UTF-8 Unicode (utf8)"] ) { - mysqlEncoding = @"utf8"; - - // west european - } else if( [encoding isEqualToString:@"US ASCII (ascii)"] ) { - mysqlEncoding = @"ascii"; - } else if ( [encoding isEqualToString:@"ISO Latin 1 (latin1)"] ) { - mysqlEncoding = @"latin1"; - } else if ( [encoding isEqualToString:@"Mac Roman (macroman)"] ) { - mysqlEncoding = @"macroman"; - - // central european - } else if ( [encoding isEqualToString:@"Windows Latin 2 (cp1250)"] ) { - mysqlEncoding = @"cp1250"; - } else if ( [encoding isEqualToString:@"ISO Latin 2 (latin2)"] ) { - mysqlEncoding = @"latin2"; - - // south european and middle east - } else if ( [encoding isEqualToString:@"Windows Arabic (cp1256)"] ) { - mysqlEncoding = @"cp1256"; - } else if ( [encoding isEqualToString:@"ISO Greek (greek)"] ) { - mysqlEncoding = @"greek"; - } else if ( [encoding isEqualToString:@"ISO Hebrew (hebrew)"] ) { - mysqlEncoding = @"hebrew"; - } else if ( [encoding isEqualToString:@"ISO Turkish (latin5)"] ) { - mysqlEncoding = @"latin5"; - - // baltic - } else if ( [encoding isEqualToString:@"Windows Baltic (cp1257)"] ) { - mysqlEncoding = @"cp1257"; - // cyrillic - } else if ( [encoding isEqualToString:@"Windows Cyrillic (cp1251)"] ) { - mysqlEncoding = @"cp1251"; + // save the encoding + [_encoding autorelease]; + _encoding = [mysqlEncoding retain]; - // asian - } else if ( [encoding isEqualToString:@"Big5 Traditional Chinese (big5)"] ) { - mysqlEncoding = @"big5"; - } else if ( [encoding isEqualToString:@"Shift-JIS Japanese (sjis)"] ) { - mysqlEncoding = @"sjis"; - } else if ( [encoding isEqualToString:@"EUC-JP Japanese (ujis)"] ) { - mysqlEncoding = @"ujis"; - - // unknown encoding - } else { - NSLog(@"error: unknown encoding %@, assuming utf8", encoding); - mysqlEncoding = @"utf8"; - } - - return [mysqlEncoding autorelease]; + // update the selected menu item + [self updateEncodingMenuWithSelectedEncoding:[self encodingNameFromMySQLEncoding:mysqlEncoding]]; } /** - * choose encoding + * when sent by an NSMenuItem, will set the encoding based on the title of the menu item */ - (IBAction)chooseEncoding:(id)sender { - [self setEncoding:[self getSelectedEncoding]]; + [self setEncoding:[self mysqlEncodingFromDisplayEncoding:[(NSMenuItem *)sender title]]]; } /** @@ -698,7 +720,7 @@ reused when user hits the close button of the variablseSheet or of the createTab */ - (BOOL)supportsEncoding { - return [chooseEncodingButton isEnabled]; + return _supportsEncoding; } @@ -961,6 +983,11 @@ passes the request to the tableDump object [tableDumpInstance importFile:[sender tag]]; } +- (IBAction)importCSV:(id)sender +{ + return [self import:sender]; +} + - (IBAction)export:(id)sender /* passes the request to the tableDump object @@ -969,64 +996,46 @@ passes the request to the tableDump object [tableDumpInstance exportFile:[sender tag]]; } -- (BOOL)validateMenuItem:(NSMenuItem *)anItem -/* -do menu validation -*/ +- (IBAction)exportTable:(id)sender { - switch ( [anItem tag] ) { - case 1: - //import dump - if ( ![self database] ) { - return NO; - } - break; - case 2: - //import CSV - if ( ![self database] || ![self table] ) { - return NO; - } - break; - case 5: - //export dump - if ( ![self database] ) { - return NO; - } - break; - case 6: - //export table content as CSV - if ( ![self database] || ![self table] ) { - return NO; - } - break; - case 7: - //export table content as XML - if ( ![self database] || ![self table] ) { - return NO; - } - break; - case 8: - //export custom result as CSV - return YES; - break; - case 9: - //export custom result as XML - return YES; - break; - case 10: - //export multiple tables as CSV - if ( ![self database] ) { - return NO; - } - break; - case 11: - //export multiple tables as XML - if ( ![self database] ) { - return NO; - } - break; - } - return YES; + return [self export:sender]; +} + +- (IBAction)exportMultipleTables:(id)sender +{ + return [self export:sender]; +} + +/** + * Menu validation + */ +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +{ + if ([menuItem action] == @selector(import:)) { + return ([self database] != nil); + } + + if ([menuItem action] == @selector(importCSV:)) { + return ([self database] != nil && [self table] != nil); + } + + if ([menuItem action] == @selector(export:)) { + return ([self database] != nil); + } + + if ([menuItem action] == @selector(exportTable:)) { + return ([self database] != nil && [self table] != nil); + } + + if ([menuItem action] == @selector(exportMultipleTables:)) { + return ([self database] != nil); + } + + if ([menuItem action] == @selector(chooseEncoding:)) { + return [self supportsEncoding]; + } + + return [super validateMenuItem:menuItem]; } - (IBAction)viewStructure:(id)sender @@ -1216,11 +1225,6 @@ sets upt the interface (small fonts) // [tableWindow makeKeyAndOrderFront:self]; prefs = [[NSUserDefaults standardUserDefaults] retain]; - if ( [prefs objectForKey:@"favorites"] != nil ) { - favorites = [[NSArray alloc] initWithArray:[prefs objectForKey:@"favorites"]]; - } else { - favorites = [[NSArray array] retain]; - } selectedFavorite = [[NSString alloc] initWithString:NSLocalizedString(@"Custom", @"menu item for custom connection")]; //register for notifications diff --git a/TableDump.m b/TableDump.m index d363f192..17119cda 100644 --- a/TableDump.m +++ b/TableDump.m @@ -270,7 +270,7 @@ saves the export file if ( [fileContent respondsToSelector:@selector(writeToFile:atomically:encoding:error:)] ) { // mac os 10.4 or later - success = [fileContent writeToFile:[sheet filename] atomically:YES encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance getSelectedEncoding] cString]] error:errorStr]; + success = [fileContent writeToFile:[sheet filename] atomically:YES encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance encoding] cString]] error:errorStr]; } else { // mac os pre 10.4 success = [fileContent writeToFile:[sheet filename] atomically:YES]; @@ -342,7 +342,7 @@ reads mysql-dumpfile //load file into string if ( [NSString respondsToSelector:@selector(stringWithContentsOfFile:encoding:error:)] ) { // mac os 10.4 or later - dumpFile = [NSString stringWithContentsOfFile:[sheet filename] encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance getSelectedEncoding] cString]] error:errorStr]; + dumpFile = [NSString stringWithContentsOfFile:[sheet filename] encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance encoding] cString]] error:errorStr]; } else { // mac os pre 10.4 dumpFile = [NSString stringWithContentsOfFile:[sheet filename]]; diff --git a/TablesList.m b/TablesList.m index 8d330a2f..d26336e9 100644 --- a/TablesList.m +++ b/TablesList.m @@ -372,122 +372,122 @@ returns YES if table status has already been loaded return [tables objectAtIndex:rowIndex]; } +/** + * adds or renames a table (in tables-array and mysql-db) + * removes new table from table-array if renaming had no success + */ - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex -/* -adds or renames a table (in tables-array and mysql-db) -removes new table from table-array if renaming had no success -*/ { - if ( [[tables objectAtIndex:rowIndex] isEqualToString:@""] ) { -//new table - if ( [anObject isEqualToString:@""] ) { - //table has no name - alertSheetOpened = YES; - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, - @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", NSLocalizedString(@"Table must have a name.", @"message of panel when no name is given for table")); - [tables removeObjectAtIndex:rowIndex]; - [tablesListView reloadData]; - } else { + if ( [[tables objectAtIndex:rowIndex] isEqualToString:@""] ) { + //new table + if ( [anObject isEqualToString:@""] ) { + //table has no name + alertSheetOpened = YES; + NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, + @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", NSLocalizedString(@"Table must have a name.", @"message of panel when no name is given for table")); + [tables removeObjectAtIndex:rowIndex]; + [tablesListView reloadData]; + } else { if ( [tableDocumentInstance supportsEncoding] ) { - [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE `%@` (id int) DEFAULT CHARACTER SET %@", anObject, [tableDocumentInstance getSelectedEncoding]]]; - } else { + [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE `%@` (id int) DEFAULT CHARACTER SET %@", anObject, [tableDocumentInstance encoding]]]; + } else { [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE `%@` (id int)", anObject]]; } if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - //added table with success -// NSLog(@"added new table with success"); - [tables replaceObjectAtIndex:rowIndex withObject:anObject]; - if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) { - [tableSourceInstance loadTable:anObject]; - structureLoaded = YES; - contentLoaded = NO; - statusLoaded = NO; - } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) { - [tableSourceInstance loadTable:anObject]; - [tableContentInstance loadTable:anObject]; - structureLoaded = YES; - contentLoaded = YES; - statusLoaded = NO; - } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) { - [tableStatusInstance loadTable:anObject]; - statusLoaded = YES; - structureLoaded = NO; - contentLoaded = NO; - } else { - statusLoaded = NO; - structureLoaded = NO; - contentLoaded = NO; - } + //added table with success + // NSLog(@"added new table with success"); + [tables replaceObjectAtIndex:rowIndex withObject:anObject]; + if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) { + [tableSourceInstance loadTable:anObject]; + structureLoaded = YES; + contentLoaded = NO; + statusLoaded = NO; + } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) { + [tableSourceInstance loadTable:anObject]; + [tableContentInstance loadTable:anObject]; + structureLoaded = YES; + contentLoaded = YES; + statusLoaded = NO; + } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) { + [tableStatusInstance loadTable:anObject]; + statusLoaded = YES; + structureLoaded = NO; + contentLoaded = NO; + } else { + statusLoaded = NO; + structureLoaded = NO; + contentLoaded = NO; + } // set window title [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user], - [tableDocumentInstance host], [tableDocumentInstance database], anObject]]; - } else { - //error while adding new table -// NSLog(@"couldn't add new table"); - alertSheetOpened = YES; - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, - @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", - [NSString stringWithFormat:NSLocalizedString(@"Couldn't add table %@.\nMySQL said: %@", @"message of panel when table cannot be created with the given name"), - anObject, [mySQLConnection getLastErrorMessage]]); - [tables removeObjectAtIndex:rowIndex]; - [tablesListView reloadData]; - } - } + [tableDocumentInstance host], [tableDocumentInstance database], anObject]]; + } else { + //error while adding new table + // NSLog(@"couldn't add new table"); + alertSheetOpened = YES; + NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, + @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", + [NSString stringWithFormat:NSLocalizedString(@"Couldn't add table %@.\nMySQL said: %@", @"message of panel when table cannot be created with the given name"), + anObject, [mySQLConnection getLastErrorMessage]]); + [tables removeObjectAtIndex:rowIndex]; + [tablesListView reloadData]; + } + } + } else { + //table modification + if ( [[tables objectAtIndex:rowIndex] isEqualToString:anObject] ) { + //no changes in table name + // NSLog(@"no changes in table name"); + } else if ( [anObject isEqualToString:@""] ) { + //table has no name + // NSLog(@"name is nil"); + alertSheetOpened = YES; + NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, + @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", NSLocalizedString(@"Table must have a name.", @"message of panel when no name is given for table")); } else { -//table modification - if ( [[tables objectAtIndex:rowIndex] isEqualToString:anObject] ) { - //no changes in table name -// NSLog(@"no changes in table name"); - } else if ( [anObject isEqualToString:@""] ) { - //table has no name -// NSLog(@"name is nil"); - alertSheetOpened = YES; - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, - @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", NSLocalizedString(@"Table must have a name.", @"message of panel when no name is given for table")); + [mySQLConnection queryString:[NSString stringWithFormat:@"RENAME TABLE `%@` TO `%@`", [tables objectAtIndex:rowIndex], anObject]]; + if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { + // NSLog(@"renamed table with success"); + //renamed with success + [tables replaceObjectAtIndex:rowIndex withObject:anObject]; + if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) { + [tableSourceInstance loadTable:anObject]; + structureLoaded = YES; + contentLoaded = NO; + statusLoaded = NO; + } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) { + [tableSourceInstance loadTable:anObject]; + [tableContentInstance loadTable:anObject]; + structureLoaded = YES; + contentLoaded = YES; + statusLoaded = NO; + } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) { + [tableStatusInstance loadTable:anObject]; + structureLoaded = NO; + contentLoaded = NO; + statusLoaded = YES; } else { - [mySQLConnection queryString:[NSString stringWithFormat:@"RENAME TABLE `%@` TO `%@`", [tables objectAtIndex:rowIndex], anObject]]; - if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { -// NSLog(@"renamed table with success"); - //renamed with success - [tables replaceObjectAtIndex:rowIndex withObject:anObject]; - if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) { - [tableSourceInstance loadTable:anObject]; - structureLoaded = YES; - contentLoaded = NO; - statusLoaded = NO; - } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) { - [tableSourceInstance loadTable:anObject]; - [tableContentInstance loadTable:anObject]; - structureLoaded = YES; - contentLoaded = YES; - statusLoaded = NO; - } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) { - [tableStatusInstance loadTable:anObject]; - structureLoaded = NO; - contentLoaded = NO; - statusLoaded = YES; - } else { - statusLoaded = NO; - structureLoaded = NO; - contentLoaded = NO; - } + statusLoaded = NO; + structureLoaded = NO; + contentLoaded = NO; + } // set window title [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user], - [tableDocumentInstance host], [tableDocumentInstance database], anObject]]; - } else { - //error while renaming -// NSLog(@"couldn't rename table"); - alertSheetOpened = YES; - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, - @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", - [NSString stringWithFormat:NSLocalizedString(@"Couldn't rename table.\nMySQL said: %@", @"message of panel when table cannot be renamed"), - [mySQLConnection getLastErrorMessage]]); - } - } + [tableDocumentInstance host], [tableDocumentInstance database], anObject]]; + } else { + //error while renaming + // NSLog(@"couldn't rename table"); + alertSheetOpened = YES; + NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, + @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", + [NSString stringWithFormat:NSLocalizedString(@"Couldn't rename table.\nMySQL said: %@", @"message of panel when table cannot be renamed"), + [mySQLConnection getLastErrorMessage]]); + } } + } } //tableView delegate methods |