OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
9 | 9 |
10 var g_slideshow_data = null; | 10 var g_slideshow_data = null; |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 this.dataModel_.prepareSort = this.prepareSort_.bind(this); | 743 this.dataModel_.prepareSort = this.prepareSort_.bind(this); |
744 | 744 |
745 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE || | 745 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE || |
746 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FOLDER || | 746 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FOLDER || |
747 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 747 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
748 this.selectionModelClass_ = cr.ui.ListSingleSelectionModel; | 748 this.selectionModelClass_ = cr.ui.ListSingleSelectionModel; |
749 } else { | 749 } else { |
750 this.selectionModelClass_ = cr.ui.ListSelectionModel; | 750 this.selectionModelClass_ = cr.ui.ListSelectionModel; |
751 } | 751 } |
752 | 752 |
| 753 this.dataModel_.addEventListener('splice', |
| 754 this.onDataModelSplice_.bind(this)); |
| 755 |
753 this.initTable_(); | 756 this.initTable_(); |
754 this.initGrid_(); | 757 this.initGrid_(); |
755 | 758 |
756 this.setListType(FileManager.ListType.DETAIL); | 759 this.setListType(FileManager.ListType.DETAIL); |
757 | 760 |
758 this.onResize_(); | 761 this.onResize_(); |
759 | 762 |
760 this.textSearchState_ = {text: '', date: new Date()}; | 763 this.textSearchState_ = {text: '', date: new Date()}; |
761 }; | 764 }; |
762 | 765 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 * @param {Entry} entry An HTML5 Entry object. | 849 * @param {Entry} entry An HTML5 Entry object. |
847 * @param {function(Entry)} successCallback The function to invoke once the | 850 * @param {function(Entry)} successCallback The function to invoke once the |
848 * icon type is known. | 851 * icon type is known. |
849 */ | 852 */ |
850 FileManager.prototype.cacheEntryIconType = function(entry, successCallback) { | 853 FileManager.prototype.cacheEntryIconType = function(entry, successCallback) { |
851 this.getIconType(entry); | 854 this.getIconType(entry); |
852 if (successCallback) | 855 if (successCallback) |
853 setTimeout(function() { successCallback(entry) }, 0); | 856 setTimeout(function() { successCallback(entry) }, 0); |
854 }; | 857 }; |
855 | 858 |
| 859 FileManager.prototype.onDataModelSplice_ = function(event) { |
| 860 var checkbox = this.document_.querySelector('#select-all-checkbox'); |
| 861 if (checkbox) |
| 862 this.updateSelectAllCheckboxState_(checkbox); |
| 863 }; |
| 864 |
856 /** | 865 /** |
857 * Get the file type of the entry, caching the result. | 866 * Get the file type of the entry, caching the result. |
858 * | 867 * |
859 * When this method completes, the entry object will get a | 868 * When this method completes, the entry object will get a |
860 * 'cachedIconType_' property (if it doesn't already have one) containing the | 869 * 'cachedIconType_' property (if it doesn't already have one) containing the |
861 * icon type of the file as a string. | 870 * icon type of the file as a string. |
862 * | 871 * |
863 * @param {Entry} entry An HTML5 Entry object. | 872 * @param {Entry} entry An HTML5 Entry object. |
864 * @param {function(Entry)} successCallback The function to invoke once the | 873 * @param {function(Entry)} successCallback The function to invoke once the |
865 * file size is known. | 874 * file size is known. |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 } | 1562 } |
1554 | 1563 |
1555 return input; | 1564 return input; |
1556 }; | 1565 }; |
1557 | 1566 |
1558 FileManager.prototype.renderNameColumnHeader_ = function(name, table) { | 1567 FileManager.prototype.renderNameColumnHeader_ = function(name, table) { |
1559 var input = this.document_.createElement('input'); | 1568 var input = this.document_.createElement('input'); |
1560 input.setAttribute('type', 'checkbox'); | 1569 input.setAttribute('type', 'checkbox'); |
1561 input.setAttribute('tabindex', -1); | 1570 input.setAttribute('tabindex', -1); |
1562 input.id = 'select-all-checkbox'; | 1571 input.id = 'select-all-checkbox'; |
1563 input.checked = this.areAllItemsSelected(); | 1572 this.updateSelectAllCheckboxState_(input); |
1564 | 1573 |
1565 var self = this; | |
1566 input.addEventListener('click', function(event) { | 1574 input.addEventListener('click', function(event) { |
1567 if (self.areAllItemsSelected()) | 1575 if (input.checked) |
| 1576 table.selectionModel.selectAll(); |
| 1577 else |
1568 table.selectionModel.unselectAll(); | 1578 table.selectionModel.unselectAll(); |
1569 else | |
1570 table.selectionModel.selectAll(); | |
1571 event.preventDefault(); | 1579 event.preventDefault(); |
1572 event.stopPropagation(); | 1580 event.stopPropagation(); |
1573 }); | 1581 }); |
1574 | 1582 |
1575 var fragment = this.document_.createDocumentFragment(); | 1583 var fragment = this.document_.createDocumentFragment(); |
1576 fragment.appendChild(input); | 1584 fragment.appendChild(input); |
1577 fragment.appendChild(this.document_.createTextNode(name)); | 1585 fragment.appendChild(this.document_.createTextNode(name)); |
1578 return fragment; | 1586 return fragment; |
1579 }; | 1587 }; |
1580 | 1588 |
1581 /** | 1589 /** |
1582 * Check if all items in the current list are selected. | 1590 * Update check and disable states of the 'Select all' checkbox. |
1583 * @return {boolean} True if all items are selected. | |
1584 */ | 1591 */ |
1585 FileManager.prototype.areAllItemsSelected = function() { | 1592 FileManager.prototype.updateSelectAllCheckboxState_ = function(checkbox) { |
1586 return this.selection && this.dataModel_.length > 0 && | 1593 checkbox.checked = this.selection && this.dataModel_.length > 0 && |
1587 this.dataModel_.length == this.selection.totalCount; | 1594 this.dataModel_.length == this.selection.totalCount; |
| 1595 checkbox.disabled = this.dataModel_.length == 0; |
1588 }; | 1596 }; |
1589 | 1597 |
1590 /** | 1598 /** |
1591 * Update the thumbnail image to fit/fill the square container. | 1599 * Update the thumbnail image to fit/fill the square container. |
1592 * | 1600 * |
1593 * Using webkit center packing does not align the image properly, so we need | 1601 * Using webkit center packing does not align the image properly, so we need |
1594 * to wait until the image loads and its proportions are known, then manually | 1602 * to wait until the image loads and its proportions are known, then manually |
1595 * position it at the center. | 1603 * position it at the center. |
1596 * | 1604 * |
1597 * @param {CSSStyleDeclaration} style Style object of the image. | 1605 * @param {CSSStyleDeclaration} style Style object of the image. |
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2934 for (var i = 0; i < this.selection.entries.length; i++) { | 2942 for (var i = 0; i < this.selection.entries.length; i++) { |
2935 var selectedIndex = this.selection.indexes[i]; | 2943 var selectedIndex = this.selection.indexes[i]; |
2936 var listItem = this.currentList_.getListItemByIndex(selectedIndex); | 2944 var listItem = this.currentList_.getListItemByIndex(selectedIndex); |
2937 if (listItem) | 2945 if (listItem) |
2938 listItem.querySelector('input[type="checkbox"]').checked = true; | 2946 listItem.querySelector('input[type="checkbox"]').checked = true; |
2939 } | 2947 } |
2940 } | 2948 } |
2941 var selectAllCheckbox = | 2949 var selectAllCheckbox = |
2942 this.document_.getElementById('select-all-checkbox'); | 2950 this.document_.getElementById('select-all-checkbox'); |
2943 if (selectAllCheckbox) | 2951 if (selectAllCheckbox) |
2944 selectAllCheckbox.checked = this.areAllItemsSelected(); | 2952 this.updateSelectAllCheckboxState_(selectAllCheckbox); |
2945 }; | 2953 }; |
2946 | 2954 |
2947 FileManager.prototype.updateOkButton_ = function(event) { | 2955 FileManager.prototype.updateOkButton_ = function(event) { |
2948 var selectable; | 2956 var selectable; |
2949 | 2957 |
2950 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 2958 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
2951 selectable = this.selection.directoryCount == 1 && | 2959 selectable = this.selection.directoryCount == 1 && |
2952 this.selection.fileCount == 0; | 2960 this.selection.fileCount == 0; |
2953 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 2961 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
2954 selectable = (this.selection.directoryCount == 0 && | 2962 selectable = (this.selection.directoryCount == 0 && |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3982 }); | 3990 }); |
3983 }, onError); | 3991 }, onError); |
3984 | 3992 |
3985 function onError(err) { | 3993 function onError(err) { |
3986 console.log('Error while checking free space: ' + err); | 3994 console.log('Error while checking free space: ' + err); |
3987 setTimeout(doCheck, 1000 * 60); | 3995 setTimeout(doCheck, 1000 * 60); |
3988 } | 3996 } |
3989 } | 3997 } |
3990 } | 3998 } |
3991 })(); | 3999 })(); |
OLD | NEW |