Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTextView, NSCoding help

NSTextView, NSCoding help
Thread Tools
Fresh-Faced Recruit
Join Date: Jul 2002
Status: Offline
Reply With Quote
Jul 30, 2002, 12:01 AM
 
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
Reply With Quote
Jul 30, 2002, 02:49 PM
 
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
Reply With Quote
Jul 30, 2002, 03:25 PM
 
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
Reply With Quote
Jul 30, 2002, 06:35 PM
 
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)initWithCoderNSCoder *)coder
{
return [super initWithFrame:NSMakeRect(0,0,100,16)];
}

// need to have this here, but don't actually need to do anything.
- (void)encodeWithCoderNSCoder *)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
Reply With Quote
Aug 4, 2002, 08:25 PM
 
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?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:16 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2