Re: Subclassing NSWindowController
Re: Subclassing NSWindowController
- Subject: Re: Subclassing NSWindowController
- From: Mike Ferris <email@hidden>
- Date: Mon, 9 Dec 2002 10:30:54 -0800
Both TextEdit and Sketch do this sort of thing. Mostly,
programmatically creating a text system is simple. If you just
alloc/init the pieces and hook them up, you'll get something that
behaves, by default, pretty much like the one in IB (the one in IB is
inside a scroll view, but you can do that too if you want).
TextEdit does it for its main editor, but it has no document/controller
separation so it creates the whole chain from storage to view together.
Sketch uses a setup very similar to what I described for editing the
text of TextArea graphics. The TextArea is the model object in this
case, and it has-a NSTextStorage. It also has code in the
-startEditingWithEvent:inView: method that shows how to contruct the
layout manager, container, and text view and then how to hook it up to
the storage.
There's some extra baggage in Sketch because of the whole "editor"
business (eg the fact that the same "editor" is used to edit multiple
NSTextStorage objects over time), but the basics are exactly the same
as I was suggesting.
Mike
Begin forwarded message:
From: Chaffinch <email@hidden>
Date: Mon Dec 9, 2002 5:30:38 AM US/Pacific
To: email@hidden
Subject: Re: Subclassing NSWindowController
--- Mike Ferris <email@hidden> wrote:
Here's one possible implementation strategy:
- document has-a NSTextStorage
- init method of your document creates an NSTextStorage
- load or read method of your document loads or reads into the
NSTextStorage
- window controller has-a
NSTextView-NSTextContainer-NSLayoutManager chain of objects (but no
NSTextStorage).
- window controller creates these objects programmatically,
probably
- window controller's setDocument: makes sure the NSLayoutManager
gets connected to the NSTextStorage of the new document (using
NSTextStorage's addLayoutManager:).
Thanks to Mike and everyone else who offered suggestions to me on this
topic.
I modified my code and got the original design working great.
However, I am interested in the points raised about using an
NSTextStorage
and keeping the model and view seperate. Therefore I am no
reimplementing my
code to use the NSTextView-NSTextContainer-NSLayoutManager chain of
objects
mentioned by Mike.
But I have one more question, the Cocoa docs have an article titled
"Assembling the Text System by Hand" which shows how to create the
TextStorage, Container and LayoutManager. Is this the procedire I
should
follow or am I over complicating things.
Regards
=====
Regards
Chaffinch
----------------------------------------------
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
_______________________________________________
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.
_______________________________________________
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.