Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/file_manager.js |
| diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js |
| index 532eab6b2787aec1d99f756528577680e0042cdc..f08fd1efef8977b4f2bf1c05dda41def0a6100e2 100644 |
| --- a/chrome/browser/resources/file_manager/js/file_manager.js |
| +++ b/chrome/browser/resources/file_manager/js/file_manager.js |
| @@ -1040,12 +1040,15 @@ FileManager.prototype = { |
| /** |
| * Index of selected item in the typeList of the dialog params. |
| - * @return {intener} Index of selected type from this.fileTypes_ + 1. 0 |
| - * means value is not specified. |
| + * @return {number} 1-based index of selected type or 0 if no type selected. |
| */ |
| FileManager.prototype.getSelectedFilterIndex_ = function() { |
| - // 0 is the 'All files' item. |
| - return Math.min(0, this.fileTypeSelector_.selectedIndex); |
| + var index = Number(this.fileTypeSelector_.selectedIndex); |
| + if (index < 0) // Nothing selected. |
| + return 0; |
| + if (this.params_.includeAllFiles) // Already 1-based. |
| + return index; |
| + return index + 1; // Convert to 1-based; |
| }; |
| /** |
| @@ -1384,37 +1387,54 @@ FileManager.prototype = { |
| * Fills the file type list or hides it. |
| */ |
| FileManager.prototype.initFileTypeFilter_ = function() { |
| - if (this.fileTypes_.length == 0) { |
| - this.fileTypeSelector_.hidden = true; |
| - return; |
| + if (this.params_.includeAllFiles) { |
| + var option = this.document_.createElement('option'); |
| + option.innerText = str('ALL_FILES_FILTER'); |
| + this.fileTypeSelector_.appendChild(option); |
| + option.value = 0; |
| } |
| - var option = this.document_.createElement('option'); |
| - option.innerText = str('ALL_FILES_FILTER'); |
| - this.fileTypeSelector_.appendChild(option); |
| - option.value = 0; |
| - |
| for (var i = 0; i < this.fileTypes_.length; i++) { |
| - var option = this.document_.createElement('option'); |
| - var description = this.fileTypes_[i].description; |
| - if (!description) { |
| - if (this.fileTypes_[i].extensions.length == 1) { |
| - description = this.getFileTypeString_('.' + |
| - this.fileTypes_[i].extensions[0]); |
| - } else { |
| - description = this.fileTypes_[i].extensions.join(', '); |
| - } |
| + var fileType = this.fileTypes_[i]; |
| + var option = this.document_.createElement('option'); |
| + var description = fileType.description; |
| + if (!description) { |
| + // See if all the extensions in the group have the same description. |
| + for (var j = 0; j != fileType.extensions.length; j++) { |
| + var currentDescription = |
| + this.getFileTypeString_('.' + fileType.extensions[j]); |
| + if (!description) // Set the first time. |
| + description = currentDescription; |
| + else if (description != currentDescription) { |
| + // No single description, fall through to the extension list. |
| + description = null; |
| + break; |
| + } |
| + } |
| + |
| + if (!description) |
| + // Convert ['jpg', 'png'] to '*.jpg, *.png'. |
| + description = fileType.extensions.map(function(s) { |
| + return '*.' + s; |
|
SeRya
2012/08/02 09:01:18
1. Indention.
2. Initially I did the same. But Dmi
|
| + }).join(', '); |
| } |
| option.innerText = description; |
| option.value = i + 1; |
| - if (this.fileTypes_[i].selected) |
| + if (fileType[i].selected) |
| option.selected = true; |
| this.fileTypeSelector_.appendChild(option); |
| } |
| + var options = this.fileTypeSelector_.querySelectorAll('option'); |
|
SeRya
2012/08/02 09:01:18
this.fileTypeSelector_.options
|
| + if (options.length < 2) { |
| + // There is in fact no choice, hide the selector. |
| + this.fileTypeSelector_.hidden = true; |
| + return; |
| + } |
| + |
| this.fileTypeSelector_.addEventListener('change', |
| this.updateFileTypeFilter_.bind(this)); |
| }; |
| @@ -1424,8 +1444,8 @@ FileManager.prototype = { |
| */ |
| FileManager.prototype.updateFileTypeFilter_ = function() { |
| this.directoryModel_.removeFilter('fileType'); |
| - var selectedIndex = Number(this.fileTypeSelector_.selectedIndex); |
| - if (selectedIndex >= 1) { // Specific filter selected. |
| + var selectedIndex = this.getSelectedFilterIndex_(); |
| + if (selectedIndex > 0) { // Specific filter selected. |
| var regexp = new RegExp('.*(' + |
| this.fileTypes_[selectedIndex - 1].extensions.join('|') + ')$', 'i'); |
| function filter(entry) { |