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

Unified Diff: ui/file_manager/file_manager/foreground/js/dialog_action_controller.js

Issue 707973004: Files.app: Move lines related with the file type drop down list to DialogActionController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/file_manager/file_manager/foreground/js/file_manager.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/dialog_action_controller.js
diff --git a/ui/file_manager/file_manager/foreground/js/dialog_action_controller.js b/ui/file_manager/file_manager/foreground/js/dialog_action_controller.js
index 05b254d9d91c97b5df7b7ad700a881a56e079c1c..f01a1465a51f9badbe7ce231a7cc7e43ba1a407c 100644
--- a/ui/file_manager/file_manager/foreground/js/dialog_action_controller.js
+++ b/ui/file_manager/file_manager/foreground/js/dialog_action_controller.js
@@ -10,8 +10,9 @@
* @param {!DialogFooter} dialogFooter Dialog footer.
* @param {!DirectoryModel} directoryModel Directory model.
* @param {!MetadataCache} metadataCache Metadata cache.
+ * @param {!FileFilter} fileFilter File filter model.
* @param {!NamingController} namingController Naming controller.
- * @param {boolean} shouldReturnLocalPath Whether the dialog should return local
+ * @param {!LaunchParam} launchParam Whether the dialog should return local
* path or not.
* @constructor
* @struct
@@ -21,8 +22,9 @@ function DialogActionController(
dialogFooter,
directoryModel,
metadataCache,
+ fileFilter,
namingController,
- shouldReturnLocalPath) {
+ launchParam) {
/**
* @type {!DialogType}
* @const
@@ -52,6 +54,13 @@ function DialogActionController(
this.metadataCache_ = metadataCache;
/**
+ * @type {!FileFilter}
+ * @const
+ * @private
+ */
+ this.fileFilter_ = fileFilter;
+
+ /**
* @type {!NamingController}
* @const
* @private
@@ -59,11 +68,18 @@ function DialogActionController(
this.namingController_ = namingController;
/**
+ * List of acceptable file types for open dialog.
+ * @type {!Array.<Object>}
+ * @private
+ */
+ this.fileTypes_ = launchParam.typeList || [];
+
+ /**
* @type {boolean}
* @const
* @private
*/
- this.shouldReturnLocalPath_ = shouldReturnLocalPath;
+ this.shouldReturnLocalPath_ = launchParam.shouldReturnLocalPath;
/**
* Bound function for onCancel_.
@@ -76,6 +92,11 @@ function DialogActionController(
'click', this.processOKAction_.bind(this));
dialogFooter.cancelButton.addEventListener(
'click', this.onCancelBound_);
+ dialogFooter.fileTypeSelector.addEventListener(
+ 'change', this.onFileTypeFilterChanged_.bind(this));
+ dialogFooter.initFileTypeFilter(
+ this.fileTypes_, launchParam.includeAllFiles);
+ this.onFileTypeFilterChanged_();
}
/**
@@ -318,3 +339,34 @@ DialogActionController.prototype.selectFilesAndClose_ = function(selection) {
this.metadataCache_.get(entries, 'external', onProperties);
}.bind(this));
};
+
+/**
+ * Filters file according to the selected file type.
+ * @private
+ */
+DialogActionController.prototype.onFileTypeFilterChanged_ = function() {
+ this.fileFilter_.removeFilter('fileType');
+ var selectedIndex = this.dialogFooter_.selectedFilterIndex;
+ if (selectedIndex > 0) { // Specific filter selected.
+ var regexp = new RegExp('\\.(' +
+ this.fileTypes_[selectedIndex - 1].extensions.join('|') + ')$', 'i');
+ var filter = function(entry) {
+ return entry.isDirectory || regexp.test(entry.name);
+ };
+ this.fileFilter_.addFilter('fileType', filter);
+
+ // In save dialog, update the destination name extension.
+ if (this.dialogType_ === DialogType.SELECT_SAVEAS_FILE) {
+ var current = this.dialogFooter_.filenameInput.value;
+ var newExt = this.fileTypes_[selectedIndex - 1].extensions[0];
+ if (newExt && !regexp.test(current)) {
+ var i = current.lastIndexOf('.');
+ if (i >= 0) {
+ this.dialogFooter_.filenameInput.value =
+ current.substr(0, i) + '.' + newExt;
+ this.dialogFooter_.selectTargetNameInFilenameInput();
+ }
+ }
+ }
+ }
+};
« no previous file with comments | « no previous file | ui/file_manager/file_manager/foreground/js/file_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698