forked from JanX2/CoolOutliner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKBBaseNode.h
executable file
·98 lines (71 loc) · 3.63 KB
/
KBBaseNode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// KBBaseNode.h
// ------------
//
// Keith Blount 2005
//
// Multi-purpose node object for use with NSOutlineView and compatible with NSTreeController. Can be used as-is or
// subclassed to add custom model attributes. Provides convenience methods for checking validitity of drag-and-drop
// and cleaning up afterwards, and makes subclassing easy by providing convenience methods that make overriding
// coding and copying methods in subclasses unnecessary.
//
// Subclasses that add new variables *must* override -mutableKeys, adding the keys for the added variables.
// If any of the variables are not objects (eg. ints, bools etc), the subclass must also override -setNilValueForKey:.
// By overriding these two methods, there is no need for subclasses to override -initWithCoder:, -encodeWithCoder: or
// -copyWithZone: - all of this will be handled by the superclass using the keys returned by -mutableKeys.
//
#import <Cocoa/Cocoa.h>
@interface KBBaseNode : NSObject <NSCoding, NSCopying>
{
NSString *title;
NSMutableDictionary *properties;
NSMutableArray *children;
BOOL isLeaf;
}
/* inits a leaf node (-init initialises a group node by default) */
- (id)initLeaf;
/*************************** Accessors ***************************/
- (void)setTitle:(NSString *)newTitle;
- (NSString *)title;
- (void)setProperties:(NSDictionary *)newProperties;
- (NSMutableDictionary *)properties;
- (void)setChildren:(NSArray *)newChildren;
- (NSMutableArray *)children;
- (void)setLeaf:(BOOL)flag;
- (BOOL)isLeaf;
/*************************** Utility Methods ***************************/
/* For sorting */
- (NSComparisonResult)compare:(KBBaseNode *)aNode;
/* Returns the count of child nodes */
- (NSUInteger)countOfChildren;
/*************************** Archiving/Copying Support ***************************/
/* Subclasses should override this method to maintain support for archiving and copying */
- (NSArray *)mutableKeys;
/* Methods for converting the node to a simple dictionary, for XML support (note that all
instance variables must be property lists type for the dictionary to be written out as XML, though) */
- (NSDictionary *)dictionaryRepresentation;
- (id)initWithDictionary:(NSDictionary *)dictionary;
/*************************** Drag'n'Drop Convenience Methods ***************************/
/* Finds the parent of the receiver from the nodes contained in the array */
- (id)parentFromArray:(NSArray *)array;
/* Searches children and children of all sub-nodes to remove given object */
- (void)removeObjectFromChildren:(id)obj;
/* Generates an array of all descendants */
- (NSArray *)descendants;
/* Generates an array of all leafs in children and children of all sub-nodes */
- (NSArray *)allChildLeafs;
/* Returns only the children that are group nodes (used by browser for showing only groups, for instance) */
- (NSArray *)groupChildren;
/* Returns YES if self is contained anywhere inside the children or children of sub-nodes of the nodes contained
inside the given array */
- (BOOL)isDescendantOfOrOneOfNodes:(NSArray*)nodes;
/* Returns YES if self is a descendent of any of the nodes in the given array */
- (BOOL)isDescendantOfNodes:(NSArray*)nodes;
/* Returns the index path of within the given array - useful for dragging and dropping */
- (NSIndexPath *)indexPathInArray:(NSArray *)array;
/*************************** Node Modification Convenience Methods ***************************/
- (void)insertObject:(id)object inChildrenAtIndex:(NSUInteger)index;
- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index;
- (id)objectInChildrenAtIndex:(NSUInteger)index;
- (void)replaceObjectInChildrenAtIndex:(NSUInteger)index withObject:(id)object;
@end