diff options
author | Max <post@wickenrode.com> | 2015-05-11 02:04:06 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-05-11 02:04:06 +0200 |
commit | 11b8718ddfd44dc5786ac745f90fa390aaf57a06 (patch) | |
tree | 95689086e2ba13016034a0cab3382e5fc7e52084 /Source/SPFavoritesController.m | |
parent | 0f11cb74639d17a2fe512ed81d67ccf33601b605 (diff) | |
download | sequelpro-11b8718ddfd44dc5786ac745f90fa390aaf57a06.tar.gz sequelpro-11b8718ddfd44dc5786ac745f90fa390aaf57a06.tar.bz2 sequelpro-11b8718ddfd44dc5786ac745f90fa390aaf57a06.zip |
* Fully enable export of favorite groups
* Favorites can now be imported, sorted even if "Quick Connect" is selected
* Favorite files containing groups will now be imported correctly
* If a favorite and the group containing said favorite are exported, the favorite will no longer be included twice
Diffstat (limited to 'Source/SPFavoritesController.m')
-rw-r--r-- | Source/SPFavoritesController.m | 40 |
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 - |