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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 handle: function(command, itemIds) { | 175 handle: function(command, itemIds) { |
169 switch (command) { | 176 switch (command) { |
170 case Command.EDIT: | 177 case Command.EDIT: |
171 var id = Array.from(itemIds)[0]; | 178 var id = Array.from(itemIds)[0]; |
172 /** @type {!BookmarksEditDialogElement} */ (this.$.editDialog.get()) | 179 /** @type {!BookmarksEditDialogElement} */ (this.$.editDialog.get()) |
173 .showEditDialog(this.getState().nodes[id]); | 180 .showEditDialog(this.getState().nodes[id]); |
174 break; | 181 break; |
175 case Command.COPY: | 182 case Command.COPY: |
176 var idList = Array.from(itemIds); | 183 var idList = Array.from(itemIds); |
177 chrome.bookmarkManagerPrivate.copy(idList, function() { | 184 chrome.bookmarkManagerPrivate.copy(idList, function() { |
178 // TODO(jiaxi): Add toast later. | 185 bookmarks.ToastManager.getInstance().show( |
| 186 loadTimeData.getString('toastUrlCopied'), false); |
179 }); | 187 }); |
180 break; | 188 break; |
181 case Command.DELETE: | 189 case Command.DELETE: |
182 chrome.bookmarkManagerPrivate.removeTrees( | 190 var idList = Array.from(this.minimizeDeletionSet_(itemIds)); |
183 Array.from(this.minimizeDeletionSet_(itemIds)), function() { | 191 var labelPromise; |
184 // TODO(jiaxi): Add toast later. | 192 if (idList.length == 1) { |
185 }); | 193 // TODO(calamity): fold this separate label into |
| 194 // 'toastItemsDeleted'. |
| 195 labelPromise = Promise.resolve(loadTimeData.getStringF( |
| 196 'toastItemDeleted', this.getState().nodes[idList[0]].title)); |
| 197 } else { |
| 198 labelPromise = cr.sendWithPromise( |
| 199 'getPluralString', 'toastItemsDeleted', idList.length); |
| 200 } |
| 201 chrome.bookmarkManagerPrivate.removeTrees(idList, function() { |
| 202 labelPromise.then(function(label) { |
| 203 bookmarks.ToastManager.getInstance().show(label, true); |
| 204 }); |
| 205 }.bind(this)); |
186 break; | 206 break; |
187 case Command.UNDO: | 207 case Command.UNDO: |
188 chrome.bookmarkManagerPrivate.undo(); | 208 chrome.bookmarkManagerPrivate.undo(); |
| 209 bookmarks.ToastManager.getInstance().hide(); |
189 break; | 210 break; |
190 case Command.REDO: | 211 case Command.REDO: |
191 chrome.bookmarkManagerPrivate.redo(); | 212 chrome.bookmarkManagerPrivate.redo(); |
192 break; | 213 break; |
193 case Command.OPEN_NEW_TAB: | 214 case Command.OPEN_NEW_TAB: |
194 case Command.OPEN_NEW_WINDOW: | 215 case Command.OPEN_NEW_WINDOW: |
195 case Command.OPEN_INCOGNITO: | 216 case Command.OPEN_INCOGNITO: |
196 this.openUrls_(this.expandUrls_(itemIds), command); | 217 this.openUrls_(this.expandUrls_(itemIds), command); |
197 break; | 218 break; |
198 case Command.OPEN: | 219 case Command.OPEN: |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 442 |
422 /** @return {!bookmarks.CommandManager} */ | 443 /** @return {!bookmarks.CommandManager} */ |
423 CommandManager.getInstance = function() { | 444 CommandManager.getInstance = function() { |
424 return assert(CommandManager.instance_); | 445 return assert(CommandManager.instance_); |
425 }; | 446 }; |
426 | 447 |
427 return { | 448 return { |
428 CommandManager: CommandManager, | 449 CommandManager: CommandManager, |
429 }; | 450 }; |
430 }); | 451 }); |
OLD | NEW |