3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.air.SystemMenu"></div>/**
\r
9 * @class Ext.air.SystemMenu
\r
11 * Provides platform independent handling of adding item to the application menu, creating the menu or
\r
12 * items as needed. <br/><br/>
\r
14 * This class also provides the ability to bind standard Ext.Action instances with NativeMenuItems
\r
18 Ext.air.SystemMenu = function(){
\r
21 if(air.NativeWindow.supportsMenu && nativeWindow.systemChrome != air.NativeWindowSystemChrome.NONE) {
\r
22 menu = new air.NativeMenu();
\r
23 nativeWindow.menu = menu;
\r
27 if(air.NativeApplication.supportsMenu) {
\r
28 menu = air.NativeApplication.nativeApplication.menu;
\r
31 function find(menu, text){
\r
32 for(var i = 0, len = menu.items.length; i < len; i++){
\r
33 if(menu.items[i]['label'] == text){
\r
34 return menu.items[i];
\r
41 <div id="method-Ext.air.SystemMenu-add"></div>/**
\r
42 * Add items to one of the application menus
\r
43 * @param {String} text The application menu to add the actions to (e.g. 'File' or 'Edit').
\r
44 * @param {Array} actions An array of Ext.Action objects or menu item configs
\r
45 * @param {Number} mindex The index of the character in "text" which should be used for
\r
47 * @return air.NativeMenu The raw submenu
\r
49 add: function(text, actions, mindex){
\r
51 var item = find(menu, text);
\r
53 item = menu.addItem(new air.NativeMenuItem(text));
\r
54 item.mnemonicIndex = mindex || 0;
\r
56 item.submenu = new air.NativeMenu();
\r
58 for (var i = 0, len = actions.length; i < len; i++) {
\r
59 item.submenu.addItem(actions[i] == '-' ? new air.NativeMenuItem("", true) : Ext.air.MenuItem(actions[i]));
\r
61 return item.submenu;
\r
64 <div id="method-Ext.air.SystemMenu-get"></div>/**
\r
65 * Returns the application menu
\r
73 // ability to bind native menu items to an Ext.Action
\r
74 Ext.air.MenuItem = function(action){
\r
75 if(!action.isAction){
\r
76 action = new Ext.Action(action);
\r
78 var cfg = action.initialConfig;
\r
79 var nativeItem = new air.NativeMenuItem(cfg.itemText || cfg.text);
\r
81 nativeItem.enabled = !cfg.disabled;
\r
83 if(!Ext.isEmpty(cfg.checked)){
\r
84 nativeItem.checked = cfg.checked;
\r
87 var handler = cfg.handler;
\r
88 var scope = cfg.scope;
\r
90 nativeItem.addEventListener(air.Event.SELECT, function(){
\r
91 handler.call(scope || window, cfg);
\r
94 action.addComponent({
\r
95 setDisabled : function(v){
\r
96 nativeItem.enabled = !v;
\r
99 setText : function(v){
\r
100 nativeItem.label = v;
\r
103 setVisible : function(v){
\r
104 // could not find way to hide in air so disable?
\r
105 nativeItem.enabled = !v;
\r
108 setHandler : function(newHandler, newScope){
\r
109 handler = newHandler;
\r