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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
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 }, | 61 }, |
61 | 62 |
62 detached: function() { | 63 detached: function() { |
63 CommandManager.instance_ = null; | 64 CommandManager.instance_ = null; |
64 document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_); | 65 document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_); |
65 document.removeEventListener('keydown', this.boundOnKeydown_); | 66 document.removeEventListener('keydown', this.boundOnKeydown_); |
66 }, | 67 }, |
67 | 68 |
68 /** | 69 /** |
69 * Display the command context menu at (|x|, |y|) in window co-ordinates. | 70 * Display the command context menu at (|x|, |y|) in window co-ordinates. |
(...skipping 26 matching lines...) Expand all Loading... |
96 | 97 |
97 /** | 98 /** |
98 * Determine if the |command| can be executed with the given |itemIds|. | 99 * Determine if the |command| can be executed with the given |itemIds|. |
99 * Commands which appear in the context menu should be implemented | 100 * Commands which appear in the context menu should be implemented |
100 * separately using `isCommandVisible_` and `isCommandEnabled_`. | 101 * separately using `isCommandVisible_` and `isCommandEnabled_`. |
101 * @param {Command} command | 102 * @param {Command} command |
102 * @param {!Set<string>} itemIds | 103 * @param {!Set<string>} itemIds |
103 * @return {boolean} | 104 * @return {boolean} |
104 */ | 105 */ |
105 canExecute: function(command, itemIds) { | 106 canExecute: function(command, itemIds) { |
106 return this.isCommandVisible_(command, itemIds) && | 107 switch (command) { |
107 this.isCommandEnabled_(command, itemIds); | 108 case Command.OPEN: |
| 109 return itemIds.size > 0; |
| 110 default: |
| 111 return this.isCommandVisible_(command, itemIds) && |
| 112 this.isCommandEnabled_(command, itemIds); |
| 113 } |
108 }, | 114 }, |
109 | 115 |
110 /** | 116 /** |
111 * @param {Command} command | 117 * @param {Command} command |
112 * @param {!Set<string>} itemIds | 118 * @param {!Set<string>} itemIds |
113 * @return {boolean} True if the command should be visible in the context | 119 * @return {boolean} True if the command should be visible in the context |
114 * menu. | 120 * menu. |
115 */ | 121 */ |
116 isCommandVisible_: function(command, itemIds) { | 122 isCommandVisible_: function(command, itemIds) { |
117 switch (command) { | 123 switch (command) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 chrome.bookmarkManagerPrivate.removeTrees( | 176 chrome.bookmarkManagerPrivate.removeTrees( |
171 Array.from(this.minimizeDeletionSet_(itemIds)), function() { | 177 Array.from(this.minimizeDeletionSet_(itemIds)), function() { |
172 // TODO(jiaxi): Add toast later. | 178 // TODO(jiaxi): Add toast later. |
173 }); | 179 }); |
174 break; | 180 break; |
175 case Command.OPEN_NEW_TAB: | 181 case Command.OPEN_NEW_TAB: |
176 case Command.OPEN_NEW_WINDOW: | 182 case Command.OPEN_NEW_WINDOW: |
177 case Command.OPEN_INCOGNITO: | 183 case Command.OPEN_INCOGNITO: |
178 this.openUrls_(this.expandUrls_(itemIds), command); | 184 this.openUrls_(this.expandUrls_(itemIds), command); |
179 break; | 185 break; |
| 186 case Command.OPEN: |
| 187 var isFolder = itemIds.size == 1 && |
| 188 this.containsMatchingNode_(itemIds, function(node) { |
| 189 return !node.url; |
| 190 }); |
| 191 if (isFolder) { |
| 192 var folderId = Array.from(itemIds)[0]; |
| 193 this.dispatch(bookmarks.actions.selectFolder( |
| 194 folderId, this.getState().nodes)); |
| 195 } else { |
| 196 this.openUrls_(this.expandUrls_(itemIds), command); |
| 197 } |
| 198 break; |
| 199 default: |
| 200 assert(false); |
180 } | 201 } |
181 }, | 202 }, |
182 | 203 |
183 //////////////////////////////////////////////////////////////////////////// | 204 //////////////////////////////////////////////////////////////////////////// |
184 // Private functions: | 205 // Private functions: |
185 | 206 |
186 /** | 207 /** |
187 * Minimize the set of |itemIds| by removing any node which has an ancestor | 208 * Minimize the set of |itemIds| by removing any node which has an ancestor |
188 * node already in the set. This ensures that instead of trying to delete | 209 * node already in the set. This ensures that instead of trying to delete |
189 * both a node and its descendant, we will only try to delete the topmost | 210 * both a node and its descendant, we will only try to delete the topmost |
(...skipping 17 matching lines...) Expand all Loading... |
207 return minimizedSet; | 228 return minimizedSet; |
208 }, | 229 }, |
209 | 230 |
210 /** | 231 /** |
211 * @param {!Array<string>} urls | 232 * @param {!Array<string>} urls |
212 * @param {Command} command | 233 * @param {Command} command |
213 * @private | 234 * @private |
214 */ | 235 */ |
215 openUrls_: function(urls, command) { | 236 openUrls_: function(urls, command) { |
216 assert( | 237 assert( |
217 command == Command.OPEN_NEW_TAB || | 238 command == Command.OPEN || command == Command.OPEN_NEW_TAB || |
218 command == Command.OPEN_NEW_WINDOW || | 239 command == Command.OPEN_NEW_WINDOW || |
219 command == Command.OPEN_INCOGNITO); | 240 command == Command.OPEN_INCOGNITO); |
220 | 241 |
221 if (urls.length == 0) | 242 if (urls.length == 0) |
222 return; | 243 return; |
223 | 244 |
224 var incognito = command == Command.OPEN_INCOGNITO; | 245 var incognito = command == Command.OPEN_INCOGNITO; |
225 if (command == Command.OPEN_NEW_WINDOW || incognito) { | 246 if (command == Command.OPEN_NEW_WINDOW || incognito) { |
226 chrome.windows.create({url: urls, incognito: incognito}); | 247 chrome.windows.create({url: urls, incognito: incognito}); |
227 } else { | 248 } else { |
| 249 if (command == Command.OPEN) |
| 250 chrome.tabs.create({url: urls.shift(), active: true}); |
228 urls.forEach(function(url) { | 251 urls.forEach(function(url) { |
229 chrome.tabs.create({url: url, active: false}); | 252 chrome.tabs.create({url: url, active: false}); |
230 }); | 253 }); |
231 } | 254 } |
232 }, | 255 }, |
233 | 256 |
234 /** | 257 /** |
235 * Returns all URLs in the given set of nodes and their immediate children. | 258 * Returns all URLs in the given set of nodes and their immediate children. |
236 * Note that these will be ordered by insertion order into the |itemIds| | 259 * Note that these will be ordered by insertion order into the |itemIds| |
237 * set, and that it is possible to duplicate a URL by passing in both the | 260 * set, and that it is possible to duplicate a URL by passing in both the |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 409 |
387 /** @return {!bookmarks.CommandManager} */ | 410 /** @return {!bookmarks.CommandManager} */ |
388 CommandManager.getInstance = function() { | 411 CommandManager.getInstance = function() { |
389 return assert(CommandManager.instance_); | 412 return assert(CommandManager.instance_); |
390 }; | 413 }; |
391 | 414 |
392 return { | 415 return { |
393 CommandManager: CommandManager, | 416 CommandManager: CommandManager, |
394 }; | 417 }; |
395 }); | 418 }); |
OLD | NEW |