diff options
author | stuconnolly <stuart02@gmail.com> | 2010-07-03 22:10:38 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-07-03 22:10:38 +0000 |
commit | 89719b64e4f6fa793c4ed7d4d1a63f8b4938812c (patch) | |
tree | af76d4247f35cdd77d3defdfadc144bfb79beb27 /Source | |
parent | e173979e6dd7b343a7a6d4a5b694b938de0956c6 (diff) | |
download | sequelpro-89719b64e4f6fa793c4ed7d4d1a63f8b4938812c.tar.gz sequelpro-89719b64e4f6fa793c4ed7d4d1a63f8b4938812c.tar.bz2 sequelpro-89719b64e4f6fa793c4ed7d4d1a63f8b4938812c.zip |
Various improvements to default connection favorites handling, including:
- Updating the default favorite popup button to reflect the sorted order of the favorites tableview.
- A new icon indicating the default favorite in the favorites tableview.
- A new 'Make Default' menu item in the favorites tableview context menu.
(Outstanding issue: Incorrect default favorite being selected upon launch because the sorting of favorites on the connection screen and preferences are independent of each other).
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionController.h | 13 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 85 | ||||
-rw-r--r-- | Source/SPPreferenceController.h | 1 | ||||
-rw-r--r-- | Source/SPPreferenceController.m | 147 |
4 files changed, 141 insertions, 105 deletions
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h index aa45b74d..6d1f23ed 100644 --- a/Source/SPConnectionController.h +++ b/Source/SPConnectionController.h @@ -46,6 +46,12 @@ @end +@interface SPFlippedView : NSView + +- (BOOL)isFlipped; + +@end + @interface SPConnectionController : NSObject { id delegate; @@ -111,7 +117,6 @@ BOOL reverseFavoritesSort; SPFavoritesSortItem previousSortItem, currentSortItem; - } @property (readwrite, assign) id delegate; @@ -164,9 +169,3 @@ - (void)splitViewDidResizeSubviews:(NSNotification *)aNotification; @end - -@interface SPFlippedView: NSView - -- (BOOL)isFlipped; - -@end diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index ad2bdf62..ee3bb724 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -58,6 +58,8 @@ @synthesize connectionSSHKeychainItemName; @synthesize connectionSSHKeychainItemAccount; +#pragma mark - + /** * Initialise the connection controller, linking it to the * parent document and setting up the parent window. @@ -682,6 +684,9 @@ } +/** + * + */ - (void)reverseSortFavorites:(id)sender { reverseFavoritesSort = (![sender state]); @@ -694,42 +699,6 @@ [sender setState:reverseFavoritesSort]; } -- (void)_sortFavorites -{ - NSString *sortKey = @""; - - switch (currentSortItem) - { - case SPFavoritesSortNameItem: - sortKey = @"name"; - break; - case SPFavoritesSortHostItem: - sortKey = @"host"; - break; - case SPFavoritesSortTypeItem: - sortKey = @"type"; - break; - default: - sortKey = @"name"; - break; - } - - NSSortDescriptor *sortDescriptor = nil; - - if (currentSortItem == SPFavoritesSortTypeItem) { - sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:sortKey ascending:(!reverseFavoritesSort)] autorelease]; - } - else { - sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:sortKey ascending:(!reverseFavoritesSort) selector:@selector(caseInsensitiveCompare:)] autorelease]; - } - NSDictionary *first = [[favorites objectAtIndex:0] retain]; - [favorites removeObjectAtIndex:0]; - [favorites sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; - [favorites insertObject:first atIndex:0]; - [favoritesTable reloadData]; - [first release]; - -} /** * Updates the local favorites array from the user defaults */ @@ -1084,6 +1053,7 @@ #pragma mark - #pragma mark Menu Validation + -(BOOL)validateMenuItem:(NSMenuItem *)menuItem { SEL action = [menuItem action]; @@ -1103,6 +1073,49 @@ return YES; } + +#pragma mark - +#pragma mark Private API + +- (void)_sortFavorites +{ + NSString *sortKey = @""; + + switch (currentSortItem) + { + case SPFavoritesSortNameItem: + sortKey = @"name"; + break; + case SPFavoritesSortHostItem: + sortKey = @"host"; + break; + case SPFavoritesSortTypeItem: + sortKey = @"type"; + break; + default: + sortKey = @"name"; + break; + } + + NSSortDescriptor *sortDescriptor = nil; + + if (currentSortItem == SPFavoritesSortTypeItem) { + sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:sortKey ascending:(!reverseFavoritesSort)] autorelease]; + } + else { + sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:sortKey ascending:(!reverseFavoritesSort) selector:@selector(caseInsensitiveCompare:)] autorelease]; + } + + NSDictionary *first = [[favorites objectAtIndex:0] retain]; + + [favorites removeObjectAtIndex:0]; + [favorites sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; + [favorites insertObject:first atIndex:0]; + [favoritesTable reloadData]; + + [first release]; +} + @end #pragma mark - diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h index 6d72fc1d..c2b4b18a 100644 --- a/Source/SPPreferenceController.h +++ b/Source/SPPreferenceController.h @@ -100,6 +100,7 @@ - (IBAction)setDefaultColors:(id)sender; - (IBAction)sortFavorites:(id)sender; - (IBAction)reverseFavoritesSortOrder:(id)sender; +- (IBAction)makeSelectedFavoriteDefault:(id)sender; // Toolbar item IBAction methods - (IBAction)displayGeneralPreferences:(id)sender; diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 518952f5..66dc2597 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -484,6 +484,19 @@ [sender setState:reverseFavoritesSort]; } +/** + * Makes the selected favorite the default. + */ +- (IBAction)makeSelectedFavoriteDefault:(id)sender +{ + // Minus 2 from index to account for the "Last Used" and separator items + [prefs setInteger:[favoritesTableView selectedRow] forKey:SPDefaultFavorite]; + + [favoritesTableView reloadData]; + + [self updateDefaultFavoritePopup]; +} + #pragma mark - #pragma mark Toolbar item IBAction methods @@ -597,9 +610,14 @@ // ------------------------------------------------------------------------------- // tableView:objectValueForTableColumn:row: // ------------------------------------------------------------------------------- -- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex { - return [[[favoritesController arrangedObjects] objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]]; + if ([[tableColumn identifier] isEqualToString:@"default"] && (rowIndex == [prefs integerForKey:SPDefaultFavorite])) { + return [NSImage imageNamed:@"blue-tick"]; + } + else { + return [[[favoritesController arrangedObjects] objectAtIndex:rowIndex] objectForKey:[tableColumn identifier]]; + } } #pragma mark - @@ -695,9 +713,11 @@ { if ([cell isKindOfClass:[SPFavoriteTextFieldCell class]]) { [cell setFavoriteName:[[[favoritesController arrangedObjects] objectAtIndex:index] objectForKey:@"name"]]; + if ([[[[favoritesController arrangedObjects] objectAtIndex:index] objectForKey:@"type"] integerValue] == SPSocketConnection) { [cell setFavoriteHost:@"localhost"]; - } else { + } + else { [cell setFavoriteHost:[[[favoritesController arrangedObjects] objectAtIndex:index] objectForKey:@"host"]]; } } @@ -1046,37 +1066,37 @@ if ([contextInfo isEqualToString:@"removeFavorite"]) { if (returnCode == NSAlertDefaultReturn) { - // Get selected favorite's details - NSString *name = [favoritesController valueForKeyPath:@"selection.name"]; - NSString *user = [favoritesController valueForKeyPath:@"selection.user"]; - NSString *host = [favoritesController valueForKeyPath:@"selection.host"]; - NSString *database = [favoritesController valueForKeyPath:@"selection.database"]; - NSString *sshUser = [favoritesController valueForKeyPath:@"selection.sshUser"]; - NSString *sshHost = [favoritesController valueForKeyPath:@"selection.sshHost"]; - NSString *favoriteid = [favoritesController valueForKeyPath:@"selection.id"]; - NSInteger type = [[favoritesController valueForKeyPath:@"selection.type"] integerValue]; - - // Remove passwords from the Keychain - [keychain deletePasswordForName:[keychain nameForFavoriteName:name id:favoriteid] - account:[keychain accountForUser:user host:((type == SPSocketConnection)?@"localhost":host) database:database]]; - [keychain deletePasswordForName:[keychain nameForSSHForFavoriteName:name id:favoriteid] - account:[keychain accountForSSHUser:sshUser sshHost:sshHost]]; - - // Reset last used favorite - if ([favoritesTableView selectedRow] == [prefs integerForKey:SPLastFavoriteIndex]) { - [prefs setInteger:0 forKey:SPLastFavoriteIndex]; - } - - // Reset default favorite - if ([favoritesTableView selectedRow] == [prefs integerForKey:SPDefaultFavorite]) { - [prefs setInteger:[prefs integerForKey:SPLastFavoriteIndex] forKey:SPDefaultFavorite]; - } + // Get selected favorite's details + NSString *name = [favoritesController valueForKeyPath:@"selection.name"]; + NSString *user = [favoritesController valueForKeyPath:@"selection.user"]; + NSString *host = [favoritesController valueForKeyPath:@"selection.host"]; + NSString *database = [favoritesController valueForKeyPath:@"selection.database"]; + NSString *sshUser = [favoritesController valueForKeyPath:@"selection.sshUser"]; + NSString *sshHost = [favoritesController valueForKeyPath:@"selection.sshHost"]; + NSString *favoriteid = [favoritesController valueForKeyPath:@"selection.id"]; + NSInteger type = [[favoritesController valueForKeyPath:@"selection.type"] integerValue]; + + // Remove passwords from the Keychain + [keychain deletePasswordForName:[keychain nameForFavoriteName:name id:favoriteid] + account:[keychain accountForUser:user host:((type == SPSocketConnection)?@"localhost":host) database:database]]; + [keychain deletePasswordForName:[keychain nameForSSHForFavoriteName:name id:favoriteid] + account:[keychain accountForSSHUser:sshUser sshHost:sshHost]]; + + // Reset last used favorite + if ([favoritesTableView selectedRow] == [prefs integerForKey:SPLastFavoriteIndex]) { + [prefs setInteger:0 forKey:SPLastFavoriteIndex]; + } + + // Reset default favorite + if ([favoritesTableView selectedRow] == [prefs integerForKey:SPDefaultFavorite]) { + [prefs setInteger:[prefs integerForKey:SPLastFavoriteIndex] forKey:SPDefaultFavorite]; + } - [favoritesController removeObjectAtArrangedObjectIndex:[favoritesTableView selectedRow]]; - - [favoritesTableView reloadData]; - - [self updateDefaultFavoritePopup]; + [favoritesController removeObjectAtArrangedObjectIndex:[favoritesTableView selectedRow]]; + + [favoritesTableView reloadData]; + + [self updateDefaultFavoritePopup]; } } } @@ -1105,7 +1125,7 @@ // // Build the default favorite popup button // ------------------------------------------------------------------------------- -- (void)updateDefaultFavoritePopup; +- (void)updateDefaultFavoritePopup { [defaultFavoritePopup removeAllItems]; @@ -1113,27 +1133,29 @@ [defaultFavoritePopup addItemWithTitle:@"Last Used"]; [[defaultFavoritePopup menu] addItem:[NSMenuItem separatorItem]]; - NSInteger i; - for(i=0; i<[[[favoritesController arrangedObjects] valueForKeyPath:@"name"] count]; i++ ){ - NSMenuItem *favoritePrefMenuItem = [[NSMenuItem alloc] initWithTitle:[[[favoritesController arrangedObjects] valueForKeyPath:@"name"] objectAtIndex:i] - action:NULL - keyEquivalent:@"" ]; - [[defaultFavoritePopup menu] addItem:favoritePrefMenuItem]; - [favoritePrefMenuItem release]; + // Add all favorites to the menu + for (NSString *favorite in [[favoritesController arrangedObjects] valueForKeyPath:@"name"]) + { + NSMenuItem *favoriteMenuItem = [[NSMenuItem alloc] initWithTitle:favorite action:NULL keyEquivalent:@""]; + + [[defaultFavoritePopup menu] addItem:favoriteMenuItem]; + + [favoriteMenuItem release]; } // Add item to switch to edit favorites pane [[defaultFavoritePopup menu] addItem:[NSMenuItem separatorItem]]; - [defaultFavoritePopup addItemWithTitle:NSLocalizedString(@"Edit Favorites…", @"edit favorites menu item")]; - [[[defaultFavoritePopup menu] itemWithTitle:NSLocalizedString(@"Edit Favorites…", @"edit favorites menu item")] setAction:@selector(displayFavoritePreferences:)]; - [[[defaultFavoritePopup menu] itemWithTitle:NSLocalizedString(@"Edit Favorites…", @"edit favorites menu item")] setTarget:self]; + + NSMenuItem *editMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Edit Favorites…", @"edit favorites menu item") action:@selector(displayFavoritePreferences:) keyEquivalent:@""]; + + [editMenuItem setTarget:self]; + + [[defaultFavoritePopup menu] addItem:editMenuItem]; + + [editMenuItem release]; // Select the default favorite from prefs - if (![prefs boolForKey:SPSelectLastFavoriteUsed]) { - [defaultFavoritePopup selectItemAtIndex:[prefs integerForKey:SPDefaultFavorite] + 2]; - } else { - [defaultFavoritePopup selectItemAtIndex:0]; - } + [defaultFavoritePopup selectItemAtIndex:(![prefs boolForKey:SPSelectLastFavoriteUsed]) ? ([prefs integerForKey:SPDefaultFavorite] + 2) : 0]; } // ------------------------------------------------------------------------------- @@ -1221,6 +1243,10 @@ return ([favoritesTableView numberOfSelectedRows] > 0); } + if (action == @selector(makeSelectedFavoriteDefault:)) { + return ([favoritesTableView numberOfSelectedRows] == 1); + } + if ((action == @selector(sortFavorites:)) || (action == @selector(reverseFavoritesSortOrder:))) { // Loop all the items in the sort by menu only checking the currently selected one @@ -1254,11 +1280,8 @@ [super dealloc]; } -@end - #pragma mark - - -@implementation SPPreferenceController (PrivateAPI) +#pragma mark Private API // ------------------------------------------------------------------------------- // _setupToolbar @@ -1347,7 +1370,7 @@ * Sorts the connection favorites based on the selected criteria. */ - (void)_sortFavorites -{ +{ NSString *sortKey = @""; switch (currentSortItem) @@ -1378,16 +1401,16 @@ [favoritesController setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]]; [favoritesTableView reloadData]; + + [self updateDefaultFavoritePopup]; } -// ------------------------------------------------------------------------------- -// _resizeWindowForContentView: -// -// Resizes the window to the size of the supplied view. -// ------------------------------------------------------------------------------- +/** + * Resizes the window to the size of the supplied view. + */ - (void)_resizeWindowForContentView:(NSView *)view { - // remove all current views + // Remove all current views NSEnumerator *en = [[[preferencesWindow contentView] subviews] objectEnumerator]; NSView *subview; @@ -1396,10 +1419,10 @@ [subview removeFromSuperview]; } - // resize window + // Resize window [preferencesWindow resizeForContentView:view titleBarVisible:YES]; - // add view + // Add view [[preferencesWindow contentView] addSubview:view]; [view setFrameOrigin:NSMakePoint(0, 0)]; } |