Re: NSOutlineView expanded state persistence
Re: NSOutlineView expanded state persistence
- Subject: Re: NSOutlineView expanded state persistence
- From: Michael McCracken <email@hidden>
- Date: Tue, 27 Jan 2004 16:14:59 -0800
Hi, Thanks, but I'm afraid this doesn't quite solve my problem, because
as it is now the data objects are completely replaced during refresh
(every time text changes, and immediately before calling reloadData)
So, saving the expanded state there seems hard.
It seems like I'd have to keep the old data around, and attempt to
compare the newly built one with the old one, then set the flags
appropriately in the new one, and finally tell the view to expand all
the ones that were set.
Surely it should be easier than that? I thought this was what the
persistentObjectForItem and itemForPersistentObject were for.
by the way, I discovered an error in my previous explanation. I did
implement persistentObjectForItem and itemForPersistentObject, to
simply return their arguments. That is probably important to explaining
why some of the state is preserved across updates and some isn't...
Does anyone have further insight?
I'm interpreting the lack of responses as either I'm using
NSOutlineView unconventionally or that it's just not well understood
what it does...
-mike
On Jan 27, 2004, at 2:34 AM, sunil kumar wrote:
>
Hi Michael,
>
To keep the OutlineView as it is even after u reloaded it ,i
>
think, u should keep a flag with in your objects so that when u reload
>
it u should check whether the object is in expanded state or not.
>
Hope u understood it.
>
>
Sunil Kumar G
>
Programmer
>
Effigent India Pvt.Ltd
>
> Hi, this question has caused me problems on and off for literally
>
> years, and it's time to get it straight in my head. I think I'm just
>
> being dumb, so bear with me...
>
>
>
> How do I refresh the data source for an NSOutlineView and keep the
>
> expanded/collapsed state?
>
>
>
> Here's one example: I have a routine that scans the text in an
>
> NSTextView on a timer, and builds a tree out of lines that start with
>
> \section or \subsection.
>
> At the moment, it's represented as nested NSMutableArrays. ( a detail,
>
> the 0th element in each array is a dictionary that has the text of the
>
> line to use as the objectvalue in the outline view)
>
>
>
> Every time the contents are re-scanned, the root array is emptied and
>
> the tree is rebuilt with new objects, which end up being equivalent to
>
> the old objects in the old tree up to the point just beyond an edit
>
> (because the text range is stored in the aforementioned dictionary).
>
>
>
> I don't implement persistentobjectforitem or its counterpart. (because
>
> I don't understand what they do and all online references to them just
>
> confused me)
>
>
>
> *What happens: on a refresh (triggered by an edit in the text view)
>
> the
>
> outline view stays the same except that the item nearest to the edit
>
> is
>
> collapsed, all the way up to its parent, and so is everything after
>
> it.
>
>
>
> *What I want: the outline should only change if the structure changed
>
> (ie, if the number of lines that had \section, etc changed or their
>
> titles changed) and I don't want anything to collapse without user
>
> intervention.
>
>
>
> Is the representation as arrays a bad idea?
>
>
>
> How does NSOutlineView handle changes in the datasource with respect
>
> to
>
> expanded/collapsed status?
>
>
>
> What does persistentobjectforitem actually do for me?
>
>
>
> Thanks,
>
> -mike
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.