• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Text Array View
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Text Array View


  • Subject: Re: Text Array View
  • From: Ryan Stevens <email@hidden>
  • Date: Sat, 17 Sep 2005 00:15:32 -0700


On Sep 16, 2005, at 5:34 PM, Rachel Blackman wrote:

I have a situation wherein I have an array of NSAttributedString objects. Things can be appended onto the end of this array, and when it's greater than a certain size, the oldest one falls off.


I just realized that I didn't describe this well. Let me actually rephrase this better, in hopes someone has already solved the problem. :)


I have a network stream of characters. It is somewhat like a terminal stream (inasmuch as I have control sequences I need to deal with for color and so on), except that I never need to worry about cursor movement. I will only ever be using one font per display, but do need other attributes. The user will not be editing the output, but should be able to select and copy it.

I am guaranteed to get text separated into nice little 'paragraphs' -- these may word-wrap (and need to be indented), but will always terminate with a newline. Each of these paragraphs should be stored separately in memory for later reference, since I may need to be able to filter them and so on.

This seems like an ideal use for an NSTextView, save the problem that after a certain point, appending anything to the NSTextStorage becomes ungodly slow. Further, the longer the NSTextStorage content, the more painful it is on a window resize. Setting an arbitrary limit to the NSTextStorage content is doable, but not ideal; this view should (in theory) be able to keep expanding as long as memory is there to handle it. I do, however, want the / option/ to limit the size of the store.

I've thought of writing a storage class which generates an NSText for every 'paragraph' in the scrollback and sticks them together into a view, but I'm not certain that works well for selecting (in terms of allowing the selection to cross paragraph boundaries, which it must). I also thought of trying to write an NSTextStorage replacement and backing my textview with that, but I'm not certain that's the right way either.

I've been buried in Win32 code at work for the past few months, so getting back into Cocoa, I'm having to wrap my brain around designing things the /right/ way, instead of just 'whatever works on Win95, Win98, WinME, Win2k /and/ WinXP.'

Any input would be most welcomed. :)


Maybe something like this? Compiled in mail, etc.


@implementation NSTextStorage (NotSoTricky)

static int cutLocation;

- (void)trickyAppendString:(NSAttributedString *)attributedString
{
    [self appendAttributedString:attributedString];

// at 175 paragraphs cut the first 100 off...
NSArray *paragraphs = [self paragraphs];
int count = [paragraphs count];
if (count <= 100) cutLocation += [attributedString length]; // build up to the cut.
if (count == 175) { // make the cut
id cutString = [self attributedSubstringFromRange:NSMakeRange (0,cutLocation)];
[self deleteCharactersInRange:NSMakeRange(0,cutLocation)];


        // do something with cutString?

    cutLocation = 0;
    }
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Text Array View (From: Rachel Blackman <email@hidden>)
 >Re: Text Array View (From: Rachel Blackman <email@hidden>)

  • Prev by Date: Re: Font scaling and string size problem?!?
  • Next by Date: COCOa Complete reference
  • Previous by thread: Re: Text Array View
  • Next by thread: Strange problem with the help menu and minimizing the app
  • Index(es):
    • Date
    • Thread