Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / SystemMenu.html
diff --git a/docs/source/SystemMenu.html b/docs/source/SystemMenu.html
new file mode 100644 (file)
index 0000000..db721cd
--- /dev/null
@@ -0,0 +1,120 @@
+<html>\r
+<head>\r
+  <title>The source code</title>\r
+    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
+    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
+</head>\r
+<body  onload="prettyPrint();">\r
+    <pre class="prettyprint lang-js"><div id="cls-Ext.air.SystemMenu"></div>/**\r
+ * @class Ext.air.SystemMenu\r
+ * \r
+ * Provides platform independent handling of adding item to the application menu, creating the menu or \r
+ * items as needed. <br/><br/>\r
+ * \r
+ * This class also provides the ability to bind standard Ext.Action instances with NativeMenuItems\r
+ * \r
+ * @singleton\r
+ */\r
+Ext.air.SystemMenu = function(){\r
+       var menu;\r
+       // windows\r
+       if(air.NativeWindow.supportsMenu && nativeWindow.systemChrome != air.NativeWindowSystemChrome.NONE) {\r
+        menu = new air.NativeMenu();\r
+        nativeWindow.menu = menu;\r
+    }\r
+    \r
+       // mac\r
+    if(air.NativeApplication.supportsMenu) {\r
+               menu = air.NativeApplication.nativeApplication.menu;\r
+    }\r
+\r
+    function find(menu, text){\r
+        for(var i = 0, len = menu.items.length; i < len; i++){\r
+            if(menu.items[i]['label'] == text){\r
+                return menu.items[i];\r
+            }\r
+        }\r
+        return null;\r
+    }\r
+\r
+    return {\r
+               <div id="method-Ext.air.SystemMenu-add"></div>/**\r
+                * Add items to one of the application menus\r
+                * @param {String} text The application menu to add the actions to (e.g. 'File' or 'Edit').\r
+                * @param {Array} actions An array of Ext.Action objects or menu item configs\r
+                * @param {Number} mindex The index of the character in "text" which should be used for \r
+                * keyboard access\r
+                * @return air.NativeMenu The raw submenu\r
+                */\r
+               add: function(text, actions, mindex){\r
+\r
+            var item = find(menu, text);\r
+            if(!item){\r
+                item = menu.addItem(new air.NativeMenuItem(text));\r
+                item.mnemonicIndex = mindex || 0;\r
+\r
+                item.submenu = new air.NativeMenu();\r
+                       }\r
+                       for (var i = 0, len = actions.length; i < len; i++) {\r
+                               item.submenu.addItem(actions[i] == '-' ? new air.NativeMenuItem("", true) : Ext.air.MenuItem(actions[i]));\r
+                       }\r
+            return item.submenu;\r
+        },\r
+               \r
+               <div id="method-Ext.air.SystemMenu-get"></div>/**\r
+                * Returns the application menu\r
+                */\r
+               get : function(){\r
+                       return menu;\r
+               }\r
+       };      \r
+}();\r
+\r
+// ability to bind native menu items to an Ext.Action\r
+Ext.air.MenuItem = function(action){\r
+       if(!action.isAction){\r
+               action = new Ext.Action(action);\r
+       }\r
+       var cfg = action.initialConfig;\r
+       var nativeItem = new air.NativeMenuItem(cfg.itemText || cfg.text);\r
+       \r
+       nativeItem.enabled = !cfg.disabled;\r
+\r
+    if(!Ext.isEmpty(cfg.checked)){\r
+        nativeItem.checked = cfg.checked;\r
+    }\r
+\r
+    var handler = cfg.handler;\r
+       var scope = cfg.scope;\r
+       \r
+       nativeItem.addEventListener(air.Event.SELECT, function(){\r
+               handler.call(scope || window, cfg);\r
+       });\r
+       \r
+       action.addComponent({\r
+               setDisabled : function(v){\r
+                       nativeItem.enabled = !v;\r
+               },\r
+               \r
+               setText : function(v){\r
+                       nativeItem.label = v;\r
+               },\r
+               \r
+               setVisible : function(v){\r
+                       // could not find way to hide in air so disable?\r
+                       nativeItem.enabled = !v;\r
+               },\r
+               \r
+               setHandler : function(newHandler, newScope){\r
+                       handler = newHandler;\r
+                       scope = newScope;\r
+               },\r
+               // empty function\r
+               on : function(){}\r
+       });\r
+       \r
+       return nativeItem;\r
+}\r
+</pre>    \r
+</body>\r
+</html>
\ No newline at end of file