| OLD | NEW |
| 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 /** | 5 /** |
| 6 * FileManager constructor. | 6 * FileManager constructor. |
| 7 * | 7 * |
| 8 * FileManager objects encapsulate the functionality of the file selector | 8 * FileManager objects encapsulate the functionality of the file selector |
| 9 * dialogs, as well as the full screen file manager application (though the | 9 * dialogs, as well as the full screen file manager application (though the |
| 10 * latter is not yet implemented). | 10 * latter is not yet implemented). |
| (...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 butter.querySelector('.actions').classList.add('hide-in-butter'); | 1034 butter.querySelector('.actions').classList.add('hide-in-butter'); |
| 1035 butter.querySelector('.progress-bar').classList.add('hide-in-butter'); | 1035 butter.querySelector('.progress-bar').classList.add('hide-in-butter'); |
| 1036 }, delay + 1000); | 1036 }, delay + 1000); |
| 1037 | 1037 |
| 1038 this.currentButter_ = null; | 1038 this.currentButter_ = null; |
| 1039 } | 1039 } |
| 1040 }; | 1040 }; |
| 1041 | 1041 |
| 1042 /** | 1042 /** |
| 1043 * Index of selected item in the typeList of the dialog params. | 1043 * Index of selected item in the typeList of the dialog params. |
| 1044 * @return {intener} Index of selected type from this.fileTypes_ + 1. 0 | 1044 * @return {number} 1-based index of selected type or 0 if no type selected. |
| 1045 * means value is not specified. | |
| 1046 */ | 1045 */ |
| 1047 FileManager.prototype.getSelectedFilterIndex_ = function() { | 1046 FileManager.prototype.getSelectedFilterIndex_ = function() { |
| 1048 // 0 is the 'All files' item. | 1047 var index = Number(this.fileTypeSelector_.selectedIndex); |
| 1049 return Math.min(0, this.fileTypeSelector_.selectedIndex); | 1048 if (index < 0) // Nothing selected. |
| 1049 return 0; |
| 1050 if (this.params_.includeAllFiles) // Already 1-based. |
| 1051 return index; |
| 1052 return index + 1; // Convert to 1-based; |
| 1050 }; | 1053 }; |
| 1051 | 1054 |
| 1052 /** | 1055 /** |
| 1053 * Force the canExecute events to be dispatched. | 1056 * Force the canExecute events to be dispatched. |
| 1054 */ | 1057 */ |
| 1055 FileManager.prototype.updateCommands_ = function() { | 1058 FileManager.prototype.updateCommands_ = function() { |
| 1056 for (var key in this.commands_) | 1059 for (var key in this.commands_) |
| 1057 this.commands_[key].disabled = !this.canExecute_(key); | 1060 this.commands_[key].disabled = !this.canExecute_(key); |
| 1058 }; | 1061 }; |
| 1059 | 1062 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 this.table_.columnModel = | 1381 this.table_.columnModel = |
| 1379 (this.isOnGData() && this.gdataColumnModel_) ? | 1382 (this.isOnGData() && this.gdataColumnModel_) ? |
| 1380 this.gdataColumnModel_ : | 1383 this.gdataColumnModel_ : |
| 1381 this.regularColumnModel_; | 1384 this.regularColumnModel_; |
| 1382 }; | 1385 }; |
| 1383 | 1386 |
| 1384 /** | 1387 /** |
| 1385 * Fills the file type list or hides it. | 1388 * Fills the file type list or hides it. |
| 1386 */ | 1389 */ |
| 1387 FileManager.prototype.initFileTypeFilter_ = function() { | 1390 FileManager.prototype.initFileTypeFilter_ = function() { |
| 1388 if (this.fileTypes_.length == 0) { | 1391 if (this.params_.includeAllFiles) { |
| 1389 this.fileTypeSelector_.hidden = true; | 1392 var option = this.document_.createElement('option'); |
| 1390 return; | 1393 option.innerText = str('ALL_FILES_FILTER'); |
| 1394 this.fileTypeSelector_.appendChild(option); |
| 1395 option.value = 0; |
| 1391 } | 1396 } |
| 1392 | 1397 |
| 1393 var option = this.document_.createElement('option'); | 1398 for (var i = 0; i < this.fileTypes_.length; i++) { |
| 1394 option.innerText = str('ALL_FILES_FILTER'); | 1399 var fileType = this.fileTypes_[i]; |
| 1395 this.fileTypeSelector_.appendChild(option); | 1400 var option = this.document_.createElement('option'); |
| 1396 option.value = 0; | 1401 var description = fileType.description; |
| 1402 if (!description) { |
| 1403 // See if all the extensions in the group have the same description. |
| 1404 for (var j = 0; j != fileType.extensions.length; j++) { |
| 1405 var currentDescription = |
| 1406 this.getFileTypeString_('.' + fileType.extensions[j]); |
| 1407 if (!description) // Set the first time. |
| 1408 description = currentDescription; |
| 1409 else if (description != currentDescription) { |
| 1410 // No single description, fall through to the extension list. |
| 1411 description = null; |
| 1412 break; |
| 1413 } |
| 1414 } |
| 1397 | 1415 |
| 1398 for (var i = 0; i < this.fileTypes_.length; i++) { | 1416 if (!description) |
| 1399 var option = this.document_.createElement('option'); | 1417 // Convert ['jpg', 'png'] to '*.jpg, *.png'. |
| 1400 var description = this.fileTypes_[i].description; | 1418 description = fileType.extensions.map(function(s) { |
| 1401 if (!description) { | 1419 return '*.' + s; |
| 1402 if (this.fileTypes_[i].extensions.length == 1) { | 1420 }).join(', '); |
| 1403 description = this.getFileTypeString_('.' + | |
| 1404 this.fileTypes_[i].extensions[0]); | |
| 1405 } else { | |
| 1406 description = this.fileTypes_[i].extensions.join(', '); | |
| 1407 } | |
| 1408 } | 1421 } |
| 1409 option.innerText = description; | 1422 option.innerText = description; |
| 1410 | 1423 |
| 1411 option.value = i + 1; | 1424 option.value = i + 1; |
| 1412 | 1425 |
| 1413 if (this.fileTypes_[i].selected) | 1426 if (fileType.selected) |
| 1414 option.selected = true; | 1427 option.selected = true; |
| 1415 | 1428 |
| 1416 this.fileTypeSelector_.appendChild(option); | 1429 this.fileTypeSelector_.appendChild(option); |
| 1417 } | 1430 } |
| 1418 | 1431 |
| 1432 var options = this.fileTypeSelector_.querySelectorAll('option'); |
| 1433 if (options.length < 2) { |
| 1434 // There is in fact no choice, hide the selector. |
| 1435 this.fileTypeSelector_.hidden = true; |
| 1436 return; |
| 1437 } |
| 1438 |
| 1419 this.fileTypeSelector_.addEventListener('change', | 1439 this.fileTypeSelector_.addEventListener('change', |
| 1420 this.updateFileTypeFilter_.bind(this)); | 1440 this.updateFileTypeFilter_.bind(this)); |
| 1421 }; | 1441 }; |
| 1422 | 1442 |
| 1423 /** | 1443 /** |
| 1424 * Filters file according to the selected file type. | 1444 * Filters file according to the selected file type. |
| 1425 */ | 1445 */ |
| 1426 FileManager.prototype.updateFileTypeFilter_ = function() { | 1446 FileManager.prototype.updateFileTypeFilter_ = function() { |
| 1427 this.directoryModel_.removeFilter('fileType'); | 1447 this.directoryModel_.removeFilter('fileType'); |
| 1428 var selectedIndex = Number(this.fileTypeSelector_.selectedIndex); | 1448 var selectedIndex = this.getSelectedFilterIndex_(); |
| 1429 if (selectedIndex >= 1) { // Specific filter selected. | 1449 if (selectedIndex > 0) { // Specific filter selected. |
| 1430 var regexp = new RegExp('.*(' + | 1450 var regexp = new RegExp('.*(' + |
| 1431 this.fileTypes_[selectedIndex - 1].extensions.join('|') + ')$', 'i'); | 1451 this.fileTypes_[selectedIndex - 1].extensions.join('|') + ')$', 'i'); |
| 1432 function filter(entry) { | 1452 function filter(entry) { |
| 1433 return entry.isDirectory || regexp.test(entry.name); | 1453 return entry.isDirectory || regexp.test(entry.name); |
| 1434 } | 1454 } |
| 1435 this.directoryModel_.addFilter('fileType', filter); | 1455 this.directoryModel_.addFilter('fileType', filter); |
| 1436 } | 1456 } |
| 1437 this.directoryModel_.rescan(); | 1457 this.directoryModel_.rescan(); |
| 1438 }; | 1458 }; |
| 1439 | 1459 |
| (...skipping 2793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4233 } | 4253 } |
| 4234 | 4254 |
| 4235 var defaultActionSeparator = | 4255 var defaultActionSeparator = |
| 4236 this.dialogDom_.querySelector('#default-action-separator'); | 4256 this.dialogDom_.querySelector('#default-action-separator'); |
| 4237 | 4257 |
| 4238 this.defaultActionMenuItem_.hidden = !taskItem; | 4258 this.defaultActionMenuItem_.hidden = !taskItem; |
| 4239 defaultActionSeparator.hidden = !taskItem; | 4259 defaultActionSeparator.hidden = !taskItem; |
| 4240 } | 4260 } |
| 4241 })(); | 4261 })(); |
| 4242 | 4262 |
| OLD | NEW |