Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 * @fileoverview Element which shows context menus and handles keyboard | 6 * @fileoverview Element which shows context menus and handles keyboard |
| 7 * shortcuts. | 7 * shortcuts. |
| 8 */ | 8 */ |
| 9 cr.define('bookmarks', function() { | 9 cr.define('bookmarks', function() { |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 /** @private {Object<Command, string>} */ | 51 /** @private {Object<Command, string>} */ |
| 52 this.shortcuts_ = {}; | 52 this.shortcuts_ = {}; |
| 53 this.shortcuts_[Command.EDIT] = cr.isMac ? 'enter' : 'f2'; | 53 this.shortcuts_[Command.EDIT] = cr.isMac ? 'enter' : 'f2'; |
| 54 this.shortcuts_[Command.COPY] = cr.isMac ? 'meta+c' : 'ctrl+c'; | 54 this.shortcuts_[Command.COPY] = cr.isMac ? 'meta+c' : 'ctrl+c'; |
| 55 this.shortcuts_[Command.DELETE] = | 55 this.shortcuts_[Command.DELETE] = |
| 56 cr.isMac ? 'delete backspace' : 'delete'; | 56 cr.isMac ? 'delete backspace' : 'delete'; |
| 57 this.shortcuts_[Command.OPEN_NEW_TAB] = | 57 this.shortcuts_[Command.OPEN_NEW_TAB] = |
| 58 cr.isMac ? 'meta+enter' : 'ctrl+enter'; | 58 cr.isMac ? 'meta+enter' : 'ctrl+enter'; |
| 59 this.shortcuts_[Command.OPEN_NEW_WINDOW] = 'shift+enter'; | 59 this.shortcuts_[Command.OPEN_NEW_WINDOW] = 'shift+enter'; |
| 60 this.shortcuts_[Command.OPEN] = cr.isMac ? 'meta+down' : 'enter'; | 60 this.shortcuts_[Command.OPEN] = cr.isMac ? 'meta+down' : 'enter'; |
| 61 this.shortcuts_[Command.UNDO] = | |
| 62 cr.isMac ? 'meta+z' : 'ctrl+z ctrl+shift+z'; | |
|
tsergeant
2017/05/23 07:34:02
Is ctrl-shift-z meant to be REDO? That's what happ
calamity
2017/05/24 07:44:14
Oops, fixed.
| |
| 63 this.shortcuts_[Command.REDO] = cr.isMac ? 'meta+shift+z' : 'ctrl+y'; | |
| 61 }, | 64 }, |
| 62 | 65 |
| 63 detached: function() { | 66 detached: function() { |
| 64 CommandManager.instance_ = null; | 67 CommandManager.instance_ = null; |
| 65 document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_); | 68 document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_); |
| 66 document.removeEventListener('keydown', this.boundOnKeydown_); | 69 document.removeEventListener('keydown', this.boundOnKeydown_); |
| 67 }, | 70 }, |
| 68 | 71 |
| 69 /** | 72 /** |
| 70 * Display the command context menu at (|x|, |y|) in window co-ordinates. | 73 * Display the command context menu at (|x|, |y|) in window co-ordinates. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 100 * Commands which appear in the context menu should be implemented | 103 * Commands which appear in the context menu should be implemented |
| 101 * separately using `isCommandVisible_` and `isCommandEnabled_`. | 104 * separately using `isCommandVisible_` and `isCommandEnabled_`. |
| 102 * @param {Command} command | 105 * @param {Command} command |
| 103 * @param {!Set<string>} itemIds | 106 * @param {!Set<string>} itemIds |
| 104 * @return {boolean} | 107 * @return {boolean} |
| 105 */ | 108 */ |
| 106 canExecute: function(command, itemIds) { | 109 canExecute: function(command, itemIds) { |
| 107 switch (command) { | 110 switch (command) { |
| 108 case Command.OPEN: | 111 case Command.OPEN: |
| 109 return itemIds.size > 0; | 112 return itemIds.size > 0; |
| 113 case Command.UNDO: | |
| 114 case Command.REDO: | |
| 115 return true; | |
| 110 default: | 116 default: |
| 111 return this.isCommandVisible_(command, itemIds) && | 117 return this.isCommandVisible_(command, itemIds) && |
| 112 this.isCommandEnabled_(command, itemIds); | 118 this.isCommandEnabled_(command, itemIds); |
| 113 } | 119 } |
| 114 }, | 120 }, |
| 115 | 121 |
| 116 /** | 122 /** |
| 117 * @param {Command} command | 123 * @param {Command} command |
| 118 * @param {!Set<string>} itemIds | 124 * @param {!Set<string>} itemIds |
| 119 * @return {boolean} True if the command should be visible in the context | 125 * @return {boolean} True if the command should be visible in the context |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 chrome.bookmarkManagerPrivate.copy(idList, function() { | 177 chrome.bookmarkManagerPrivate.copy(idList, function() { |
| 172 // TODO(jiaxi): Add toast later. | 178 // TODO(jiaxi): Add toast later. |
| 173 }); | 179 }); |
| 174 break; | 180 break; |
| 175 case Command.DELETE: | 181 case Command.DELETE: |
| 176 chrome.bookmarkManagerPrivate.removeTrees( | 182 chrome.bookmarkManagerPrivate.removeTrees( |
| 177 Array.from(this.minimizeDeletionSet_(itemIds)), function() { | 183 Array.from(this.minimizeDeletionSet_(itemIds)), function() { |
| 178 // TODO(jiaxi): Add toast later. | 184 // TODO(jiaxi): Add toast later. |
| 179 }); | 185 }); |
| 180 break; | 186 break; |
| 187 case Command.UNDO: | |
| 188 chrome.bookmarkManagerPrivate.undo(); | |
| 189 break; | |
| 190 case Command.REDO: | |
| 191 chrome.bookmarkManagerPrivate.redo(); | |
| 192 break; | |
| 181 case Command.OPEN_NEW_TAB: | 193 case Command.OPEN_NEW_TAB: |
| 182 case Command.OPEN_NEW_WINDOW: | 194 case Command.OPEN_NEW_WINDOW: |
| 183 case Command.OPEN_INCOGNITO: | 195 case Command.OPEN_INCOGNITO: |
| 184 this.openUrls_(this.expandUrls_(itemIds), command); | 196 this.openUrls_(this.expandUrls_(itemIds), command); |
| 185 break; | 197 break; |
| 186 case Command.OPEN: | 198 case Command.OPEN: |
| 187 var isFolder = itemIds.size == 1 && | 199 var isFolder = itemIds.size == 1 && |
| 188 this.containsMatchingNode_(itemIds, function(node) { | 200 this.containsMatchingNode_(itemIds, function(node) { |
| 189 return !node.url; | 201 return !node.url; |
| 190 }); | 202 }); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 | 421 |
| 410 /** @return {!bookmarks.CommandManager} */ | 422 /** @return {!bookmarks.CommandManager} */ |
| 411 CommandManager.getInstance = function() { | 423 CommandManager.getInstance = function() { |
| 412 return assert(CommandManager.instance_); | 424 return assert(CommandManager.instance_); |
| 413 }; | 425 }; |
| 414 | 426 |
| 415 return { | 427 return { |
| 416 CommandManager: CommandManager, | 428 CommandManager: CommandManager, |
| 417 }; | 429 }; |
| 418 }); | 430 }); |
| OLD | NEW |