Re: NSTreeController - please help, can't see the forest for the tree controller
Re: NSTreeController - please help, can't see the forest for the tree controller
- Subject: Re: NSTreeController - please help, can't see the forest for the tree controller
- From: Keith Blount <email@hidden>
- Date: Fri, 24 Jun 2005 10:54:23 -0700 (PDT)
Many thanks for the reply.
> tree controller is a subclass of array controller...
> so it should
> have arrangedObjects.. but it isnt anywhere near as
> simple to deal
> with this because there is no way of seeing which
> level you are at.
It was my understanding that NSTreeController is a
subclass of NSObjectController, not NSArrayController,
which means that it has -arrangedObjects because many
equivalent methods have been created, but not
-arrangeObjects: (which it would have it was a
subclass of NSArrayController). Your comment about it
being much more complicated is a good point - I had
been thinking that if arrangeObjects: existed, it
would be as easy to filter as NSArrayController, which
is of course nonsense because of the nested levels
(and perhaps why arrangeObjects: isn't implemented?).
Anyway, implementing addLeaf: turned out to be
trivial, despite the confusion it caused me at first.
Here is how I did it for anyone who is interested -
this is in my NSTreeController subclass and is for a
non-Core Data app (but could be converted easily):
// Note that my model has an isLeaf BOOL instance
variable that is bound
// the leaf key path of the tree controller. It also
has a contents NSMutableArray
// that is bound to the children key path.
//
- (void)addLeaf:(id)sender
{
if (![self selectionIndexPath])
return;
// Can't add nodes to leaves
if ([[[self selectedObjects] objectAtIndex:0]
isLeaf])
return;
KBNode *node = [[KBNode alloc] initLeaf];
// We want to add the node as the last child of the
currently selected object,
// to mirror addChild:'s behaviour:
NSIndexPath *indexPath = [self selectionIndexPath];
indexPath = [indexPath
indexPathByAddingIndex:[[[[self selectedObjects]
objectAtIndex:0] contents] count]];
[super insertObject:node
atArrangedObjectIndexPath:indexPath];
[node release];
}
I have still had no luck getting the datasource
methods -persistentObjectForItem: and
itemForPersistentObject: to work, though. The former
is easy enough - I can just use -observedObject on the
proxy object passed in as (id)item to get a unique ID
stored in my object and save that as the persistent
object.
-itemForPersistentObject: is still problematic,
though, as it expects an item of type
_NSControllerTreeNode. Scott Ahten's suggestion of
using itemAtRow: was promising, as in theory I could
have iterated through the proxy objects returned by
itemAtRow: until I found one with an -observedObject
that matched my persistent object information, and
returned that. However, it turns out that at the time
itemForPersistentObject: is called, -numberOfRows is 0
- meaning that this doesn't work. So either I have to
write routines to save all of this myself, which seems
an incredible waste of time when datasource methods
are there precisely for this purpose (and moreover I
have to figure out a way of storing the information -
storing it within my project file would be horrible),
or my outline view can't save its state... Or (I
hope!) maybe someone out there will yet have a
suggestion on how to get NSTreeController to work with
these methods...
Thanks again,
Keith
--- Scott Anguish <email@hidden> wrote:
> keith
>
> tree controller is a subclass of array controller...
> so it should
> have arrangedObjects.. but it isnt anywhere near as
> simple to deal
> with this because there is no way of seeing which
> level you are at.
>
>
> On Jun 21, 2005, at 1:35 PM, Keith Blount wrote:
>
> > Many thanks for the reply.
> >
> >
> >> you'll want to look
> >> more closely at the documentation. There is
> indeed
> >> an -
> >> arrangedObjects method for NSTreeController. It
> >> returns an array just
> >> like an NSArrayController.
> >>
> >
> > I have been through the documentation (what there
> is
> > of it - I've filed an enhancement request) and
> know
> > that there is an arrangedObjects method, but I was
> > talking about the -arrangeObjects: method - this
> > method is present in NSArrayController but not in
> > NSTreeController, and it is this method that
> mmalc's
> > filtering controller overrrides. I did try
> overriding
> > -arrangedObjects instead, but it turns out that
> > NSTreeController's -arrangedObjects method doesn't
> > return an NSArray directly, but an object of
> private
> > class _NSControllerTreeProxy, so it's impossible
> (?)
> > to alter. (This seems to be the trouble all the
> way
> > through with NSTreeController - any time you want
> to
> > access anything, you run into proxy objects of
> > undocumented private classes in a manner
> unprecedented
> > anywhere else.)
> >
> >
> >> Also, though probably not the best solution,
> you
> >> can always bind
> >> the NSTreeController's contentArray to another
> >> controller ...
> >>
> >
> > Thanks for the suggestion - could you please
> > elaborate? The content array is already set to an
> > NSMutableArray in MyDocument. But like I say, my
> main
> > problem is that I want to use the same array of
> node
> > objects in different ways in two different outline
> > views. The node object can have an isFolder ivar
> set
> > to YES or NO. If it is NO, it should not be
> allowed to
> > have children and should not be visible in the
> > folders-only outline view, only in the associated
> > table view. But ALL nodes, folder or not, should
> be
> > visible in another outline view... This is why a
> > filter for the folders-only outline view seemed
> > simplest, but maybe there is another way?
> >
> > Many thanks again for taking the time to reply -
> any
> > other suggestions would be greatly appreciated,
> > Keith
> >
> > --- SA Dev <email@hidden> wrote:
> >
> >
> >> Keith:
> >>
> >> First, the pun is good, really. ;-) Second,
> >> you'll want to look
> >> more closely at the documentation. There is
> indeed
> >> an -
> >> arrangedObjects method for NSTreeController. It
> >> returns an array just
> >> like an NSArrayController.
> >>
> >> Also, though probably not the best solution,
> you
> >> can always bind
> >> the NSTreeController's contentArray to another
> >> controller ...
> >>
> >>
> >>
> >> On Jun 21, 2005, at 12:34 PM, Keith Blount wrote:
> >>
> >>
> >>> Hello,
> >>>
> >>> I am beginning to think that NSTreeController is
> >>>
> >> only
> >>
> >>> half-finished, but in a last, desperate attempt
> to
> >>> find anyone who might know how to resolve some
> of
> >>>
> >> its
> >>
> >>> major issues, I hope no one minds me asking my
> >>> questions again here. (First, let me apologise
> >>>
> >> posting
> >>
> >>> a message three times yesterday - this wasn't an
> >>> intentional spam, just a [human] problem with my
> >>> e-mail.)
> >>>
> >>> 1) Is there ANY way to filter an
> NSTreeController?
> >>> Mmalc's Filtering Controller example shows how
> to
> >>>
> >> do
> >>
> >>> it for NSArrayController by overriding
> >>> -arrangeObjects:, but there is no equivalent
> >>>
> >> method in
> >>
> >>> NSTreeController.
> >>>
> >>> 2) Failing that, which would be the ideal
> solution
> >>>
> >> to
> >>
> >>> my problem (I think), this is what I want to do
> -
> >>>
> >> I
> >>
> >>> would be grateful to anybody who could tell me
> >>>
> >> where
> >>
> >>> to start: I have an NSTreeController that is
> >>>
> >> supposed
> >>
> >>> to show folders in an NSOutlineView, and an
> >>> NSArrayController that is supposed to show the
> >>> contents of these folders in an NSTableView,
> much
> >>>
> >> like
> >>
> >>> in Mail. The trouble is that in a separate view,
> I
> >>> want to set up an NSTreeController that will
> show
> >>>
> >> both
> >>
> >>> folders AND contents in a single NSOutlineView.
> >>>
> >> What
> >>
> >>> is the best way to set this up? Without
> filtering,
> >>>
> >> it
> >>
> >>> seems impossible...
> >>>
> >>> 3) I have asked this a few times, so I am pretty
> >>>
> >> sure
> >>
> >>> that no one knows the answer - in fact, I'm
> pretty
> >>> sure that NSTreeController screws this up so
> badly
> >>> that it's impossible - but... Is there *any* way
> >>>
> >> to
> >>
> >>> get NSOutlineView's
> >>> -outlineView:persistentObjectForItem: and
> >>> -outlineView:itemForPersistentObject: datasource
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden