aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFavoritesController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPFavoritesController.m')
-rw-r--r--Source/SPFavoritesController.m40
1 files changed, 34 insertions, 6 deletions
diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m
index ce6e5427..625b46cc 100644
--- a/Source/SPFavoritesController.m
+++ b/Source/SPFavoritesController.m
@@ -45,7 +45,7 @@ static SPFavoritesController *sharedFavoritesController = nil;
- (void)_addNode:(SPTreeNode *)node asChildOfNode:(SPTreeNode *)parent;
- (SPTreeNode *)_constructBranchForNodeData:(NSDictionary *)nodeData;
-
+- (SPTreeNode *)_addFavoriteNodeWithData:(NSMutableDictionary *)data asChildOfNode:(SPTreeNode *)parent;
@end
@implementation SPFavoritesController
@@ -164,6 +164,7 @@ static SPFavoritesController *sharedFavoritesController = nil;
[self _addNode:node asChildOfNode:parent];
+ [self saveFavorites];
[[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self];
return node;
@@ -179,11 +180,40 @@ static SPFavoritesController *sharedFavoritesController = nil;
*/
- (SPTreeNode *)addFavoriteNodeWithData:(NSMutableDictionary *)data asChildOfNode:(SPTreeNode *)parent
{
- SPTreeNode *node = [SPTreeNode treeNodeWithRepresentedObject:[SPFavoriteNode favoriteNodeWithDictionary:data]];
-
+ SPTreeNode *node = [self _addFavoriteNodeWithData:data asChildOfNode:parent];
+
+ [self saveFavorites];
+ [[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self];
+
+ return node;
+}
+
+/**
+ * Inner recursive variant of the method above
+ */
+- (SPTreeNode *)_addFavoriteNodeWithData:(NSMutableDictionary *)data asChildOfNode:(SPTreeNode *)parent
+{
+ id object;
+ NSArray *childs = nil;
+ //if it has "Children" it must be a group node, otherwise assume favorite node
+ if ([data objectForKey:SPFavoriteChildrenKey]) {
+ object = [SPGroupNode groupNodeWithDictionary:data];
+ childs = [data objectForKey:SPFavoriteChildrenKey];
+ }
+ else {
+ object = [SPFavoriteNode favoriteNodeWithDictionary:data];
+ }
+
+ SPTreeNode *node = [SPTreeNode treeNodeWithRepresentedObject:object];
+
[self _addNode:node asChildOfNode:parent];
- [[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self];
+ //also add the children
+ if(childs) {
+ for (NSMutableDictionary *childData in childs) {
+ [self _addFavoriteNodeWithData:childData asChildOfNode:node];
+ }
+ }
return node;
}
@@ -460,8 +490,6 @@ static SPFavoritesController *sharedFavoritesController = nil;
else {
[[[[favoritesTree mutableChildNodes] objectAtIndex:0] mutableChildNodes] addObject:node];
}
-
- [self saveFavorites];
}
#pragma mark -