Everything in this page that isn’t owned by someone else is in the public domain. That means there’s no copyright, and you can do what you want. Okay, in the USA there’s an automatic copyright that’s implied by writing, so I guess I have to say explicitely that this is public domain.
This demo shows how I’ve manipulated NSTextView in order to
The demo and the class are probably slightly misnamed, since JSDTextView would seem to indicate an NSView subclass. This is not the case. JSDTextView is actually an NSView subclass the builds the NSTextView by hand, including the enclosing NSScrollView instance.
To implement the view in a nib, make sure IB knows about the JSDTextView.h file (i.e., drag it to your nib). You can then put a CustomView on your window or view, and change its custom class to JSDTextView. Explore the header file for useful functions. Default instantiation in the program will show line numbers and will not wrap text.
The downside to this approach is that you lose most of the IB configurability of an NSTextView. Oh well; it’s easy to do in code. Just remember that the real NSTextView properties and methods are buried one level lower, i.e., use [[instance textView] methodName] to work with the real NSTextView instance. Again, look at the header file to see what else could be useful.
Someday if there’s interest and I have time, I could expose more of the buried instance-properties and write an Interface Builder palette for this class. After all, I need a good excuse to write one someday, and that’s the only unused chapter in my Hillegas book!
I hope to save you the trouble and time that it took me to figure out how to do this. Good luck!
I’d like to give especial thanks to Koen van der Drift <kvddrift@earthlink.net>, without whose code I wouldn’t have gotten line numbering to work at all!
The real answer is that NSLayoutManager hasn’t drawn any glyphs on that line, thus there’s no simple way to ascertain the coordinates to draw the line number. The answer I’m inclined to say is that I think this is proper behavior because until there’s text there, there’s no line that exists, not even a carriage return. As soon as you type a single character, you now have a line.
I’d have to say the same reason as above, i.e., there’s no glyph and hence no coordinate to draw the line number. But I still think that this is proper behavior, for the same reasons above.
This demo simply shows how you can go about loading assembled views from a Nib file into an existing window. There are two big reasons I can think of that you would want to do this:
I hope to save you the trouble and time that it took me to figure out how to do this. The Apple mailing list archives at http://cocoa.mamasam.com are a great resource, but for this particular task (and this particular Cocoa newbie) it was like wading through mud. Good luck!