Re: Autofill a text view with newlines
Re: Autofill a text view with newlines
- Subject: Re: Autofill a text view with newlines
- From: Keith Blount <email@hidden>
- Date: Thu, 28 Oct 2004 14:38:45 -0700 (PDT)
Many thanks for the reply, much appreciated.
Your suggestion does make sense, and it was something
I considered when first putting together my notes view
(mainly because someone else on this board came up
with a similar idea when I was implenting the first
version of this view a month or so ago). In theory it
would indeed be much better than what I am currently
doing, but these are the problems I had when thinking
about this approach:
- It could be very expensive. For a long document,
there could be hundreds of extra text fields/text
views forming the notes.
- How to sync them? If I understand your suggestion
correctly (apologies if I don't), you are saying that
I could add an NSTextAttachment in the main text view
that would act as an anchor. But then, presumably, I
would have to check for any such attachments in
textDidChange and move text fields around
accordingly...
- I would have to store all of these text views/fields
somehow and reconstruct them each time I load an
associated document (with the current approach, I just
have to load a string).
Thinking about it, though, I do wonder if I might try
to implement your suggestion, as my current approach
is a bit of a hack. If you don't mind, could you
please elaborate on what you meant by aligning the
text field with an attachment? Did you mean an
NSTextAttachment for this?
Many thanks again,
Keith
--- Eric Ocean <email@hidden> wrote:
>
 Keith,
>
 
>
 I doubt adding newlines is a good way to go about
>
 what you're trying to  
>
 do.
>
 
>
 Instead, search Apple's documentation for
>
 information on the "Text  
>
 System Storage Layer".
>
 
>
 You can sync up two text views using techniques
>
 discussed in the paper  
>
 without inserting tons of newlines.
>
 
>
 That being said, I highly doubt that the general
>
 approach you're taking  
>
 is what you really want. What if someone deletes
>
 something in the main  
>
 text view? To keep things in sync, you'd have to
>
 find and remove some  
>
 newlines, etc. Major pain. Now they copy and paste,
>
 or reorder. Even  
>
 more problems.
>
 
>
 Instead, what I would do is create a custom view for
>
 your notes side,  
>
 that handle a mouseDown: message specially. What it
>
 would do on a mouse  
>
 down not on an existing note is *attach* to the
>
 corresponding text in  
>
 the main container, and would also create and align
>
 a text field with  
>
 that attachment. You can figure out where the
>
 attachement's position is  
>
 in the layout manager (so that you can keep the
>
 corresponding note  
>
 synced up) using the reference above.
>
 
>
 Now, regardless of how the text is moved, your note
>
 will stay with it  
>
 (because it's attached). You'll have to custom draw
>
 the text in your  
>
 custom notes view, but Cocoa makes that easy.
>
 
>
 This is not a trivial thing to do IMHO, so you
>
 should make up some CRC  
>
 cards and do a little role playing before you
>
 implement it. That being  
>
 said, it shouldn't take more than a day or two of
>
 programming to get a  
>
 robust, correct implementation.
>
 
>
 Regards,
>
 
>
 Eric Ocean
>
 
>
 On Oct 28, 2004, at 12:21 PM, Keith Blount wrote:
>
 
>
 > Hello,
>
 >
>
 > I would be very grateful if somebody could help me
>
 > with the following issue:
>
 >
>
 > I have two text views alongside one another. One
>
 is
>
 > used to contain the main text, the other is used
>
 for
>
 > making brief notes on that text. Whenever the main
>
 > text view has a document loaded into it (eg. an
>
 RTF),
>
 > the other text view should be filled with newline
>
 > characters so that the user can scroll down
>
 anywhere
>
 > in the document and still be able to click into
>
 the
>
 > notes text view and start typing from there.
>
 >
>
 > I have tried implementing this but it has some
>
 > annoying problems. My first method was this:
>
 >
>
 > 1) Monitor NSViewFrameDidChangeNotifications.
>
 > 2) Upon a change, check to see the sender is the
>
 notes
>
 > view or the main view.
>
 > 3) If it is either, check to see if the notes view
>
 > bounds size.height is less than the main text view
>
 > bounds size.height.
>
 > 4) If so, add a newline to the end of the notes
>
 view.
>
 > -> 4) will cause the frame of the notes view to
>
 > change, kicking off the whole sequence again,
>
 until
>
 > the two views are approximately the same size and
>
 the
>
 > notes view is filled with newlines.
>
 >
>
 > This method works, but it is sloooow. I guess this
>
 is
>
 > because it adds a newline character, then waits
>
 for
>
 > the notification, then starts again - it can take
>
 a
>
 > minute or two to fill the notes view with newline
>
 > characters when loading a long document, which is
>
 > obviously unacceptable.
>
 >
>
 > So then I tried adding a for... loop, as follows:
>
 >
>
 > 1) - 3) the same as above.
>
 > 4) If so, call a for loop like this:
>
 >
>
 > for (i = notes view height; i < main view height;
>
 i +=
>
 > notes font height)
>
 >   add newline to end of notes view
>
 >
>
 > But this doesn't work well either - in this case,
>
 too
>
 > many newlines get added for some reason - twice as
>
 > many as required, I think, and I can't seem to be
>
 able
>
 > to fix it.
>
 >
>
 > If anybody has a good suggestion of how I can fill
>
 one
>
 > text view with newline characters (quickly) so
>
 that
>
 > its height matches that of an adjacent text view,
>
 I
>
 > would be *really* grateful.
>
 >
>
 > Many thanks,
>
 > Keith
>
 >
>
 >
>
 > 		
>
 > __________________________________
>
 > Do you Yahoo!?
>
 > Yahoo! Mail Address AutoComplete - You start. We
>
 finish.
>
 > http://promotions.yahoo.com/new_mail
>
 >  _______________________________________________
>
 > Do not post admin requests to the list. They will
>
 be ignored.
>
 > Cocoa-dev mailing list     
>
 (email@hidden)
>
 > Help/Unsubscribe/Update your Subscription:
>
 > email@hidden
>
 >
>
 > This email sent to email@hidden
>
 >
>
 
		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 
 _______________________________________________
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