From 0eff207065c74b903c1358a91f7bffadd631b8e7 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 7 Dec 2008 17:43:18 +0000 Subject: - Add new favourites as NSMutableDictionaries instead of NSDictionaries - properly fixes Issue #110. - Save favourites on exit - this saves edits such as favourite name changes within the connection sheet which aren't otherwise caught. - Removes an outdated property (selectedFavourite) --- TableDocument.h | 1 - TableDocument.m | 14 +++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/TableDocument.h b/TableDocument.h index 2a54a37c..ac20b335 100644 --- a/TableDocument.h +++ b/TableDocument.h @@ -81,7 +81,6 @@ NSMutableArray *favorites; NSArray *variables; NSString *selectedDatabase; - NSString *selectedFavorite; NSString *mySQLVersion; NSUserDefaults *prefs; diff --git a/TableDocument.m b/TableDocument.m index 59aad2e0..e88a62ad 100644 --- a/TableDocument.m +++ b/TableDocument.m @@ -260,9 +260,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa [portField setStringValue:[self valueForKeyPath:@"selectedFavorite.port"]]; [databaseField setStringValue:[self valueForKeyPath:@"selectedFavorite.database"]]; [passwordField setStringValue:[self selectedFavoritePassword]]; - - [selectedFavorite release]; - selectedFavorite = [[favoritesButton titleOfSelectedItem] retain]; } /** @@ -368,7 +365,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa [self willChangeValueForKey:@"favorites"]; // write favorites and password - NSDictionary *newFavorite = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:favoriteName, host, socket, user, port, database, nil] + NSMutableDictionary *newFavorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:favoriteName, host, socket, user, port, database, nil] forKeys:[NSArray arrayWithObjects:@"name", @"host", @"socket", @"user", @"port", @"database", nil]]; [favorites addObject:newFavorite]; @@ -378,9 +375,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa account:[NSString stringWithFormat:@"%@@%@/%@", user, host, database]]; } - // select new favorite - selectedFavorite = [favoriteName retain]; - [self didChangeValueForKey:@"favorites"]; [favoritesController setSelectedObjects:[NSArray arrayWithObject:newFavorite]]; } @@ -1428,7 +1422,6 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFa // [tableWindow makeKeyAndOrderFront:self]; prefs = [[NSUserDefaults standardUserDefaults] retain]; - selectedFavorite = [[NSString alloc] initWithString:NSLocalizedString(@"Custom", @"menu item for custom connection")]; //register for notifications [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPerformQuery:) @@ -1593,6 +1586,10 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn - (IBAction)terminate:(id)sender { [[NSApp orderedDocuments] makeObjectsPerformSelector:@selector(cancelConnectSheet:) withObject:nil]; + + // Save the favourites - commits any unsaved changes ie favourite renames + [prefs setObject:[self favorites] forKey:@"favorites"]; + [NSApp terminate:sender]; } @@ -1603,7 +1600,6 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn [favorites release]; [variables release]; [selectedDatabase release]; - [selectedFavorite release]; [mySQLVersion release]; [prefs release]; -- cgit v1.2.3