Re: Inserting lists into NSTextView
Re: Inserting lists into NSTextView
- Subject: Re: Inserting lists into NSTextView
- From: "Micah Wylde" <email@hidden>
- Date: Wed, 21 Feb 2007 17:02:02 -0800
Does no one know how to do this? Certainly it's possible since the
ruler does it. I'm sure I've seen 3rd party applications use
NSTextView to do this as well. The complete lack of documentation has
been driving me up a wall here. Can any one help me?
On 2/17/07, Micah Wylde <email@hidden> wrote:
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
--
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