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 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 new cr.ui.table.TableColumn('cachedMtime_', | 1149 new cr.ui.table.TableColumn('cachedMtime_', |
1150 str('DATE_COLUMN_LABEL'), 21) | 1150 str('DATE_COLUMN_LABEL'), 21) |
1151 ]; | 1151 ]; |
1152 | 1152 |
1153 columns[0].renderFunction = this.renderName_.bind(this); | 1153 columns[0].renderFunction = this.renderName_.bind(this); |
1154 columns[1].renderFunction = this.renderSize_.bind(this); | 1154 columns[1].renderFunction = this.renderSize_.bind(this); |
1155 columns[2].renderFunction = this.renderType_.bind(this); | 1155 columns[2].renderFunction = this.renderType_.bind(this); |
1156 columns[3].renderFunction = this.renderDate_.bind(this); | 1156 columns[3].renderFunction = this.renderDate_.bind(this); |
1157 | 1157 |
1158 if (this.showCheckboxes_) { | 1158 if (this.showCheckboxes_) { |
1159 columns.unshift(new cr.ui.table.TableColumn('checkbox_', '', 3.6)); | |
1160 columns[0].renderFunction = this.renderCheckbox_.bind(this); | |
1161 columns[0].headerRenderFunction = | 1159 columns[0].headerRenderFunction = |
1162 this.renderCheckboxColumnHeader_.bind(this); | 1160 this.renderNameColumnHeader_.bind(this, columns[0].name); |
1163 } | 1161 } |
1164 | 1162 |
1165 this.table_ = this.dialogDom_.querySelector('.detail-table'); | 1163 this.table_ = this.dialogDom_.querySelector('.detail-table'); |
1166 cr.ui.Table.decorate(this.table_); | 1164 cr.ui.Table.decorate(this.table_); |
1167 | 1165 |
1168 this.table_.selectionModel = new this.selectionModelClass_(); | 1166 this.table_.selectionModel = new this.selectionModelClass_(); |
1169 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); | 1167 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); |
1170 | 1168 |
1171 this.table_.addEventListener( | 1169 this.table_.addEventListener( |
1172 'dblclick', this.onDetailDoubleClick_.bind(this)); | 1170 'dblclick', this.onDetailDoubleClick_.bind(this)); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 if (this.selection && this.selection.entries.indexOf(entry) != -1) { | 1536 if (this.selection && this.selection.entries.indexOf(entry) != -1) { |
1539 // Our DOM nodes get discarded as soon as we're scrolled out of view, | 1537 // Our DOM nodes get discarded as soon as we're scrolled out of view, |
1540 // so we have to make sure the check state is correct when we're brought | 1538 // so we have to make sure the check state is correct when we're brought |
1541 // back to life. | 1539 // back to life. |
1542 input.checked = true; | 1540 input.checked = true; |
1543 } | 1541 } |
1544 | 1542 |
1545 return input; | 1543 return input; |
1546 }; | 1544 }; |
1547 | 1545 |
1548 FileManager.prototype.renderCheckboxColumnHeader_ = function(table) { | 1546 FileManager.prototype.renderNameColumnHeader_ = function(name, table) { |
1549 var input = this.document_.createElement('input'); | 1547 var input = this.document_.createElement('input'); |
1550 input.setAttribute('type', 'checkbox'); | 1548 input.setAttribute('type', 'checkbox'); |
1551 input.setAttribute('tabindex', -1); | 1549 input.setAttribute('tabindex', -1); |
1552 input.id = 'select-all-checkbox'; | 1550 input.id = 'select-all-checkbox'; |
1553 input.checked = this.areAllItemsSelected(); | 1551 input.checked = this.areAllItemsSelected(); |
1554 | 1552 |
1555 var self = this; | 1553 var self = this; |
1556 input.addEventListener('click', function(event) { | 1554 input.addEventListener('click', function(event) { |
1557 if (self.areAllItemsSelected()) | 1555 if (self.areAllItemsSelected()) |
1558 table.selectionModel.unselectAll(); | 1556 table.selectionModel.unselectAll(); |
1559 else | 1557 else |
1560 table.selectionModel.selectAll(); | 1558 table.selectionModel.selectAll(); |
1561 event.preventDefault(); | 1559 event.preventDefault(); |
| 1560 event.stopPropagation(); |
1562 }); | 1561 }); |
1563 | 1562 |
1564 return input; | 1563 var fragment = this.document_.createDocumentFragment(); |
| 1564 fragment.appendChild(input); |
| 1565 fragment.appendChild(this.document_.createTextNode(name)); |
| 1566 return fragment; |
1565 }; | 1567 }; |
1566 | 1568 |
1567 /** | 1569 /** |
1568 * Check if all items in the current list are selected. | 1570 * Check if all items in the current list are selected. |
1569 * @return {boolean} True if all items are selected. | 1571 * @return {boolean} True if all items are selected. |
1570 */ | 1572 */ |
1571 FileManager.prototype.areAllItemsSelected = function() { | 1573 FileManager.prototype.areAllItemsSelected = function() { |
1572 return this.selection && | 1574 return this.selection && this.dataModel_.length > 0 && |
1573 this.dataModel_.length == this.selection.totalCount; | 1575 this.dataModel_.length == this.selection.totalCount; |
1574 }; | 1576 }; |
1575 | 1577 |
1576 /** | 1578 /** |
1577 * Insert a thumbnail image to fit/fill the container. | 1579 * Insert a thumbnail image to fit/fill the container. |
1578 * | 1580 * |
1579 * 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 |
1580 * 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 |
1581 * position it at the center. | 1583 * position it at the center. |
1582 * | 1584 * |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 /** | 1663 /** |
1662 * Render the type column of the detail table. | 1664 * Render the type column of the detail table. |
1663 * | 1665 * |
1664 * Invoked by cr.ui.Table when a file needs to be rendered. | 1666 * Invoked by cr.ui.Table when a file needs to be rendered. |
1665 * | 1667 * |
1666 * @param {Entry} entry The Entry object to render. | 1668 * @param {Entry} entry The Entry object to render. |
1667 * @param {string} columnId The id of the column to be rendered. | 1669 * @param {string} columnId The id of the column to be rendered. |
1668 * @param {cr.ui.Table} table The table doing the rendering. | 1670 * @param {cr.ui.Table} table The table doing the rendering. |
1669 */ | 1671 */ |
1670 FileManager.prototype.renderIconType_ = function(entry, columnId, table) { | 1672 FileManager.prototype.renderIconType_ = function(entry, columnId, table) { |
1671 var div = this.document_.createElement('div'); | |
1672 div.className = 'detail-icon-container'; | |
1673 | |
1674 var icon = this.document_.createElement('div'); | 1673 var icon = this.document_.createElement('div'); |
1675 icon.className = 'detail-icon'; | 1674 icon.className = 'detail-icon'; |
1676 this.getIconType(entry); | 1675 this.getIconType(entry); |
1677 icon.setAttribute('iconType', entry.cachedIconType_); | 1676 icon.setAttribute('iconType', entry.cachedIconType_); |
1678 div.appendChild(icon); | 1677 return icon; |
1679 | |
1680 return div; | |
1681 }; | 1678 }; |
1682 | 1679 |
1683 FileManager.prototype.getLabelForRootPath_ = function(path) { | 1680 FileManager.prototype.getLabelForRootPath_ = function(path) { |
1684 // This hack lets us localize the top level directories. | 1681 // This hack lets us localize the top level directories. |
1685 if (path == 'Downloads') | 1682 if (path == 'Downloads') |
1686 return str('DOWNLOADS_DIRECTORY_LABEL'); | 1683 return str('DOWNLOADS_DIRECTORY_LABEL'); |
1687 | 1684 |
1688 if (path == 'archive') | 1685 if (path == 'archive') |
1689 return str('ARCHIVE_DIRECTORY_LABEL'); | 1686 return str('ARCHIVE_DIRECTORY_LABEL'); |
1690 | 1687 |
1691 if (path == 'removable') | 1688 if (path == 'removable') |
1692 return str('REMOVABLE_DIRECTORY_LABEL'); | 1689 return str('REMOVABLE_DIRECTORY_LABEL'); |
1693 | 1690 |
1694 return path || str('ROOT_DIRECTORY_LABEL'); | 1691 return path || str('ROOT_DIRECTORY_LABEL'); |
1695 }; | 1692 }; |
1696 | 1693 |
1697 /** | 1694 /** |
1698 * Render the Name column of the detail table. | 1695 * Render the Name column of the detail table. |
1699 * | 1696 * |
1700 * Invoked by cr.ui.Table when a file needs to be rendered. | 1697 * Invoked by cr.ui.Table when a file needs to be rendered. |
1701 * | 1698 * |
1702 * @param {Entry} entry The Entry object to render. | 1699 * @param {Entry} entry The Entry object to render. |
1703 * @param {string} columnId The id of the column to be rendered. | 1700 * @param {string} columnId The id of the column to be rendered. |
1704 * @param {cr.ui.Table} table The table doing the rendering. | 1701 * @param {cr.ui.Table} table The table doing the rendering. |
1705 */ | 1702 */ |
1706 FileManager.prototype.renderName_ = function(entry, columnId, table) { | 1703 FileManager.prototype.renderName_ = function(entry, columnId, table) { |
1707 var label = this.document_.createElement('div'); | 1704 var label = this.document_.createElement('div'); |
| 1705 if (this.showCheckboxes_) |
| 1706 label.appendChild(this.renderCheckbox_(entry)); |
1708 label.appendChild(this.renderIconType_(entry, columnId, table)); | 1707 label.appendChild(this.renderIconType_(entry, columnId, table)); |
1709 label.entry = entry; | 1708 label.entry = entry; |
1710 label.className = 'detail-name filename-label'; | 1709 label.className = 'detail-name'; |
1711 if (this.currentDirEntry_.name == '') { | 1710 if (this.currentDirEntry_.name == '') { |
1712 label.appendChild(this.document_.createTextNode( | 1711 label.appendChild(this.document_.createTextNode( |
1713 this.getLabelForRootPath_(entry.name))); | 1712 this.getLabelForRootPath_(entry.name))); |
1714 } else { | 1713 } else { |
1715 label.appendChild(this.document_.createTextNode(entry.name)); | 1714 label.appendChild(this.document_.createTextNode(entry.name)); |
1716 } | 1715 } |
1717 | 1716 |
1718 return label; | 1717 return label; |
1719 }; | 1718 }; |
1720 | 1719 |
1721 /** | 1720 /** |
1722 * Render the Size column of the detail table. | 1721 * Render the Size column of the detail table. |
1723 * | 1722 * |
1724 * @param {Entry} entry The Entry object to render. | 1723 * @param {Entry} entry The Entry object to render. |
1725 * @param {string} columnId The id of the column to be rendered. | 1724 * @param {string} columnId The id of the column to be rendered. |
1726 * @param {cr.ui.Table} table The table doing the rendering. | 1725 * @param {cr.ui.Table} table The table doing the rendering. |
1727 */ | 1726 */ |
1728 FileManager.prototype.renderSize_ = function(entry, columnId, table) { | 1727 FileManager.prototype.renderSize_ = function(entry, columnId, table) { |
1729 var div = this.document_.createElement('div'); | 1728 var div = this.document_.createElement('div'); |
1730 div.className = 'detail-size'; | |
1731 | 1729 |
1732 div.textContent = '...'; | 1730 div.textContent = '...'; |
1733 cacheEntrySize(entry, function(entry) { | 1731 cacheEntrySize(entry, function(entry) { |
1734 if (entry.cachedSize_ == -1) { | 1732 if (entry.cachedSize_ == -1) { |
1735 div.textContent = ''; | 1733 div.textContent = ''; |
1736 } else { | 1734 } else { |
1737 div.textContent = util.bytesToSi(entry.cachedSize_); | 1735 div.textContent = util.bytesToSi(entry.cachedSize_); |
1738 } | 1736 } |
1739 }, null, true); | 1737 }, null, true); |
1740 | 1738 |
1741 return div; | 1739 return div; |
1742 }; | 1740 }; |
1743 | 1741 |
1744 /** | 1742 /** |
1745 * Render the Type column of the detail table. | 1743 * Render the Type column of the detail table. |
1746 * | 1744 * |
1747 * @param {Entry} entry The Entry object to render. | 1745 * @param {Entry} entry The Entry object to render. |
1748 * @param {string} columnId The id of the column to be rendered. | 1746 * @param {string} columnId The id of the column to be rendered. |
1749 * @param {cr.ui.Table} table The table doing the rendering. | 1747 * @param {cr.ui.Table} table The table doing the rendering. |
1750 */ | 1748 */ |
1751 FileManager.prototype.renderType_ = function(entry, columnId, table) { | 1749 FileManager.prototype.renderType_ = function(entry, columnId, table) { |
1752 var div = this.document_.createElement('div'); | 1750 var div = this.document_.createElement('div'); |
1753 div.className = 'detail-type'; | |
1754 | 1751 |
1755 this.cacheEntryFileType(entry, function(entry) { | 1752 this.cacheEntryFileType(entry, function(entry) { |
1756 var info = entry.cachedFileType_; | 1753 var info = entry.cachedFileType_; |
1757 if (info.name) { | 1754 if (info.name) { |
1758 if (info.subtype) | 1755 if (info.subtype) |
1759 div.textContent = strf(info.name, info.subtype); | 1756 div.textContent = strf(info.name, info.subtype); |
1760 else | 1757 else |
1761 div.textContent = str(info.name); | 1758 div.textContent = str(info.name); |
1762 } else | 1759 } else |
1763 div.textContent = ''; | 1760 div.textContent = ''; |
1764 }, true); | 1761 }, true); |
1765 | 1762 |
1766 return div; | 1763 return div; |
1767 }; | 1764 }; |
1768 | 1765 |
1769 /** | 1766 /** |
1770 * Render the Date column of the detail table. | 1767 * Render the Date column of the detail table. |
1771 * | 1768 * |
1772 * @param {Entry} entry The Entry object to render. | 1769 * @param {Entry} entry The Entry object to render. |
1773 * @param {string} columnId The id of the column to be rendered. | 1770 * @param {string} columnId The id of the column to be rendered. |
1774 * @param {cr.ui.Table} table The table doing the rendering. | 1771 * @param {cr.ui.Table} table The table doing the rendering. |
1775 */ | 1772 */ |
1776 FileManager.prototype.renderDate_ = function(entry, columnId, table) { | 1773 FileManager.prototype.renderDate_ = function(entry, columnId, table) { |
1777 var div = this.document_.createElement('div'); | 1774 var div = this.document_.createElement('div'); |
1778 div.className = 'detail-date'; | |
1779 | 1775 |
1780 div.textContent = '...'; | 1776 div.textContent = '...'; |
1781 | 1777 |
1782 var self = this; | 1778 var self = this; |
1783 cacheEntryDate(entry, function(entry) { | 1779 cacheEntryDate(entry, function(entry) { |
1784 if (isSystemDirEntry(self.currentDirEntry_) && | 1780 if (isSystemDirEntry(self.currentDirEntry_) && |
1785 entry.cachedMtime_.getTime() == 0) { | 1781 entry.cachedMtime_.getTime() == 0) { |
1786 // Mount points for FAT volumes have this time associated with them. | 1782 // Mount points for FAT volumes have this time associated with them. |
1787 // We'd rather display nothing than this bogus date. | 1783 // We'd rather display nothing than this bogus date. |
1788 div.textContent = ''; | 1784 div.textContent = ''; |
(...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3853 }); | 3849 }); |
3854 }, onError); | 3850 }, onError); |
3855 | 3851 |
3856 function onError(err) { | 3852 function onError(err) { |
3857 console.log('Error while checking free space: ' + err); | 3853 console.log('Error while checking free space: ' + err); |
3858 setTimeout(doCheck, 1000 * 60); | 3854 setTimeout(doCheck, 1000 * 60); |
3859 } | 3855 } |
3860 } | 3856 } |
3861 } | 3857 } |
3862 })(); | 3858 })(); |
OLD | NEW |