Chromium Code Reviews| Index: chrome/browser/resources/task_manager/main.js |
| diff --git a/chrome/browser/resources/task_manager/main.js b/chrome/browser/resources/task_manager/main.js |
| index 6dbed2bfba2a2cc7e90f222da37a450adcb92a01..ba6c5b6e04376210329a903d59810a79ce6679b7 100644 |
| --- a/chrome/browser/resources/task_manager/main.js |
| +++ b/chrome/browser/resources/task_manager/main.js |
| @@ -122,6 +122,14 @@ TaskManager.prototype = { |
| }, |
| /** |
| + * Sends command to activate a page. |
| + * @public |
| + */ |
| + activatePage: function (uniqueId) { |
| + chrome.send('activatePage', [uniqueId]); |
| + }, |
| + |
| + /** |
| * Initializes taskmanager. |
| * @public |
| */ |
| @@ -263,20 +271,26 @@ TaskManager.prototype = { |
| this.table_menu_commands_ = []; |
| this.tableContextMenu_ = this.document_.createElement('menu'); |
| - // Creates command element to receive event. |
| - var command = this.document_.createElement('command'); |
| - command.id = 'tableContextMenu-inspect'; |
| - cr.ui.Command.decorate(command); |
| - this.table_menu_commands_[command.id] = command; |
| - this.commandsElement_.appendChild(command); |
| - |
| - // Creates menuitem element. |
| - var item = this.document_.createElement('menuitem'); |
| - item.command = command; |
| - command.menuitem = item; |
| - var localized_label = localStrings.getString('INSPECT'); |
| - item.textContent = (localized_label != "") ? localized_label : "Inspect"; |
| - this.tableContextMenu_.appendChild(item); |
| + var addMenuItem = function (tm, command_id, string_id, default_label) { |
| + // Creates command element to receive event. |
| + var command = tm.document_.createElement('command'); |
| + command.id = 'tableContextMenu-' + command_id; |
| + cr.ui.Command.decorate(command); |
| + tm.table_menu_commands_[command.id] = command; |
| + tm.commandsElement_.appendChild(command); |
| + |
| + // Creates menuitem element. |
| + var item = tm.document_.createElement('menuitem'); |
| + item.command = command; |
| + command.menuitem = item; |
| + var localized_label = localStrings.getString(string_id); |
| + item.textContent |
|
mazda
2011/11/09 07:16:14
item.textContent = localized_label || default_labe
yoshiki
2011/11/10 05:09:47
Done.
|
| + = (localized_label != "") ? localized_label : default_label; |
| + tm.tableContextMenu_.appendChild(item); |
| + }; |
| + |
| + addMenuItem(this, 'inspect', 'INSPECT', "Inspect"); |
| + addMenuItem(this, 'activate', 'ACTIVATE', "Activate"); |
| this.document_.body.appendChild(this.tableContextMenu_); |
| cr.ui.Menu.decorate(this.tableContextMenu_); |
| @@ -349,6 +363,10 @@ TaskManager.prototype = { |
| cr.ui.contextMenuHandler.addContextMenuProperty(label); |
| label.contextMenu = this.tableContextMenu_; |
| + label.addEventListener('dblclick', (function(uniqueId) { |
| + this.activatePage(uniqueId); |
| + }).bind(this, entry['uniqueId'][i])); |
| + |
| label.data = entry; |
| label.index_in_group = i; |
| } else { |
| @@ -406,10 +424,16 @@ TaskManager.prototype = { |
| if (command.id.substr(0, 18) == 'columnContextMenu-') { |
| console.log(command.id.substr(18)); |
| this.onColumnContextMenu_(command.id.substr(18), command); |
| - } else if (command.id == 'tableContextMenu-inspect') { |
| - var contextMenuTarget = this.currentContextMenuTarget_; |
| - if (contextMenuTarget) { |
| - this.inspect(contextMenuTarget); |
| + } else if (command.id.substr(0, 17) == 'tableContextMenu-') { |
|
mazda
2011/11/09 07:16:14
Please make a constant variable for 'tableContextM
yoshiki
2011/11/10 05:09:47
Done.
|
| + var target_unique_id = this.currentContextMenuTarget_; |
| + var sub_command = command.id.substr(17); |
| + |
| + if (target_unique_id) { |
|
mazda
2011/11/09 07:16:14
if (!target_unique_id)
return;
if (sub_command
yoshiki
2011/11/10 05:09:47
Done.
|
| + if (sub_command = 'inspect') |
| + this.inspect(target_unique_id); |
| + else if (sub_command == 'activate') |
| + this.activate(target_unique_id); |
| + |
| this.currentContextMenuTarget_ = undefined; |
| } |
| } |
| @@ -424,12 +448,13 @@ TaskManager.prototype = { |
| * will be replaced when it is refleshed. |
| */ |
| onTableContextMenuOpened_: function (e) { |
| - var command = this.table_menu_commands_['tableContextMenu-inspect']; |
| - var menuItem = command.menuitem; |
| + var mc = this.table_menu_commands_; |
| + var inspect_menuitem = mc['tableContextMenu-inspect'].menuitem; |
| + var activate_menuitem = mc['tableContextMenu-activate'].menuitem; |
| // Disabled by default. |
| - menuItem.disabled = true; |
| - this.currentContextMenuTarget_ = undefined; |
| + inspect_menuitem.disabled = true; |
| + activate_menuitem.disabled = true; |
| var target = e.target; |
| var classes = target.classList; |
| @@ -442,14 +467,18 @@ TaskManager.prototype = { |
| if (!target) |
| return; |
| + // Sets the uniqueId for current target page under the mouse corsor. |
| + this.currentContextMenuTarget_ = target.data['uniqueId'][index_in_group]; |
| + |
| var index_in_group = target.index_in_group; |
| - var canInspect = target.data['canInspect'][index_in_group]; |
| - if (canInspect) { |
| - menuItem.disabled = false; |
| - this.currentContextMenuTarget_ = |
| - target.data['uniqueId'][index_in_group]; |
| - } |
| + // Enables if the page can be inspected. |
| + if (target.data['canInspect'][index_in_group]) |
| + inspect_menuitem.disabled = false; |
| + |
| + // Enables if the page can be activated. |
| + if (target.data['canActivate'][index_in_group]) |
| + activate_menuitem.disabled = false; |
| }, |
| onColumnContextMenu_: function(id, command) { |