2 * Ext JS Library 0.30
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.air.SystemMenu
\r
12 * Provides platform independent handling of adding item to the application menu, creating the menu or
\r
13 * items as needed. <br/><br/>
\r
15 * This class also provides the ability to bind standard Ext.Action instances with NativeMenuItems
\r
19 Ext.air.SystemMenu = function(){
\r
22 if(air.NativeWindow.supportsMenu && nativeWindow.systemChrome != air.NativeWindowSystemChrome.NONE) {
\r
23 menu = new air.NativeMenu();
\r
24 nativeWindow.menu = menu;
\r
28 if(air.NativeApplication.supportsMenu) {
\r
29 menu = air.NativeApplication.nativeApplication.menu;
\r
32 function find(menu, text){
\r
33 for(var i = 0, len = menu.items.length; i < len; i++){
\r
34 if(menu.items[i]['label'] == text){
\r
35 return menu.items[i];
\r
43 * Add items to one of the application menus
\r
44 * @param {String} text The application menu to add the actions to (e.g. 'File' or 'Edit').
\r
45 * @param {Array} actions An array of Ext.Action objects or menu item configs
\r
46 * @param {Number} mindex The index of the character in "text" which should be used for
\r
48 * @return air.NativeMenu The raw submenu
\r
50 add: function(text, actions, mindex){
\r
52 var item = find(menu, text);
\r
54 item = menu.addItem(new air.NativeMenuItem(text));
\r
55 item.mnemonicIndex = mindex || 0;
\r
57 item.submenu = new air.NativeMenu();
\r
59 for (var i = 0, len = actions.length; i < len; i++) {
\r
60 item.submenu.addItem(actions[i] == '-' ? new air.NativeMenuItem("", true) : Ext.air.MenuItem(actions[i]));
\r
62 return item.submenu;
\r
66 * Returns the application menu
\r
74 // ability to bind native menu items to an Ext.Action
\r
75 Ext.air.MenuItem = function(action){
\r
76 if(!action.isAction){
\r
77 action = new Ext.Action(action);
\r
79 var cfg = action.initialConfig;
\r
80 var nativeItem = new air.NativeMenuItem(cfg.itemText || cfg.text);
\r
82 nativeItem.enabled = !cfg.disabled;
\r
84 if(!Ext.isEmpty(cfg.checked)){
\r
85 nativeItem.checked = cfg.checked;
\r
88 var handler = cfg.handler;
\r
89 var scope = cfg.scope;
\r
91 nativeItem.addEventListener(air.Event.SELECT, function(){
\r
92 handler.call(scope || window, cfg);
\r
95 action.addComponent({
\r
96 setDisabled : function(v){
\r
97 nativeItem.enabled = !v;
\r
100 setText : function(v){
\r
101 nativeItem.label = v;
\r
104 setVisible : function(v){
\r
105 // could not find way to hide in air so disable?
\r
106 nativeItem.enabled = !v;
\r
109 setHandler : function(newHandler, newScope){
\r
110 handler = newHandler;
\r