Re: Sync NSOutlineView and NSTextView for outliner
Re: Sync NSOutlineView and NSTextView for outliner
- Subject: Re: Sync NSOutlineView and NSTextView for outliner
- From: Keith Blount <email@hidden>
- Date: Sun, 17 Jul 2005 10:19:17 -0700 (PDT)
Many thanks for your reply, Todd. I'm not sure if I
misunderstand you or if we are at cross-purposes.
Using the method you suggest, I would be able to
change what is in the text view depending on what is
selected in the outline view, but that is not quite
what I mean. I will try to explain more clearly:
Suppose the user creates an item entitled "SCENE 1" in
the outline view. The words "SCENE 1" should then also
appear in the text view. Now say the user creates an
item entitled "SCENE 2" in the outline view beneath
"SCENE 1". These words will also appear in the text
view, beneath where it says "SCENE 2", like this:
SCENE 1
SCENE 2
These are just the titles to text blocks. Now suppose
the user starts editing the text view so that it looks
like this:
SCENE 1
Here is some text that relates to scene 1.
SCENE 2
Something very exciting probably happens in scene 2...
Now the outline view should act as an alternative way
of shuffling these scenes around to just cutting and
pasting. So, say the user drags "SCENE 2" up above
"SCENE 1" in the outline view, now the text view will
look like this:
SCENE 2
Something very exciting probably happens in scene 2...
SCENE 1
Here is some text that relates to scene 1.
You may be right that it would be easier to compose
the text from the outline rather than vice versa,
although I don't see a way around using custom
attributes for this when working out what text belongs
to each outline item.
If the text view wasn't editable it should be fairly
straightforward. I could associate an attributed
string with each outline view object and, every time
an outline view item is moved, recompose everything in
the text view by going through the items in the outine
view and appending its string to the text view. But it
gets more complicated when the text view can be
edited, because every time its text changes, the text
associated with the outline view items has to be
updated too...
Many thanks for the help so far and any more
suggestions,
All the best,
Keith
P.S. OT: Avenir is turning into a fantastic piece of
software. The program I am working on is similar in
nature - aimed at writers - and when I started it a
year ago Avenir was little more than a table view and
a text view in two separate textured-window apps. If
Avenir then had looked and worked like it does now
(and 2.3 looks even better), I may never have started
work on my own app - but obviously having spent a year
on it, I am determined to finish it!
--- Todd Ransom <email@hidden> wrote:
> I have recently tackled the same problem and here is
> what I came up
> with.
>
> The items in your outline view are instances of some
> custom class.
> Add an instance variable of type NSTextStorage to
> your custom class
> along with appropriate accessors. Whenever the
> selection on your
> outline view changes, swap the text storage of the
> text view using
>
> [[textView layoutManager] replaceTextStorage:]
>
> I also looked at using the text itself as the main
> storage and tying
> it to the outline items via custom attributes. It
> seemed much easier
> to me to compose the text from properties of the
> outline items than
> to try and decompose the text into a bunch of
> outline items.
>
> Let me know if you need more detail.
>
> Todd Ransom
> Return Self Software
> http://returnself.com
>
>
>
> On Jul 17, 2005, at 4:48 AM, Keith Blount wrote:
>
> > Hello,
> >
> > I am hoping somebody might have some conceptual
> advice
> > on how to approach the following problem:
> >
> > As part of the app I'm working on, I would like to
> > include an outliner like the one in Mellel or like
> > Jer's Novel Writer. The set-up would be like this:
> >
> > There would be an outline view on the left and a
> text
> > view on the right. Whenever an item is added to
> the
> > outline view, a new text section is simultaneously
> > added to the text view. (This part is
> straightforward,
> > as I can just inset the text at the same time as
> > inserting the item in the outline view.)
> >
> > Thus, each item in the outline view should
> represent a
> > block of text in the text view. Whenever an item
> is
> > moved around (eg. through drag'n'drop) in the
> outline
> > view, it should also be moved around in the text
> view.
> > And vice versa - if the user cuts and pastes a
> section
> > to a different place in the text view, the outline
> > view should reflect that.
> >
> > At the moment I'm at a bit of a loss as to the
> best
> > way to approach this. I am thinking that whenever
> the
> > user adds an item to the outline view, I could add
> > some text with the same title as the item into the
> > text view, with a custom attribute set to that
> text
> > referencing the item in the outline view, but
> there
> > are still a lot of conceptual problems here - for
> > instance, tracking what level an item should be at
> > when moved around in the text view.
> >
> > If anyone has any suggestions at all, I would be
> very
> > grateful.
> >
> > Many thanks,
> > Keith
> >
> >
> >
> >
> ____________________________________________________
> > Start your day with Yahoo! - make it your home
> page
> > http://www.yahoo.com/r/hs
> >
> > _______________________________________________
> > 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
> >
>
>
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
_______________________________________________
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