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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 | 632 |
633 this.document_.addEventListener('canExecute', | 633 this.document_.addEventListener('canExecute', |
634 this.onCanExecute_.bind(this)); | 634 this.onCanExecute_.bind(this)); |
635 this.document_.addEventListener('command', this.onCommand_.bind(this)); | 635 this.document_.addEventListener('command', this.onCommand_.bind(this)); |
636 } | 636 } |
637 | 637 |
638 /** | 638 /** |
639 * One-time initialization of dialogs. | 639 * One-time initialization of dialogs. |
640 */ | 640 */ |
641 FileManager.prototype.initDialogs_ = function() { | 641 FileManager.prototype.initDialogs_ = function() { |
642 cr.ui.dialogs.BaseDialog.OK_LABEL = str('OK_LABEL'); | 642 var d = cr.ui.dialogs; |
643 cr.ui.dialogs.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL'); | 643 d.BaseDialog.OK_LABEL = str('OK_LABEL'); |
644 this.alert = new cr.ui.dialogs.AlertDialog(this.dialogDom_); | 644 d.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL'); |
645 this.confirm = new cr.ui.dialogs.ConfirmDialog(this.dialogDom_); | 645 this.alert = new d.AlertDialog(this.dialogDom_); |
646 this.prompt = new cr.ui.dialogs.PromptDialog(this.dialogDom_); | 646 this.confirm = new d.ConfirmDialog(this.dialogDom_); |
| 647 this.prompt = new d.PromptDialog(this.dialogDom_); |
647 }; | 648 }; |
648 | 649 |
649 /** | 650 /** |
650 * One-time initialization of various DOM nodes. | 651 * One-time initialization of various DOM nodes. |
651 */ | 652 */ |
652 FileManager.prototype.initDom_ = function() { | 653 FileManager.prototype.initDom_ = function() { |
653 // Cache nodes we'll be manipulating. | 654 // Cache nodes we'll be manipulating. |
654 this.previewThumbnails_ = | 655 this.previewThumbnails_ = |
655 this.dialogDom_.querySelector('.preview-thumbnails'); | 656 this.dialogDom_.querySelector('.preview-thumbnails'); |
656 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); | 657 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 new cr.ui.table.TableColumn('cachedMtime_', | 1151 new cr.ui.table.TableColumn('cachedMtime_', |
1151 str('DATE_COLUMN_LABEL'), 21) | 1152 str('DATE_COLUMN_LABEL'), 21) |
1152 ]; | 1153 ]; |
1153 | 1154 |
1154 columns[0].renderFunction = this.renderName_.bind(this); | 1155 columns[0].renderFunction = this.renderName_.bind(this); |
1155 columns[1].renderFunction = this.renderSize_.bind(this); | 1156 columns[1].renderFunction = this.renderSize_.bind(this); |
1156 columns[2].renderFunction = this.renderType_.bind(this); | 1157 columns[2].renderFunction = this.renderType_.bind(this); |
1157 columns[3].renderFunction = this.renderDate_.bind(this); | 1158 columns[3].renderFunction = this.renderDate_.bind(this); |
1158 | 1159 |
1159 if (this.showCheckboxes_) { | 1160 if (this.showCheckboxes_) { |
1160 columns.unshift(new cr.ui.table.TableColumn('checkbox_', '', 3)); | 1161 columns.unshift(new cr.ui.table.TableColumn('checkbox_', '', 3.6)); |
1161 columns[0].renderFunction = this.renderCheckbox_.bind(this); | 1162 columns[0].renderFunction = this.renderCheckbox_.bind(this); |
| 1163 columns[0].headerRenderFunction = |
| 1164 this.renderCheckboxColumnHeader_.bind(this); |
1162 } | 1165 } |
1163 | 1166 |
1164 this.table_ = this.dialogDom_.querySelector('.detail-table'); | 1167 this.table_ = this.dialogDom_.querySelector('.detail-table'); |
1165 cr.ui.Table.decorate(this.table_); | 1168 cr.ui.Table.decorate(this.table_); |
1166 | 1169 |
1167 this.table_.selectionModel = new this.selectionModelClass_(); | 1170 this.table_.selectionModel = new this.selectionModelClass_(); |
1168 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); | 1171 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); |
1169 | 1172 |
1170 this.table_.addEventListener( | 1173 this.table_.addEventListener( |
1171 'dblclick', this.onDetailDoubleClick_.bind(this)); | 1174 'dblclick', this.onDetailDoubleClick_.bind(this)); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 if (this.selection && this.selection.entries.indexOf(entry) != -1) { | 1540 if (this.selection && this.selection.entries.indexOf(entry) != -1) { |
1538 // Our DOM nodes get discarded as soon as we're scrolled out of view, | 1541 // Our DOM nodes get discarded as soon as we're scrolled out of view, |
1539 // so we have to make sure the check state is correct when we're brought | 1542 // so we have to make sure the check state is correct when we're brought |
1540 // back to life. | 1543 // back to life. |
1541 input.checked = true; | 1544 input.checked = true; |
1542 } | 1545 } |
1543 | 1546 |
1544 return input; | 1547 return input; |
1545 }; | 1548 }; |
1546 | 1549 |
| 1550 FileManager.prototype.renderCheckboxColumnHeader_ = function(table) { |
| 1551 var input = this.document_.createElement('input'); |
| 1552 input.setAttribute('type', 'checkbox'); |
| 1553 input.setAttribute('tabindex', -1); |
| 1554 input.id = 'select-all-checkbox'; |
| 1555 input.checked = this.areAllItemsSelected(); |
| 1556 |
| 1557 var self = this; |
| 1558 input.addEventListener('click', function(event) { |
| 1559 if (self.areAllItemsSelected()) |
| 1560 table.selectionModel.unselectAll(); |
| 1561 else |
| 1562 table.selectionModel.selectAll(); |
| 1563 event.preventDefault(); |
| 1564 }); |
| 1565 |
| 1566 return input; |
| 1567 }; |
| 1568 |
| 1569 /** |
| 1570 * Check if all items in the current list are selected. |
| 1571 * @return {boolean} True if all items are selected. |
| 1572 */ |
| 1573 FileManager.prototype.areAllItemsSelected = function() { |
| 1574 return this.selection && |
| 1575 this.dataModel_.length == this.selection.totalCount; |
| 1576 }; |
| 1577 |
1547 /** | 1578 /** |
1548 * Insert a thumbnail image to fit/fill the container. | 1579 * Insert a thumbnail image to fit/fill the container. |
1549 * | 1580 * |
1550 * Using webkit center packing does not align the image properly, so we need | 1581 * Using webkit center packing does not align the image properly, so we need |
1551 * to wait until the image loads and its proportions are known, then manually | 1582 * to wait until the image loads and its proportions are known, then manually |
1552 * position it at the center. | 1583 * position it at the center. |
1553 * | 1584 * |
1554 * @param {HTMLElement} parent | 1585 * @param {HTMLElement} parent |
1555 * @param {HTMLImageElement} img | 1586 * @param {HTMLImageElement} img |
1556 * @param {string} url | 1587 * @param {string} url |
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2812 if (this.selection.totalCount > 0) { | 2843 if (this.selection.totalCount > 0) { |
2813 // If more than one file is selected, make sure all checkboxes are lit | 2844 // If more than one file is selected, make sure all checkboxes are lit |
2814 // up. | 2845 // up. |
2815 for (var i = 0; i < this.selection.entries.length; i++) { | 2846 for (var i = 0; i < this.selection.entries.length; i++) { |
2816 var selectedIndex = this.selection.indexes[i]; | 2847 var selectedIndex = this.selection.indexes[i]; |
2817 var listItem = this.currentList_.getListItemByIndex(selectedIndex); | 2848 var listItem = this.currentList_.getListItemByIndex(selectedIndex); |
2818 if (listItem) | 2849 if (listItem) |
2819 listItem.querySelector('input[type="checkbox"]').checked = true; | 2850 listItem.querySelector('input[type="checkbox"]').checked = true; |
2820 } | 2851 } |
2821 } | 2852 } |
| 2853 var selectAllCheckbox = |
| 2854 this.document_.getElementById('select-all-checkbox'); |
| 2855 if (selectAllCheckbox) |
| 2856 selectAllCheckbox.checked = this.areAllItemsSelected(); |
2822 }; | 2857 }; |
2823 | 2858 |
2824 FileManager.prototype.updateOkButton_ = function(event) { | 2859 FileManager.prototype.updateOkButton_ = function(event) { |
2825 var selectable; | 2860 var selectable; |
2826 | 2861 |
2827 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 2862 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
2828 selectable = this.selection.directoryCount == 1 && | 2863 selectable = this.selection.directoryCount == 1 && |
2829 this.selection.fileCount == 0; | 2864 this.selection.fileCount == 0; |
2830 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 2865 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
2831 selectable = (this.selection.directoryCount == 0 && | 2866 selectable = (this.selection.directoryCount == 0 && |
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3814 }); | 3849 }); |
3815 }, onError); | 3850 }, onError); |
3816 | 3851 |
3817 function onError(err) { | 3852 function onError(err) { |
3818 console.log('Error while checking free space: ' + err); | 3853 console.log('Error while checking free space: ' + err); |
3819 setTimeout(doCheck, 1000 * 60); | 3854 setTimeout(doCheck, 1000 * 60); |
3820 } | 3855 } |
3821 } | 3856 } |
3822 } | 3857 } |
3823 })(); | 3858 })(); |
OLD | NEW |