• 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
Inserting lists into NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Inserting lists into NSTextView


  • Subject: Inserting lists into NSTextView
  • From: "Micah Wylde" <email@hidden>
  • Date: Sat, 17 Feb 2007 15:48:03 -0800

Hello, everyone. This is my first post to this list, so please be kind :)

I've been working with NSTextView, trying to make it suitable for
outlining, and been running into a number of problems. There is a
class, NSTextList, wish would seem from the documentation to create
list formatting. However, in reality it does not such thing. So my
first question is, is there a simple way to programatically add a list
into a NSTextView, like clicking the list button on the ruler does?
I've found a number of mailing list posts asking this question, but I
have not yet found an answer.

Having failed so far to find a simple way to do this and have the
NSTextView manage my lists, I've subclassed it and overridden keyDown
to handle the backspace, enter, and tab keys. I've found a bizarre
behavior, though, with inserting into the NSTextStorage this sequence:
@"\t{bullet}\t", where {bullet} is the unicode for a bullet, and
setting the NSParagraphStyleAttribute with a NSTextList. I'm using
code that amounts to essentially this:

[[self textStorage] beginEditing];
NSMutableAttributedString *text = [[NSMutableAttributedString
alloc]initWithAttributedString:[self textStorage]];

NSMutableParagraphStyle *mps = [NSParagraphStyle defaultParagraphStyle];
NSTextList *listItem = [[NSTextList alloc] initWithMarkerFormat:
@"{circle}" options:NSTextListPrependEnclosingMarker];
[mps setTextLists:[NSArray arrayWithObject:listItem]];
NSMutableString *tabs = [@"\t" mutableCopy];
for(int i = 0; i < currentIndentation; i++)
{
	[tabs appendString:@"\t"];
}
[text appendAttributedString: [[NSAttributedString alloc]
initWithString:[NSString stringWithFormat:@"%@%@\t", tabs, [listItem
markerForItemNumber:1]]
attributes:[NSDictionary dictionaryWithObject:mps
forKey:NSParagraphStyleAttributeName]]];
[[self textStorage] setAttributedString:text];
[[self textStorage] endEditing];						

For some reason, the NSTextView seems to recognize it as a list, which
causes problems; it also adds an extra line every time the user
presses enter. If I don't add the NSTextList, it no longer shows this
behavior.

I've been working on this problem for a while now, and am now pretty
stuck. The documentation surrounding NSTextList is terrible, and there
is no (AFAIK) documentation about how NSTextView handles lists. Thanks
in advance for any help.
--
Micah Wylde
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Inserting lists into NSTextView
      • From: "Micah Wylde" <email@hidden>
  • Prev by Date: Need Better Understanding of Modal Delegates
  • Next by Date: Re: Need Better Understanding of Modal Delegates
  • Previous by thread: Re: Need Better Understanding of Modal Delegates
  • Next by thread: Re: Inserting lists into NSTextView
  • Index(es):
    • Date
    • Thread