diff --git a/src/as/com/threerings/flex/CommandMenu.as b/src/as/com/threerings/flex/CommandMenu.as index c7c07766..571a2fb8 100644 --- a/src/as/com/threerings/flex/CommandMenu.as +++ b/src/as/com/threerings/flex/CommandMenu.as @@ -65,6 +65,9 @@ use namespace mx_internal; * IFlexDisplayObject to use as the icon. This will only be applied if the "icon" property * (which specifies a Class) is not used. * + * Another 'type' now supported is "title", which gives the label for that item the style + * '.menuTitle' and disables it. Your ".menuTitle" style should use the disabledColor. + * * Example dataProvider array: * [ { label: "Go home", icon: homeIconClass, * command: Controller.GO_HOME, arg: homeId }, @@ -105,6 +108,26 @@ public class CommandMenu extends Menu return menu; } + /** + * Add a title to the TOP of the specified menu. + * + * @param icon may be a Class or IFlexDisplayObject. + */ + public static function addTitle ( + menuItems :Array, title :String, icon :* = null, separatorAfter :Boolean = true) :void + { + var o :Object = { label: title, type: "title" }; + if (icon is Class) { + o["icon"] = icon; + } else if (icon is IFlexDisplayObject) { + o["iconObj"] = icon; + } + if (separatorAfter) { + menuItems.unshift({ type: "separator" }); + } + menuItems.unshift(o); + } + /** * Add a separator to the specified menu, unless it would not make sense to do so, because * the menu is empty or already ends with a separator. diff --git a/src/as/com/threerings/flex/menuClasses/CommandMenuItemRenderer.as b/src/as/com/threerings/flex/menuClasses/CommandMenuItemRenderer.as index 490e81ee..831ec544 100644 --- a/src/as/com/threerings/flex/menuClasses/CommandMenuItemRenderer.as +++ b/src/as/com/threerings/flex/menuClasses/CommandMenuItemRenderer.as @@ -24,6 +24,8 @@ package com.threerings.flex.menuClasses { import flash.display.DisplayObject; +import mx.controls.Menu; +import mx.controls.menuClasses.IMenuDataDescriptor; import mx.controls.menuClasses.MenuItemRenderer; public class CommandMenuItemRenderer extends MenuItemRenderer @@ -43,6 +45,17 @@ public class CommandMenuItemRenderer extends MenuItemRenderer addChild(DisplayObject(icon)); } } + + if (label.visible) { + var dataDescriptor :IMenuDataDescriptor = Menu(listData.owner).dataDescriptor; + var typeVal :String = dataDescriptor.getType(data); + if (typeVal == "title") { + dataDescriptor.setEnabled(data, false); + label.enabled = false; + label.styleName = "menuTitle"; + invalidateDisplayList(); + } + } } } }