Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: chrome/browser/resources/md_bookmarks/command_manager.js

Issue 2872163002: MD Bookmarks: Add 'Open' command, to open in either the BMM or in new tabs (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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;
calamity 2017/05/17 05:09:22 Can we also add a default: assert(false); here
tsergeant 2017/05/17 07:04:38 Done.
180 } 199 }
181 }, 200 },
182 201
183 //////////////////////////////////////////////////////////////////////////// 202 ////////////////////////////////////////////////////////////////////////////
184 // Private functions: 203 // Private functions:
185 204
186 /** 205 /**
187 * Minimize the set of |itemIds| by removing any node which has an ancestor 206 * 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 207 * 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 208 * both a node and its descendant, we will only try to delete the topmost
(...skipping 17 matching lines...) Expand all
207 return minimizedSet; 226 return minimizedSet;
208 }, 227 },
209 228
210 /** 229 /**
211 * @param {!Array<string>} urls 230 * @param {!Array<string>} urls
212 * @param {Command} command 231 * @param {Command} command
213 * @private 232 * @private
214 */ 233 */
215 openUrls_: function(urls, command) { 234 openUrls_: function(urls, command) {
216 assert( 235 assert(
217 command == Command.OPEN_NEW_TAB || 236 command == Command.OPEN || command == Command.OPEN_NEW_TAB ||
218 command == Command.OPEN_NEW_WINDOW || 237 command == Command.OPEN_NEW_WINDOW ||
219 command == Command.OPEN_INCOGNITO); 238 command == Command.OPEN_INCOGNITO);
220 239
221 if (urls.length == 0) 240 if (urls.length == 0)
222 return; 241 return;
223 242
224 var incognito = command == Command.OPEN_INCOGNITO; 243 var incognito = command == Command.OPEN_INCOGNITO;
225 if (command == Command.OPEN_NEW_WINDOW || incognito) { 244 if (command == Command.OPEN_NEW_WINDOW || incognito) {
226 chrome.windows.create({url: urls, incognito: incognito}); 245 chrome.windows.create({url: urls, incognito: incognito});
227 } else { 246 } else {
247 if (command == Command.OPEN)
248 chrome.tabs.create({url: urls.shift(), active: true});
228 urls.forEach(function(url) { 249 urls.forEach(function(url) {
229 chrome.tabs.create({url: url, active: false}); 250 chrome.tabs.create({url: url, active: false});
230 }); 251 });
231 } 252 }
232 }, 253 },
233 254
234 /** 255 /**
235 * Returns all URLs in the given set of nodes and their immediate children. 256 * 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| 257 * 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 258 * 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
386 407
387 /** @return {!bookmarks.CommandManager} */ 408 /** @return {!bookmarks.CommandManager} */
388 CommandManager.getInstance = function() { 409 CommandManager.getInstance = function() {
389 return assert(CommandManager.instance_); 410 return assert(CommandManager.instance_);
390 }; 411 };
391 412
392 return { 413 return {
393 CommandManager: CommandManager, 414 CommandManager: CommandManager,
394 }; 415 };
395 }); 416 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/constants.js » ('j') | chrome/browser/resources/md_bookmarks/item.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698