| 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 // WK Bug 55728 is fixed on the chrome 12 branch but not on the trunk. | 5 // WK Bug 55728 is fixed on the chrome 12 branch but not on the trunk. |
| 6 // TODO(rginda): Enable this everywhere once we have a trunk-worthy fix. | 6 // TODO(rginda): Enable this everywhere once we have a trunk-worthy fix. |
| 7 const ENABLE_EXIF_READER = navigator.userAgent.match(/chrome\/12\.0/i); | 7 const ENABLE_EXIF_READER = navigator.userAgent.match(/chrome\/12\.0/i); |
| 8 | 8 |
| 9 // Thumbnail view is painful without the exif reader. | 9 // Thumbnail view is painful without the exif reader. |
| 10 const ENABLE_THUMBNAIL_VIEW = ENABLE_EXIF_READER; | 10 const ENABLE_THUMBNAIL_VIEW = ENABLE_EXIF_READER; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 this.document_ = dialogDom.ownerDocument; | 46 this.document_ = dialogDom.ownerDocument; |
| 47 this.dialogType_ = | 47 this.dialogType_ = |
| 48 this.params_.type || FileManager.DialogType.FULL_PAGE; | 48 this.params_.type || FileManager.DialogType.FULL_PAGE; |
| 49 | 49 |
| 50 this.defaultPath_ = this.params_.defaultPath || '/'; | 50 this.defaultPath_ = this.params_.defaultPath || '/'; |
| 51 | 51 |
| 52 // DirectoryEntry representing the current directory of the dialog. | 52 // DirectoryEntry representing the current directory of the dialog. |
| 53 this.currentDirEntry_ = null; | 53 this.currentDirEntry_ = null; |
| 54 | 54 |
| 55 window.addEventListener('popstate', this.onPopState_.bind(this)); |
| 55 this.addEventListener('directory-changed', | 56 this.addEventListener('directory-changed', |
| 56 this.onDirectoryChanged_.bind(this)); | 57 this.onDirectoryChanged_.bind(this)); |
| 57 this.addEventListener('selection-summarized', | 58 this.addEventListener('selection-summarized', |
| 58 this.onSelectionSummarized_.bind(this)); | 59 this.onSelectionSummarized_.bind(this)); |
| 59 | 60 |
| 60 this.initDom_(); | 61 this.initDom_(); |
| 61 this.initDialogType_(); | 62 this.initDialogType_(); |
| 62 | 63 |
| 63 this.onDetailSelectionChanged_(); | 64 this.onDetailSelectionChanged_(); |
| 64 | 65 |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 553 |
| 553 this.table_.selectionModel = new this.selectionModelClass_(); | 554 this.table_.selectionModel = new this.selectionModelClass_(); |
| 554 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); | 555 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); |
| 555 | 556 |
| 556 this.table_.addEventListener( | 557 this.table_.addEventListener( |
| 557 'dblclick', this.onDetailDoubleClick_.bind(this)); | 558 'dblclick', this.onDetailDoubleClick_.bind(this)); |
| 558 this.table_.selectionModel.addEventListener( | 559 this.table_.selectionModel.addEventListener( |
| 559 'change', this.onDetailSelectionChanged_.bind(this)); | 560 'change', this.onDetailSelectionChanged_.bind(this)); |
| 560 }; | 561 }; |
| 561 | 562 |
| 563 /** |
| 564 * Respond to the back button. |
| 565 */ |
| 566 FileManager.prototype.onPopState_ = function(event) { |
| 567 this.changeDirectory(event.state, false); |
| 568 }; |
| 569 |
| 570 /** |
| 571 * Resize details and thumb views to fit the new window size. |
| 572 */ |
| 562 FileManager.prototype.onResize_ = function() { | 573 FileManager.prototype.onResize_ = function() { |
| 563 this.table_.style.height = this.grid_.style.height = | 574 this.table_.style.height = this.grid_.style.height = |
| 564 this.grid_.parentNode.clientHeight + 'px'; | 575 this.grid_.parentNode.clientHeight + 'px'; |
| 565 this.table_.style.width = this.grid_.style.width = | 576 this.table_.style.width = this.grid_.style.width = |
| 566 this.grid_.parentNode.clientWidth + 'px'; | 577 this.grid_.parentNode.clientWidth + 'px'; |
| 567 | 578 |
| 568 this.table_.list_.style.width = this.table_.parentNode.clientWidth + 'px'; | 579 this.table_.list_.style.width = this.table_.parentNode.clientWidth + 'px'; |
| 569 this.table_.list_.style.height = (this.table_.clientHeight - 1 - | 580 this.table_.list_.style.height = (this.table_.clientHeight - 1 - |
| 570 this.table_.header_.clientHeight) + 'px'; | 581 this.table_.header_.clientHeight) + 'px'; |
| 571 | 582 |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 setTimeout(function() { callback(iconType, entry.toURL()) }); | 1158 setTimeout(function() { callback(iconType, entry.toURL()) }); |
| 1148 }; | 1159 }; |
| 1149 | 1160 |
| 1150 /** | 1161 /** |
| 1151 * Change the current directory. | 1162 * Change the current directory. |
| 1152 * | 1163 * |
| 1153 * Dispatches the 'directory-changed' event when the directory is successfully | 1164 * Dispatches the 'directory-changed' event when the directory is successfully |
| 1154 * changed. | 1165 * changed. |
| 1155 * | 1166 * |
| 1156 * @param {string} path The absolute path to the new directory. | 1167 * @param {string} path The absolute path to the new directory. |
| 1168 * @param {bool} opt_saveHistory Save this in the history stack (defaults |
| 1169 * to true). |
| 1157 */ | 1170 */ |
| 1158 FileManager.prototype.changeDirectory = function(path) { | 1171 FileManager.prototype.changeDirectory = function(path, opt_saveHistory) { |
| 1159 var self = this; | 1172 var self = this; |
| 1160 | 1173 |
| 1174 if (arguments.length == 1) { |
| 1175 opt_saveHistory = true; |
| 1176 } else { |
| 1177 opt_saveHistory = !!opt_saveHistory; |
| 1178 } |
| 1179 |
| 1161 function onPathFound(dirEntry) { | 1180 function onPathFound(dirEntry) { |
| 1162 if (self.currentDirEntry_ && | 1181 if (self.currentDirEntry_ && |
| 1163 self.currentDirEntry_.fullPath == dirEntry.fullPath) { | 1182 self.currentDirEntry_.fullPath == dirEntry.fullPath) { |
| 1164 // Directory didn't actually change. | 1183 // Directory didn't actually change. |
| 1165 return; | 1184 return; |
| 1166 } | 1185 } |
| 1167 | 1186 |
| 1168 var e = new cr.Event('directory-changed'); | 1187 var e = new cr.Event('directory-changed'); |
| 1169 e.previousDirEntry = self.currentDirEntry_; | 1188 e.previousDirEntry = self.currentDirEntry_; |
| 1170 e.newDirEntry = dirEntry; | 1189 e.newDirEntry = dirEntry; |
| 1190 e.saveHistory = opt_saveHistory; |
| 1171 self.currentDirEntry_ = dirEntry; | 1191 self.currentDirEntry_ = dirEntry; |
| 1172 self.dispatchEvent(e); | 1192 self.dispatchEvent(e); |
| 1173 }; | 1193 }; |
| 1174 | 1194 |
| 1175 if (path == '/') | 1195 if (path == '/') |
| 1176 return onPathFound(this.filesystem_.root); | 1196 return onPathFound(this.filesystem_.root); |
| 1177 | 1197 |
| 1178 this.filesystem_.root.getDirectory( | 1198 this.filesystem_.root.getDirectory( |
| 1179 path, {create: false}, onPathFound, | 1199 path, {create: false}, onPathFound, |
| 1180 function(err) { | 1200 function(err) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 this.onOk_(); | 1322 this.onOk_(); |
| 1303 | 1323 |
| 1304 }; | 1324 }; |
| 1305 | 1325 |
| 1306 /** | 1326 /** |
| 1307 * Update the UI when the current directory changes. | 1327 * Update the UI when the current directory changes. |
| 1308 * | 1328 * |
| 1309 * @param {cr.Event} event The directory-changed event. | 1329 * @param {cr.Event} event The directory-changed event. |
| 1310 */ | 1330 */ |
| 1311 FileManager.prototype.onDirectoryChanged_ = function(event) { | 1331 FileManager.prototype.onDirectoryChanged_ = function(event) { |
| 1332 if (event.saveHistory) { |
| 1333 history.pushState(this.currentDirEntry_.fullPath, |
| 1334 this.currentDirEntry_.fullPath, |
| 1335 location.href); |
| 1336 } |
| 1337 this.document_.title = this.currentDirEntry_.fullPath; |
| 1312 this.rescanDirectory_(); | 1338 this.rescanDirectory_(); |
| 1313 }; | 1339 }; |
| 1314 | 1340 |
| 1315 /** | 1341 /** |
| 1316 * Update the UI when a disk is mounted or unmounted. | 1342 * Update the UI when a disk is mounted or unmounted. |
| 1317 * | 1343 * |
| 1318 * @param {string} path The path that has been mounted or unmounted. | 1344 * @param {string} path The path that has been mounted or unmounted. |
| 1319 */ | 1345 */ |
| 1320 FileManager.prototype.onDiskChanged_ = function(event) { | 1346 FileManager.prototype.onDiskChanged_ = function(event) { |
| 1321 // TODO(rginda): Please check and wire handling of other data passed here. | 1347 // TODO(rginda): Please check and wire handling of other data passed here. |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 1600 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
| 1575 if (!this.selection.leadEntry.isFile) | 1601 if (!this.selection.leadEntry.isFile) |
| 1576 throw new Error('Selected entry is not a file!'); | 1602 throw new Error('Selected entry is not a file!'); |
| 1577 } | 1603 } |
| 1578 | 1604 |
| 1579 chrome.fileBrowserPrivate.selectFile(ary[0], 0); | 1605 chrome.fileBrowserPrivate.selectFile(ary[0], 0); |
| 1580 window.close(); | 1606 window.close(); |
| 1581 }; | 1607 }; |
| 1582 | 1608 |
| 1583 })(); | 1609 })(); |
| OLD | NEW |