aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPConnectionController.m27
-rw-r--r--Source/SPConnectionControllerDelegate.m4
-rw-r--r--Source/SPTreeNode.h8
-rw-r--r--Source/SPTreeNode.m74
4 files changed, 63 insertions, 50 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index f48cdc06..89dc6405 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -188,10 +188,6 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist";
[self addObserver:self forKeyPath:SPFavoriteSSLCertificateFileLocationKey options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:NULL];
[self addObserver:self forKeyPath:SPFavoriteSSLCACertFileLocationEnabledKey options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:NULL];
[self addObserver:self forKeyPath:SPFavoriteSSLCACertFileLocationKey options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:NULL];
-
- // Sort the favourites to match prefs and select the appropriate row - if a valid sort option is selected
- // TODO: Fix me, sorting currently does not work in the new outline view
- //if (currentSortItem > -1) [self _sortFavorites];
SPTreeNode *favorite = [self _favoriteNodeForFavoriteID:[prefs integerForKey:([prefs boolForKey:SPSelectLastFavoriteUsed]) ? SPLastFavoriteID : SPDefaultFavorite]];
@@ -1180,18 +1176,18 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist";
sortKey = SPFavoriteTypeKey;
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];
+
+ // First sort the contents of all groups
+ for (SPTreeNode *node in [[[favoritesRoot childNodes] objectAtIndex:0] groupChildren])
+ {
+ [[node mutableChildNodes] sortUsingSelector:@selector(compare:)];
}
-
- // TODO: Perform actual sorting here
+ // Secondly sort the root's leaf nodes
+ [[[[favoritesRoot childNodes] objectAtIndex:0] childLeafs] sortUsingSelector:@selector(compare:)];
+
+ [favoritesController saveFavorites];
+
[self _reloadFavoritesViewData];
}
@@ -1218,8 +1214,7 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist";
}
/**
- * Convenience method for rebuilding the connection favorites tree, reloading the outline view, expanding the
- * items and scrolling to the selected item.
+ * Convenience method for reloading the outline view, expanding the root item and scrolling to the selected item.
*/
- (void)_reloadFavoritesViewData
{
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m
index 922d2405..6ad83963 100644
--- a/Source/SPConnectionControllerDelegate.m
+++ b/Source/SPConnectionControllerDelegate.m
@@ -227,7 +227,7 @@
SPTreeNode *node = (item) ? item : [[[[favoritesRoot childNodes] objectAtIndex:0] childNodes] objectAtIndex:0];
- // TODO: Fix me, disable automatic sorting
+ // TODO: Fix me
// Disable all automatic sorting
//currentSortItem = -1;
@@ -479,7 +479,7 @@
if ((action == @selector(sortFavorites:)) || (action == @selector(reverseSortFavorites:))) {
- // TODO: Fix me, disabled because of new outline view
+ // TODO: Fix me
return NO;
// Loop all the items in the sort by menu only checking the currently selected one
diff --git a/Source/SPTreeNode.h b/Source/SPTreeNode.h
index f93157ea..62682af8 100644
--- a/Source/SPTreeNode.h
+++ b/Source/SPTreeNode.h
@@ -42,14 +42,14 @@
- (void)removeObjectFromChildren:(id)object;
-- (NSArray *)descendants;
-- (NSArray *)allChildLeafs;
-- (NSArray *)groupChildren;
+- (NSMutableArray *)descendants;
+- (NSMutableArray *)childLeafs;
+- (NSMutableArray *)allChildLeafs;
+- (NSMutableArray *)groupChildren;
- (SPTreeNode *)parentFromArray:(NSArray *)array;
- (BOOL)isDescendantOfOrOneOfNodes:(NSArray *)nodes;
-- (BOOL)isDescendantOfNodes:(NSArray *)nodes;
- (NSDictionary *)dictionaryRepresentation;
diff --git a/Source/SPTreeNode.m b/Source/SPTreeNode.m
index 507939c4..79217a9f 100644
--- a/Source/SPTreeNode.m
+++ b/Source/SPTreeNode.m
@@ -77,7 +77,7 @@
*
* @return The array of decendant nodes.
*/
-- (NSArray *)descendants
+- (NSMutableArray *)descendants
{
NSMutableArray *descendants = [NSMutableArray array];
@@ -94,11 +94,31 @@
}
/**
- * Generates an array of all leafs in children and children of all sub-nodes.
+ * Generates an array of this node's child leafs nodes.
*
* @return The array of child nodes.
*/
-- (NSArray *)allChildLeafs
+- (NSMutableArray *)childLeafs
+{
+ NSMutableArray *childLeafs = [NSMutableArray array];
+
+ for (SPTreeNode *node in [self childNodes])
+ {
+ if ([node isLeaf]) {
+ [childLeafs addObject:node];
+ }
+ }
+
+ return childLeafs;
+}
+
+/**
+ * Generates an array of all leafs in children and children of all sub-nodes (effectively all leaf nodes below
+ * this node.
+ *
+ * @return The array of child nodes.
+ */
+- (NSMutableArray *)allChildLeafs
{
NSMutableArray *childLeafs = [NSMutableArray array];
@@ -120,7 +140,7 @@
*
* @return The array of child group nodes.
*/
-- (NSArray *)groupChildren
+- (NSMutableArray *)groupChildren
{
NSMutableArray *groupChildren = [NSMutableArray array];
@@ -171,9 +191,9 @@
* Returns YES if self is contained anywhere inside the children or children of
* sub-nodes of the nodes contained inside the supplied array.
*
- * @param nodes
+ * @param nodes The array of nodes to search
*
- * @return
+ * @return A BOOL indicating whether or not it's a descendent
*/
- (BOOL)isDescendantOfOrOneOfNodes:(NSArray *)nodes
{
@@ -193,28 +213,6 @@
}
/**
- * Returns YES if any node in the array passed in is an ancestor of ours.
- *
- * @param nodes
- *
- * @return
- */
-- (BOOL)isDescendantOfNodes:(NSArray *)nodes
-{
- for (SPTreeNode *node in nodes)
- {
- // Check all the sub-nodes
- if (![node isLeaf]) {
- if ([self isDescendantOfOrOneOfNodes:[node childNodes]]) {
- return YES;
- }
- }
- }
-
- return NO;
-}
-
-/**
* Constructs a dictionary representation of the favorite.
*
* @return The dictionary representation.
@@ -249,4 +247,24 @@
return dictionary;
}
+#pragma mark -
+#pragma mark Other
+
+/*- (NSComparisonResult)compare:(SPTreeNode *)node
+{
+ id selfObject = [self representedObject];
+ id nodeObject = [node representedObject];
+
+ if ([selfObject isKindOfClass:[SPFavoriteNode class]] && [nodeObject isKindOfClass:[SPFavoriteNode class]]) {
+
+ return [[[selfObject nodeFavorite] objectForKey:SPFavoriteNameKey] localizedCaseInsensitiveCompare:[[nodeObject nodeFavorite] objectForKey:SPFavoriteNameKey]];
+ }
+ else if ([selfObject isKindOfClass:[SPGroupNode class]] && [nodeObject isKindOfClass:[SPGroupNode class]]) {
+
+ return [[selfObject nodeName] localizedCaseInsensitiveCompare:[nodeObject nodeName]];
+ }
+
+ return NSOrderedSame;
+}*/
+
@end