| 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 UI.CommandMenu = class { | 7 QuickOpen.CommandMenu = class { |
| 8 constructor() { | 8 constructor() { |
| 9 this._commands = []; | 9 this._commands = []; |
| 10 this._loadCommands(); | 10 this._loadCommands(); |
| 11 } | 11 } |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * @param {string} category | 14 * @param {string} category |
| 15 * @param {string} keys | 15 * @param {string} keys |
| 16 * @param {string} title | 16 * @param {string} title |
| 17 * @param {string} shortcut | 17 * @param {string} shortcut |
| 18 * @param {function()} executeHandler | 18 * @param {function()} executeHandler |
| 19 * @param {function()=} availableHandler | 19 * @param {function()=} availableHandler |
| 20 * @return {!UI.CommandMenu.Command} | 20 * @return {!QuickOpen.CommandMenu.Command} |
| 21 */ | 21 */ |
| 22 static createCommand(category, keys, title, shortcut, executeHandler, availabl
eHandler) { | 22 static createCommand(category, keys, title, shortcut, executeHandler, availabl
eHandler) { |
| 23 // Separate keys by null character, to prevent fuzzy matching from matching
across them. | 23 // Separate keys by null character, to prevent fuzzy matching from matching
across them. |
| 24 var key = keys.replace(/,/g, '\0'); | 24 var key = keys.replace(/,/g, '\0'); |
| 25 return new UI.CommandMenu.Command(category, title, key, shortcut, executeHan
dler, availableHandler); | 25 return new QuickOpen.CommandMenu.Command(category, title, key, shortcut, exe
cuteHandler, availableHandler); |
| 26 } | 26 } |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * @param {!Runtime.Extension} extension | 29 * @param {!Runtime.Extension} extension |
| 30 * @param {string} title | 30 * @param {string} title |
| 31 * @param {V} value | 31 * @param {V} value |
| 32 * @return {!UI.CommandMenu.Command} | 32 * @return {!QuickOpen.CommandMenu.Command} |
| 33 * @template V | 33 * @template V |
| 34 */ | 34 */ |
| 35 static createSettingCommand(extension, title, value) { | 35 static createSettingCommand(extension, title, value) { |
| 36 var category = extension.descriptor()['category'] || ''; | 36 var category = extension.descriptor()['category'] || ''; |
| 37 var tags = extension.descriptor()['tags'] || ''; | 37 var tags = extension.descriptor()['tags'] || ''; |
| 38 var setting = Common.settings.moduleSetting(extension.descriptor()['settingN
ame']); | 38 var setting = Common.settings.moduleSetting(extension.descriptor()['settingN
ame']); |
| 39 return UI.CommandMenu.createCommand(category, tags, title, '', setting.set.b
ind(setting, value), availableHandler); | 39 return QuickOpen.CommandMenu.createCommand( |
| 40 category, tags, title, '', setting.set.bind(setting, value), availableHa
ndler); |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * @return {boolean} | 43 * @return {boolean} |
| 43 */ | 44 */ |
| 44 function availableHandler() { | 45 function availableHandler() { |
| 45 return setting.get() !== value; | 46 return setting.get() !== value; |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 49 /** | 50 /** |
| 50 * @param {!UI.Action} action | 51 * @param {!UI.Action} action |
| 51 * @return {!UI.CommandMenu.Command} | 52 * @return {!QuickOpen.CommandMenu.Command} |
| 52 */ | 53 */ |
| 53 static createActionCommand(action) { | 54 static createActionCommand(action) { |
| 54 var shortcut = UI.shortcutRegistry.shortcutTitleForAction(action.id()) || ''
; | 55 var shortcut = UI.shortcutRegistry.shortcutTitleForAction(action.id()) || ''
; |
| 55 return UI.CommandMenu.createCommand( | 56 return QuickOpen.CommandMenu.createCommand( |
| 56 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)); |
| 57 } | 58 } |
| 58 | 59 |
| 59 /** | 60 /** |
| 60 * @param {!Runtime.Extension} extension | 61 * @param {!Runtime.Extension} extension |
| 61 * @return {!UI.CommandMenu.Command} | 62 * @return {!QuickOpen.CommandMenu.Command} |
| 62 */ | 63 */ |
| 63 static createRevealPanelCommand(extension) { | 64 static createRevealPanelCommand(extension) { |
| 64 var panelName = extension.descriptor()['name']; | 65 var panelName = extension.descriptor()['name']; |
| 65 var tags = extension.descriptor()['tags'] || ''; | 66 var tags = extension.descriptor()['tags'] || ''; |
| 66 return UI.CommandMenu.createCommand( | 67 return QuickOpen.CommandMenu.createCommand( |
| 67 Common.UIString('Panel'), tags, Common.UIString('Show %s', extension.tit
le()), '', executeHandler, | 68 Common.UIString('Panel'), tags, Common.UIString('Show %s', extension.tit
le()), '', executeHandler, |
| 68 availableHandler); | 69 availableHandler); |
| 69 | 70 |
| 70 /** | 71 /** |
| 71 * @return {boolean} | 72 * @return {boolean} |
| 72 */ | 73 */ |
| 73 function availableHandler() { | 74 function availableHandler() { |
| 74 return true; | 75 return true; |
| 75 } | 76 } |
| 76 | 77 |
| 77 function executeHandler() { | 78 function executeHandler() { |
| 78 UI.viewManager.showView(panelName); | 79 UI.viewManager.showView(panelName); |
| 79 } | 80 } |
| 80 } | 81 } |
| 81 | 82 |
| 82 /** | 83 /** |
| 83 * @param {!Runtime.Extension} extension | 84 * @param {!Runtime.Extension} extension |
| 84 * @return {!UI.CommandMenu.Command} | 85 * @return {!QuickOpen.CommandMenu.Command} |
| 85 */ | 86 */ |
| 86 static createRevealDrawerCommand(extension) { | 87 static createRevealDrawerCommand(extension) { |
| 87 var drawerId = extension.descriptor()['id']; | 88 var drawerId = extension.descriptor()['id']; |
| 88 var executeHandler = UI.viewManager.showView.bind(UI.viewManager, drawerId); | 89 var executeHandler = UI.viewManager.showView.bind(UI.viewManager, drawerId); |
| 89 var tags = extension.descriptor()['tags'] || ''; | 90 var tags = extension.descriptor()['tags'] || ''; |
| 90 return UI.CommandMenu.createCommand( | 91 return QuickOpen.CommandMenu.createCommand( |
| 91 Common.UIString('Drawer'), tags, Common.UIString('Show %s', extension.ti
tle()), '', executeHandler); | 92 Common.UIString('Drawer'), tags, Common.UIString('Show %s', extension.ti
tle()), '', executeHandler); |
| 92 } | 93 } |
| 93 | 94 |
| 94 _loadCommands() { | 95 _loadCommands() { |
| 95 // Populate panels. | 96 // Populate panels. |
| 96 var panelExtensions = self.runtime.extensions(UI.Panel); | 97 var panelExtensions = self.runtime.extensions(UI.Panel); |
| 97 for (var extension of panelExtensions) | 98 for (var extension of panelExtensions) |
| 98 this._commands.push(UI.CommandMenu.createRevealPanelCommand(extension)); | 99 this._commands.push(QuickOpen.CommandMenu.createRevealPanelCommand(extensi
on)); |
| 99 | 100 |
| 100 // Populate drawers. | 101 // Populate drawers. |
| 101 var drawerExtensions = self.runtime.extensions('view'); | 102 var drawerExtensions = self.runtime.extensions('view'); |
| 102 for (var extension of drawerExtensions) { | 103 for (var extension of drawerExtensions) { |
| 103 if (extension.descriptor()['location'] !== 'drawer-view') | 104 if (extension.descriptor()['location'] !== 'drawer-view') |
| 104 continue; | 105 continue; |
| 105 this._commands.push(UI.CommandMenu.createRevealDrawerCommand(extension)); | 106 this._commands.push(QuickOpen.CommandMenu.createRevealDrawerCommand(extens
ion)); |
| 106 } | 107 } |
| 107 | 108 |
| 108 // Populate whitelisted settings. | 109 // Populate whitelisted settings. |
| 109 var settingExtensions = self.runtime.extensions('setting'); | 110 var settingExtensions = self.runtime.extensions('setting'); |
| 110 for (var extension of settingExtensions) { | 111 for (var extension of settingExtensions) { |
| 111 var options = extension.descriptor()['options']; | 112 var options = extension.descriptor()['options']; |
| 112 if (!options || !extension.descriptor()['category']) | 113 if (!options || !extension.descriptor()['category']) |
| 113 continue; | 114 continue; |
| 114 for (var pair of options) | 115 for (var pair of options) |
| 115 this._commands.push(UI.CommandMenu.createSettingCommand(extension, pair[
'title'], pair['value'])); | 116 this._commands.push(QuickOpen.CommandMenu.createSettingCommand(extension
, pair['title'], pair['value'])); |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 | 119 |
| 119 /** | 120 /** |
| 120 * @return {!Array.<!UI.CommandMenu.Command>} | 121 * @return {!Array.<!QuickOpen.CommandMenu.Command>} |
| 121 */ | 122 */ |
| 122 commands() { | 123 commands() { |
| 123 return this._commands; | 124 return this._commands; |
| 124 } | 125 } |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 /** | 128 /** |
| 128 * @unrestricted | 129 * @unrestricted |
| 129 */ | 130 */ |
| 130 UI.CommandMenuDelegate = class extends UI.FilteredListWidget.Delegate { | 131 QuickOpen.CommandMenuDelegate = class extends QuickOpen.FilteredListWidget.Deleg
ate { |
| 131 constructor() { | 132 constructor() { |
| 132 super([]); | 133 super([]); |
| 133 this._commands = []; | 134 this._commands = []; |
| 134 this._appendAvailableCommands(); | 135 this._appendAvailableCommands(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 _appendAvailableCommands() { | 138 _appendAvailableCommands() { |
| 138 var allCommands = UI.commandMenu.commands(); | 139 var allCommands = QuickOpen.commandMenu.commands(); |
| 139 | 140 |
| 140 // Populate whitelisted actions. | 141 // Populate whitelisted actions. |
| 141 var actions = UI.actionRegistry.availableActions(); | 142 var actions = UI.actionRegistry.availableActions(); |
| 142 for (var action of actions) { | 143 for (var action of actions) { |
| 143 if (action.category()) | 144 if (action.category()) |
| 144 this._commands.push(UI.CommandMenu.createActionCommand(action)); | 145 this._commands.push(QuickOpen.CommandMenu.createActionCommand(action)); |
| 145 } | 146 } |
| 146 | 147 |
| 147 for (var command of allCommands) { | 148 for (var command of allCommands) { |
| 148 if (command.available()) | 149 if (command.available()) |
| 149 this._commands.push(command); | 150 this._commands.push(command); |
| 150 } | 151 } |
| 151 | 152 |
| 152 this._commands = this._commands.sort(commandComparator); | 153 this._commands = this._commands.sort(commandComparator); |
| 153 | 154 |
| 154 /** | 155 /** |
| 155 * @param {!UI.CommandMenu.Command} left | 156 * @param {!QuickOpen.CommandMenu.Command} left |
| 156 * @param {!UI.CommandMenu.Command} right | 157 * @param {!QuickOpen.CommandMenu.Command} right |
| 157 * @return {number} | 158 * @return {number} |
| 158 */ | 159 */ |
| 159 function commandComparator(left, right) { | 160 function commandComparator(left, right) { |
| 160 var cats = left.category().compareTo(right.category()); | 161 var cats = left.category().compareTo(right.category()); |
| 161 return cats ? cats : left.title().compareTo(right.title()); | 162 return cats ? cats : left.title().compareTo(right.title()); |
| 162 } | 163 } |
| 163 } | 164 } |
| 164 | 165 |
| 165 /** | 166 /** |
| 166 * @override | 167 * @override |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 * @override | 209 * @override |
| 209 * @param {number} itemIndex | 210 * @param {number} itemIndex |
| 210 * @param {string} query | 211 * @param {string} query |
| 211 * @param {!Element} titleElement | 212 * @param {!Element} titleElement |
| 212 * @param {!Element} subtitleElement | 213 * @param {!Element} subtitleElement |
| 213 */ | 214 */ |
| 214 renderItem(itemIndex, query, titleElement, subtitleElement) { | 215 renderItem(itemIndex, query, titleElement, subtitleElement) { |
| 215 var command = this._commands[itemIndex]; | 216 var command = this._commands[itemIndex]; |
| 216 titleElement.removeChildren(); | 217 titleElement.removeChildren(); |
| 217 var tagElement = titleElement.createChild('span', 'tag'); | 218 var tagElement = titleElement.createChild('span', 'tag'); |
| 218 var index = String.hashCode(command.category()) % UI.CommandMenuDelegate.Mat
erialPaletteColors.length; | 219 var index = String.hashCode(command.category()) % QuickOpen.CommandMenuDeleg
ate.MaterialPaletteColors.length; |
| 219 tagElement.style.backgroundColor = UI.CommandMenuDelegate.MaterialPaletteCol
ors[index]; | 220 tagElement.style.backgroundColor = QuickOpen.CommandMenuDelegate.MaterialPal
etteColors[index]; |
| 220 tagElement.textContent = command.category(); | 221 tagElement.textContent = command.category(); |
| 221 titleElement.createTextChild(command.title()); | 222 titleElement.createTextChild(command.title()); |
| 222 this.highlightRanges(titleElement, query); | 223 this.highlightRanges(titleElement, query); |
| 223 subtitleElement.textContent = command.shortcut(); | 224 subtitleElement.textContent = command.shortcut(); |
| 224 } | 225 } |
| 225 | 226 |
| 226 /** | 227 /** |
| 227 * @override | 228 * @override |
| 228 * @param {?number} itemIndex | 229 * @param {?number} itemIndex |
| 229 * @param {string} promptValue | 230 * @param {string} promptValue |
| (...skipping 14 matching lines...) Expand all Loading... |
| 244 | 245 |
| 245 /** | 246 /** |
| 246 * @override | 247 * @override |
| 247 * @return {boolean} | 248 * @return {boolean} |
| 248 */ | 249 */ |
| 249 renderMonospace() { | 250 renderMonospace() { |
| 250 return false; | 251 return false; |
| 251 } | 252 } |
| 252 }; | 253 }; |
| 253 | 254 |
| 254 UI.CommandMenuDelegate.MaterialPaletteColors = [ | 255 QuickOpen.CommandMenuDelegate.MaterialPaletteColors = [ |
| 255 '#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#03A9F4', '#00BCD4', '
#009688', '#4CAF50', '#8BC34A', | 256 '#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#03A9F4', '#00BCD4', '
#009688', '#4CAF50', '#8BC34A', |
| 256 '#CDDC39', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B' | 257 '#CDDC39', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B' |
| 257 ]; | 258 ]; |
| 258 | 259 |
| 259 /** | 260 /** |
| 260 * @unrestricted | 261 * @unrestricted |
| 261 */ | 262 */ |
| 262 UI.CommandMenu.Command = class { | 263 QuickOpen.CommandMenu.Command = class { |
| 263 /** | 264 /** |
| 264 * @param {string} category | 265 * @param {string} category |
| 265 * @param {string} title | 266 * @param {string} title |
| 266 * @param {string} key | 267 * @param {string} key |
| 267 * @param {string} shortcut | 268 * @param {string} shortcut |
| 268 * @param {function()} executeHandler | 269 * @param {function()} executeHandler |
| 269 * @param {function()=} availableHandler | 270 * @param {function()=} availableHandler |
| 270 */ | 271 */ |
| 271 constructor(category, title, key, shortcut, executeHandler, availableHandler)
{ | 272 constructor(category, title, key, shortcut, executeHandler, availableHandler)
{ |
| 272 this._category = category; | 273 this._category = category; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 available() { | 312 available() { |
| 312 return this._availableHandler ? this._availableHandler() : true; | 313 return this._availableHandler ? this._availableHandler() : true; |
| 313 } | 314 } |
| 314 | 315 |
| 315 execute() { | 316 execute() { |
| 316 this._executeHandler(); | 317 this._executeHandler(); |
| 317 } | 318 } |
| 318 }; | 319 }; |
| 319 | 320 |
| 320 | 321 |
| 321 /** @type {!UI.CommandMenu} */ | 322 /** @type {!QuickOpen.CommandMenu} */ |
| 322 UI.commandMenu = new UI.CommandMenu(); | 323 QuickOpen.commandMenu = new QuickOpen.CommandMenu(); |
| 323 | 324 |
| 324 /** | 325 /** |
| 325 * @implements {UI.ActionDelegate} | 326 * @implements {UI.ActionDelegate} |
| 326 * @unrestricted | 327 * @unrestricted |
| 327 */ | 328 */ |
| 328 UI.CommandMenu.ShowActionDelegate = class { | 329 QuickOpen.CommandMenu.ShowActionDelegate = class { |
| 329 /** | 330 /** |
| 330 * @override | 331 * @override |
| 331 * @param {!UI.Context} context | 332 * @param {!UI.Context} context |
| 332 * @param {string} actionId | 333 * @param {string} actionId |
| 333 * @return {boolean} | 334 * @return {boolean} |
| 334 */ | 335 */ |
| 335 handleAction(context, actionId) { | 336 handleAction(context, actionId) { |
| 336 new UI.FilteredListWidget(new UI.CommandMenuDelegate()).showAsDialog(); | 337 new QuickOpen.FilteredListWidget(new QuickOpen.CommandMenuDelegate()).showAs
Dialog(); |
| 337 InspectorFrontendHost.bringToFront(); | 338 InspectorFrontendHost.bringToFront(); |
| 338 return true; | 339 return true; |
| 339 } | 340 } |
| 340 }; | 341 }; |
| OLD | NEW |