diff options
author | rowanbeentje <rowan@beent.je> | 2009-04-12 00:02:54 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-04-12 00:02:54 +0000 |
commit | 31f8188faffabfca596a273ea4b376326f324f78 (patch) | |
tree | c040975e230d7882c36c96d45bd79b26fd6a814f | |
parent | 40a49b30a8feaf8f0cdd7a084d9843ce7d6da77f (diff) | |
download | sequelpro-31f8188faffabfca596a273ea4b376326f324f78.tar.gz sequelpro-31f8188faffabfca596a273ea4b376326f324f78.tar.bz2 sequelpro-31f8188faffabfca596a273ea4b376326f324f78.zip |
- Correctly set default editor font to Monaco 10
- Restore pref upgrade methods, make compatibible with both lastUsedVersion and LastUsedVersion keys
- Add upgrade method to map old pref keys to new pref keys, delete old keys
-rw-r--r-- | Resources/PreferenceDefaults.plist | 2 | ||||
-rw-r--r-- | Source/SPPreferenceController.h | 2 | ||||
-rw-r--r-- | Source/SPPreferenceController.m | 140 |
3 files changed, 140 insertions, 4 deletions
diff --git a/Resources/PreferenceDefaults.plist b/Resources/PreferenceDefaults.plist index ac2af799..6e4738f8 100644 --- a/Resources/PreferenceDefaults.plist +++ b/Resources/PreferenceDefaults.plist @@ -33,7 +33,7 @@ <key>KeepAliveInterval</key> <integer>60</integer> <key>CustomQueryEditorFont</key> - <data>BAtzdHJlYW10eXBlZIHoA4QBQISEhAZOU0ZvbnQehIQITlNPYmplY3QAhYQBaUCEBVs2NGNdBgAAADgAAAD//kIAaQB0AHMAdAByAGUAYQBtAFYAZQByAGEAUwBhAG4AcwBNAG8AbgBvAC0AUgBvAG0AYQBuAIQBZguEAWMAmAGYAJgAhg==</data> + <data>BAtzdHJlYW10eXBlZIHoA4QBQISEhAZOU0ZvbnQehIQITlNPYmplY3QAhYQBaRiEBVsyNGNdBgAAAA4AAAD//k0AbwBuAGEAYwBvAAAAhAFmCoQBYwCYAZgAmACG</data> <key>CustomQueryAutoindent</key> <true/> <key>CustomQueryAutopair</key> diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h index 0198303c..f946b824 100644 --- a/Source/SPPreferenceController.h +++ b/Source/SPPreferenceController.h @@ -56,6 +56,8 @@ NSUserDefaults *prefs; } +- (void)applyRevisionChanges; + // IBAction methods - (IBAction)addFavorite:(id)sender; - (IBAction)removeFavorite:(id)sender; diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 657bcd3f..4be1f790 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -54,7 +54,11 @@ // ------------------------------------------------------------------------------- - (id)init { - return [super initWithWindowNibName:@"Preferences"]; + if (self = [super initWithWindowNibName:@"Preferences"]) { + prefs = [NSUserDefaults standardUserDefaults]; + [self applyRevisionChanges]; + } + return self; } // ------------------------------------------------------------------------------- @@ -64,9 +68,8 @@ { [self _setupToolbar]; - prefs = [NSUserDefaults standardUserDefaults]; keychain = [[KeyChain alloc] init]; - + SPFavoriteTextFieldCell *tableCell = [[[SPFavoriteTextFieldCell alloc] init] autorelease]; [tableCell setImage:[NSImage imageNamed:@"database"]]; @@ -82,6 +85,137 @@ [self _updateDefaultFavoritePopup]; } +// ------------------------------------------------------------------------------- +// applyRevisionChanges +// Checks the revision number, applies any preference upgrades, and updates to +// latest revision. +// Currently uses both lastUsedVersion and LastUsedVersion for <0.9.5 compatibility. +// ------------------------------------------------------------------------------- +- (void)applyRevisionChanges +{ + int currentVersionNumber, recordedVersionNumber = 0; + + // Get the current bundle version number (the SVN build number) for per-version upgrades + currentVersionNumber = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]; + + // Get the current revision + if ([prefs objectForKey:@"lastUsedVersion"]) recordedVersionNumber = [[prefs objectForKey:@"lastUsedVersion"] intValue]; + if ([prefs objectForKey:@"LastUsedVersion"]) recordedVersionNumber = [[prefs objectForKey:@"LastUsedVersion"] intValue]; + + // Skip processing if the current version matches recorded version + if (currentVersionNumber == recordedVersionNumber) return; + + // If no recorded version, update to current revision and skip processing + if (!recordedVersionNumber) { + [prefs setObject:[NSNumber numberWithInt:currentVersionNumber] forKey:@"LastUsedVersion"]; + return; + } + + // For versions prior to r336 (0.9.4), where column widths have been saved, walk through them and remove + // any table widths set to 15 or less (fix for mangled columns caused by Issue #140) + if (recordedVersionNumber < 336 && [prefs objectForKey:@"tableColumnWidths"] != nil) { + NSEnumerator *databaseEnumerator, *tableEnumerator, *columnEnumerator; + NSString *databaseKey, *tableKey, *columnKey; + NSMutableDictionary *newDatabase, *newTable; + float columnWidth; + NSMutableDictionary *newTableColumnWidths = [[NSMutableDictionary alloc] init]; + + databaseEnumerator = [[prefs objectForKey:@"tableColumnWidths"] keyEnumerator]; + while (databaseKey = [databaseEnumerator nextObject]) { + newDatabase = [[NSMutableDictionary alloc] init]; + tableEnumerator = [[[prefs objectForKey:@"tableColumnWidths"] objectForKey:databaseKey] keyEnumerator]; + while (tableKey = [tableEnumerator nextObject]) { + newTable = [[NSMutableDictionary alloc] init]; + columnEnumerator = [[[[prefs objectForKey:@"tableColumnWidths"] objectForKey:databaseKey] objectForKey:tableKey] keyEnumerator]; + while (columnKey = [columnEnumerator nextObject]) { + columnWidth = [[[[[prefs objectForKey:@"tableColumnWidths"] objectForKey:databaseKey] objectForKey:tableKey] objectForKey:columnKey] floatValue]; + if (columnWidth >= 15) { + [newTable setObject:[NSNumber numberWithFloat:columnWidth] forKey:[NSString stringWithString:columnKey]]; + } + } + if ([newTable count]) { + [newDatabase setObject:[NSDictionary dictionaryWithDictionary:newTable] forKey:[NSString stringWithString:tableKey]]; + } + [newTable release]; + } + if ([newDatabase count]) { + [newTableColumnWidths setObject:[NSDictionary dictionaryWithDictionary:newDatabase] forKey:[NSString stringWithString:databaseKey]]; + } + [newDatabase release]; + } + [prefs setObject:[NSDictionary dictionaryWithDictionary:newTableColumnWidths] forKey:@"tableColumnWidths"]; + [newTableColumnWidths release]; + } + + // For versions prior to r561 (0.9.5), migrate old pref keys where they exist to the new pref keys + if (recordedVersionNumber < 561) { + if ([prefs objectForKey:@"encoding"]) { + [prefs setObject:[prefs objectForKey:@"encoding"] forKey:@"DefaultEncoding"]; + [prefs removeObjectForKey:@"encoding"]; + } + if ([prefs objectForKey:@"useMonospacedFonts"]) { + [prefs setObject:[prefs objectForKey:@"useMonospacedFonts"] forKey:@"UseMonospacedFonts"]; + [prefs removeObjectForKey:@"useMonospacedFonts"]; + } + if ([prefs objectForKey:@"reloadAfterAdding"]) { + [prefs setObject:[prefs objectForKey:@"reloadAfterAdding"] forKey:@"ReloadAfterAddingRow"]; + [prefs removeObjectForKey:@"reloadAfterAdding"]; + } + if ([prefs objectForKey:@"reloadAfterEditing"]) { + [prefs setObject:[prefs objectForKey:@"reloadAfterEditing"] forKey:@"ReloadAfterEditingRow"]; + [prefs removeObjectForKey:@"reloadAfterEditing"]; + } + if ([prefs objectForKey:@"reloadAfterRemoving"]) { + [prefs setObject:[prefs objectForKey:@"reloadAfterRemoving"] forKey:@"ReloadAfterRemovingRow"]; + [prefs removeObjectForKey:@"reloadAfterRemoving"]; + } + if ([prefs objectForKey:@"dontShowBlob"]) { + [prefs setObject:[prefs objectForKey:@"dontShowBlob"] forKey:@"LoadBlobsAsNeeded"]; + [prefs removeObjectForKey:@"dontShowBlob"]; + } + if ([prefs objectForKey:@"fetchRowCount"]) { + [prefs setObject:[prefs objectForKey:@"fetchRowCount"] forKey:@"FetchCorrectRowCount"]; + [prefs removeObjectForKey:@"fetchRowCount"]; + } + if ([prefs objectForKey:@"limitRows"]) { + [prefs setObject:[prefs objectForKey:@"limitRows"] forKey:@"LimitResults"]; + [prefs removeObjectForKey:@"limitRows"]; + } + if ([prefs objectForKey:@"limitRowsValue"]) { + [prefs setObject:[prefs objectForKey:@"limitRowsValue"] forKey:@"LimitResultsValue"]; + [prefs removeObjectForKey:@"limitRowsValue"]; + } + if ([prefs objectForKey:@"nullValue"]) { + [prefs setObject:[prefs objectForKey:@"nullValue"] forKey:@"NullValue"]; + [prefs removeObjectForKey:@"nullValue"]; + } + if ([prefs objectForKey:@"showError"]) { + [prefs setObject:[prefs objectForKey:@"showError"] forKey:@"ShowNoAffectedRowsError"]; + [prefs removeObjectForKey:@"showError"]; + } + if ([prefs objectForKey:@"connectionTimeout"]) { + [prefs setObject:[prefs objectForKey:@"connectionTimeout"] forKey:@"ConnectionTimeoutValue"]; + [prefs removeObjectForKey:@"connectionTimeout"]; + } + if ([prefs objectForKey:@"keepAliveInterval"]) { + [prefs setObject:[prefs objectForKey:@"keepAliveInterval"] forKey:@"KeepAliveInterval"]; + [prefs removeObjectForKey:@"keepAliveInterval"]; + } + if ([prefs objectForKey:@"lastFavoriteIndex"]) { + [prefs setObject:[prefs objectForKey:@"lastFavoriteIndex"] forKey:@"LastFavoriteIndex"]; + [prefs removeObjectForKey:@"lastFavoriteIndex"]; + } + + // Remove outdated keys + [prefs removeObjectForKey:@"lastUsedVersion"]; + [prefs removeObjectForKey:@"version"]; + } + + // Update the prefs revision + [prefs setObject:[NSNumber numberWithInt:currentVersionNumber] forKey:@"LastUsedVersion"]; +} + + #pragma mark - #pragma mark IBAction methods |