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

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

Issue 2962283002: MD Bookmarks: Add 'show in folder' command to search result context menu (Closed)
Patch Set: Rebase Created 3 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/constants.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 var CommandManager = Polymer({ 11 var CommandManager = Polymer({
12 is: 'bookmarks-command-manager', 12 is: 'bookmarks-command-manager',
13 13
14 behaviors: [ 14 behaviors: [
15 bookmarks.StoreClient, 15 bookmarks.StoreClient,
16 ], 16 ],
17 17
18 properties: { 18 properties: {
19 /** @private {!Array<Command>} */ 19 /** @private {!Array<Command>} */
20 menuCommands_: { 20 menuCommands_: {
21 type: Array, 21 type: Array,
22 value: function() { 22 value: function() {
23 return [ 23 return [
24 Command.EDIT, 24 Command.EDIT,
25 Command.COPY_URL, 25 Command.COPY_URL,
26 Command.SHOW_IN_FOLDER,
26 Command.DELETE, 27 Command.DELETE,
27 // <hr> 28 // <hr>
28 Command.OPEN_NEW_TAB, 29 Command.OPEN_NEW_TAB,
29 Command.OPEN_NEW_WINDOW, 30 Command.OPEN_NEW_WINDOW,
30 Command.OPEN_INCOGNITO, 31 Command.OPEN_INCOGNITO,
31 ]; 32 ];
32 }, 33 },
33 }, 34 },
34 35
35 /** @private {Set<string>} */ 36 /** @private {Set<string>} */
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 * menu. 192 * menu.
192 */ 193 */
193 isCommandVisible_: function(command, itemIds) { 194 isCommandVisible_: function(command, itemIds) {
194 switch (command) { 195 switch (command) {
195 case Command.EDIT: 196 case Command.EDIT:
196 return itemIds.size == 1 && this.globalCanEdit_; 197 return itemIds.size == 1 && this.globalCanEdit_;
197 case Command.COPY_URL: 198 case Command.COPY_URL:
198 return this.isSingleBookmark_(itemIds); 199 return this.isSingleBookmark_(itemIds);
199 case Command.DELETE: 200 case Command.DELETE:
200 return itemIds.size > 0 && this.globalCanEdit_; 201 return itemIds.size > 0 && this.globalCanEdit_;
202 case Command.SHOW_IN_FOLDER:
203 // Hack: We only want this command to appear for list items (not
204 // sidebar folders) while a search is active. This works because right
205 // clicking a sidebar node will select that folder, clearing the
206 // search before the menu is displayed.
calamity 2017/07/10 05:51:38 Why not add a source to openCommandMenuAtPostion/E
tsergeant 2017/07/11 02:58:59 Done. I've added a MenuSource to the list for dete
207 return itemIds.size == 1 && this.getState().search.term != '' &&
208 !this.containsMatchingNode_(itemIds, function(node) {
209 return !node.parentId || node.parentId == ROOT_NODE_ID;
210 });
201 case Command.OPEN_NEW_TAB: 211 case Command.OPEN_NEW_TAB:
202 case Command.OPEN_NEW_WINDOW: 212 case Command.OPEN_NEW_WINDOW:
203 case Command.OPEN_INCOGNITO: 213 case Command.OPEN_INCOGNITO:
204 return itemIds.size > 0; 214 return itemIds.size > 0;
205 default: 215 default:
206 return false; 216 return false;
207 } 217 }
208 }, 218 },
209 219
210 /** 220 /**
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 Promise.resolve(loadTimeData.getString('toastUrlCopied')); 265 Promise.resolve(loadTimeData.getString('toastUrlCopied'));
256 } else { 266 } else {
257 labelPromise = cr.sendWithPromise( 267 labelPromise = cr.sendWithPromise(
258 'getPluralString', 'toastItemsCopied', idList.length); 268 'getPluralString', 'toastItemsCopied', idList.length);
259 } 269 }
260 270
261 this.showTitleToast_( 271 this.showTitleToast_(
262 labelPromise, state.nodes[idList[0]].title, false); 272 labelPromise, state.nodes[idList[0]].title, false);
263 }.bind(this)); 273 }.bind(this));
264 break; 274 break;
275 case Command.SHOW_IN_FOLDER:
276 var id = Array.from(itemIds)[0];
277 this.dispatch(bookmarks.actions.selectFolder(
278 assert(state.nodes[id].parentId), state.nodes));
279 break;
265 case Command.DELETE: 280 case Command.DELETE:
266 var idList = Array.from(this.minimizeDeletionSet_(itemIds)); 281 var idList = Array.from(this.minimizeDeletionSet_(itemIds));
267 var title = state.nodes[idList[0]].title; 282 var title = state.nodes[idList[0]].title;
268 var labelPromise = cr.sendWithPromise( 283 var labelPromise = cr.sendWithPromise(
269 'getPluralString', 'toastItemsDeleted', idList.length); 284 'getPluralString', 'toastItemsDeleted', idList.length);
270 chrome.bookmarkManagerPrivate.removeTrees(idList, function() { 285 chrome.bookmarkManagerPrivate.removeTrees(idList, function() {
271 this.showTitleToast_(labelPromise, title, true); 286 this.showTitleToast_(labelPromise, title, true);
272 }.bind(this)); 287 }.bind(this));
273 break; 288 break;
274 case Command.UNDO: 289 case Command.UNDO:
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 var id = Array.from(this.menuIds_)[0]; 510 var id = Array.from(this.menuIds_)[0];
496 var itemUrl = this.getState().nodes[id].url; 511 var itemUrl = this.getState().nodes[id].url;
497 label = itemUrl ? 'menuEdit' : 'menuRename'; 512 label = itemUrl ? 'menuEdit' : 'menuRename';
498 break; 513 break;
499 case Command.COPY_URL: 514 case Command.COPY_URL:
500 label = 'menuCopyURL'; 515 label = 'menuCopyURL';
501 break; 516 break;
502 case Command.DELETE: 517 case Command.DELETE:
503 label = 'menuDelete'; 518 label = 'menuDelete';
504 break; 519 break;
520 case Command.SHOW_IN_FOLDER:
521 label = 'menuShowInFolder';
522 break;
505 case Command.OPEN_NEW_TAB: 523 case Command.OPEN_NEW_TAB:
506 label = multipleNodes ? 'menuOpenAllNewTab' : 'menuOpenNewTab'; 524 label = multipleNodes ? 'menuOpenAllNewTab' : 'menuOpenNewTab';
507 break; 525 break;
508 case Command.OPEN_NEW_WINDOW: 526 case Command.OPEN_NEW_WINDOW:
509 label = multipleNodes ? 'menuOpenAllNewWindow' : 'menuOpenNewWindow'; 527 label = multipleNodes ? 'menuOpenAllNewWindow' : 'menuOpenNewWindow';
510 break; 528 break;
511 case Command.OPEN_INCOGNITO: 529 case Command.OPEN_INCOGNITO:
512 label = multipleNodes ? 'menuOpenAllIncognito' : 'menuOpenIncognito'; 530 label = multipleNodes ? 'menuOpenAllIncognito' : 'menuOpenIncognito';
513 break; 531 break;
514 } 532 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 662
645 /** @return {!bookmarks.CommandManager} */ 663 /** @return {!bookmarks.CommandManager} */
646 CommandManager.getInstance = function() { 664 CommandManager.getInstance = function() {
647 return assert(CommandManager.instance_); 665 return assert(CommandManager.instance_);
648 }; 666 };
649 667
650 return { 668 return {
651 CommandManager: CommandManager, 669 CommandManager: CommandManager,
652 }; 670 };
653 }); 671 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/constants.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698