aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConstants.h10
-rw-r--r--Source/SPConstants.m2
-rw-r--r--Source/SPPreferenceController.h21
-rw-r--r--Source/SPPreferenceController.m95
-rw-r--r--Source/TableDocument.m6
5 files changed, 126 insertions, 8 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 54bce4d1..c849c3ba 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -93,6 +93,14 @@ typedef enum
SPSSHPasswordNone = 2
} SPSSHTunnelPasswordMode;
+// Sort by constants
+typedef enum
+{
+ SPFavoritesSortNameItem = 0,
+ SPFavoritesSortHostItem = 1,
+ SPFavoritesSortTypeItem = 2
+} SPFavoritesSortItem;
+
// Long running notification time for Growl messages
extern const CGFloat SPLongRunningNotificationTime;
@@ -200,6 +208,8 @@ extern NSString *SPTableInformationPanelCollapsed;
extern NSString *SPTableColumnWidths;
extern NSString *SPProcessListShowProcessID;
extern NSString *SPProcessListShowFullProcessList;
+extern NSString *SPFavoritesSortedBy;
+extern NSString *SPFavoritesSortedInReverse;
// Hidden Prefs
extern NSString *SPPrintWarningRowLimit;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index f0df9dac..8a2729e8 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -130,6 +130,8 @@ NSString *SPTableInformationPanelCollapsed = @"TableInformationPanelCollap
NSString *SPTableColumnWidths = @"tableColumnWidths";
NSString *SPProcessListShowProcessID = @"ProcessListShowProcessID";
NSString *SPProcessListShowFullProcessList = @"ProcessListShowFullProcessList";
+NSString *SPFavoritesSortedBy = @"FavoritesSortedBy";
+NSString *SPFavoritesSortedInReverse = @"FavoritesSortedInReverse";
// Hidden Prefs
NSString *SPPrintWarningRowLimit = @"PrintWarningRowLimit";
diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h
index e8e7a50d..029993d9 100644
--- a/Source/SPPreferenceController.h
+++ b/Source/SPPreferenceController.h
@@ -25,6 +25,8 @@
#import <Cocoa/Cocoa.h>
+#import "SPConstants.h"
+
@class SPKeychain;
@interface SPPreferenceController : NSWindowController
@@ -57,15 +59,13 @@
IBOutlet NSTextField *favoriteHostTextFieldSSH;
IBOutlet id tableCell;
-
- SPKeychain *keychain;
- NSDictionary *currentFavorite;
-
+
IBOutlet NSTextField *editorFontName;
IBOutlet NSTextField *globalResultTableFontName;
- NSInteger fontChangeTarget;
-
+ SPKeychain *keychain;
+ NSDictionary *currentFavorite;
+
NSToolbar *toolbar;
NSToolbarItem *generalItem;
@@ -80,7 +80,10 @@
NSUserDefaults *prefs;
BOOL favoriteNameFieldWasTouched;
- NSInteger favoriteType;
+ NSInteger favoriteType, fontChangeTarget;
+
+ BOOL reverseFavoritesSort;
+ SPFavoritesSortItem previousSortItem, currentSortItem;
}
- (void)applyRevisionChanges;
@@ -89,10 +92,12 @@
- (IBAction)addFavorite:(id)sender;
- (IBAction)removeFavorite:(id)sender;
- (IBAction)duplicateFavorite:(id)sender;
- - (IBAction)updateDefaultFavorite:(id)sender;
+- (IBAction)updateDefaultFavorite:(id)sender;
- (IBAction)showCustomQueryFontPanel:(id)sender;
- (IBAction)showGlobalResultTableFontPanel:(id)sender;
- (IBAction)setDefaultColors:(id)sender;
+- (IBAction)sortFavorites:(id)sender;
+- (IBAction)reverseFavoritesSortOrder:(id)sender;
// Toolbar item IBAction methods
- (IBAction)displayGeneralPreferences:(id)sender;
diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m
index 33cc9e81..760a48b8 100644
--- a/Source/SPPreferenceController.m
+++ b/Source/SPPreferenceController.m
@@ -34,6 +34,7 @@
@interface SPPreferenceController (PrivateAPI)
- (void)_setupToolbar;
+- (void)_sortFavorites;
- (void)_resizeWindowForContentView:(NSView *)view;
@end
@@ -57,6 +58,9 @@
favoriteNameFieldWasTouched = YES;
favoriteType = 0;
fontChangeTarget = 0;
+ reverseFavoritesSort = NO;
+
+ previousSortItem = SPFavoritesSortNameItem;
}
return self;
@@ -71,6 +75,10 @@
keychain = [[SPKeychain alloc] init];
+ // Set sort items
+ currentSortItem = [prefs integerForKey:SPFavoritesSortedBy];
+ reverseFavoritesSort = [prefs boolForKey:SPFavoritesSortedInReverse];
+
[tableCell setImage:[NSImage imageNamed:@"database"]];
// Replace column's NSTextFieldCell with custom SWProfileTextFieldCell
@@ -87,6 +95,8 @@
[self updateDefaultFavoritePopup];
[prefs synchronize];
+
+ [self _sortFavorites];
}
#pragma mark -
@@ -425,6 +435,38 @@
}
}
+/**
+ * Sorts the favorites table view based on the selected sort by item
+ */
+- (IBAction)sortFavorites:(id)sender
+{
+ previousSortItem = currentSortItem;
+ currentSortItem = [[sender menu] indexOfItem:sender];
+
+ [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy];
+
+ // Perform sorting
+ [self _sortFavorites];
+
+ [[[sender menu] itemAtIndex:previousSortItem] setState:NSOffState];
+ [[[sender menu] itemAtIndex:currentSortItem] setState:NSOnState];
+}
+
+/**
+ * Reverses the favorites table view sorting based on the selected criteria
+ */
+- (IBAction)reverseFavoritesSortOrder:(id)sender
+{
+ reverseFavoritesSort = (![sender state]);
+
+ [prefs setBool:reverseFavoritesSort forKey:SPFavoritesSortedInReverse];
+
+ // Perform re-sorting
+ [self _sortFavorites];
+
+ [sender setState:reverseFavoritesSort];
+}
+
#pragma mark -
#pragma mark Toolbar item IBAction methods
@@ -1113,6 +1155,22 @@
return ([favoritesTableView numberOfSelectedRows] > 0);
}
+ if ((action == @selector(sortFavorites:)) || (action == @selector(reverseFavoritesSortOrder:))) {
+
+ // Loop all the items in the sort by menu only checking the currently selected one
+ for (NSMenuItem *item in [[menuItem menu] itemArray])
+ {
+ [item setState:([[menuItem menu] indexOfItem:item] == currentSortItem) ? NSOnState : NSOffState];
+ }
+
+ // Check or uncheck the reverse sort item
+ if (action == @selector(reverseFavoritesSortOrder:)) {
+ [menuItem setState:reverseFavoritesSort];
+ }
+
+ return [[toolbar selectedItemIdentifier] isEqualToString:SPPreferenceToolbarFavorites];
+ }
+
return YES;
}
@@ -1219,6 +1277,43 @@
[self displayGeneralPreferences:nil];
}
+/**
+ * Sorts the connection favorites based on the selected criteria.
+ */
+- (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];
+ }
+
+ [favoritesController setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
+
+ [favoritesTableView reloadData];
+}
+
// -------------------------------------------------------------------------------
// _resizeWindowForContentView:
//
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index d73fa943..2a95c158 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -3148,6 +3148,12 @@
return ([[tablesListInstance valueForKeyPath:@"tables"] count] > 1);
}
+
+ // If validation for the sort favorites tableview items reaches here then the preferences window isn't
+ // open return NO.
+ if (([menuItem action] == @selector(sortFavorites:)) || ([menuItem action] == @selector(reverseFavoritesSortOrder:))) {
+ return NO;
+ }
return [super validateMenuItem:menuItem];
}