| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 QuickOpen.CommandMenu = class { | 7 QuickOpen.CommandMenu = class { |
| 8 constructor() { | 8 constructor() { |
| 9 this._commands = []; | 9 this._commands = []; |
| 10 this._loadCommands(); | 10 this._loadCommands(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 * @return {!QuickOpen.CommandMenu.Command} | 52 * @return {!QuickOpen.CommandMenu.Command} |
| 53 */ | 53 */ |
| 54 static createActionCommand(action) { | 54 static createActionCommand(action) { |
| 55 var shortcut = UI.shortcutRegistry.shortcutTitleForAction(action.id()) || ''
; | 55 var shortcut = UI.shortcutRegistry.shortcutTitleForAction(action.id()) || ''
; |
| 56 return QuickOpen.CommandMenu.createCommand( | 56 return QuickOpen.CommandMenu.createCommand( |
| 57 action.category(), action.tags(), action.title(), shortcut, action.execu
te.bind(action)); | 57 action.category(), action.tags(), action.title(), shortcut, action.execu
te.bind(action)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * @param {!Runtime.Extension} extension | 61 * @param {!Runtime.Extension} extension |
| 62 * @param {string} category |
| 62 * @return {!QuickOpen.CommandMenu.Command} | 63 * @return {!QuickOpen.CommandMenu.Command} |
| 63 */ | 64 */ |
| 64 static createRevealPanelCommand(extension) { | 65 static createRevealViewCommand(extension, category) { |
| 65 var panelId = extension.descriptor()['id']; | 66 var viewId = extension.descriptor()['id']; |
| 66 var executeHandler = UI.viewManager.showView.bind(UI.viewManager, panelId); | 67 var executeHandler = UI.viewManager.showView.bind(UI.viewManager, viewId); |
| 67 var tags = extension.descriptor()['tags'] || ''; | 68 var tags = extension.descriptor()['tags'] || ''; |
| 68 return QuickOpen.CommandMenu.createCommand( | 69 return QuickOpen.CommandMenu.createCommand( |
| 69 Common.UIString('Panel'), tags, Common.UIString('Show %s', extension.tit
le()), '', executeHandler); | 70 category, tags, Common.UIString('Show %s', extension.title()), '', execu
teHandler); |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * @param {!Runtime.Extension} extension | |
| 74 * @return {!QuickOpen.CommandMenu.Command} | |
| 75 */ | |
| 76 static createRevealDrawerCommand(extension) { | |
| 77 var drawerId = extension.descriptor()['id']; | |
| 78 var executeHandler = UI.viewManager.showView.bind(UI.viewManager, drawerId); | |
| 79 var tags = extension.descriptor()['tags'] || ''; | |
| 80 return QuickOpen.CommandMenu.createCommand( | |
| 81 Common.UIString('Drawer'), tags, Common.UIString('Show %s', extension.ti
tle()), '', executeHandler); | |
| 82 } | 71 } |
| 83 | 72 |
| 84 _loadCommands() { | 73 _loadCommands() { |
| 74 var locations = new Map(); |
| 75 self.runtime.extensions(UI.ViewLocationResolver).forEach(extension => { |
| 76 var category = extension.descriptor()['category']; |
| 77 var name = extension.descriptor()['name']; |
| 78 if (category && name) |
| 79 locations.set(name, category); |
| 80 }); |
| 85 var viewExtensions = self.runtime.extensions('view'); | 81 var viewExtensions = self.runtime.extensions('view'); |
| 86 for (var extension of viewExtensions) { | 82 for (var extension of viewExtensions) { |
| 87 if (extension.descriptor()['location'] === 'panel') | 83 var category = locations.get(extension.descriptor()['location']); |
| 88 this._commands.push(QuickOpen.CommandMenu.createRevealPanelCommand(exten
sion)); | 84 if (category) |
| 89 else if (extension.descriptor()['location'] === 'drawer-view') | 85 this._commands.push(QuickOpen.CommandMenu.createRevealViewCommand(extens
ion, category)); |
| 90 this._commands.push(QuickOpen.CommandMenu.createRevealDrawerCommand(exte
nsion)); | |
| 91 } | 86 } |
| 92 | 87 |
| 93 // Populate whitelisted settings. | 88 // Populate whitelisted settings. |
| 94 var settingExtensions = self.runtime.extensions('setting'); | 89 var settingExtensions = self.runtime.extensions('setting'); |
| 95 for (var extension of settingExtensions) { | 90 for (var extension of settingExtensions) { |
| 96 var options = extension.descriptor()['options']; | 91 var options = extension.descriptor()['options']; |
| 97 if (!options || !extension.descriptor()['category']) | 92 if (!options || !extension.descriptor()['category']) |
| 98 continue; | 93 continue; |
| 99 for (var pair of options) | 94 for (var pair of options) |
| 100 this._commands.push(QuickOpen.CommandMenu.createSettingCommand(extension
, pair['title'], pair['value'])); | 95 this._commands.push(QuickOpen.CommandMenu.createSettingCommand(extension
, pair['title'], pair['value'])); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 * @override | 309 * @override |
| 315 * @param {!UI.Context} context | 310 * @param {!UI.Context} context |
| 316 * @param {string} actionId | 311 * @param {string} actionId |
| 317 * @return {boolean} | 312 * @return {boolean} |
| 318 */ | 313 */ |
| 319 handleAction(context, actionId) { | 314 handleAction(context, actionId) { |
| 320 QuickOpen.QuickOpen.show('>'); | 315 QuickOpen.QuickOpen.show('>'); |
| 321 return true; | 316 return true; |
| 322 } | 317 } |
| 323 }; | 318 }; |
| OLD | NEW |