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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager_commands.js

Issue 23944007: [Files.app] Remove CommandUtil.getCommandPath() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 'use strict'; 5 'use strict';
6 6
7 var CommandUtil = {}; 7 var CommandUtil = {};
8 8
9 /** 9 /**
10 * Extracts entry on which command event was dispatched. 10 * Extracts entry on which command event was dispatched.
(...skipping 30 matching lines...) Expand all
41 // element is a normal List (eg. the file list on the right panel). 41 // element is a normal List (eg. the file list on the right panel).
42 var entry = element.selectedItem; 42 var entry = element.selectedItem;
43 return entry; 43 return entry;
44 } else { 44 } else {
45 console.warn('Unsupported element'); 45 console.warn('Unsupported element');
46 return null; 46 return null;
47 } 47 }
48 }; 48 };
49 49
50 /** 50 /**
51 * Extracts path on which command event was dispatched.
52 * TODO(yoshiki): Remove this method after adding automatically removing an
53 * inactive shortcut on M31.
54 *
55 * @param {NavigationList|NavigationListItem} element Directory to extract a
56 * path from.
57 * @return {string} Path of the found node.
58 */
59 CommandUtil.getCommandPath = function(element) {
60 if (element instanceof NavigationList) {
61 // element is a NavigationList.
62
63 /** @type {NavigationModelItem} */
64 var selectedItem = element.selectedItem;
65 return selectedItem && selectedItem.path;
66 } else if (element instanceof NavigationListItem) {
67 // element is a subitem of NavigationList.
68 /** @type {NavigationList} */
69 var navigationList = element.parentElement;
70 var index = navigationList.getIndexOfListItem(element);
71 /** @type {NavigationModelItem} */
72 var item = (index != -1) ? navigationList.dataModel.item(index) : null;
73 return item && item.path;
74 }
75
76 console.error('Unsupported element.');
77 };
78
79 /**
80 * @param {NavigationList} navigationList navigation list to extract root node. 51 * @param {NavigationList} navigationList navigation list to extract root node.
81 * @return {?RootType} Type of the found root. 52 * @return {?RootType} Type of the found root.
82 */ 53 */
83 CommandUtil.getCommandRootType = function(navigationList) { 54 CommandUtil.getCommandRootType = function(navigationList) {
84 var root = CommandUtil.getCommandEntry(navigationList); 55 var root = CommandUtil.getCommandEntry(navigationList);
85 return root && 56 return root &&
86 PathUtil.isRootPath(root.fullPath) && 57 PathUtil.isRootPath(root.fullPath) &&
87 PathUtil.getRootType(root.fullPath); 58 PathUtil.getRootType(root.fullPath);
88 }; 59 };
89 60
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 /** 610 /**
640 * Removes the folder shortcut. 611 * Removes the folder shortcut.
641 */ 612 */
642 Commands.removeFolderShortcutCommand = { 613 Commands.removeFolderShortcutCommand = {
643 /** 614 /**
644 * @param {Event} event Command event. 615 * @param {Event} event Command event.
645 * @param {FileManager} fileManager The file manager instance. 616 * @param {FileManager} fileManager The file manager instance.
646 */ 617 */
647 execute: function(event, fileManager) { 618 execute: function(event, fileManager) {
648 var entry = CommandUtil.getCommandEntry(event.target); 619 var entry = CommandUtil.getCommandEntry(event.target);
649 var path = 620 if (entry && entry.fullPath)
650 entry ? entry.fullPath : CommandUtil.getCommandPath(event.target); 621 fileManager.removeFolderShortcut(entry.fullPath);
651 if (path)
652 fileManager.removeFolderShortcut(path);
653 }, 622 },
654 623
655 /** 624 /**
656 * @param {Event} event Command event. 625 * @param {Event} event Command event.
657 * @param {FileManager} fileManager The file manager instance. 626 * @param {FileManager} fileManager The file manager instance.
658 */ 627 */
659 canExecute: function(event, fileManager) { 628 canExecute: function(event, fileManager) {
660 var target = event.target; 629 var target = event.target;
661 if (!target instanceof NavigationListItem && 630 if (!target instanceof NavigationListItem &&
662 !target instanceof DirectoryItem) { 631 !target instanceof DirectoryItem) {
663 event.command.setHidden(true); 632 event.command.setHidden(true);
664 return; 633 return;
665 } 634 }
666 635
667 var entry = CommandUtil.getCommandEntry(target); 636 var entry = CommandUtil.getCommandEntry(target);
668 var path = 637 var path = entry && entry.fullPath;
669 entry ? entry.fullPath : CommandUtil.getCommandPath(event.target);
670 638
671 var eligible = path && PathUtil.isEligibleForFolderShortcut(path); 639 var eligible = path && PathUtil.isEligibleForFolderShortcut(path);
672 var isShortcut = path && fileManager.folderShortcutExists(path); 640 var isShortcut = path && fileManager.folderShortcutExists(path);
673 event.canExecute = isShortcut && eligible; 641 event.canExecute = isShortcut && eligible;
674 event.command.setHidden(!event.canExecute); 642 event.command.setHidden(!event.canExecute);
675 } 643 }
676 }; 644 };
677 645
678 /** 646 /**
679 * Zoom in to the Files.app. 647 * Zoom in to the Files.app.
(...skipping 17 matching lines...) Expand all
697 665
698 /** 666 /**
699 * Reset the zoom factor. 667 * Reset the zoom factor.
700 */ 668 */
701 Commands.zoomResetCommand = { 669 Commands.zoomResetCommand = {
702 execute: function(event) { 670 execute: function(event) {
703 chrome.fileBrowserPrivate.zoom('reset'); 671 chrome.fileBrowserPrivate.zoom('reset');
704 }, 672 },
705 canExecute: CommandUtil.canExecuteAlways 673 canExecute: CommandUtil.canExecuteAlways
706 }; 674 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698