Commit 62a3c8c4 authored by François Degros's avatar François Degros Committed by Commit Bot

[Files app] ES6 class for gear_menu_controller.js

Bug: 778674
Change-Id: I70cced32faaf0577efe412bd8f7bbef837c2c3c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1611423
Auto-Submit: François Degros <fdegros@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659785}
parent 10174d09
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/** class GearMenuController {
/**
* @param {!cr.ui.MultiMenuButton} gearButton * @param {!cr.ui.MultiMenuButton} gearButton
* @param {!FilesToggleRipple} toggleRipple * @param {!FilesToggleRipple} toggleRipple
* @param {!GearMenu} gearMenu * @param {!GearMenu} gearMenu
...@@ -10,52 +11,26 @@ ...@@ -10,52 +11,26 @@
* @param {!DirectoryModel} directoryModel * @param {!DirectoryModel} directoryModel
* @param {!CommandHandler} commandHandler * @param {!CommandHandler} commandHandler
* @param {!ProvidersModel} providersModel * @param {!ProvidersModel} providersModel
* @constructor
* @struct
*/ */
function GearMenuController( constructor(
gearButton, toggleRipple, gearMenu, providersMenu, directoryModel, gearButton, toggleRipple, gearMenu, providersMenu, directoryModel,
commandHandler, providersModel) { commandHandler, providersModel) {
/** /** @private @const {!FilesToggleRipple} */
* @type {!FilesToggleRipple}
* @const
* @private
*/
this.toggleRipple_ = toggleRipple; this.toggleRipple_ = toggleRipple;
/** /** @private @const {!GearMenu} */
* @type {!GearMenu}
* @const
* @private
*/
this.gearMenu_ = gearMenu; this.gearMenu_ = gearMenu;
/** /** @private @const {!ProvidersMenu} */
* @type {!ProvidersMenu}
* @const
* @private
*/
this.providersMenu_ = providersMenu; this.providersMenu_ = providersMenu;
/** /** @private @const {!DirectoryModel} */
* @type {!DirectoryModel}
* @const
* @private
*/
this.directoryModel_ = directoryModel; this.directoryModel_ = directoryModel;
/** /** @private @const {!CommandHandler} */
* @type {!CommandHandler}
* @const
* @private
*/
this.commandHandler_ = commandHandler; this.commandHandler_ = commandHandler;
/** /** @private @const {!ProvidersModel} */
* @type {!ProvidersModel}
* @const
* @private
*/
this.providersModel_ = providersModel; this.providersModel_ = providersModel;
gearButton.addEventListener('menushow', this.onShowGearMenu_.bind(this)); gearButton.addEventListener('menushow', this.onShowGearMenu_.bind(this));
...@@ -65,18 +40,18 @@ function GearMenuController( ...@@ -65,18 +40,18 @@ function GearMenuController(
chrome.fileManagerPrivate.onPreferencesChanged.addListener( chrome.fileManagerPrivate.onPreferencesChanged.addListener(
this.onPreferencesChanged_.bind(this)); this.onPreferencesChanged_.bind(this));
this.onPreferencesChanged_(); this.onPreferencesChanged_();
} }
/** /**
* @private * @private
*/ */
GearMenuController.prototype.onShowGearMenu_ = function() { onShowGearMenu_() {
this.toggleRipple_.activated = true; this.toggleRipple_.activated = true;
this.refreshRemainingSpace_(false); /* Without loading caption. */ this.refreshRemainingSpace_(false); /* Without loading caption. */
this.updateNewServiceItem(); this.updateNewServiceItem();
}; }
/** /**
* Update "New service" menu item to either directly show the Webstore dialog * Update "New service" menu item to either directly show the Webstore dialog
* when there isn't any service/FSP extension installed, or display the * when there isn't any service/FSP extension installed, or display the
* providers menu with the currently installed extensions and also install new * providers menu with the currently installed extensions and also install new
...@@ -84,7 +59,7 @@ GearMenuController.prototype.onShowGearMenu_ = function() { ...@@ -84,7 +59,7 @@ GearMenuController.prototype.onShowGearMenu_ = function() {
* *
* @private * @private
*/ */
GearMenuController.prototype.updateNewServiceItem = function() { updateNewServiceItem() {
this.providersModel_.getMountableProviders().then(providers => { this.providersModel_.getMountableProviders().then(providers => {
// Go straight to webstore to install the first provider. // Go straight to webstore to install the first provider.
let desiredMenu = '#install-new-extension'; let desiredMenu = '#install-new-extension';
...@@ -102,33 +77,32 @@ GearMenuController.prototype.updateNewServiceItem = function() { ...@@ -102,33 +77,32 @@ GearMenuController.prototype.updateNewServiceItem = function() {
this.gearMenu_.setNewServiceCommand(desiredMenu, label); this.gearMenu_.setNewServiceCommand(desiredMenu, label);
}); });
}; }
/** /**
* @private * @private
*/ */
GearMenuController.prototype.onHideGearMenu_ = function() { onHideGearMenu_() {
this.toggleRipple_.activated = false; this.toggleRipple_.activated = false;
}; }
/** /**
* @param {Event} event * @param {Event} event
* @private * @private
*/ */
GearMenuController.prototype.onDirectoryChanged_ = function(event) { onDirectoryChanged_(event) {
event = /** @type {DirectoryChangeEvent} */ (event); event = /** @type {DirectoryChangeEvent} */ (event);
if (event.volumeChanged) { if (event.volumeChanged) {
this.refreshRemainingSpace_(true); this.refreshRemainingSpace_(true);
} // Show loading caption. } // Show loading caption.
}; }
/** /**
* Refreshes space info of the current volume. * Refreshes space info of the current volume.
* @param {boolean} showLoadingCaption Whether show loading caption or not. * @param {boolean} showLoadingCaption Whether show loading caption or not.
* @private * @private
*/ */
GearMenuController.prototype.refreshRemainingSpace_ = function( refreshRemainingSpace_(showLoadingCaption) {
showLoadingCaption) {
const currentDirectory = this.directoryModel_.getCurrentDirEntry(); const currentDirectory = this.directoryModel_.getCurrentDirEntry();
if (!currentDirectory || util.isRecentRoot(currentDirectory)) { if (!currentDirectory || util.isRecentRoot(currentDirectory)) {
this.gearMenu_.setSpaceInfo(null, false); this.gearMenu_.setSpaceInfo(null, false);
...@@ -144,12 +118,14 @@ GearMenuController.prototype.refreshRemainingSpace_ = function( ...@@ -144,12 +118,14 @@ GearMenuController.prototype.refreshRemainingSpace_ = function(
// file systems. // file systems.
// TODO(fukino): Add support for remaining space indication for documents // TODO(fukino): Add support for remaining space indication for documents
// provider roots. crbug.com/953657. // provider roots. crbug.com/953657.
if (currentVolumeInfo.volumeType == VolumeManagerCommon.VolumeType.PROVIDED || if (currentVolumeInfo.volumeType ==
VolumeManagerCommon.VolumeType.PROVIDED ||
currentVolumeInfo.volumeType == currentVolumeInfo.volumeType ==
VolumeManagerCommon.VolumeType.MEDIA_VIEW || VolumeManagerCommon.VolumeType.MEDIA_VIEW ||
currentVolumeInfo.volumeType == currentVolumeInfo.volumeType ==
VolumeManagerCommon.VolumeType.DOCUMENTS_PROVIDER || VolumeManagerCommon.VolumeType.DOCUMENTS_PROVIDER ||
currentVolumeInfo.volumeType == VolumeManagerCommon.VolumeType.ARCHIVE) { currentVolumeInfo.volumeType ==
VolumeManagerCommon.VolumeType.ARCHIVE) {
this.gearMenu_.setSpaceInfo(null, false); this.gearMenu_.setSpaceInfo(null, false);
return; return;
} }
...@@ -160,13 +136,13 @@ GearMenuController.prototype.refreshRemainingSpace_ = function( ...@@ -160,13 +136,13 @@ GearMenuController.prototype.refreshRemainingSpace_ = function(
currentVolumeInfo.volumeId, fulfill); currentVolumeInfo.volumeId, fulfill);
}), }),
true); true);
}; }
/** /**
* Handles preferences change and updates menu. * Handles preferences change and updates menu.
* @private * @private
*/ */
GearMenuController.prototype.onPreferencesChanged_ = function() { onPreferencesChanged_() {
chrome.fileManagerPrivate.getPreferences(prefs => { chrome.fileManagerPrivate.getPreferences(prefs => {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
return; return;
...@@ -178,4 +154,5 @@ GearMenuController.prototype.onPreferencesChanged_ = function() { ...@@ -178,4 +154,5 @@ GearMenuController.prototype.onPreferencesChanged_ = function() {
this.gearMenu_.syncButton.removeAttribute('checked'); this.gearMenu_.syncButton.removeAttribute('checked');
} }
}); });
}; }
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment