• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextView synchronization ...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextView synchronization ...


  • Subject: Re: NSTextView synchronization ...
  • From: Andy Lee <email@hidden>
  • Date: Sun, 29 May 2005 22:46:54 -0400

On May 29, 2005, at 10:10 PM, T Reaves wrote:
I have an NSTExtView on a window. I have a button that toggle's a drawer. The drawer has another NSTextView. Both are bound to the same string in a CoreData class. I'd like the text in the two to be synchronized, as the one on the main window is small, and the user would open the drawer for a larger edit window.

I don't think I can share the instance of the NSTextView, as their sizes differ. The text in one is updated in the other when the text view's focus is lost.

If you like, you can actually have them stay in sync automatically as you type rather than waiting for one to lose focus. The way you do it is by having the two NSTextViews share the same NSTextStorage. I *believe* you can do this:


    [[textViewOne layoutManager]
        replaceTextStorage:[textViewTwo textStorage]];

I'm definitely rusty on my knowledge of the Cocoa text architecture, so before committing a line like this in my code, I would study up a bit to make sure it does what I think it does.

Basically, your NSTextView is part of a graph of objects that include an object to manage layout (NSLayoutManager) and another to store the text itself (NSTextStorage). If you look at this...

<file:///Developer/ADC Reference Library/documentation/Cocoa/ Conceptual/TextArchitecture/Tasks/AssembleSysByHand.html#//apple_ref/ doc/uid/20000843>

...you'll get a high-level view of how multiple text views can share the same text storage. Further reading is here:

<file:///Developer/ADC Reference Library/documentation/Cocoa/ Conceptual/TextArchitecture/index.html#//apple_ref/doc/uid/10000086i>

and here:

<file:///Developer/ADC Reference Library/documentation/Cocoa/ Conceptual/TextStorageLayer/index.html#//apple_ref/doc/uid/10000087i>

--Andy


_______________________________________________ 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
References: 
 >NSTextView synchronization ... (From: T Reaves <email@hidden>)

  • Prev by Date: Re: Tiger Decoding problem
  • Next by Date: Exception raised during posting of notification
  • Previous by thread: NSTextView synchronization ...
  • Next by thread: Exception raised during posting of notification
  • Index(es):
    • Date
    • Thread