| 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 26 matching lines...) Expand all Loading... |
| 37 }, | 37 }, |
| 38 | 38 |
| 39 attached: function() { | 39 attached: function() { |
| 40 assert(CommandManager.instance_ == null); | 40 assert(CommandManager.instance_ == null); |
| 41 CommandManager.instance_ = this; | 41 CommandManager.instance_ = this; |
| 42 | 42 |
| 43 /** @private {function(!Event)} */ | 43 /** @private {function(!Event)} */ |
| 44 this.boundOnOpenItemMenu_ = this.onOpenItemMenu_.bind(this); | 44 this.boundOnOpenItemMenu_ = this.onOpenItemMenu_.bind(this); |
| 45 document.addEventListener('open-item-menu', this.boundOnOpenItemMenu_); | 45 document.addEventListener('open-item-menu', this.boundOnOpenItemMenu_); |
| 46 | 46 |
| 47 /** @private {function()} */ |
| 48 this.boundOnCommandUndo_ = function() { |
| 49 this.handle(Command.UNDO, new Set()); |
| 50 }.bind(this); |
| 51 document.addEventListener('command-undo', this.boundOnCommandUndo_); |
| 52 |
| 47 /** @private {function(!Event)} */ | 53 /** @private {function(!Event)} */ |
| 48 this.boundOnKeydown_ = this.onKeydown_.bind(this); | 54 this.boundOnKeydown_ = this.onKeydown_.bind(this); |
| 49 document.addEventListener('keydown', this.boundOnKeydown_); | 55 document.addEventListener('keydown', this.boundOnKeydown_); |
| 50 | 56 |
| 51 /** @private {Object<Command, string>} */ | 57 /** @private {Object<Command, string>} */ |
| 52 this.shortcuts_ = {}; | 58 this.shortcuts_ = {}; |
| 53 this.shortcuts_[Command.EDIT] = cr.isMac ? 'enter' : 'f2'; | 59 this.shortcuts_[Command.EDIT] = cr.isMac ? 'enter' : 'f2'; |
| 54 this.shortcuts_[Command.COPY] = cr.isMac ? 'meta+c' : 'ctrl+c'; | 60 this.shortcuts_[Command.COPY] = cr.isMac ? 'meta+c' : 'ctrl+c'; |
| 55 this.shortcuts_[Command.DELETE] = | 61 this.shortcuts_[Command.DELETE] = |
| 56 cr.isMac ? 'delete backspace' : 'delete'; | 62 cr.isMac ? 'delete backspace' : 'delete'; |
| 57 this.shortcuts_[Command.OPEN_NEW_TAB] = | 63 this.shortcuts_[Command.OPEN_NEW_TAB] = |
| 58 cr.isMac ? 'meta+enter' : 'ctrl+enter'; | 64 cr.isMac ? 'meta+enter' : 'ctrl+enter'; |
| 59 this.shortcuts_[Command.OPEN_NEW_WINDOW] = 'shift+enter'; | 65 this.shortcuts_[Command.OPEN_NEW_WINDOW] = 'shift+enter'; |
| 60 this.shortcuts_[Command.OPEN] = cr.isMac ? 'meta+down' : 'enter'; | 66 this.shortcuts_[Command.OPEN] = cr.isMac ? 'meta+down' : 'enter'; |
| 61 this.shortcuts_[Command.UNDO] = cr.isMac ? 'meta+z' : 'ctrl+z'; | 67 this.shortcuts_[Command.UNDO] = cr.isMac ? 'meta+z' : 'ctrl+z'; |
| 62 this.shortcuts_[Command.REDO] = | 68 this.shortcuts_[Command.REDO] = |
| 63 cr.isMac ? 'meta+shift+z' : 'ctrl+y ctrl+shift+z'; | 69 cr.isMac ? 'meta+shift+z' : 'ctrl+y ctrl+shift+z'; |
| 64 }, | 70 }, |
| 65 | 71 |
| 66 detached: function() { | 72 detached: function() { |
| 67 CommandManager.instance_ = null; | 73 CommandManager.instance_ = null; |
| 68 document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_); | 74 document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_); |
| 75 document.removeEventListener('command-undo', this.boundOnCommandUndo_); |
| 69 document.removeEventListener('keydown', this.boundOnKeydown_); | 76 document.removeEventListener('keydown', this.boundOnKeydown_); |
| 70 }, | 77 }, |
| 71 | 78 |
| 72 /** | 79 /** |
| 73 * Display the command context menu at (|x|, |y|) in window co-ordinates. | 80 * Display the command context menu at (|x|, |y|) in window co-ordinates. |
| 74 * Commands will execute on the currently selected items. | 81 * Commands will execute on the currently selected items. |
| 75 * @param {number} x | 82 * @param {number} x |
| 76 * @param {number} y | 83 * @param {number} y |
| 77 */ | 84 */ |
| 78 openCommandMenuAtPosition: function(x, y) { | 85 openCommandMenuAtPosition: function(x, y) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 handle: function(command, itemIds) { | 179 handle: function(command, itemIds) { |
| 173 switch (command) { | 180 switch (command) { |
| 174 case Command.EDIT: | 181 case Command.EDIT: |
| 175 var id = Array.from(itemIds)[0]; | 182 var id = Array.from(itemIds)[0]; |
| 176 /** @type {!BookmarksEditDialogElement} */ (this.$.editDialog.get()) | 183 /** @type {!BookmarksEditDialogElement} */ (this.$.editDialog.get()) |
| 177 .showEditDialog(this.getState().nodes[id]); | 184 .showEditDialog(this.getState().nodes[id]); |
| 178 break; | 185 break; |
| 179 case Command.COPY: | 186 case Command.COPY: |
| 180 var idList = Array.from(itemIds); | 187 var idList = Array.from(itemIds); |
| 181 chrome.bookmarkManagerPrivate.copy(idList, function() { | 188 chrome.bookmarkManagerPrivate.copy(idList, function() { |
| 182 // TODO(jiaxi): Add toast later. | 189 bookmarks.ToastManager.getInstance().show( |
| 190 loadTimeData.getString('toastUrlCopied'), false); |
| 183 }); | 191 }); |
| 184 break; | 192 break; |
| 185 case Command.DELETE: | 193 case Command.DELETE: |
| 186 chrome.bookmarkManagerPrivate.removeTrees( | 194 var idList = Array.from(this.minimizeDeletionSet_(itemIds)); |
| 187 Array.from(this.minimizeDeletionSet_(itemIds)), function() { | 195 var labelPromise; |
| 188 // TODO(jiaxi): Add toast later. | 196 if (idList.length == 1) { |
| 189 }); | 197 // TODO(calamity): fold this separate label into |
| 198 // 'toastItemsDeleted'. |
| 199 labelPromise = Promise.resolve(loadTimeData.getStringF( |
| 200 'toastItemDeleted', this.getState().nodes[idList[0]].title)); |
| 201 } else { |
| 202 labelPromise = cr.sendWithPromise( |
| 203 'getPluralString', 'toastItemsDeleted', idList.length); |
| 204 } |
| 205 chrome.bookmarkManagerPrivate.removeTrees(idList, function() { |
| 206 labelPromise.then(function(label) { |
| 207 bookmarks.ToastManager.getInstance().show(label, true); |
| 208 }); |
| 209 }.bind(this)); |
| 190 break; | 210 break; |
| 191 case Command.UNDO: | 211 case Command.UNDO: |
| 192 chrome.bookmarkManagerPrivate.undo(); | 212 chrome.bookmarkManagerPrivate.undo(); |
| 213 bookmarks.ToastManager.getInstance().hide(); |
| 193 break; | 214 break; |
| 194 case Command.REDO: | 215 case Command.REDO: |
| 195 chrome.bookmarkManagerPrivate.redo(); | 216 chrome.bookmarkManagerPrivate.redo(); |
| 196 break; | 217 break; |
| 197 case Command.OPEN_NEW_TAB: | 218 case Command.OPEN_NEW_TAB: |
| 198 case Command.OPEN_NEW_WINDOW: | 219 case Command.OPEN_NEW_WINDOW: |
| 199 case Command.OPEN_INCOGNITO: | 220 case Command.OPEN_INCOGNITO: |
| 200 this.openUrls_(this.expandUrls_(itemIds), command); | 221 this.openUrls_(this.expandUrls_(itemIds), command); |
| 201 break; | 222 break; |
| 202 case Command.OPEN: | 223 case Command.OPEN: |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 457 |
| 437 /** @return {!bookmarks.CommandManager} */ | 458 /** @return {!bookmarks.CommandManager} */ |
| 438 CommandManager.getInstance = function() { | 459 CommandManager.getInstance = function() { |
| 439 return assert(CommandManager.instance_); | 460 return assert(CommandManager.instance_); |
| 440 }; | 461 }; |
| 441 | 462 |
| 442 return { | 463 return { |
| 443 CommandManager: CommandManager, | 464 CommandManager: CommandManager, |
| 444 }; | 465 }; |
| 445 }); | 466 }); |
| OLD | NEW |