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 // 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 | 7 |
8 /** | 8 /** |
9 * FileManager constructor. | 9 * FileManager constructor. |
10 * | 10 * |
(...skipping 18 matching lines...) Expand all Loading... | |
29 this.selection = null; | 29 this.selection = null; |
30 | 30 |
31 this.butterTimer_ = null; | 31 this.butterTimer_ = null; |
32 this.currentButter_ = null; | 32 this.currentButter_ = null; |
33 this.butterLastShowTime_ = 0; | 33 this.butterLastShowTime_ = 0; |
34 | 34 |
35 this.watchedDirectoryUrl_ = null; | 35 this.watchedDirectoryUrl_ = null; |
36 | 36 |
37 this.commands_ = {}; | 37 this.commands_ = {}; |
38 | 38 |
39 this.thumbnailUrlCache_ = {}; | |
40 | |
39 this.document_ = dialogDom.ownerDocument; | 41 this.document_ = dialogDom.ownerDocument; |
40 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE; | 42 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE; |
41 | 43 |
42 metrics.recordEnum('Create', this.dialogType_, | 44 metrics.recordEnum('Create', this.dialogType_, |
43 [FileManager.DialogType.SELECT_FOLDER, | 45 [FileManager.DialogType.SELECT_FOLDER, |
44 FileManager.DialogType.SELECT_SAVEAS_FILE, | 46 FileManager.DialogType.SELECT_SAVEAS_FILE, |
45 FileManager.DialogType.SELECT_OPEN_FILE, | 47 FileManager.DialogType.SELECT_OPEN_FILE, |
46 FileManager.DialogType.SELECT_OPEN_MULTI_FILE, | 48 FileManager.DialogType.SELECT_OPEN_MULTI_FILE, |
47 FileManager.DialogType.FULL_PAGE]); | 49 FileManager.DialogType.FULL_PAGE]); |
48 | 50 |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 this.document_.addEventListener('keydown', this.onKeyDown_.bind(this)); | 651 this.document_.addEventListener('keydown', this.onKeyDown_.bind(this)); |
650 this.document_.addEventListener('copy', | 652 this.document_.addEventListener('copy', |
651 this.copySelectionToClipboard_.bind(this)); | 653 this.copySelectionToClipboard_.bind(this)); |
652 // Disable the default browser context menu. | 654 // Disable the default browser context menu. |
653 this.document_.addEventListener('contextmenu', | 655 this.document_.addEventListener('contextmenu', |
654 function (e) { e.preventDefault() }); | 656 function (e) { e.preventDefault() }); |
655 | 657 |
656 // We need to store a reference to the function returned by bind. Later, in | 658 // We need to store a reference to the function returned by bind. Later, in |
657 // canPaste function, we need to temporarily remove this event handler and | 659 // canPaste function, we need to temporarily remove this event handler and |
658 // use another 'paste' event handler to check the state of system clipboard. | 660 // use another 'paste' event handler to check the state of system clipboard. |
659 this.pasteFromClipboardBind_ = this.pasteFromClipboard_.bind(this); | 661 this.onPasteBound_ = this.onPaste_.bind(this); |
660 this.document_.addEventListener('paste', this.pasteFromClipboardBind_); | 662 this.document_.addEventListener('paste', this.onPasteBound_); |
661 | 663 |
662 // In pasteFromClipboard function, we need to reset system clipboard after | 664 // In pasteFromClipboard function, we need to reset system clipboard after |
663 // 'cut' and 'paste' command sequence. The clipboardData.clearData doesn't | 665 // 'cut' and 'paste' command sequence. The clipboardData.clearData doesn't |
664 // seem to work. We reset the system clipboard in another 'cut' event | 666 // seem to work. We reset the system clipboard in another 'cut' event |
665 // handler as a workaround. This reference is used to temporarily remove | 667 // handler as a workaround. This reference is used to temporarily remove |
666 // 'cut' event handler as well. | 668 // 'cut' event handler as well. |
667 this.cutFromClipboardBind_ = this.cutSelectionToClipboard_.bind(this); | 669 this.cutFromClipboardBind_ = this.cutSelectionToClipboard_.bind(this); |
668 this.document_.addEventListener('cut', this.cutFromClipboardBind_); | 670 this.document_.addEventListener('cut', this.cutFromClipboardBind_); |
669 | 671 |
670 this.renameInput_ = this.document_.createElement('input'); | 672 this.renameInput_ = this.document_.createElement('input'); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 var clipboardCanPaste = function(event) { | 1109 var clipboardCanPaste = function(event) { |
1108 event.preventDefault(); | 1110 event.preventDefault(); |
1109 // Here we need to use lower case as clipboardData.types return lower | 1111 // Here we need to use lower case as clipboardData.types return lower |
1110 // case DomStringList. | 1112 // case DomStringList. |
1111 if (event.clipboardData && | 1113 if (event.clipboardData && |
1112 event.clipboardData.types && | 1114 event.clipboardData.types && |
1113 event.clipboardData.types.indexOf('fs/iscut') != -1) | 1115 event.clipboardData.types.indexOf('fs/iscut') != -1) |
1114 canPaste = true; | 1116 canPaste = true; |
1115 }; | 1117 }; |
1116 | 1118 |
1117 this.document_.removeEventListener('paste', this.pasteFromClipboardBind_); | 1119 this.document_.removeEventListener('paste', this.onPasteBound_); |
1118 this.document_.addEventListener('paste', clipboardCanPaste); | 1120 this.document_.addEventListener('paste', clipboardCanPaste); |
1119 this.document_.execCommand('paste'); | 1121 this.document_.execCommand('paste'); |
1120 this.document_.removeEventListener('paste', clipboardCanPaste); | 1122 this.document_.removeEventListener('paste', clipboardCanPaste); |
1121 this.document_.addEventListener('paste', this.pasteFromClipboardBind_); | 1123 this.document_.addEventListener('paste', this.onPasteBound_); |
1122 return canPaste && !readonly; | 1124 return canPaste && !readonly; |
1123 }; | 1125 }; |
1124 | 1126 |
1125 /** | 1127 /** |
1126 * @param {string} commandId Command identifier. | 1128 * @param {string} commandId Command identifier. |
1127 * @return {boolean} True if the command can be executed for current | 1129 * @return {boolean} True if the command can be executed for current |
1128 * selection. | 1130 * selection. |
1129 */ | 1131 */ |
1130 FileManager.prototype.canExecute_ = function(commandId) { | 1132 FileManager.prototype.canExecute_ = function(commandId) { |
1131 var readonly = this.directoryModel_.readonly; | 1133 var readonly = this.directoryModel_.readonly; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1245 */ | 1247 */ |
1246 FileManager.prototype.initGrid_ = function() { | 1248 FileManager.prototype.initGrid_ = function() { |
1247 var self = this; | 1249 var self = this; |
1248 this.grid_.itemConstructor = GridItem.bind(null, this); | 1250 this.grid_.itemConstructor = GridItem.bind(null, this); |
1249 | 1251 |
1250 this.grid_.addEventListener( | 1252 this.grid_.addEventListener( |
1251 'dblclick', this.onDetailDoubleClick_.bind(this)); | 1253 'dblclick', this.onDetailDoubleClick_.bind(this)); |
1252 cr.ui.contextMenuHandler.setContextMenu(this.grid_, this.fileContextMenu_); | 1254 cr.ui.contextMenuHandler.setContextMenu(this.grid_, this.fileContextMenu_); |
1253 this.grid_.addEventListener('mousedown', | 1255 this.grid_.addEventListener('mousedown', |
1254 this.onGridOrTableMouseDown_.bind(this)); | 1256 this.onGridOrTableMouseDown_.bind(this)); |
1257 this.setupDragAndDrop_(this.grid_); | |
1255 }; | 1258 }; |
1256 | 1259 |
1257 /** | 1260 /** |
1258 * Initialize the file list table. | 1261 * Initialize the file list table. |
1259 */ | 1262 */ |
1260 FileManager.prototype.initTable_ = function() { | 1263 FileManager.prototype.initTable_ = function() { |
1261 var columns = [ | 1264 var columns = [ |
1262 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), | 1265 new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'), |
1263 64), | 1266 64), |
1264 new cr.ui.table.TableColumn('cachedSize_', | 1267 new cr.ui.table.TableColumn('cachedSize_', |
(...skipping 24 matching lines...) Expand all Loading... | |
1289 | 1292 |
1290 // Don't pay attention to double clicks on the table header. | 1293 // Don't pay attention to double clicks on the table header. |
1291 this.table_.querySelector('.list').addEventListener( | 1294 this.table_.querySelector('.list').addEventListener( |
1292 'dblclick', this.onDetailDoubleClick_.bind(this)); | 1295 'dblclick', this.onDetailDoubleClick_.bind(this)); |
1293 | 1296 |
1294 cr.ui.contextMenuHandler.setContextMenu(this.table_.querySelector('.list'), | 1297 cr.ui.contextMenuHandler.setContextMenu(this.table_.querySelector('.list'), |
1295 this.fileContextMenu_); | 1298 this.fileContextMenu_); |
1296 | 1299 |
1297 this.table_.addEventListener('mousedown', | 1300 this.table_.addEventListener('mousedown', |
1298 this.onGridOrTableMouseDown_.bind(this)); | 1301 this.onGridOrTableMouseDown_.bind(this)); |
1302 this.setupDragAndDrop_(this.table_.list); | |
1303 }; | |
1304 | |
1305 FileManager.prototype.setupDragAndDrop_ = function(list) { | |
1306 var self = this; | |
1307 const container = this.document_.querySelector('#drag-image-container'); | |
dgozman
2012/03/26 13:10:23
|container| and |self| are not used
| |
1308 list.addEventListener('dragstart', this.onDragDtart_.bind(this)); | |
1309 }; | |
1310 | |
1311 FileManager.prototype.onDragDtart_ = function(event) { | |
dgozman
2012/03/26 13:10:23
typo: onDragDtart -> onDragStart
| |
1312 var dt = event.dataTransfer; | |
1313 var container = this.document_.querySelector('#drag-image-container'); | |
1314 for (var i = 0; i < this.selection.dragNodes.length; i++) { | |
1315 var listItem = this.selection.dragNodes[i]; | |
1316 listItem.selected = true; | |
1317 container.appendChild(listItem); | |
1318 } | |
1319 | |
1320 this.cutOrCopyToClipboard_(dt, false); | |
1321 | |
1322 dt.setDragImage(container, 0, 0); | |
1323 dt.effectAllowed = 'copyMove'; | |
1299 }; | 1324 }; |
1300 | 1325 |
1301 FileManager.prototype.initButter_ = function() { | 1326 FileManager.prototype.initButter_ = function() { |
1302 var self = this; | 1327 var self = this; |
1303 var progress = this.copyManager_.getProgress(); | 1328 var progress = this.copyManager_.getProgress(); |
1304 | 1329 |
1305 var options = {progress: progress.percentage, actions:{}}; | 1330 var options = {progress: progress.percentage, actions:{}}; |
1306 options.actions[str('CANCEL_LABEL')] = function cancelPaste() { | 1331 options.actions[str('CANCEL_LABEL')] = function cancelPaste() { |
1307 self.copyManager_.requestCancel(); | 1332 self.copyManager_.requestCancel(); |
1308 }; | 1333 }; |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1722 * the image has been loaded before inserting | 1747 * the image has been loaded before inserting |
1723 * it into the DOM. | 1748 * it into the DOM. |
1724 * @return {HTMLDivElement} | 1749 * @return {HTMLDivElement} |
1725 */ | 1750 */ |
1726 FileManager.prototype.renderThumbnailBox_ = function(entry, fill, | 1751 FileManager.prototype.renderThumbnailBox_ = function(entry, fill, |
1727 opt_imageLoadCallback) { | 1752 opt_imageLoadCallback) { |
1728 var box = this.document_.createElement('div'); | 1753 var box = this.document_.createElement('div'); |
1729 box.className = 'img-container'; | 1754 box.className = 'img-container'; |
1730 var img = this.document_.createElement('img'); | 1755 var img = this.document_.createElement('img'); |
1731 var self = this; | 1756 var self = this; |
1732 this.getThumbnailURL(entry, function(iconType, url, transform) { | 1757 |
1758 function onThumbnailURL(iconType, url, transform) { | |
1759 self.thumbnailUrlCache_[entry.fullPath] = { | |
1760 iconType: iconType, | |
1761 url: url, | |
1762 transform: transform | |
1763 }; | |
1733 img.onload = function() { | 1764 img.onload = function() { |
1734 self.centerImage_(img.style, img.width, img.height, fill); | 1765 self.centerImage_(img.style, img.width, img.height, fill); |
1735 if (opt_imageLoadCallback) | 1766 if (opt_imageLoadCallback) |
1736 opt_imageLoadCallback(img, transform); | 1767 opt_imageLoadCallback(img, transform); |
1737 box.appendChild(img); | 1768 box.appendChild(img); |
1738 }; | 1769 }; |
1739 img.src = url; | 1770 img.src = url; |
1740 self.applyImageTransformation_(box, transform); | 1771 self.applyImageTransformation_(box, transform); |
1741 }); | 1772 } |
1773 | |
1774 var cached = this.thumbnailUrlCache_[entry.fullPath]; | |
1775 if (cached) | |
1776 onThumbnailURL(cached.iconType, cached.url, cached.transform); | |
1777 else | |
1778 this.getThumbnailURL(entry, onThumbnailURL); | |
1779 | |
1742 return box; | 1780 return box; |
1743 }; | 1781 }; |
1744 | 1782 |
1745 FileManager.prototype.decorateThumbnail_ = function(li, entry) { | 1783 FileManager.prototype.decorateThumbnail_ = function(li, entry) { |
1746 li.className = 'thumbnail-item'; | 1784 li.className = 'thumbnail-item'; |
1747 | 1785 |
1748 if (this.showCheckboxes_) | 1786 if (this.showCheckboxes_) |
1749 li.appendChild(this.renderCheckbox_(entry)); | 1787 li.appendChild(this.renderCheckbox_(entry)); |
1750 | 1788 |
1751 li.appendChild(this.renderThumbnailBox_(entry, false)); | 1789 li.appendChild(this.renderThumbnailBox_(entry, false)); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2069 */ | 2107 */ |
2070 FileManager.prototype.summarizeSelection_ = function() { | 2108 FileManager.prototype.summarizeSelection_ = function() { |
2071 var selection = this.selection = { | 2109 var selection = this.selection = { |
2072 entries: [], | 2110 entries: [], |
2073 urls: [], | 2111 urls: [], |
2074 totalCount: 0, | 2112 totalCount: 0, |
2075 fileCount: 0, | 2113 fileCount: 0, |
2076 directoryCount: 0, | 2114 directoryCount: 0, |
2077 bytes: 0, | 2115 bytes: 0, |
2078 iconType: null, | 2116 iconType: null, |
2079 indexes: this.currentList_.selectionModel.selectedIndexes | 2117 indexes: this.currentList_.selectionModel.selectedIndexes, |
2118 files: [], | |
2119 dragNodes: [] | |
2080 }; | 2120 }; |
2081 | 2121 |
2082 if (!selection.indexes.length) { | 2122 if (!selection.indexes.length) { |
2083 this.updateCommonActionButtons_(); | 2123 this.updateCommonActionButtons_(); |
2084 this.updatePreviewPanelVisibility_(); | 2124 this.updatePreviewPanelVisibility_(); |
2085 cr.dispatchSimpleEvent(this, 'selection-summarized'); | 2125 cr.dispatchSimpleEvent(this, 'selection-summarized'); |
2086 return; | 2126 return; |
2087 } | 2127 } |
2088 | 2128 |
2089 this.previewSummary_.textContent = str('COMPUTING_SELECTION'); | 2129 this.previewSummary_.textContent = str('COMPUTING_SELECTION'); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2122 var thumbnail = this.renderThumbnailBox_(entry, true, imageLoadCalback); | 2162 var thumbnail = this.renderThumbnailBox_(entry, true, imageLoadCalback); |
2123 box.appendChild(thumbnail); | 2163 box.appendChild(thumbnail); |
2124 box.style.zIndex = MAX_PREVIEW_THUMBAIL_COUNT + 1 - i; | 2164 box.style.zIndex = MAX_PREVIEW_THUMBAIL_COUNT + 1 - i; |
2125 box.addEventListener('click', | 2165 box.addEventListener('click', |
2126 this.dispatchDefaultTask_.bind(this, selection)); | 2166 this.dispatchDefaultTask_.bind(this, selection)); |
2127 | 2167 |
2128 this.previewThumbnails_.appendChild(box); | 2168 this.previewThumbnails_.appendChild(box); |
2129 thumbnailCount++; | 2169 thumbnailCount++; |
2130 } | 2170 } |
2131 | 2171 |
2172 if (selection.dragNodes.length < MAX_PREVIEW_THUMBAIL_COUNT) | |
2173 selection.dragNodes.push(new GridItem(this, entry)); | |
dgozman
2012/03/26 13:10:23
Why do you create items here and not in dragstart?
SeRya
2012/03/26 13:37:45
Added comment describing the reason.
| |
2174 | |
2132 selection.totalCount++; | 2175 selection.totalCount++; |
2133 | 2176 |
2134 if (entry.isFile) { | 2177 if (entry.isFile) { |
2135 selection.fileCount += 1; | 2178 selection.fileCount += 1; |
2136 if (!('cachedSize_' in entry)) { | 2179 if (!('cachedSize_' in entry)) { |
2137 // Any file that hasn't been rendered may be missing its cachedSize_ | 2180 // Any file that hasn't been rendered may be missing its cachedSize_ |
2138 // property. For example, visit a large file list, and press ctrl-a | 2181 // property. For example, visit a large file list, and press ctrl-a |
2139 // to select all. In this case, we need to asynchronously get the | 2182 // to select all. In this case, we need to asynchronously get the |
2140 // sizes for these files before telling the world the selection has | 2183 // sizes for these files before telling the world the selection has |
2141 // been summarized. See the 'computeNextFile' logic below. | 2184 // been summarized. See the 'computeNextFile' logic below. |
2142 pendingFiles.push(entry); | 2185 pendingFiles.push(entry); |
2143 continue; | 2186 continue; |
2144 } else { | 2187 } else { |
2145 selection.bytes += entry.cachedSize_; | 2188 selection.bytes += entry.cachedSize_; |
2146 } | 2189 } |
2190 // entry.file([].push.bind(selection.files)); | |
dgozman
2012/03/26 13:10:23
Commented code.
SeRya
2012/03/26 13:37:45
Done.
| |
2191 entry.file(function(f) { | |
dgozman
2012/03/26 13:10:23
Again, why not in dragstart?
SeRya
2012/03/26 13:37:45
Added comment describing the reason.
| |
2192 selection.files.push(f); | |
2193 }); | |
2147 } else { | 2194 } else { |
2148 selection.directoryCount += 1; | 2195 selection.directoryCount += 1; |
2149 } | 2196 } |
2150 } | 2197 } |
2151 | 2198 |
2152 // Now this.selection is complete. Update buttons. | 2199 // Now this.selection is complete. Update buttons. |
2153 this.updateCommonActionButtons_(); | 2200 this.updateCommonActionButtons_(); |
2154 this.updatePreviewPanelVisibility_(); | 2201 this.updatePreviewPanelVisibility_(); |
2155 | 2202 |
2156 var self = this; | 2203 var self = this; |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3054 var listItem = self.currentList_.getListItemByIndex(selectedIndex); | 3101 var listItem = self.currentList_.getListItemByIndex(selectedIndex); |
3055 if (listItem) | 3102 if (listItem) |
3056 listItem.classList.remove('blink'); | 3103 listItem.classList.remove('blink'); |
3057 } | 3104 } |
3058 }, 100); | 3105 }, 100); |
3059 }; | 3106 }; |
3060 | 3107 |
3061 /** | 3108 /** |
3062 * Write the current selection to system clipboard. | 3109 * Write the current selection to system clipboard. |
3063 * | 3110 * |
3064 * @param {Event} event Cut or Copy event. | 3111 * @param {Clipboard} clipboard Clipboard from the event. |
3065 * @param {boolean} isCut True if the current command is cut. | 3112 * @param {boolean} isCut True if the current command is cut. |
3066 */ | 3113 */ |
3067 FileManager.prototype.cutOrCopyToClipboard_ = function(event, isCut) { | 3114 FileManager.prototype.cutOrCopyToClipboard_ = function(clipboard, isCut) { |
3068 event.preventDefault(); | 3115 var directories = ''; |
3116 var files = ''; | |
3117 for(var i = 0, entry; i < this.selection.entries.length; i++) { | |
3118 entry = this.selection.entries[i]; | |
3119 if (entry.isDirectory) | |
3120 directories += entry.fullPath + '\n'; | |
3121 else | |
3122 files += entry.fullPath + '\n'; | |
3123 } | |
3069 | 3124 |
3070 var directories = ''; | 3125 clipboard.setData('fs/isCut', isCut.toString()); |
3071 var files = ''; | 3126 clipboard.setData('fs/sourceDir', |
3072 for(var i = 0, entry; i < this.selection.entries.length; i++) { | |
3073 entry = this.selection.entries[i]; | |
3074 if (entry.isDirectory) | |
3075 directories += entry.fullPath + '\n'; | |
3076 else | |
3077 files += entry.fullPath + '\n'; | |
3078 } | |
3079 | |
3080 event.clipboardData.setData('fs/isCut', isCut.toString()); | |
3081 event.clipboardData.setData('fs/isOnGData', | |
3082 this.isOnGData().toString()); | |
3083 event.clipboardData.setData('fs/sourceDir', | |
3084 this.directoryModel_.currentEntry.fullPath); | 3127 this.directoryModel_.currentEntry.fullPath); |
3085 event.clipboardData.setData('fs/directories', directories); | 3128 clipboard.setData('fs/sourceOnGData', this.isOnGData()); |
3086 event.clipboardData.setData('fs/files', files); | 3129 clipboard.setData('fs/directories', directories); |
3130 clipboard.setData('fs/files', files); | |
3087 } | 3131 } |
3088 | 3132 |
3089 FileManager.prototype.copySelectionToClipboard_ = function(event) { | 3133 FileManager.prototype.copySelectionToClipboard_ = function(event) { |
dgozman
2012/03/26 13:10:23
Rename this to onCopy_ for consistency?
SeRya
2012/03/26 13:37:45
Done.
| |
3090 if (!this.selection || this.selection.totalCount == 0) | 3134 if (!this.selection || this.selection.totalCount == 0) |
3091 return; | 3135 return; |
3092 | 3136 |
3093 this.cutOrCopyToClipboard_(event, false); | 3137 event.preventDefault(); |
3138 this.cutOrCopyToClipboard_(event.clipboardData, false); | |
3094 | 3139 |
3095 this.blinkSelection(); | 3140 this.blinkSelection(); |
3096 }; | 3141 }; |
3097 | 3142 |
3098 FileManager.prototype.cutSelectionToClipboard_ = function(event) { | 3143 FileManager.prototype.cutSelectionToClipboard_ = function(event) { |
dgozman
2012/03/26 13:10:23
Rename this to onCut_ for consistency?
SeRya
2012/03/26 13:37:45
Done.
| |
3099 if (!this.selection || this.selection.totalCount == 0 || | 3144 if (!this.selection || this.selection.totalCount == 0 || |
3100 this.commands_['cut'].disabled) | 3145 this.commands_['cut'].disabled) |
3101 return; | 3146 return; |
3102 | 3147 |
3103 this.cutOrCopyToClipboard_(event, true); | 3148 event.preventDefault(); |
3149 this.cutOrCopyToClipboard_(event.clipboardData, true); | |
3104 | 3150 |
3105 this.blinkSelection(); | 3151 this.blinkSelection(); |
3106 }; | 3152 }; |
3107 | 3153 |
3154 FileManager.prototype.onPaste_ = function(event) { | |
3155 event.preventDefault(); | |
3156 this.pasteFromClipboard_(event.clipboardData); | |
3157 }; | |
3158 | |
3108 /** | 3159 /** |
3109 * Queue up a file copy operation based on the current system clipboard. | 3160 * Queue up a file copy operation based on the current system clipboard. |
3110 */ | 3161 */ |
3111 FileManager.prototype.pasteFromClipboard_ = function(event) { | 3162 FileManager.prototype.pasteFromClipboard_ = function(clipboard) { |
3112 event.preventDefault(); | |
3113 | |
3114 if (!event.clipboardData.getData('fs/isCut')) | 3163 if (!event.clipboardData.getData('fs/isCut')) |
3115 return; | 3164 return; |
3116 | 3165 |
3117 var clipboard = { | 3166 var operationInfo = { |
3118 isCut: event.clipboardData.getData('fs/isCut'), | 3167 isCut: clipboard.getData('fs/isCut'), |
3119 isOnGData: event.clipboardData.getData('fs/isOnGData'), | 3168 sourceDir: clipboard.getData('fs/sourceDir'), |
3120 sourceDir: event.clipboardData.getData('fs/sourceDir'), | 3169 sourceOnGData: clipboard.getData('fs/sourceOnGData'), |
3121 directories: event.clipboardData.getData('fs/directories'), | 3170 directories: clipboard.getData('fs/directories'), |
3122 files: event.clipboardData.getData('fs/files') | 3171 files: clipboard.getData('fs/files') |
3123 }; | 3172 }; |
3124 | 3173 |
3125 this.copyManager_.paste(clipboard, | 3174 // If both source and target are on GData, FileCopyManager uses |
3175 // FileEntry.copyTo() / FileEntry.moveTo() to copy / move files. | |
3176 var sourceAndTargetOnGData = operationInfo.sourceOnGData && | |
3177 this.isOnGData(); | |
3178 this.copyManager_.paste(operationInfo, | |
3126 this.directoryModel_.currentEntry, | 3179 this.directoryModel_.currentEntry, |
3127 this.isOnGData(), | 3180 this.isOnGData(), |
3128 this.filesystem_.root); | 3181 this.filesystem_.root); |
3129 | 3182 |
3130 var clearClipboard = function (event) { | 3183 var clearClipboard = function (event) { |
3131 event.preventDefault(); | 3184 event.preventDefault(); |
3132 event.clipboardData.setData('fs/clear', ''); | 3185 event.clipboardData.setData('fs/clear', ''); |
3133 } | 3186 } |
3134 | 3187 |
3135 // On cut, we clear the clipboard after the file is pasted/moved so we don't | 3188 // On cut, we clear the clipboard after the file is pasted/moved so we don't |
3136 // try to move/delete the original file again. | 3189 // try to move/delete the original file again. |
3137 if (clipboard.isCut == 'true') { | 3190 if (operationInfo.isCut == 'true') { |
3138 this.document_.removeEventListener('cut', this.cutFromClipboardBind_); | 3191 this.document_.removeEventListener('cut', this.cutFromClipboardBind_); |
3139 this.document_.addEventListener('cut', clearClipboard); | 3192 this.document_.addEventListener('cut', clearClipboard); |
3140 this.document_.execCommand('cut'); | 3193 this.document_.execCommand('cut'); |
3141 this.document_.removeEventListener('cut', clearClipboard); | 3194 this.document_.removeEventListener('cut', clearClipboard); |
3142 this.document_.addEventListener('cut', this.cutFromClipboardBind_); | 3195 this.document_.addEventListener('cut', this.cutFromClipboardBind_); |
3143 } | 3196 } |
3144 }; | 3197 }; |
3145 | 3198 |
3146 /** | 3199 /** |
3147 * Update the selection summary UI when the selection summarization completes. | 3200 * Update the selection summary UI when the selection summarization completes. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3258 if (this.selection && | 3311 if (this.selection && |
3259 this.selection.totalCount == 1 && | 3312 this.selection.totalCount == 1 && |
3260 this.selection.entries[0].isFile && | 3313 this.selection.entries[0].isFile && |
3261 this.filenameInput_.value != this.selection.entries[0].name) { | 3314 this.filenameInput_.value != this.selection.entries[0].name) { |
3262 this.filenameInput_.value = this.selection.entries[0].name; | 3315 this.filenameInput_.value = this.selection.entries[0].name; |
3263 } | 3316 } |
3264 } | 3317 } |
3265 | 3318 |
3266 this.updateOkButton_(); | 3319 this.updateOkButton_(); |
3267 | 3320 |
3268 var self = this; | 3321 var newThumbnailUrlCache = {}; |
3269 setTimeout(function() { self.onSelectionChangeComplete_(event) }, 0); | 3322 if (this.selection) { |
3323 const entries = this.selection.entries; | |
3324 for (var i = 0; i < entries.length; i++) { | |
3325 var path = entries[i].fullPath; | |
3326 if (path in this.thumbnailUrlCache_) | |
3327 newThumbnailUrlCache[path] = this.thumbnailUrlCache_[path]; | |
3328 } | |
3329 } | |
3330 this.thumbnailUrlCache_ = newThumbnailUrlCache; | |
3331 | |
3332 setTimeout(this.onSelectionChangeComplete_.bind(this, event), 0); | |
3270 }; | 3333 }; |
3271 | 3334 |
3272 /** | 3335 /** |
3273 * Handle selection change related tasks that won't run properly during | 3336 * Handle selection change related tasks that won't run properly during |
3274 * the actual selection change event. | 3337 * the actual selection change event. |
3275 */ | 3338 */ |
3276 FileManager.prototype.onSelectionChangeComplete_ = function(event) { | 3339 FileManager.prototype.onSelectionChangeComplete_ = function(event) { |
3277 // Inform tests it's OK to click buttons now. | 3340 // Inform tests it's OK to click buttons now. |
3278 chrome.test.sendMessage('selection-change-complete'); | 3341 chrome.test.sendMessage('selection-change-complete'); |
3279 | 3342 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3512 if (metadata && dm.rootEntry == rootEntry) | 3575 if (metadata && dm.rootEntry == rootEntry) |
3513 dm.readonly = metadata.isReadOnly; | 3576 dm.readonly = metadata.isReadOnly; |
3514 }); | 3577 }); |
3515 }; | 3578 }; |
3516 | 3579 |
3517 FileManager.prototype.findListItemForEvent_ = function(event) { | 3580 FileManager.prototype.findListItemForEvent_ = function(event) { |
3518 return this.findListItemForNode_(event.srcElement); | 3581 return this.findListItemForNode_(event.srcElement); |
3519 }; | 3582 }; |
3520 | 3583 |
3521 FileManager.prototype.findListItemForNode_ = function(node) { | 3584 FileManager.prototype.findListItemForNode_ = function(node) { |
3522 var list = this.currentList_; | 3585 var item = this.currentList_.getListItemAncestor(node); |
3523 // Assume list items are direct children of the list. | 3586 // TODO(serya): list should check that. |
3524 if (node == list) | 3587 return item && this.currentList_.isItem(item) ? item : null; |
3525 return null; | |
3526 while (node) { | |
3527 var parent = node.parentNode; | |
3528 if (parent == list && node instanceof cr.ui.ListItem) | |
3529 return node; | |
3530 node = parent; | |
3531 } | |
3532 return null; | |
3533 }; | 3588 }; |
3534 | 3589 |
3535 FileManager.prototype.onGridOrTableMouseDown_ = function(event) { | 3590 FileManager.prototype.onGridOrTableMouseDown_ = function(event) { |
3536 var item = this.findListItemForEvent_(event); | 3591 var item = this.findListItemForEvent_(event); |
3537 if (!item) | 3592 if (!item) |
3538 return; | 3593 return; |
3539 | 3594 |
3540 if (this.allowRenameClick_(event, item)) { | 3595 if (this.allowRenameClick_(event, item)) { |
3541 event.preventDefault(); | 3596 event.preventDefault(); |
3542 this.directoryModel_.fileListSelection.selectedIndex = item.listIndex; | 3597 this.directoryModel_.fileListSelection.selectedIndex = item.listIndex; |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4279 }); | 4334 }); |
4280 }, onError); | 4335 }, onError); |
4281 | 4336 |
4282 function onError(err) { | 4337 function onError(err) { |
4283 console.log('Error while checking free space: ' + err); | 4338 console.log('Error while checking free space: ' + err); |
4284 setTimeout(doCheck, 1000 * 60); | 4339 setTimeout(doCheck, 1000 * 60); |
4285 } | 4340 } |
4286 } | 4341 } |
4287 } | 4342 } |
4288 })(); | 4343 })(); |
OLD | NEW |