 |
 |
NSTextView, NSCoding help
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2002
Status:
Offline
|
|
Hi.
I've got a custom NSTextView as a NSToolbarItem. It appears in the toolbar, I can type in it, everything seems hunky dory. Unfortunately, if I fire off the runCustomizationPalette: method to play with/move around the items in the toolbar, the sheet doesn't appear & I get a console message saying . . .
*** NSCoding is explicitly not supported by the new text
system. Save the rtfd contents and as much of the setup as necessary yourself.
I assume this means my custom NSTextView needs to implement -initWithCoder & -encodeWithCoder, but what should I encode? I've tried grabbing the text view string, throwing it into an NSData*, encoding that, and the unencoding the data & putting it back in the text view, but all I manage to do is get a signal 10 crash.
Any help would be greatly appreciated!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status:
Offline
|
|
I don't see anything in the docs about toolbar items having to support NSCoding (NSCopying is there, but not NSCoding). Try setting a breakpoint on -[NSTextView encodeWithCoder:] (go into the breakpoints panel, click the new button and then type that in) and run it with the debugger, so you can get a stack trace of where this is being called, which might give some clues as to why it's being called.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
bewebste didn't read carefully enough. From the NSToolbarItem docs:
"Also, everything recursively contained in view must be archivable if the customization palette is used. For a view item to be archivable, it and all of its contents must conform to the NSCoding protocol."
It sounds like you're SOL for using an NSTextView as a toolbar item. Could you get away with an NSTextField, maybe?
-Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2002
Status:
Offline
|
|
So, thanks for the replies. I sort of figured out my problem, but now I've got another one in the same vein.
Here's how I solved my problem: I added the following 2 methods:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">
- (id)initWithCoder  NSCoder *)coder
{
return [super initWithFrame:NSMakeRect(0,0,100,16)];
}
// need to have this here, but don't actually need to do anything.
- (void)encodeWithCoder  NSCoder *)coder
{
return;
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I don't actually need to save anything from this NSTextView - so an empty encode method is OK. And with this, the toolbar customization method works again.
Now the problem is with that initWithFrame: call. This item is one of my default toolbar items, so it appears twice in the customization palette. The first time it appears - things are A-OK. The problem is in the "or choose the default set" box. There, I have a white rectangle in the bottom left corner of the view - which looks suspiciously like a 100x16 rectangle located at origin 0,0. Any idea how I can change the initWithFrame call to just draw a rectangle in the coordinates of this view only?
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2002
Status:
Offline
|
|
I solved my problem, and so that others won't spend the same time I did trying to figure out what was wrong, I'll post what I did.
to recap: i had a custom view containg a scrollview containing a text view, which I needed to encode/decode.
The problem was my NSScrollView remembered that it's document view was the NSTextView. However, the NSClipView which sits between the scroll view & text view had, um, "forgotten". So, when I encoded the TextView, I also encoded it's superview (ie, the clip view), and then when I decoded the text view, I setDocumentView of the encoded clip view back to the text view.
Make sense?
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|