diff options
author | ritsuka <[email protected]> | 2014-08-09 17:10:45 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2014-08-09 17:10:45 +0000 |
commit | 666e210efe202dc13273dd32de1b1901e194e4ce (patch) | |
tree | 95e3c1886f10552e023a517aee569866df806219 /macosx/HBTreeNode.m | |
parent | d4e3de96a998ba90f61d31045d5c725428cd030d (diff) |
MacGui: added the list of the presets at the bottom of the preset menu and a “New Folder” menu item. Removed the “delete built-in presets” item because it takes just two clicks to remove them manually.
Refactored part of HBPreset to a separate HBTreeNode class.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6278 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBTreeNode.m')
-rw-r--r-- | macosx/HBTreeNode.m | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/macosx/HBTreeNode.m b/macosx/HBTreeNode.m new file mode 100644 index 000000000..28be2c1fd --- /dev/null +++ b/macosx/HBTreeNode.m @@ -0,0 +1,95 @@ +/* HBTreeNode.m $ + + This file is part of the HandBrake source code. + Homepage: <http://handbrake.fr/>. + It may be used under the terms of the GNU General Public License. */ + +#import "HBTreeNode.h" + +@implementation HBTreeNode + +- (instancetype)init +{ + self = [super init]; + if (self) { + _children = [[NSMutableArray alloc] init]; + _isLeaf = YES; + } + return self; +} + +- (void)dealloc +{ + [_children release]; + [super dealloc]; +} + +- (NSUInteger)countOfChildren +{ + return self.children.count; +} + +- (id)objectInChildrenAtIndex:(NSUInteger)index +{ + return [self.children objectAtIndex:index]; +} + +- (void)insertObject:(id)presetObject inChildrenAtIndex:(NSUInteger)index +{ + [self.children insertObject:presetObject atIndex:index]; + [presetObject setDelegate:self.delegate]; + + [self.delegate nodeDidChange]; +} + +- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index +{ + [self.children removeObjectAtIndex:index]; + [self.delegate nodeDidChange]; +} + +#pragma mark - Enumeration + +- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSIndexPath *idx, BOOL *stop))block +{ + BOOL stop = NO; + NSMutableArray *queue = [[NSMutableArray alloc] init]; + NSMutableArray *indexesQueue = [[NSMutableArray alloc] init]; + + [queue addObject:self]; + [indexesQueue addObject:[[[NSIndexPath alloc] init] autorelease]]; + + HBTreeNode *node = nil; + while ((node = [queue lastObject]) != nil) + { + // Get the index path of the current object + NSIndexPath *indexPath = [indexesQueue lastObject]; + + // Call the block + block(node, indexPath, &stop); + + if (stop) + { + break; + } + + [indexesQueue removeLastObject]; + + for (NSInteger i = node.children.count - 1; i >= 0; i--) + { + [indexesQueue addObject:[indexPath indexPathByAddingIndex:i]]; + } + + [queue removeLastObject]; + + for (id childNode in [node.children reverseObjectEnumerator]) + { + [queue addObject:childNode]; + } + } + + [queue release]; + [indexesQueue release]; +} + +@end |