/Sidebar/SidebarNode.m

http://github.com/bububa/MongoHub-Mac · Objective C · 91 lines · 62 code · 22 blank · 7 comment · 3 complexity · 9a03facb890c2307ebd79c68942a54ca MD5 · raw file

  1. //
  2. // SidebarNode.m
  3. // Sidebar
  4. //
  5. // Created by Matteo Bertozzi on 3/8/09.
  6. // Copyright 2009 Matteo Bertozzi. All rights reserved.
  7. //
  8. #import "SidebarNode.h"
  9. @implementation SidebarNode
  10. @synthesize actionTarget;
  11. @synthesize action;
  12. @synthesize badgeValue;
  13. @synthesize hasBadge;
  14. @synthesize parentKey;
  15. @synthesize nodeType;
  16. @synthesize nodeKey;
  17. @synthesize caption;
  18. @synthesize icon;
  19. @synthesize data;
  20. - (id)init {
  21. if ((self = [super init])) {
  22. children = [[NSMutableArray alloc] init];
  23. hasBadge = NO;
  24. }
  25. return self;
  26. }
  27. - (void)dealloc {
  28. [children release];
  29. [caption release];
  30. [icon release];
  31. [data release];
  32. [super dealloc];
  33. }
  34. - (void)setAction:(SEL)aSelector target:(id)target {
  35. actionTarget = target;
  36. action = aSelector;
  37. }
  38. - (BOOL)hasAction {
  39. return(action != NULL);
  40. }
  41. - (void)setBadgeValue:(NSInteger)value {
  42. hasBadge = YES;
  43. badgeValue = value;
  44. }
  45. - (void)unsetBadgeValue {
  46. hasBadge = NO;
  47. }
  48. - (void)addChild:(SidebarNode *)node {
  49. [children addObject:node];
  50. }
  51. - (void)insertChild:(SidebarNode *)node atIndex:(NSUInteger)index {
  52. [children insertObject:node atIndex:index];
  53. }
  54. - (void)removeChild:(SidebarNode *)node {
  55. [children removeObject:node];
  56. }
  57. - (NSInteger)indexOfChild:(SidebarNode *)node {
  58. return [children indexOfObject:node];
  59. }
  60. - (SidebarNode *)childAtIndex:(int)index {
  61. return([children objectAtIndex:index]);
  62. }
  63. - (NSUInteger)numberOfChildren {
  64. return([children count]);
  65. }
  66. - (BOOL)isDraggable {
  67. return(nodeType != kSidebarNodeTypeSection);
  68. }
  69. @end