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