| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 */ | 7 */ |
| 8 WebInspector.CommandMenu = function() | 8 WebInspector.CommandMenu = function() |
| 9 { | 9 { |
| 10 this._commands = []; | 10 this._commands = []; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 * @constructor | 48 * @constructor |
| 49 * @extends {WebInspector.FilteredListWidget.Delegate} | 49 * @extends {WebInspector.FilteredListWidget.Delegate} |
| 50 */ | 50 */ |
| 51 WebInspector.CommandMenuDelegate = function() | 51 WebInspector.CommandMenuDelegate = function() |
| 52 { | 52 { |
| 53 WebInspector.FilteredListWidget.Delegate.call(this, []); | 53 WebInspector.FilteredListWidget.Delegate.call(this, []); |
| 54 this._commands = []; | 54 this._commands = []; |
| 55 this._appendAvailableCommands(); | 55 this._appendAvailableCommands(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 WebInspector.CommandMenuDelegate.MaterialPaletteColors = ["#F44336", "#E91E63",
"#9C27B0", "#673AB7", "#3F51B5", "#03A9F4", "#00BCD4", "#009688", "#4CAF50", "#8
BC34A", "#CDDC39", "#FFC107", "#FF9800", "#FF5722", "#795548", "#9E9E9E", "#607D
8B"]; |
| 59 |
| 58 WebInspector.CommandMenuDelegate.prototype = { | 60 WebInspector.CommandMenuDelegate.prototype = { |
| 59 _appendAvailableCommands: function() | 61 _appendAvailableCommands: function() |
| 60 { | 62 { |
| 61 var allCommands = WebInspector.commandMenu.commands(); | 63 var allCommands = WebInspector.commandMenu.commands(); |
| 62 | 64 |
| 63 // Populate whitelisted actions. | 65 // Populate whitelisted actions. |
| 64 var actions = WebInspector.actionRegistry.availableActions(); | 66 var actions = WebInspector.actionRegistry.availableActions(); |
| 65 for (var action of actions) { | 67 for (var action of actions) { |
| 66 if (action.category()) | 68 if (action.category()) |
| 67 this._commands.push(WebInspector.CommandMenu.createActionCommand
(action)); | 69 this._commands.push(WebInspector.CommandMenu.createActionCommand
(action)); |
| 68 } | 70 } |
| 69 | 71 |
| 70 for (var command of allCommands) { | 72 for (var command of allCommands) { |
| 71 if (command.available()) | 73 if (command.available()) |
| 72 this._commands.push(command); | 74 this._commands.push(command); |
| 73 } | 75 } |
| 74 | 76 |
| 75 this._commands = this._commands.sort(commandComparator); | 77 this._commands = this._commands.sort(commandComparator); |
| 76 | 78 |
| 77 /** | 79 /** |
| 78 * @param {!WebInspector.CommandMenu.Command} left | 80 * @param {!WebInspector.CommandMenu.Command} left |
| 79 * @param {!WebInspector.CommandMenu.Command} right | 81 * @param {!WebInspector.CommandMenu.Command} right |
| 80 * @return {number} | 82 * @return {number} |
| 81 */ | 83 */ |
| 82 function commandComparator(left, right) | 84 function commandComparator(left, right) |
| 83 { | 85 { |
| 84 return left.title().compareTo(right.title()); | 86 var cats = left.category().compareTo(right.category()); |
| 87 return cats ? cats : left.title().compareTo(right.title()); |
| 85 } | 88 } |
| 86 }, | 89 }, |
| 87 | 90 |
| 88 /** | 91 /** |
| 89 * @override | 92 * @override |
| 90 * @return {number} | 93 * @return {number} |
| 91 */ | 94 */ |
| 92 itemCount: function() | 95 itemCount: function() |
| 93 { | 96 { |
| 94 return this._commands.length; | 97 return this._commands.length; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 115 var command = this._commands[itemIndex]; | 118 var command = this._commands[itemIndex]; |
| 116 var opcodes = WebInspector.Diff.charDiff(query.toLowerCase(), command.ti
tle().toLowerCase()); | 119 var opcodes = WebInspector.Diff.charDiff(query.toLowerCase(), command.ti
tle().toLowerCase()); |
| 117 var score = 0; | 120 var score = 0; |
| 118 // Score longer sequences higher. | 121 // Score longer sequences higher. |
| 119 for (var i = 0; i < opcodes.length; ++i) { | 122 for (var i = 0; i < opcodes.length; ++i) { |
| 120 if (opcodes[i][0] === WebInspector.Diff.Operation.Equal) | 123 if (opcodes[i][0] === WebInspector.Diff.Operation.Equal) |
| 121 score += opcodes[i][1].length * opcodes[i][1].length; | 124 score += opcodes[i][1].length * opcodes[i][1].length; |
| 122 } | 125 } |
| 123 | 126 |
| 124 // Score panel/drawer reveals above regular actions. | 127 // Score panel/drawer reveals above regular actions. |
| 125 if (command.title().startsWith("Panel")) | 128 if (command.category().startsWith("Panel")) |
| 126 score += 2; | 129 score += 2; |
| 127 else if (command.title().startsWith("Drawer")) | 130 else if (command.category().startsWith("Drawer")) |
| 128 score += 1; | 131 score += 1; |
| 129 | 132 |
| 130 return score; | 133 return score; |
| 131 }, | 134 }, |
| 132 | 135 |
| 133 /** | 136 /** |
| 134 * @override | 137 * @override |
| 135 * @param {number} itemIndex | 138 * @param {number} itemIndex |
| 136 * @param {string} query | 139 * @param {string} query |
| 137 * @param {!Element} titleElement | 140 * @param {!Element} titleElement |
| 138 * @param {!Element} subtitleElement | 141 * @param {!Element} subtitleElement |
| 139 */ | 142 */ |
| 140 renderItem: function(itemIndex, query, titleElement, subtitleElement) | 143 renderItem: function(itemIndex, query, titleElement, subtitleElement) |
| 141 { | 144 { |
| 142 var command = this._commands[itemIndex]; | 145 var command = this._commands[itemIndex]; |
| 143 titleElement.textContent = command.title(); | 146 titleElement.removeChildren(); |
| 147 var tagElement = titleElement.createChild("span", "tag"); |
| 148 var index = String.hashCode(command.category()) % WebInspector.CommandMe
nuDelegate.MaterialPaletteColors.length; |
| 149 tagElement.style.backgroundColor = WebInspector.CommandMenuDelegate.Mate
rialPaletteColors[index]; |
| 150 tagElement.textContent = command.category(); |
| 151 titleElement.createTextChild(command.title()); |
| 144 this.highlightRanges(titleElement, query); | 152 this.highlightRanges(titleElement, query); |
| 145 subtitleElement.textContent = command.shortcut(); | 153 subtitleElement.textContent = command.shortcut(); |
| 146 }, | 154 }, |
| 147 | 155 |
| 148 /** | 156 /** |
| 149 * @override | 157 * @override |
| 150 * @param {?number} itemIndex | 158 * @param {?number} itemIndex |
| 151 * @param {string} promptValue | 159 * @param {string} promptValue |
| 152 */ | 160 */ |
| 153 selectItem: function(itemIndex, promptValue) | 161 selectItem: function(itemIndex, promptValue) |
| 154 { | 162 { |
| 155 this._commands[itemIndex].execute(); | 163 this._commands[itemIndex].execute(); |
| 156 }, | 164 }, |
| 157 | 165 |
| 158 /** | 166 /** |
| 159 * @override | 167 * @override |
| 160 * @return {boolean} | 168 * @return {boolean} |
| 161 */ | 169 */ |
| 162 caseSensitive: function() | 170 caseSensitive: function() |
| 163 { | 171 { |
| 164 return false; | 172 return false; |
| 165 }, | 173 }, |
| 166 | 174 |
| 175 /** |
| 176 * @override |
| 177 * @return {boolean} |
| 178 */ |
| 179 renderMonospace: function() |
| 180 { |
| 181 return false; |
| 182 }, |
| 183 |
| 167 __proto__: WebInspector.FilteredListWidget.Delegate.prototype | 184 __proto__: WebInspector.FilteredListWidget.Delegate.prototype |
| 168 } | 185 } |
| 169 | 186 |
| 170 /** | 187 /** |
| 171 * @constructor | 188 * @constructor |
| 189 * @param {string} category |
| 172 * @param {string} title | 190 * @param {string} title |
| 173 * @param {string} key | 191 * @param {string} key |
| 174 * @param {string} shortcut | 192 * @param {string} shortcut |
| 175 * @param {function()} executeHandler | 193 * @param {function()} executeHandler |
| 176 * @param {function()=} availableHandler | 194 * @param {function()=} availableHandler |
| 177 */ | 195 */ |
| 178 WebInspector.CommandMenu.Command = function(title, key, shortcut, executeHandler
, availableHandler) | 196 WebInspector.CommandMenu.Command = function(category, title, key, shortcut, exec
uteHandler, availableHandler) |
| 179 { | 197 { |
| 198 this._category = category; |
| 180 this._title = title; | 199 this._title = title; |
| 181 this._key = title + "\0" + key; | 200 this._key = category + "\0" + title + "\0" + key; |
| 182 this._shortcut = shortcut; | 201 this._shortcut = shortcut; |
| 183 this._executeHandler = executeHandler; | 202 this._executeHandler = executeHandler; |
| 184 this._availableHandler = availableHandler; | 203 this._availableHandler = availableHandler; |
| 185 } | 204 } |
| 186 | 205 |
| 187 WebInspector.CommandMenu.Command.prototype = { | 206 WebInspector.CommandMenu.Command.prototype = { |
| 188 /** | 207 /** |
| 189 * @return {string} | 208 * @return {string} |
| 190 */ | 209 */ |
| 210 category: function() |
| 211 { |
| 212 return this._category; |
| 213 }, |
| 214 |
| 215 /** |
| 216 * @return {string} |
| 217 */ |
| 191 title: function() | 218 title: function() |
| 192 { | 219 { |
| 193 return this._title; | 220 return this._title; |
| 194 }, | 221 }, |
| 195 | 222 |
| 196 /** | 223 /** |
| 197 * @return {string} | 224 * @return {string} |
| 198 */ | 225 */ |
| 199 key: function() | 226 key: function() |
| 200 { | 227 { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 228 * @param {string} keys | 255 * @param {string} keys |
| 229 * @param {string} title | 256 * @param {string} title |
| 230 * @param {string} shortcut | 257 * @param {string} shortcut |
| 231 * @param {function()} executeHandler | 258 * @param {function()} executeHandler |
| 232 * @param {function()=} availableHandler | 259 * @param {function()=} availableHandler |
| 233 * @return {!WebInspector.CommandMenu.Command} | 260 * @return {!WebInspector.CommandMenu.Command} |
| 234 */ | 261 */ |
| 235 WebInspector.CommandMenu.createCommand = function(category, keys, title, shortcu
t, executeHandler, availableHandler) | 262 WebInspector.CommandMenu.createCommand = function(category, keys, title, shortcu
t, executeHandler, availableHandler) |
| 236 { | 263 { |
| 237 // Separate keys by null character, to prevent fuzzy matching from matching
across them. | 264 // Separate keys by null character, to prevent fuzzy matching from matching
across them. |
| 238 var key = keys ? keys.split(",").join("\0") : ""; | 265 var key = keys.replace(/,/g, "\0"); |
| 239 title = category ? WebInspector.UIString("%s: %s", category, title) : title; | 266 return new WebInspector.CommandMenu.Command(category, title, key, shortcut,
executeHandler, availableHandler); |
| 240 return new WebInspector.CommandMenu.Command(title, key, shortcut, executeHan
dler, availableHandler); | |
| 241 } | 267 } |
| 242 | 268 |
| 243 /** | 269 /** |
| 244 * @param {!Runtime.Extension} extension | 270 * @param {!Runtime.Extension} extension |
| 245 * @param {string} title | 271 * @param {string} title |
| 246 * @param {V} value | 272 * @param {V} value |
| 247 * @return {!WebInspector.CommandMenu.Command} | 273 * @return {!WebInspector.CommandMenu.Command} |
| 248 * @template V | 274 * @template V |
| 249 */ | 275 */ |
| 250 WebInspector.CommandMenu.createSettingCommand = function(extension, title, value
) | 276 WebInspector.CommandMenu.createSettingCommand = function(extension, title, value
) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 348 |
| 323 WebInspector.CommandMenu.ShowActionDelegate.prototype = { | 349 WebInspector.CommandMenu.ShowActionDelegate.prototype = { |
| 324 /** | 350 /** |
| 325 * @override | 351 * @override |
| 326 * @param {!WebInspector.Context} context | 352 * @param {!WebInspector.Context} context |
| 327 * @param {string} actionId | 353 * @param {string} actionId |
| 328 * @return {boolean} | 354 * @return {boolean} |
| 329 */ | 355 */ |
| 330 handleAction: function(context, actionId) | 356 handleAction: function(context, actionId) |
| 331 { | 357 { |
| 332 new WebInspector.FilteredListWidget(new WebInspector.CommandMenuDelegate
(), false).showAsDialog(); | 358 new WebInspector.FilteredListWidget(new WebInspector.CommandMenuDelegate
()).showAsDialog(); |
| 333 InspectorFrontendHost.bringToFront(); | 359 InspectorFrontendHost.bringToFront(); |
| 334 return true; | 360 return true; |
| 335 } | 361 } |
| 336 } | 362 } |
| 337 | 363 |
| OLD | NEW |