Re: Placing SimpleTreeData for NSOutline on pasteboard
Re: Placing SimpleTreeData for NSOutline on pasteboard
- Subject: Re: Placing SimpleTreeData for NSOutline on pasteboard
- From: Renaud Boisjoly <email@hidden>
- Date: Fri, 11 Apr 2003 11:28:23 -0400
I've decided to try to implement NSCoding for the Tree structure. I'm
having lots of fun. Here are my coding routines for the SimpleNodeData
and TreeNode as well as MyPage (my page data)
-(void)encodeWithCoder:(NSCoder *)coder {
NSLog(@"Encoding SimpleNodeData!");
[coder encodeObject:name];
[coder encodeValueOfObjCType:@encode(BOOL) at:&isLeaf];
[coder encodeValueOfObjCType:@encode(BOOL) at:&isExpandable];
[coder encodeObject:page]; //an object of a custom class
}
-(void)initWithCoder:(NSCoder *)coder {
NSLog(@"Decoding SimpleNodeData!");
self = [super init];
[self setName:[coder decodeObject]];
[coder decodeValueOfObjCType:@encode(BOOL) at:&isLeaf];
[coder decodeValueOfObjCType:@encode(BOOL) at:&isExpandable];
[self setPage:[coder decodeObject]];
return self;
}
-(void)initWithCoder:(NSCoder *)coder {
NSLog(@"Decoding TreeNode!");
self = [super init];
[self setNode
Data:[coder decodeObject]];
[self setNodeChildren:[coder decodeObject]];
[self setNodeParent:[coder decodeObject]];
return self;
}
-(void)encodeWithCoder:(NSCoder *)coder {
NSLog(@"Encoding TreeNode");
[coder encodeObject:nodeData]; //nodeData is of type
SimpleNodeData, so this calls the above encoding and decoding
[coder encodeObject:nodeChildren]; //an array of this same type of
node
[coder encodeObject:nodeParent]; //each node's parent
}
-(void)encodeWithCoder:(NSCoder *)coder {
NSLog(@"Encoding page");
[coder encodeObject:pageData];
}
- (id)initWithCoder:(NSCoder *)coder {
self = [super init]
[self setPage
Data:[coder decodeObject]];
NSLog(@"Decoding page");
return self;
}
When I try to Archive and dearchive my data, I get this in my Log:
2003-04-11 11:13:02.587 TestApp[3079] Encoding TreeNode
2003-04-11 11:13:02.588 TestApp[3079] Encoding SimpleNodeData!
2003-04-11 11:13:02.588 TestApp[3079] Encoding page
2003-04-11 11:13:02.588 TestApp[3079] Encoding TreeNode
2003-04-11 11:13:02.588 TestApp[3079] Encoding SimpleNodeData!
2003-04-11 11:13:02.588 TestApp[3079] Encoding TreeNode
2003-04-11 11:13:02.588 TestApp[3079] Encoding SimpleNodeData!
2003-04-11 11:13:02.589 TestApp[3079] Encoding page
2003-04-11 11:13:02.589 TestApp[3079] Encoding TreeNode
2003-04-11 11:13:02.589 TestApp[3079] Encoding SimpleNodeData!
2003-04-11 11:13:02.589 TestApp[3079] Decoding TreeNode!
2003-04-11 11:13:02.589 TestApp[3079] Decoding SimpleNodeData!
2003-04-11 11:13:02.590 TestApp[3079] Decoding page
2003-04-11 11:13:02.590 TestApp[3079] Decoding TreeNode!
2003-04-11 11:13:02.590 TestApp[3079] Decoding SimpleNodeData!
2003-04-11 11:13:02.591 TestApp[3079] *** -[NSPlaceholderMutableArray
initWithObjects:count:]: attempt to insert nil
Now, since my root object doesn't contain a page object per se, it is
NULL, and some elements may or may not contain "name" objects, would
this make a difference?
I've been reading through the documentation for the last three days,
I'm probably not grasping something because of lack of experience...
This is how I'm calling all this:
- (BOOL)outlineView:(NSOutlineView *)olv writeItems:(NSArray*)tempitems
toPasteboard:(NSPasteboard*)pboard {
draggedNodes = tempitems;
[pboard declareTypes:[NSArray arrayWithObjects:
DragDropSimplePboardType, nil] owner:self];
NSData *data = [NSArchiver archivedDataWithRootObject: tempitems];
[pboard setData: data forType:DragDropSimplePboardType];
NSLog(@"write items to pb: %@",tempitems); //for comparison with
what I'm reading back
NSLog(@"getting from pasteboard: %@",[NSUnarchiver
unarchiveObjectWith
Data:[pboard dataForType: DragDropSimplePboardType]]
);
Any clues?
Thanks for any help
Renaud
On Friday, Apr 11, 2003, at 01:00 America/Montreal,
email@hidden wrote:
Hello all!
I've been playing around with the TreeData and SimpleTree stuff from
Apple's DragNDropOutlineView example.
Boy, is it confusing! Well ok, I'm not a very high-level programmer,
but I find it confusing. There are four pieces in all this,
SimpleTreeNode which seems to be a subclass of TreeNode
SimpleNoteData which looks like a subclass of TreeNodeData
TreeNode and TreeNodeData
But for some reason, there is information stored in different places
which are unclear to me. I'm not clear on why they are paired in the
same files and why the file SimpleTreeNode.m contains SimplenoteData
first (or does it make a difference?
SimpleNodeData holds some data and TreeNode has others, so you cannot
just refer to some of the values in the child or parent, but also in
the node part.
Then you use these weird calls (SAFENODE(n) or NODE_DATA(n) to access
the values and all that. Not the simplest of naming schemes.
i read on this list that some people prefer to create their data
structures otherwise. Does any one know where I could read some good
stuff on doing this? any approaches which would make more sense?
The issue I have is that I can get all this to work within a single
document, but in order to support the Pasteboard between documents, I
need to archive all this using NSArchiver and NSUnarchiver, but that
too seems to be complicated because of this different structure.
has anyone built a simple tree structure for storing outline data which
is simpler to use and allows Archiving in a simpler manner? Or know of
another example which could help me understand all this?
What I need is to store RTFD data in each node and have the tools to
manage the outline drag and drop it in the same or a different
document.
Thanks for any pointers
Renaud
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.