Re: Newbie Question about Document/Window/Text Field
Re: Newbie Question about Document/Window/Text Field
- Subject: Re: Newbie Question about Document/Window/Text Field
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 15 May 2001 02:36:47 -0700
On Tuesday, May 15, 2001, at 02:23 AM, Keith Bauer wrote:
Please excuse the newbie question...
I am trying to create a simple text-editor in my quest to learn Cocoa,
so I've created a project with the document-based app template and
added a big scrolling text field to the window. Bingo! I have a
working text editor. Gotta love that ;)
Now I want to implement saving, so my question is: how do I get the
text that's in the text view when I get asked to save my document?
Look at "TextEdit" in /Developer/Examples/AppKit/TextEdit. The code you
want is in Document.m, in the method
- (void)saveDocument:(BOOL)showSavePanel
rememberName:(BOOL)rememberNewNameAndSuch shouldClose:(BOOL)shouldClose
whenDone:(SEL)callback
..which is rather more elaborate than you need, but it is a working
example.
To do it much more simply, ask the textField for its textContainer, ask
the textContainer for its string, run the save panel and use the path
you get from the save panel to tell the string where to write itself out
in -saveToFile:atomically:
-jcr
For every complex problem there is an answer that is clear, simple, and
wrong. -- H L Mencken