3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.menu.Manager
17 * Provides a common registry of all menus on a page.
20 Ext.define('Ext.menu.Manager', {
23 'Ext.util.MixedCollection',
26 alternateClassName: 'Ext.menu.MenuMgr',
28 uses: ['Ext.menu.Menu'],
38 me.active = Ext.create('Ext.util.MixedCollection');
39 Ext.getDoc().addKeyListener(27, function() {
40 if (me.active.length > 0) {
47 * Hides all menus that are currently visible
48 * @return {Boolean} success True if any active menus were hidden.
51 var active = this.active,
53 if (active && active.length > 0) {
67 if (active.length < 1) {
68 Ext.getDoc().un('mousedown', me.onMouseDown, me);
77 attached = me.attached,
81 me.lastShow = new Date();
84 Ext.getDoc().on('mousedown', me.onMouseDown, me);
90 onBeforeHide: function(m) {
94 if (m.autoHideTimer) {
95 clearTimeout(m.autoHideTimer);
96 delete m.autoHideTimer;
100 onBeforeShow: function(m) {
101 var active = this.active,
102 parentMenu = m.parentMenu;
105 if (!parentMenu && !m.allowOtherMenus) {
108 else if (parentMenu && parentMenu.activeChild && m != parentMenu.activeChild) {
109 parentMenu.activeChild.hide();
114 onMouseDown: function(e) {
117 lastShow = me.lastShow;
119 if (Ext.Date.getElapsed(lastShow) > 50 && active.length > 0 && !e.getTarget('.' + Ext.baseCSSPrefix + 'menu')) {
125 register: function(menu) {
133 me.menus[menu.id] = menu;
135 beforehide: me.onBeforeHide,
137 beforeshow: me.onBeforeShow,
145 * Returns a {@link Ext.menu.Menu} object
146 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
147 * be used to generate and return a new Menu this.
148 * @return {Ext.menu.Menu} The specified menu, or null if none are found
150 get: function(menu) {
151 var menus = this.menus;
153 if (typeof menu == 'string') { // menu id
154 if (!menus) { // not initialized, no menus to return
158 } else if (menu.isMenu) { // menu instance
160 } else if (Ext.isArray(menu)) { // array of menu items
161 return Ext.create('Ext.menu.Menu', {items:menu});
162 } else { // otherwise, must be a config
163 return Ext.ComponentManager.create(menu, 'menu');
168 unregister: function(menu) {
173 delete menus[menu.id];
176 beforehide: me.onBeforeHide,
178 beforeshow: me.onBeforeShow,
185 registerCheckable: function(menuItem) {
186 var groups = this.groups,
187 groupId = menuItem.group;
190 if (!groups[groupId]) {
191 groups[groupId] = [];
194 groups[groupId].push(menuItem);
199 unregisterCheckable: function(menuItem) {
200 var groups = this.groups,
201 groupId = menuItem.group;
204 Ext.Array.remove(groups[groupId], menuItem);
208 onCheckChange: function(menuItem, state) {
209 var groups = this.groups,
210 groupId = menuItem.group,
214 if (groupId && state) {
215 group = groups[groupId];
217 for (; i < ln; i++) {
219 if (curr != menuItem) {
220 curr.setChecked(false);