aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPPreferenceController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPPreferenceController.m')
-rw-r--r--Source/SPPreferenceController.m147
1 files changed, 85 insertions, 62 deletions
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)];
}