Re: Creating a styles menu like the one in the ruler accessory view of NSLayoutManager...
Re: Creating a styles menu like the one in the ruler accessory view of NSLayoutManager...
- Subject: Re: Creating a styles menu like the one in the ruler accessory view of NSLayoutManager...
- From: Keith Blount <email@hidden>
- Date: Mon, 28 Jul 2008 09:24:11 -0700 (PDT)
Hmm,
Looking into this some more, it seems that the user's favourite styles can be accessed like this:
NSDictionary *favStyles = [[NSUserDefaults standardUserDefaults] objectForKey:@"NSFavoriteStyles"];
Presumably this is what is used to generate the pop-up menu in NSLayoutManager's ruler accessory view.
However, given that I cannot find anything on this in the docs, I am guessing that this is undocumented and not recommended? Looking at the dictionary that this returns, it does seem that it would be fairly straightforward to grab the keys (which are the names of the styles) and then go through the inner dictionaries that contain the attributes and apply them to the text selection, but is there a more standard way of getting the styles information for use like this? (Again, I'm trying to create my own format bar rather than use the standard text view ruler accessory view.) My feeling is that this is probably not a recommended route given that I can find no documentation or information on it.
Thanks and all the best,
Keith
--- ORIGINAL MESSAGE ---
Hi,
I'm fairly sure that this isn't possible without hooking into private methods of NSLayoutManager, but it's worth asking on the off-chance...
In a standard rich textNSTextView, the ruler view has an accessory view provided by NSLayoutManager. This accessory view has several handy controls in it - a styles pop-up menu, a lists pop-up menu, an alignment segmented control and so forth. However, for my own app I'm overriding NSLayoutManager to get rid of this accessory view. Instead, I'm providing a Pages-like format bar; the reason for this is that, given that you can split the editor in my app and therefore have two text views visible, you can also have two accessory views visible which can take up more screen estate than necessary; having the same controls in one bar that affects both text views will take up less space and provide a less cluttered experience. Adding most of the controls to this format bar is straightforward - bold, italic, underline, foreground/background colour, alignment etc are all relatively easy. However, it seems that there is no way of grabbing a list of available styles
in order to provide a styles menu like the one that appears in the standard accessory view (nor no way of grabbing the lists menu, for that matter). I can just create a button that calls -orderFrontStylesPanel: if necessary, but this will involve more steps for the user (having to go through the sheet to get to the menu), and I'd really just like to provide a list of styles like the one in the standard NSLayoutManager accessory view.
Is there any way of doing this? As I say, from surveying the docs and searching online, I don't think it's possible - I think these lists and how the menus are generated by NSLayoutManager's accessory view are all contained in private methods - but I'd love to discover I'm wrong.
Many thanks in advance and all the best,
Keith
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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