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 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 new cr.ui.table.TableColumn('cachedMtime_', | 1153 new cr.ui.table.TableColumn('cachedMtime_', |
1154 str('DATE_COLUMN_LABEL'), 21) | 1154 str('DATE_COLUMN_LABEL'), 21) |
1155 ]; | 1155 ]; |
1156 | 1156 |
1157 columns[0].renderFunction = this.renderName_.bind(this); | 1157 columns[0].renderFunction = this.renderName_.bind(this); |
1158 columns[1].renderFunction = this.renderSize_.bind(this); | 1158 columns[1].renderFunction = this.renderSize_.bind(this); |
1159 columns[2].renderFunction = this.renderType_.bind(this); | 1159 columns[2].renderFunction = this.renderType_.bind(this); |
1160 columns[3].renderFunction = this.renderDate_.bind(this); | 1160 columns[3].renderFunction = this.renderDate_.bind(this); |
1161 | 1161 |
1162 if (this.showCheckboxes_) { | 1162 if (this.showCheckboxes_) { |
1163 columns.unshift(new cr.ui.table.TableColumn('checkbox_', '', 3.6)); | |
1164 columns[0].renderFunction = this.renderCheckbox_.bind(this); | |
1165 columns[0].headerRenderFunction = | 1163 columns[0].headerRenderFunction = |
1166 this.renderCheckboxColumnHeader_.bind(this); | 1164 this.renderNameColumnHeader_.bind(this, columns[0].name); |
1167 } | 1165 } |
1168 | 1166 |
1169 this.table_ = this.dialogDom_.querySelector('.detail-table'); | 1167 this.table_ = this.dialogDom_.querySelector('.detail-table'); |
1170 cr.ui.Table.decorate(this.table_); | 1168 cr.ui.Table.decorate(this.table_); |
1171 | 1169 |
1172 this.table_.selectionModel = new this.selectionModelClass_(); | 1170 this.table_.selectionModel = new this.selectionModelClass_(); |
1173 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); | 1171 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); |
1174 | 1172 |
1175 this.table_.addEventListener( | 1173 this.table_.addEventListener( |
1176 'dblclick', this.onDetailDoubleClick_.bind(this)); | 1174 'dblclick', this.onDetailDoubleClick_.bind(this)); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 if (this.selection && this.selection.entries.indexOf(entry) != -1) { | 1540 if (this.selection && this.selection.entries.indexOf(entry) != -1) { |
1543 // 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, |
1544 // 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 |
1545 // back to life. | 1543 // back to life. |
1546 input.checked = true; | 1544 input.checked = true; |
1547 } | 1545 } |
1548 | 1546 |
1549 return input; | 1547 return input; |
1550 }; | 1548 }; |
1551 | 1549 |
1552 FileManager.prototype.renderCheckboxColumnHeader_ = function(table) { | 1550 FileManager.prototype.renderNameColumnHeader_ = function(name, table) { |
1553 var input = this.document_.createElement('input'); | 1551 var input = this.document_.createElement('input'); |
1554 input.setAttribute('type', 'checkbox'); | 1552 input.setAttribute('type', 'checkbox'); |
1555 input.setAttribute('tabindex', -1); | 1553 input.setAttribute('tabindex', -1); |
1556 input.id = 'select-all-checkbox'; | 1554 input.id = 'select-all-checkbox'; |
1557 input.checked = this.areAllItemsSelected(); | 1555 input.checked = this.areAllItemsSelected(); |
1558 | 1556 |
1559 var self = this; | 1557 var self = this; |
1560 input.addEventListener('click', function(event) { | 1558 input.addEventListener('click', function(event) { |
1561 if (self.areAllItemsSelected()) | 1559 if (self.areAllItemsSelected()) |
1562 table.selectionModel.unselectAll(); | 1560 table.selectionModel.unselectAll(); |
1563 else | 1561 else |
1564 table.selectionModel.selectAll(); | 1562 table.selectionModel.selectAll(); |
1565 event.preventDefault(); | 1563 event.preventDefault(); |
| 1564 event.stopPropagation(); |
1566 }); | 1565 }); |
1567 | 1566 |
1568 return input; | 1567 var fragment = this.document_.createDocumentFragment(); |
| 1568 fragment.appendChild(input); |
| 1569 fragment.appendChild(this.document_.createTextNode(name)); |
| 1570 return fragment; |
1569 }; | 1571 }; |
1570 | 1572 |
1571 /** | 1573 /** |
1572 * Check if all items in the current list are selected. | 1574 * Check if all items in the current list are selected. |
1573 * @return {boolean} True if all items are selected. | 1575 * @return {boolean} True if all items are selected. |
1574 */ | 1576 */ |
1575 FileManager.prototype.areAllItemsSelected = function() { | 1577 FileManager.prototype.areAllItemsSelected = function() { |
1576 return this.selection && | 1578 return this.selection && this.dataModel_.length > 0 && |
1577 this.dataModel_.length == this.selection.totalCount; | 1579 this.dataModel_.length == this.selection.totalCount; |
1578 }; | 1580 }; |
1579 | 1581 |
1580 /** | 1582 /** |
1581 * Update the thumbnail image to fit/fill the square container. | 1583 * Update the thumbnail image to fit/fill the square container. |
1582 * | 1584 * |
1583 * Using webkit center packing does not align the image properly, so we need | 1585 * Using webkit center packing does not align the image properly, so we need |
1584 * to wait until the image loads and its proportions are known, then manually | 1586 * to wait until the image loads and its proportions are known, then manually |
1585 * position it at the center. | 1587 * position it at the center. |
1586 * | 1588 * |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 /** | 1677 /** |
1676 * Render the type column of the detail table. | 1678 * Render the type column of the detail table. |
1677 * | 1679 * |
1678 * Invoked by cr.ui.Table when a file needs to be rendered. | 1680 * Invoked by cr.ui.Table when a file needs to be rendered. |
1679 * | 1681 * |
1680 * @param {Entry} entry The Entry object to render. | 1682 * @param {Entry} entry The Entry object to render. |
1681 * @param {string} columnId The id of the column to be rendered. | 1683 * @param {string} columnId The id of the column to be rendered. |
1682 * @param {cr.ui.Table} table The table doing the rendering. | 1684 * @param {cr.ui.Table} table The table doing the rendering. |
1683 */ | 1685 */ |
1684 FileManager.prototype.renderIconType_ = function(entry, columnId, table) { | 1686 FileManager.prototype.renderIconType_ = function(entry, columnId, table) { |
1685 var div = this.document_.createElement('div'); | |
1686 div.className = 'detail-icon-container'; | |
1687 | |
1688 var icon = this.document_.createElement('div'); | 1687 var icon = this.document_.createElement('div'); |
1689 icon.className = 'detail-icon'; | 1688 icon.className = 'detail-icon'; |
1690 this.getIconType(entry); | 1689 this.getIconType(entry); |
1691 icon.setAttribute('iconType', entry.cachedIconType_); | 1690 icon.setAttribute('iconType', entry.cachedIconType_); |
1692 div.appendChild(icon); | 1691 return icon; |
1693 | |
1694 return div; | |
1695 }; | 1692 }; |
1696 | 1693 |
1697 FileManager.prototype.getLabelForRootPath_ = function(path) { | 1694 FileManager.prototype.getLabelForRootPath_ = function(path) { |
1698 // This hack lets us localize the top level directories. | 1695 // This hack lets us localize the top level directories. |
1699 if (path == 'Downloads') | 1696 if (path == 'Downloads') |
1700 return str('DOWNLOADS_DIRECTORY_LABEL'); | 1697 return str('DOWNLOADS_DIRECTORY_LABEL'); |
1701 | 1698 |
1702 if (path == 'archive') | 1699 if (path == 'archive') |
1703 return str('ARCHIVE_DIRECTORY_LABEL'); | 1700 return str('ARCHIVE_DIRECTORY_LABEL'); |
1704 | 1701 |
1705 if (path == 'removable') | 1702 if (path == 'removable') |
1706 return str('REMOVABLE_DIRECTORY_LABEL'); | 1703 return str('REMOVABLE_DIRECTORY_LABEL'); |
1707 | 1704 |
1708 return path || str('ROOT_DIRECTORY_LABEL'); | 1705 return path || str('ROOT_DIRECTORY_LABEL'); |
1709 }; | 1706 }; |
1710 | 1707 |
1711 /** | 1708 /** |
1712 * Render the Name column of the detail table. | 1709 * Render the Name column of the detail table. |
1713 * | 1710 * |
1714 * Invoked by cr.ui.Table when a file needs to be rendered. | 1711 * Invoked by cr.ui.Table when a file needs to be rendered. |
1715 * | 1712 * |
1716 * @param {Entry} entry The Entry object to render. | 1713 * @param {Entry} entry The Entry object to render. |
1717 * @param {string} columnId The id of the column to be rendered. | 1714 * @param {string} columnId The id of the column to be rendered. |
1718 * @param {cr.ui.Table} table The table doing the rendering. | 1715 * @param {cr.ui.Table} table The table doing the rendering. |
1719 */ | 1716 */ |
1720 FileManager.prototype.renderName_ = function(entry, columnId, table) { | 1717 FileManager.prototype.renderName_ = function(entry, columnId, table) { |
1721 var label = this.document_.createElement('div'); | 1718 var label = this.document_.createElement('div'); |
| 1719 if (this.showCheckboxes_) |
| 1720 label.appendChild(this.renderCheckbox_(entry)); |
1722 label.appendChild(this.renderIconType_(entry, columnId, table)); | 1721 label.appendChild(this.renderIconType_(entry, columnId, table)); |
1723 label.entry = entry; | 1722 label.entry = entry; |
1724 label.className = 'detail-name filename-label'; | 1723 label.className = 'detail-name'; |
1725 if (this.currentDirEntry_.name == '') { | 1724 if (this.currentDirEntry_.name == '') { |
1726 label.appendChild(this.document_.createTextNode( | 1725 label.appendChild(this.document_.createTextNode( |
1727 this.getLabelForRootPath_(entry.name))); | 1726 this.getLabelForRootPath_(entry.name))); |
1728 } else { | 1727 } else { |
1729 label.appendChild(this.document_.createTextNode(entry.name)); | 1728 label.appendChild(this.document_.createTextNode(entry.name)); |
1730 } | 1729 } |
1731 | 1730 |
1732 return label; | 1731 return label; |
1733 }; | 1732 }; |
1734 | 1733 |
1735 /** | 1734 /** |
1736 * Render the Size column of the detail table. | 1735 * Render the Size column of the detail table. |
1737 * | 1736 * |
1738 * @param {Entry} entry The Entry object to render. | 1737 * @param {Entry} entry The Entry object to render. |
1739 * @param {string} columnId The id of the column to be rendered. | 1738 * @param {string} columnId The id of the column to be rendered. |
1740 * @param {cr.ui.Table} table The table doing the rendering. | 1739 * @param {cr.ui.Table} table The table doing the rendering. |
1741 */ | 1740 */ |
1742 FileManager.prototype.renderSize_ = function(entry, columnId, table) { | 1741 FileManager.prototype.renderSize_ = function(entry, columnId, table) { |
1743 var div = this.document_.createElement('div'); | 1742 var div = this.document_.createElement('div'); |
1744 div.className = 'detail-size'; | |
1745 | 1743 |
1746 div.textContent = '...'; | 1744 div.textContent = '...'; |
1747 cacheEntrySize(entry, function(entry) { | 1745 cacheEntrySize(entry, function(entry) { |
1748 if (entry.cachedSize_ == -1) { | 1746 if (entry.cachedSize_ == -1) { |
1749 div.textContent = ''; | 1747 div.textContent = ''; |
1750 } else { | 1748 } else { |
1751 div.textContent = util.bytesToSi(entry.cachedSize_); | 1749 div.textContent = util.bytesToSi(entry.cachedSize_); |
1752 } | 1750 } |
1753 }, null, true); | 1751 }, null, true); |
1754 | 1752 |
1755 return div; | 1753 return div; |
1756 }; | 1754 }; |
1757 | 1755 |
1758 /** | 1756 /** |
1759 * Render the Type column of the detail table. | 1757 * Render the Type column of the detail table. |
1760 * | 1758 * |
1761 * @param {Entry} entry The Entry object to render. | 1759 * @param {Entry} entry The Entry object to render. |
1762 * @param {string} columnId The id of the column to be rendered. | 1760 * @param {string} columnId The id of the column to be rendered. |
1763 * @param {cr.ui.Table} table The table doing the rendering. | 1761 * @param {cr.ui.Table} table The table doing the rendering. |
1764 */ | 1762 */ |
1765 FileManager.prototype.renderType_ = function(entry, columnId, table) { | 1763 FileManager.prototype.renderType_ = function(entry, columnId, table) { |
1766 var div = this.document_.createElement('div'); | 1764 var div = this.document_.createElement('div'); |
1767 div.className = 'detail-type'; | |
1768 | 1765 |
1769 this.cacheEntryFileType(entry, function(entry) { | 1766 this.cacheEntryFileType(entry, function(entry) { |
1770 var info = entry.cachedFileType_; | 1767 var info = entry.cachedFileType_; |
1771 if (info.name) { | 1768 if (info.name) { |
1772 if (info.subtype) | 1769 if (info.subtype) |
1773 div.textContent = strf(info.name, info.subtype); | 1770 div.textContent = strf(info.name, info.subtype); |
1774 else | 1771 else |
1775 div.textContent = str(info.name); | 1772 div.textContent = str(info.name); |
1776 } else | 1773 } else |
1777 div.textContent = ''; | 1774 div.textContent = ''; |
1778 }, true); | 1775 }, true); |
1779 | 1776 |
1780 return div; | 1777 return div; |
1781 }; | 1778 }; |
1782 | 1779 |
1783 /** | 1780 /** |
1784 * Render the Date column of the detail table. | 1781 * Render the Date column of the detail table. |
1785 * | 1782 * |
1786 * @param {Entry} entry The Entry object to render. | 1783 * @param {Entry} entry The Entry object to render. |
1787 * @param {string} columnId The id of the column to be rendered. | 1784 * @param {string} columnId The id of the column to be rendered. |
1788 * @param {cr.ui.Table} table The table doing the rendering. | 1785 * @param {cr.ui.Table} table The table doing the rendering. |
1789 */ | 1786 */ |
1790 FileManager.prototype.renderDate_ = function(entry, columnId, table) { | 1787 FileManager.prototype.renderDate_ = function(entry, columnId, table) { |
1791 var div = this.document_.createElement('div'); | 1788 var div = this.document_.createElement('div'); |
1792 div.className = 'detail-date'; | |
1793 | 1789 |
1794 div.textContent = '...'; | 1790 div.textContent = '...'; |
1795 | 1791 |
1796 var self = this; | 1792 var self = this; |
1797 cacheEntryDate(entry, function(entry) { | 1793 cacheEntryDate(entry, function(entry) { |
1798 if (isSystemDirEntry(self.currentDirEntry_) && | 1794 if (isSystemDirEntry(self.currentDirEntry_) && |
1799 entry.cachedMtime_.getTime() == 0) { | 1795 entry.cachedMtime_.getTime() == 0) { |
1800 // Mount points for FAT volumes have this time associated with them. | 1796 // Mount points for FAT volumes have this time associated with them. |
1801 // We'd rather display nothing than this bogus date. | 1797 // We'd rather display nothing than this bogus date. |
1802 div.textContent = ''; | 1798 div.textContent = ''; |
(...skipping 2147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3950 }); | 3946 }); |
3951 }, onError); | 3947 }, onError); |
3952 | 3948 |
3953 function onError(err) { | 3949 function onError(err) { |
3954 console.log('Error while checking free space: ' + err); | 3950 console.log('Error while checking free space: ' + err); |
3955 setTimeout(doCheck, 1000 * 60); | 3951 setTimeout(doCheck, 1000 * 60); |
3956 } | 3952 } |
3957 } | 3953 } |
3958 } | 3954 } |
3959 })(); | 3955 })(); |
OLD | NEW |