I’m trying to dynamically add a separator item to a popup button:
make new menu item at end of menu of popup button "theEmail" with properties {separator item:true, enabled:false}
set x to separator item of menu item 3 of popup button "theEmail"
log x --> false
set separator item of (menu item 3 of menu of popup button "theEmail") to true
Using the separator item property flag in ASS is not supported, although it is documented. The only way to do this is by creating a custom method that you can call to do it for you in objective-c. To do this…
Open your nib file in IB.
Click on the “Classes” Tab in the ‘MainMenu.nib’ window.
Scroll all the way to the left of the class hierarchy and select “NSObject”.
In the “Classes” Main Menu, select “Subclass NSObject”.
Some thoughts about naming your subclass…
A new nsobject subclass will be created in your nib, and will be named ‘MyObject’, by default. Change this to the name you want to use for your subclass. Typically, you want to pick a unique identifier which you will use to customize all subclasses you create, and it is common to use some sort of reference to or abbreviation of your app name as an identifier. For example, if your app is named “SuperApp” an appropriate identifier might be “SA”. Any subclasses you create for your app should then be something like ‘SAObject’ or ‘SABorderlessWindow’. This clarifies that these are subclasses unique to your app, and as long as you avoid using any of the default class identifiers (like NS, CF, or QT) you’ll be all right. In the examples below, change all occurences of “MYObject” to whatever you decide to name your subclass. It is common for serious ASS developers to end up using many custom subclasses in their projects to fill in the blanks with obj-c methods that ASS can’t provide, so keep in mind that naming it something like ‘XYZObject’ is more scalable and leaves you more flexibility in the future should you wish to add more generic methods later.
Select “Create Files for “MYObject”” from the “Classes” Main Menu.
When the panel opens up, make sure that ‘MYObject.h’ and ‘MYObject.m’ are both checked, and click “Create”.
Save your nib file and then go back into Xcode. You’ll find two new files ‘MYObject.h’ and ‘MYObject.m’ in your project, probably in the “Other Sources” group. I usually create a new group named “Classes” and move them there, but it doesn’t matter.
Put the contents for the .h and .m files in their respective files, as listed below…
@end[/code]
9) Use some AS code like one of the following examples to programmatically add a separator item. Note that this method will add a separator item to ANY valid NSMenu that you pass to the method as the parameter…
tell popup button "somePopupButton" of window "someWindow" to set theMenu to menu of it
call method "createSeparatorItem:" of class "MYObject" with parameter theMenu
-- OR --
tell menu of popup button "somePopupButton" of window "someWindow"
set separatorItem to call method "createSeparatorItem:" of class "MYObject" with parameter it
end tell
Is this till valid with IB 3.1.2 interface?
I don’t find points 2) and 3)
I’ve added .m and .h file in Xcode inside Other Sources folder but then I can’t see separator but only “–”