diff options
author | stuconnolly <stuart02@gmail.com> | 2010-09-26 14:49:42 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-09-26 14:49:42 +0000 |
commit | 25ef15930d0b8d4ce558ca89e721910aa2391dd8 (patch) | |
tree | 2eeb3e57f0758639d155d2f9e1976a594b23d9d9 /Source | |
parent | 8fbd6bbedd98e012b2b2a56e3c9a87672e55e179 (diff) | |
download | sequelpro-25ef15930d0b8d4ce558ca89e721910aa2391dd8.tar.gz sequelpro-25ef15930d0b8d4ce558ca89e721910aa2391dd8.tar.bz2 sequelpro-25ef15930d0b8d4ce558ca89e721910aa2391dd8.zip |
- Correctly sort connection favourites upon startup for both the connection and preferences view. Fixes issue #807.
- Remove the default favourite indicator from the preferences view.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionController.m | 30 | ||||
-rw-r--r-- | Source/SPPreferenceController.m | 57 |
2 files changed, 31 insertions, 56 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index aefca1fd..6e760a9d 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -94,7 +94,7 @@ isConnecting = NO; mySQLConnectionCancelled = NO; favoritesPBoardType = @"FavoritesPBoardType"; - + // Load the connection nib, keeping references to the top-level objects for later release nibObjectsToRelease = [[NSMutableArray alloc] init]; NSArray *connectionViewTopLevelObjects = nil; @@ -106,17 +106,20 @@ // Hide the main view and position and display the connection view [databaseConnectionView setHidden:YES]; [connectionView setFrame:[databaseConnectionView frame]]; - [databaseConnectionSuperview addSubview:connectionView]; + [databaseConnectionSuperview addSubview:connectionView]; [connectionSplitView setPosition:[[tableDocument valueForKey:@"dbTablesTableView"] frame].size.width-6 ofDividerAtIndex:0]; [connectionSplitViewButtonBar setSplitViewDelegate:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollViewFrameChanged:) name:NSViewFrameDidChangeNotification object:nil]; - + // Set up a keychain instance and preferences reference, and create the initial favorites list keychain = [[SPKeychain alloc] init]; prefs = [[NSUserDefaults standardUserDefaults] retain]; + favorites = nil; + + // Load favorites [self updateFavorites]; - + // Register an observer for changes within the favorites [prefs addObserver:self forKeyPath:SPFavorites options:NSKeyValueObservingOptionNew context:NULL]; @@ -131,7 +134,7 @@ [favoritesTable setDraggingSourceOperationMask:NSDragOperationMove forLocal:YES]; // Sort the favourites to match prefs and select the appropriate row - if (currentSortItem > -1) [self _sortFavorites]; + [self _sortFavorites]; NSInteger tableRow = ([prefs integerForKey:[prefs boolForKey:SPSelectLastFavoriteUsed] ? SPLastFavoriteIndex : SPDefaultFavorite] + 1); @@ -140,11 +143,13 @@ [favoritesTable selectRowIndexes:[NSIndexSet indexSetWithIndex:tableRow] byExtendingSelection:NO]; [self resizeTabViewToConnectionType:[[[favorites objectAtIndex:tableRow] objectForKey:@"type"] integerValue] animating:NO]; [favoritesTable scrollRowToVisible:[favoritesTable selectedRow]]; - } else { + } + else { previousType = SPTCPIPConnection; [self resizeTabViewToConnectionType:SPTCPIPConnection animating:NO]; } } + return self; } @@ -488,26 +493,27 @@ * interface, allowing the application to run as normal. */ - (void)addConnectionToDocument -{ - +{ // Hide the connection view and restore the main view [connectionView removeFromSuperviewWithoutNeedingDisplay]; [databaseConnectionView setHidden:NO]; - + // Restore the toolbar icons NSArray *toolbarItems = [[[tableDocument parentWindow] toolbar] items]; + for (NSInteger i = 0; i < [toolbarItems count]; i++) [[toolbarItems objectAtIndex:i] setEnabled:YES]; // Set keychain id for saving SPF files - if([self valueForKeyPath:@"selectedFavorite.id"]) + if ([self valueForKeyPath:@"selectedFavorite.id"]) { [tableDocument setKeychainID:[[self valueForKeyPath:@"selectedFavorite.id"] stringValue]]; - else + } + else { [tableDocument setKeychainID:@""]; + } // Pass the connection to the table document, allowing it to set // up the other classes and the rest of the interface. [tableDocument setConnection:mySQLConnection]; - } #pragma mark - diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index f12cd54a..4441c75d 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -109,10 +109,8 @@ [prefs synchronize]; - if (currentSortItem > -1) { - [self _sortFavorites]; - } - + // Sort favorites + [self _sortFavorites]; NSTableColumn *column; SPColorWellCell *colorCell; @@ -903,9 +901,6 @@ #pragma mark - #pragma mark TableView datasource methods -// ------------------------------------------------------------------------------- -// numberOfRowsInTableView: -// ------------------------------------------------------------------------------- - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { if(aTableView == colorSettingTableView) @@ -916,26 +911,18 @@ return [[favoritesController arrangedObjects] count]; } -// ------------------------------------------------------------------------------- -// tableView:objectValueForTableColumn:row: -// ------------------------------------------------------------------------------- - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex { - if(tableView == colorSettingTableView) { - if ([[tableColumn identifier] isEqualToString:@"name"]) - return [editorNameForColors objectAtIndex:rowIndex]; - else - return [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:[editorColors objectAtIndex:rowIndex]]]; - } else if(tableView == editThemeListTable) { + if (tableView == colorSettingTableView) { + return ([[tableColumn identifier] isEqualToString:@"name"]) ? [editorNameForColors objectAtIndex:rowIndex] : [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:[editorColors objectAtIndex:rowIndex]]]; + } + else if (tableView == editThemeListTable) { return [editThemeListItems objectAtIndex:rowIndex]; - } else { - if ([[tableColumn identifier] isEqualToString:@"default"] && (rowIndex == [prefs integerForKey:SPDefaultFavorite])) { - return [NSImage imageNamed:@"blue-tick"]; - } - else { - return [[[favoritesController arrangedObjects] objectAtIndex:rowIndex] objectForKey:[tableColumn identifier]]; - } + } + else { + return [[[favoritesController arrangedObjects] objectAtIndex:rowIndex] objectForKey:[tableColumn identifier]]; } + return nil; } @@ -988,9 +975,6 @@ #pragma mark - #pragma mark TableView drag & drop delegate methods -// ------------------------------------------------------------------------------- -// tableView:writeRowsWithIndexes:toPasteboard: -// ------------------------------------------------------------------------------- - (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rows toPasteboard:(NSPasteboard*)pboard { @@ -1007,9 +991,6 @@ } } -// ------------------------------------------------------------------------------- -// tableView:validateDrop:proposedRow:proposedDropOperation: -// ------------------------------------------------------------------------------- - (NSDragOperation)tableView:(NSTableView *)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation { @@ -1031,9 +1012,6 @@ return NSDragOperationNone; } -// ------------------------------------------------------------------------------- -// tableView:acceptDrop:row:dropOperation: -// ------------------------------------------------------------------------------- - (BOOL)tableView:(NSTableView *)tv acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation { @@ -1068,8 +1046,9 @@ } draggedRow = [NSMutableDictionary dictionaryWithDictionary:[[favoritesController arrangedObjects] objectAtIndex:originalRow]]; - //Before deleting this favorite, we need to save the current index. - //because removeObjectAtArrangedObjectIndex will set prefs LastFavoriteIndex to 0 + + // Before deleting this favorite, we need to save the current index. + // because removeObjectAtArrangedObjectIndex will set prefs LastFavoriteIndex to 0 lastFavoriteIndexCached = [prefs integerForKey:SPLastFavoriteIndex]; [favoritesController removeObjectAtArrangedObjectIndex:originalRow]; @@ -1117,9 +1096,6 @@ return YES; } -// ------------------------------------------------------------------------------- -// tableView:willDisplayCell:forTableColumn:row: -// ------------------------------------------------------------------------------- - (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)index { @@ -1161,12 +1137,8 @@ } } -// ------------------------------------------------------------------------------- -// tableViewSelectionDidChange: -// ------------------------------------------------------------------------------- - (void)tableViewSelectionDidChange:(NSNotification *)notification { - if([notification object] == colorSettingTableView) return; if ([[favoritesTableView selectedRowIndexes] count] > 0) { @@ -1205,9 +1177,6 @@ #pragma mark - #pragma mark Toolbar delegate methods -// ------------------------------------------------------------------------------- -// toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar: -// ------------------------------------------------------------------------------- - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag { if ([itemIdentifier isEqualToString:SPPreferenceToolbarGeneral]) { |