Commit aa7dae2e authored by hirono's avatar hirono Committed by Commit bot

Files.app: Make NamingControll class.

BUG=267281
TEST=None

Review URL: https://codereview.chromium.org/693503002

Cr-Commit-Position: refs/heads/master@{#302220}
parent edc72771
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
'./file_watcher.js', './file_watcher.js',
'./folder_shortcuts_data_model.js', './folder_shortcuts_data_model.js',
'./metadata/metadata_cache.js', './metadata/metadata_cache.js',
'./naming_controller.js',
'./navigation_list_model.js', './navigation_list_model.js',
'./progress_center_item_group.js', './progress_center_item_group.js',
'./search_controller.js', './search_controller.js',
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
* latter is not yet implemented). * latter is not yet implemented).
* *
* @constructor * @constructor
* @struct
*/ */
function FileManager() { function FileManager() {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -166,6 +167,13 @@ function FileManager() { ...@@ -166,6 +167,13 @@ function FileManager() {
*/ */
this.directoryTree_ = null; this.directoryTree_ = null;
/**
* Naming controller.
* @type {NamingController}
* @private
*/
this.namingController_ = null;
/** /**
* Controller for search UI. * Controller for search UI.
* @type {SearchController} * @type {SearchController}
...@@ -551,7 +559,7 @@ function FileManager() { ...@@ -551,7 +559,7 @@ function FileManager() {
Object.preventExtensions(this); Object.preventExtensions(this);
} }
FileManager.prototype = { FileManager.prototype = /** @struct */ {
__proto__: cr.EventTarget.prototype, __proto__: cr.EventTarget.prototype,
/** /**
* @return {DirectoryModel} * @return {DirectoryModel}
...@@ -1555,6 +1563,12 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52; ...@@ -1555,6 +1563,12 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
}.bind(this) }.bind(this)
}); });
// Create naming controller.
assert(this.ui_.alertDialog);
this.namingController_ = new NamingController(
this.fileFilter_,
this.ui_.alertDialog);
// Update metadata to change 'Today' and 'Yesterday' dates. // Update metadata to change 'Today' and 'Yesterday' dates.
var today = new Date(); var today = new Date();
today.setHours(0); today.setHours(0);
...@@ -2960,9 +2974,10 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52; ...@@ -2960,9 +2974,10 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
// TODO(haruki): this.getCurrentDirectoryEntry() might not return the actual // TODO(haruki): this.getCurrentDirectoryEntry() might not return the actual
// parent if the directory content is a search result. Fix it to do proper // parent if the directory content is a search result. Fix it to do proper
// validation. // validation.
this.validateFileName_(this.getCurrentDirectoryEntry(), this.namingController_.validateFileName(
newName, this.getCurrentDirectoryEntry(),
validationDone.bind(this)); newName,
validationDone.bind(this));
}; };
/** /**
...@@ -3597,7 +3612,8 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52; ...@@ -3597,7 +3612,8 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
throw new Error('Missing filename!'); throw new Error('Missing filename!');
var directory = this.getCurrentDirectoryEntry(); var directory = this.getCurrentDirectoryEntry();
this.validateFileName_(directory, filename, function(isValid) { this.namingController_.validateFileName(
directory, filename, function(isValid) {
if (!isValid) if (!isValid)
return; return;
...@@ -3712,30 +3728,6 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52; ...@@ -3712,30 +3728,6 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
this.selectFilesAndClose_(singleSelection); this.selectFilesAndClose_(singleSelection);
}; };
/**
* Verifies the user entered name for file or folder to be created or
* renamed to. See also util.validateFileName.
*
* @param {DirectoryEntry} parentEntry The URL of the parent directory entry.
* @param {string} name New file or folder name.
* @param {function(boolean)} onDone Function to invoke when user closes the
* warning box or immediatelly if file name is correct. If the name was
* valid it is passed true, and false otherwise.
* @private
*/
FileManager.prototype.validateFileName_ = function(
parentEntry, name, onDone) {
var fileNameErrorPromise = util.validateFileName(
parentEntry,
name,
this.fileFilter_.isFilterHiddenOn());
fileNameErrorPromise.then(onDone.bind(null, true), function(message) {
this.alert.show(message, onDone.bind(null, false));
}.bind(this)).catch(function(error) {
console.error(error.stack || error);
});
};
/** /**
* Toggle whether mobile data is used for sync. * Toggle whether mobile data is used for sync.
*/ */
......
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
//<include src="file_watcher.js"> //<include src="file_watcher.js">
//<include src="folder_shortcuts_data_model.js"> //<include src="folder_shortcuts_data_model.js">
//<include src="metadata/metadata_cache.js"> //<include src="metadata/metadata_cache.js">
//<include src="naming_controller.js">
//<include src="navigation_list_model.js"> //<include src="navigation_list_model.js">
//<include src="progress_center_item_group.js"> //<include src="progress_center_item_group.js">
//<include src="search_controller.js"> //<include src="search_controller.js">
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* Controller to handle naming.
*
* @param {!FileFilter} fileFilter
* @param {!cr.ui.dialogs.AlertDialog} alertDialog
* @constructor
* @struct
*/
function NamingController(fileFilter, alertDialog) {
/**
* File filter.
* @type {!FileFilter}
* @const
* @private
*/
this.fileFilter_ = fileFilter;
/**
* Alert dialog.
* @type {!cr.ui.dialogs.AlertDialog}
* @const
* @private
*/
this.alertDialog_ = alertDialog;
}
/**
* Verifies the user entered name for file or folder to be created or
* renamed to. See also util.validateFileName.
*
* @param {DirectoryEntry} parentEntry The URL of the parent directory entry.
* @param {string} name New file or folder name.
* @param {function(boolean)} onDone Function to invoke when user closes the
* warning box or immediatelly if file name is correct. If the name was
* valid it is passed true, and false otherwise.
*/
NamingController.prototype.validateFileName = function(
parentEntry, name, onDone) {
var fileNameErrorPromise = util.validateFileName(
parentEntry,
name,
this.fileFilter_.isFilterHiddenOn());
fileNameErrorPromise.then(onDone.bind(null, true), function(message) {
this.alertDialog_.show(message, onDone.bind(null, false));
}.bind(this)).catch(function(error) {
console.error(error.stack || error);
});
};
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
<script src="foreground/js/file_watcher.js"></script> <script src="foreground/js/file_watcher.js"></script>
<script src="foreground/js/folder_shortcuts_data_model.js"></script> <script src="foreground/js/folder_shortcuts_data_model.js"></script>
<script src="foreground/js/metadata/metadata_cache.js"></script> <script src="foreground/js/metadata/metadata_cache.js"></script>
<script src="foreground/js/naming_controller.js"></script>
<script src="foreground/js/navigation_list_model.js"></script> <script src="foreground/js/navigation_list_model.js"></script>
<script src="foreground/js/progress_center_item_group.js"></script> <script src="foreground/js/progress_center_item_group.js"></script>
<script src="foreground/js/search_controller.js"></script> <script src="foreground/js/search_controller.js"></script>
......
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