From 876dde21d97897ad4ee98aa0d6b11898282982ce Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 13 Dec 2014 18:02:01 +0100 Subject: Change [NSArray arrayWithObject:] to @[] literal Note: [NSArray arrayWithObjects:...,nil] is left unchanged as that could possibly cause a NPE if converted to @[] --- Source/SPFavoritesController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/SPFavoritesController.m') diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m index d5564428..07d74ee0 100644 --- a/Source/SPFavoritesController.m +++ b/Source/SPFavoritesController.m @@ -237,7 +237,7 @@ static SPFavoritesController *sharedFavoritesController = nil; favoritesData = [[NSMutableDictionary alloc] initWithContentsOfFile:favoritesFile]; } else { - NSMutableDictionary *newFavorites = [NSMutableDictionary dictionaryWithObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Favorites", @"favorites label"), SPFavoritesGroupNameKey, [NSArray array], SPFavoriteChildrenKey, nil] forKey:SPFavoritesRootKey]; + NSMutableDictionary *newFavorites = [NSMutableDictionary dictionaryWithObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Favorites", @"favorites label"), SPFavoritesGroupNameKey, @[], SPFavoriteChildrenKey, nil] forKey:SPFavoritesRootKey]; error = nil; NSString *errorString = nil; -- cgit v1.2.3 From 3b251b8e3d4dc9a694ef76562b388ab07da54785 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 13 Dec 2014 19:48:41 +0100 Subject: Replace some NSDictionaries with literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [NSDictionary dictionary] → @{} * [NSDictionary dictionaryWithObject:forKey:] can safely be replaced. object==nil would have already thrown a NPE in the past. * Also replaced some (hopefully safe) NSArray initializers (ie. their objects should always exist). --- Source/SPFavoritesController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/SPFavoritesController.m') diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m index 07d74ee0..76f376e8 100644 --- a/Source/SPFavoritesController.m +++ b/Source/SPFavoritesController.m @@ -377,7 +377,7 @@ static SPFavoritesController *sharedFavoritesController = nil; // from the current favourites tree and convert it to a dictionary representation // to create the plist data. This is done before file changes as it can sometimes // be terminated during shutdown. - NSDictionary *dictionary = [NSDictionary dictionaryWithObject:data forKey:SPFavoritesRootKey]; + NSDictionary *dictionary = @{SPFavoritesRootKey : data}; NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary format:NSPropertyListXMLFormat_v1_0 -- cgit v1.2.3 From 2735e15bf5d4b3a976435ebb29ca9073de0e5071 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 4 Jan 2015 03:57:26 +0100 Subject: Formalize [x release], x = nil; convention Take this commit as a proposal to formalize our existing "[x release], x = nil;" convention by introducing a macro for it. Feel free to revert this commit if you see issues with the approch or implementation. --- Source/SPFavoritesController.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/SPFavoritesController.m') diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m index 76f376e8..ce6e5427 100644 --- a/Source/SPFavoritesController.m +++ b/Source/SPFavoritesController.m @@ -218,7 +218,7 @@ static SPFavoritesController *sharedFavoritesController = nil; NSError *error = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; - if (favoritesData) [favoritesData release], favoritesData = nil; + if (favoritesData) SPClear(favoritesData); NSString *dataPath = [fileManager applicationSupportDirectoryForSubDirectory:SPDataSupportFolder error:&error]; @@ -468,8 +468,8 @@ static SPFavoritesController *sharedFavoritesController = nil; - (void)dealloc { - if (favoritesTree) [favoritesTree release], favoritesTree = nil; - if (favoritesData) [favoritesData release], favoritesData = nil; + if (favoritesTree) SPClear(favoritesTree); + if (favoritesData) SPClear(favoritesData); pthread_mutex_destroy(&writeLock); pthread_mutex_destroy(&favoritesLock); -- cgit v1.2.3 From 11b8718ddfd44dc5786ac745f90fa390aaf57a06 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 11 May 2015 02:04:06 +0200 Subject: * 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 --- Source/SPFavoritesController.m | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'Source/SPFavoritesController.m') 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 - -- cgit v1.2.3