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

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

Issue 12221082: Add gear menu to /downloads and /external_storage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 7 years, 10 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
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 // This variable is checked in SelectFileDialogExtensionBrowserTest. 5 // This variable is checked in SelectFileDialogExtensionBrowserTest.
6 var JSErrorCount = 0; 6 var JSErrorCount = 0;
7 7
8 /** 8 /**
9 * Count uncaught exceptions. 9 * Count uncaught exceptions.
10 */ 10 */
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 cr.ui.Menu.decorate(this.rootsContextMenu_); 537 cr.ui.Menu.decorate(this.rootsContextMenu_);
538 538
539 this.downloadsRootContextMenu_ = 539 this.downloadsRootContextMenu_ =
540 this.dialogDom_.querySelector('#downloads-root-context-menu'); 540 this.dialogDom_.querySelector('#downloads-root-context-menu');
541 cr.ui.Menu.decorate(this.downloadsRootContextMenu_); 541 cr.ui.Menu.decorate(this.downloadsRootContextMenu_);
542 542
543 this.textContextMenu_ = 543 this.textContextMenu_ =
544 this.dialogDom_.querySelector('#text-context-menu'); 544 this.dialogDom_.querySelector('#text-context-menu');
545 cr.ui.Menu.decorate(this.textContextMenu_); 545 cr.ui.Menu.decorate(this.textContextMenu_);
546 546
547 this.driveSettingsMenu_ = this.dialogDom_.querySelector('#drive-settings'); 547 this.gearButton_ = this.dialogDom_.querySelector('#gear-button');
548 cr.ui.decorate(this.driveSettingsMenu_, cr.ui.MenuButton); 548 this.gearButton_.addEventListener('menushow',
549 549 this.refreshRemainingSpace_.bind(this,
550 this.driveSettingsMenu_.addEventListener('menushow', 550 false /* Without loading caption. */));
551 this.onDriveMenuShow_.bind(this)); 551 cr.ui.decorate(this.gearButton_, cr.ui.MenuButton);
552 552
553 this.syncButton.checkable = true; 553 this.syncButton.checkable = true;
554 this.hostedButton.checkable = true; 554 this.hostedButton.checkable = true;
555 }; 555 };
556 556
557 /** 557 /**
558 * One-time initialization of commands. 558 * One-time initialization of commands.
559 */ 559 */
560 FileManager.prototype.initCommands_ = function() { 560 FileManager.prototype.initCommands_ = function() {
561 var commandButtons = this.dialogDom_.querySelectorAll('button[command]'); 561 var commandButtons = this.dialogDom_.querySelectorAll('button[command]');
(...skipping 23 matching lines...) Expand all
585 585
586 CommandUtil.registerCommand(this.rootsList_, 'import-photos', 586 CommandUtil.registerCommand(this.rootsList_, 'import-photos',
587 Commands.importCommand, this.rootsList_); 587 Commands.importCommand, this.rootsList_);
588 588
589 CommandUtil.registerCommand(doc, 'delete', 589 CommandUtil.registerCommand(doc, 'delete',
590 Commands.deleteFileCommand, this); 590 Commands.deleteFileCommand, this);
591 591
592 CommandUtil.registerCommand(doc, 'rename', 592 CommandUtil.registerCommand(doc, 'rename',
593 Commands.renameFileCommand, this); 593 Commands.renameFileCommand, this);
594 594
595 CommandUtil.registerCommand(doc, 'volume-help',
596 Commands.volumeHelpCommand, this);
597
595 CommandUtil.registerCommand(doc, 'drive-buy-more-space', 598 CommandUtil.registerCommand(doc, 'drive-buy-more-space',
596 Commands.driveBuySpaceCommand, this); 599 Commands.driveBuySpaceCommand, this);
597 600
598 CommandUtil.registerCommand(doc, 'drive-help',
599 Commands.driveHelpCommand, this);
600
601 CommandUtil.registerCommand(doc, 'drive-clear-local-cache', 601 CommandUtil.registerCommand(doc, 'drive-clear-local-cache',
602 Commands.driveClearCacheCommand, this); 602 Commands.driveClearCacheCommand, this);
603 603
604 CommandUtil.registerCommand(doc, 'drive-reload', 604 CommandUtil.registerCommand(doc, 'drive-reload',
605 Commands.driveReloadCommand, this); 605 Commands.driveReloadCommand, this);
606 606
607 CommandUtil.registerCommand(doc, 'drive-go-to-drive', 607 CommandUtil.registerCommand(doc, 'drive-go-to-drive',
608 Commands.driveGoToDriveCommand, this); 608 Commands.driveGoToDriveCommand, this);
609 609
610 CommandUtil.registerCommand(doc, 'files-app-help', 610 CommandUtil.registerCommand(doc, 'files-app-help',
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 772
773 this.dialogDom_.querySelector('#search-box').addEventListener( 773 this.dialogDom_.querySelector('#search-box').addEventListener(
774 'input', this.onSearchBoxUpdate_.bind(this)); 774 'input', this.onSearchBoxUpdate_.bind(this));
775 775
776 this.defaultActionMenuItem_ = 776 this.defaultActionMenuItem_ =
777 this.dialogDom_.querySelector('#default-action'); 777 this.dialogDom_.querySelector('#default-action');
778 778
779 this.openWithCommand_ = 779 this.openWithCommand_ =
780 this.dialogDom_.querySelector('#open-with'); 780 this.dialogDom_.querySelector('#open-with');
781 781
782 this.driveBuyMoreStorageCommand_ =
783 this.dialogDom_.querySelector('#drive-buy-more-space');
784
782 this.defaultActionMenuItem_.addEventListener('activate', 785 this.defaultActionMenuItem_.addEventListener('activate',
783 this.dispatchSelectionAction_.bind(this)); 786 this.dispatchSelectionAction_.bind(this));
784 787
785 this.fileTypeSelector_ = this.dialogDom_.querySelector('#file-type'); 788 this.fileTypeSelector_ = this.dialogDom_.querySelector('#file-type');
786 this.initFileTypeFilter_(); 789 this.initFileTypeFilter_();
787 790
788 this.updateWindowState_(); 791 this.updateWindowState_();
789 // Populate the static localized strings. 792 // Populate the static localized strings.
790 i18nTemplate.process(this.document_, loadTimeData); 793 i18nTemplate.process(this.document_, loadTimeData);
791 }; 794 };
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 if (this.downloadsRootContextMenuListener_) { 1466 if (this.downloadsRootContextMenuListener_) {
1464 cr.ui.contextMenuHandler.removeEventListener( 1467 cr.ui.contextMenuHandler.removeEventListener(
1465 'show', this.downloadsRootContextMenuListener_); 1468 'show', this.downloadsRootContextMenuListener_);
1466 } 1469 }
1467 this.downloadsRootContextMenuListener_ = function(ev) { 1470 this.downloadsRootContextMenuListener_ = function(ev) {
1468 // Check available space on opening the context menu for Downloads. 1471 // Check available space on opening the context menu for Downloads.
1469 if (ev.element != li || ev.menu != downloadsRootContextMenu) 1472 if (ev.element != li || ev.menu != downloadsRootContextMenu)
1470 return; 1473 return;
1471 1474
1472 downloadsSpaceInnerBar.setAttribute('pending', ''); 1475 downloadsSpaceInnerBar.setAttribute('pending', '');
1476 spaceInfoLabel.textContent = strf('SPACE_AVAILABLE', sizeStr);
1477
1473 chrome.fileBrowserPrivate.getSizeStats( 1478 chrome.fileBrowserPrivate.getSizeStats(
1474 util.makeFilesystemUrl(path), 1479 util.makeFilesystemUrl(path),
1475 function(sizeStats) { 1480 function(sizeStats) {
1476 updateSpaceInfo(sizeStats, downloadsSpaceInnerBar, 1481 updateSpaceInfo(sizeStats, downloadsSpaceInnerBar,
1477 downloadsSpaceInfoLabel, downloadsSpaceOuterBar); 1482 downloadsSpaceInfoLabel, downloadsSpaceOuterBar);
1478 }); 1483 });
1479 }; 1484 };
1480 1485
1481 cr.ui.contextMenuHandler.addEventListener( 1486 cr.ui.contextMenuHandler.addEventListener(
1482 'show', this.downloadsRootContextMenuListener_); 1487 'show', this.downloadsRootContextMenuListener_);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 /** 1977 /**
1973 * Updates search box value when directory gets changed. 1978 * Updates search box value when directory gets changed.
1974 */ 1979 */
1975 FileManager.prototype.updateSearchBoxOnDirChange_ = function() { 1980 FileManager.prototype.updateSearchBoxOnDirChange_ = function() {
1976 var searchBox = this.dialogDom_.querySelector('#search-box'); 1981 var searchBox = this.dialogDom_.querySelector('#search-box');
1977 if (!searchBox.disabled) 1982 if (!searchBox.disabled)
1978 searchBox.value = ''; 1983 searchBox.value = '';
1979 }, 1984 },
1980 1985
1981 /** 1986 /**
1987 * Update the gear menu.
1988 */
1989 FileManager.prototype.updateGearMenu_ = function() {
1990 this.syncButton.hidden = !this.isOnDrive();
1991 this.hostedButton.hidden = !this.isOnDrive();
1992
1993 // If volume has changed, then fetch remaining space data.
1994 if (this.previousRootUrl_ != this.directoryModel_.getCurrentRootUrl())
1995 this.refreshRemainingSpace_(true); // Show loading caption.
1996
1997 this.previousRootUrl_ = this.directoryModel_.getCurrentRootUrl();
1998 },
1999
2000 /**
2001 * Refreshes space info of the current volume.
2002 * @param {boolean} showLoadingCaption Whether show loading caption or not.
2003 */
2004 FileManager.prototype.refreshRemainingSpace_ = function(showLoadingCaption) {
2005 var volumeSpaceInfoLabel =
2006 this.dialogDom_.querySelector('#volume-space-info-label');
2007 var volumeSpaceInnerBar =
2008 this.dialogDom_.querySelector('#volume-space-info-bar');
2009 var volumeSpaceOuterBar =
2010 this.dialogDom_.querySelector('#volume-space-info-bar').parentNode;
2011
2012 volumeSpaceInnerBar.setAttribute('pending', '');
2013
2014 if (showLoadingCaption) {
2015 volumeSpaceInfoLabel.innerText = str('WAITING_FOR_SPACE_INFO');
2016 volumeSpaceInnerBar.style.width = '100%';
2017 }
2018
2019 var currentRootUrl = this.directoryModel_.getCurrentRootUrl();
2020 chrome.fileBrowserPrivate.getSizeStats(
2021 this.directoryModel_.getCurrentRootUrl(), function(result) {
2022 if (this.directoryModel_.getCurrentRootUrl() != currentRootUrl)
2023 return;
2024 updateSpaceInfo(result,
2025 volumeSpaceInnerBar,
2026 volumeSpaceInfoLabel,
2027 volumeSpaceOuterBar);
2028 }.bind(this));
2029 }
2030
2031 /**
1982 * Update the UI when the current directory changes. 2032 * Update the UI when the current directory changes.
1983 * 2033 *
1984 * @param {cr.Event} event The directory-changed event. 2034 * @param {cr.Event} event The directory-changed event.
1985 */ 2035 */
1986 FileManager.prototype.onDirectoryChanged_ = function(event) { 2036 FileManager.prototype.onDirectoryChanged_ = function(event) {
1987 this.selectionHandler_.onFileSelectionChanged(); 2037 this.selectionHandler_.onFileSelectionChanged();
1988 this.updateSearchBoxOnDirChange_(); 2038 this.updateSearchBoxOnDirChange_();
1989 if (this.dialogType == DialogType.FULL_PAGE) 2039 if (this.dialogType == DialogType.FULL_PAGE)
1990 this.table_.showOfflineColumn(this.isOnDrive()); 2040 this.table_.showOfflineColumn(this.isOnDrive());
1991 2041
1992 util.updateAppState(event.initial, this.getCurrentDirectory()); 2042 util.updateAppState(event.initial, this.getCurrentDirectory());
1993 2043
1994 if (this.closeOnUnmount_ && !event.initial && 2044 if (this.closeOnUnmount_ && !event.initial &&
1995 PathUtil.getRootPath(event.previousDirEntry.fullPath) != 2045 PathUtil.getRootPath(event.previousDirEntry.fullPath) !=
1996 PathUtil.getRootPath(event.newDirEntry.fullPath)) { 2046 PathUtil.getRootPath(event.newDirEntry.fullPath)) {
1997 this.closeOnUnmount_ = false; 2047 this.closeOnUnmount_ = false;
1998 } 2048 }
1999 2049
2000 this.updateUnformattedDriveStatus_(); 2050 this.updateUnformattedDriveStatus_();
2001
2002 this.updateTitle_(); 2051 this.updateTitle_();
2052 this.updateGearMenu_();
2003 }; 2053 };
2004 2054
2005 FileManager.prototype.updateUnformattedDriveStatus_ = function() { 2055 FileManager.prototype.updateUnformattedDriveStatus_ = function() {
2006 var volumeInfo = this.volumeManager_.getVolumeInfo_( 2056 var volumeInfo = this.volumeManager_.getVolumeInfo_(
2007 this.directoryModel_.getCurrentRootPath()); 2057 this.directoryModel_.getCurrentRootPath());
2008 2058
2009 if (volumeInfo.error) { 2059 if (volumeInfo.error) {
2010 this.dialogContainer_.setAttribute('unformatted', ''); 2060 this.dialogDom_.setAttribute('unformatted', '');
2011 2061
2012 var errorNode = this.dialogDom_.querySelector('#format-panel > .error'); 2062 var errorNode = this.dialogDom_.querySelector('#format-panel > .error');
2013 if (volumeInfo.error == VolumeManager.Error.UNSUPPORTED_FILESYSTEM) { 2063 if (volumeInfo.error == VolumeManager.Error.UNSUPPORTED_FILESYSTEM) {
2014 errorNode.textContent = str('UNSUPPORTED_FILESYSTEM_WARNING'); 2064 errorNode.textContent = str('UNSUPPORTED_FILESYSTEM_WARNING');
2015 } else { 2065 } else {
2016 errorNode.textContent = str('UNKNOWN_FILESYSTEM_WARNING'); 2066 errorNode.textContent = str('UNKNOWN_FILESYSTEM_WARNING');
2017 } 2067 }
2018 2068
2019 // Update 'canExecute' for format command so the format button's disabled 2069 // Update 'canExecute' for format command so the format button's disabled
2020 // property is properly set. 2070 // property is properly set.
2021 var formatCommand = this.dialogDom_.querySelector('command#format'); 2071 var formatCommand = this.dialogDom_.querySelector('command#format');
2022 formatCommand.canExecuteChange(errorNode); 2072 formatCommand.canExecuteChange(errorNode);
2023 } else { 2073 } else {
2024 this.dialogContainer_.removeAttribute('unformatted'); 2074 this.dialogDom_.removeAttribute('unformatted');
2025 } 2075 }
2026 }; 2076 };
2027 2077
2028 FileManager.prototype.findListItemForEvent_ = function(event) { 2078 FileManager.prototype.findListItemForEvent_ = function(event) {
2029 return this.findListItemForNode_(event.touchedElement || event.srcElement); 2079 return this.findListItemForNode_(event.touchedElement || event.srcElement);
2030 }; 2080 };
2031 2081
2032 FileManager.prototype.findListItemForNode_ = function(node) { 2082 FileManager.prototype.findListItemForNode_ = function(node) {
2033 var item = this.currentList_.getListItemAncestor(node); 2083 var item = this.currentList_.getListItemAncestor(node);
2034 // TODO(serya): list should check that. 2084 // TODO(serya): list should check that.
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
2860 handleSplitterDragEnd: function(e) { 2910 handleSplitterDragEnd: function(e) {
2861 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); 2911 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments);
2862 this.ownerDocument.documentElement.classList.remove('col-resize'); 2912 this.ownerDocument.documentElement.classList.remove('col-resize');
2863 } 2913 }
2864 }; 2914 };
2865 2915
2866 customSplitter.decorate(splitterElement); 2916 customSplitter.decorate(splitterElement);
2867 }; 2917 };
2868 2918
2869 /** 2919 /**
2870 * Listener invoked on drive menu show event, to update drive free/total
2871 * space info in opened menu.
2872 * @private
2873 */
2874 FileManager.prototype.onDriveMenuShow_ = function() {
2875 var driveSpaceInfoLabel =
2876 this.dialogDom_.querySelector('#drive-space-info-label');
2877
2878 var driveSpaceInnerBar =
2879 this.dialogDom_.querySelector('#drive-space-info-bar');
2880 var driveSpaceOuterBar =
2881 this.dialogDom_.querySelector('#drive-space-info-bar').parentNode;
2882
2883 driveSpaceInnerBar.setAttribute('pending', '');
2884 chrome.fileBrowserPrivate.getSizeStats(
2885 this.directoryModel_.getCurrentRootUrl(), function(result) {
2886 updateSpaceInfo(result, driveSpaceInnerBar, driveSpaceInfoLabel,
2887 driveSpaceOuterBar);
2888 });
2889 };
2890
2891 /**
2892 * Updates default action menu item to match passed taskItem (icon, 2920 * Updates default action menu item to match passed taskItem (icon,
2893 * label and action). 2921 * label and action).
2894 * 2922 *
2895 * @param {Object} defaultItem - taskItem to match. 2923 * @param {Object} defaultItem - taskItem to match.
2896 * @param {boolean} isMultiple - if multiple tasks available. 2924 * @param {boolean} isMultiple - if multiple tasks available.
2897 */ 2925 */
2898 FileManager.prototype.updateContextMenuActionItems = function(defaultItem, 2926 FileManager.prototype.updateContextMenuActionItems = function(defaultItem,
2899 isMultiple) { 2927 isMultiple) {
2900 if (defaultItem) { 2928 if (defaultItem) {
2901 if (defaultItem.iconType) { 2929 if (defaultItem.iconType) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2954 return this.directoryModel_.getFileList(); 2982 return this.directoryModel_.getFileList();
2955 }; 2983 };
2956 2984
2957 /** 2985 /**
2958 * @return {cr.ui.List} Current list object. 2986 * @return {cr.ui.List} Current list object.
2959 */ 2987 */
2960 FileManager.prototype.getCurrentList = function() { 2988 FileManager.prototype.getCurrentList = function() {
2961 return this.currentList_; 2989 return this.currentList_;
2962 }; 2990 };
2963 })(); 2991 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698