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 // TODO(rginda): Remove this and related code after zel's file scheme fix lands. | 5 // TODO(rginda): Remove this and related code after zel's file scheme fix lands. |
6 const ENABLE_EXIF_READER = false; | 6 const ENABLE_EXIF_READER = false; |
7 | 7 |
8 // TODO(rginda): Remove this when the thumbnail view is less janky. | 8 // TODO(rginda): Remove this when the thumbnail view is less janky. |
9 const ENABLE_THUMBNAIL_VIEW = false; | 9 const ENABLE_THUMBNAIL_VIEW = false; |
10 | 10 |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 452 |
453 this.dataModel_ = new cr.ui.table.TableDataModel([]); | 453 this.dataModel_ = new cr.ui.table.TableDataModel([]); |
454 this.dataModel_.sort('name'); | 454 this.dataModel_.sort('name'); |
455 this.dataModel_.addEventListener('sorted', | 455 this.dataModel_.addEventListener('sorted', |
456 this.onDataModelSorted_.bind(this)); | 456 this.onDataModelSorted_.bind(this)); |
457 this.dataModel_.prepareSort = this.prepareSort_.bind(this); | 457 this.dataModel_.prepareSort = this.prepareSort_.bind(this); |
458 | 458 |
459 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE || | 459 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE || |
460 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FOLDER || | 460 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FOLDER || |
461 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 461 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
462 this.selectionModel_ = new cr.ui.table.TableSingleSelectionModel(); | 462 this.selectionModelClass_ = cr.ui.table.TableSingleSelectionModel; |
463 } else { | 463 } else { |
464 this.selectionModel_ = new cr.ui.table.TableSelectionModel(); | 464 this.selectionModelClass_ = cr.ui.table.TableSelectionModel; |
465 } | 465 } |
466 | 466 |
467 this.initTable_(); | 467 this.initTable_(); |
468 this.initGrid_(); | 468 this.initGrid_(); |
469 | 469 |
470 this.setListType(FileManager.ListType.DETAIL); | 470 this.setListType(FileManager.ListType.DETAIL); |
471 | 471 |
472 this.onResize_(); | 472 this.onResize_(); |
473 this.dialogDom_.style.opacity = '1'; | 473 this.dialogDom_.style.opacity = '1'; |
474 }; | 474 }; |
(...skipping 24 matching lines...) Expand all Loading... |
499 this.currentList_.redraw(); | 499 this.currentList_.redraw(); |
500 }; | 500 }; |
501 | 501 |
502 /** | 502 /** |
503 * Initialize the file thumbnail grid. | 503 * Initialize the file thumbnail grid. |
504 */ | 504 */ |
505 FileManager.prototype.initGrid_ = function() { | 505 FileManager.prototype.initGrid_ = function() { |
506 this.grid_ = this.dialogDom_.querySelector('.thumbnail-grid'); | 506 this.grid_ = this.dialogDom_.querySelector('.thumbnail-grid'); |
507 cr.ui.Grid.decorate(this.grid_); | 507 cr.ui.Grid.decorate(this.grid_); |
508 this.grid_.dataModel = this.dataModel_; | 508 this.grid_.dataModel = this.dataModel_; |
509 this.grid_.selectionModel = this.selectionModel_; | 509 this.grid_.selectionModel = new this.selectionModelClass_(); |
510 | 510 |
511 var self = this; | 511 var self = this; |
512 this.grid_.itemConstructor = function(entry) { | 512 this.grid_.itemConstructor = function(entry) { |
513 return self.renderThumbnail_(entry); | 513 return self.renderThumbnail_(entry); |
514 }; | 514 }; |
515 | 515 |
516 this.grid_.addEventListener( | 516 this.grid_.addEventListener( |
517 'dblclick', this.onDetailDoubleClick_.bind(this)); | 517 'dblclick', this.onDetailDoubleClick_.bind(this)); |
518 this.grid_.selectionModel.addEventListener( | 518 this.grid_.selectionModel.addEventListener( |
519 'change', this.onDetailSelectionChanged_.bind(this)); | 519 'change', this.onDetailSelectionChanged_.bind(this)); |
(...skipping 14 matching lines...) Expand all Loading... |
534 | 534 |
535 columns[0].renderFunction = this.renderIconType_.bind(this); | 535 columns[0].renderFunction = this.renderIconType_.bind(this); |
536 columns[1].renderFunction = this.renderName_.bind(this); | 536 columns[1].renderFunction = this.renderName_.bind(this); |
537 columns[2].renderFunction = this.renderSize_.bind(this); | 537 columns[2].renderFunction = this.renderSize_.bind(this); |
538 columns[3].renderFunction = this.renderDate_.bind(this); | 538 columns[3].renderFunction = this.renderDate_.bind(this); |
539 | 539 |
540 this.table_ = this.dialogDom_.querySelector('.detail-table'); | 540 this.table_ = this.dialogDom_.querySelector('.detail-table'); |
541 cr.ui.Table.decorate(this.table_); | 541 cr.ui.Table.decorate(this.table_); |
542 | 542 |
543 this.table_.dataModel = this.dataModel_; | 543 this.table_.dataModel = this.dataModel_; |
544 this.table_.selectionModel = this.selectionModel_; | 544 this.table_.selectionModel = new this.selectionModelClass_(); |
545 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); | 545 this.table_.columnModel = new cr.ui.table.TableColumnModel(columns); |
546 | 546 |
547 this.table_.addEventListener( | 547 this.table_.addEventListener( |
548 'dblclick', this.onDetailDoubleClick_.bind(this)); | 548 'dblclick', this.onDetailDoubleClick_.bind(this)); |
549 this.table_.selectionModel.addEventListener( | 549 this.table_.selectionModel.addEventListener( |
550 'change', this.onDetailSelectionChanged_.bind(this)); | 550 'change', this.onDetailSelectionChanged_.bind(this)); |
551 }; | 551 }; |
552 | 552 |
553 FileManager.prototype.onResize_ = function() { | 553 FileManager.prototype.onResize_ = function() { |
554 this.table_.style.height = this.grid_.style.height = | 554 this.table_.style.height = this.grid_.style.height = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 | 632 |
633 default: | 633 default: |
634 throw new Error('Unknown dialog type: ' + this.dialogType_); | 634 throw new Error('Unknown dialog type: ' + this.dialogType_); |
635 } | 635 } |
636 | 636 |
637 this.okButton_.textContent = okLabel; | 637 this.okButton_.textContent = okLabel; |
638 | 638 |
639 dialogTitle = this.params_.title || defaultTitle; | 639 dialogTitle = this.params_.title || defaultTitle; |
640 this.dialogDom_.querySelector('.dialog-title').textContent = dialogTitle; | 640 this.dialogDom_.querySelector('.dialog-title').textContent = dialogTitle; |
641 | 641 |
642 ary = defaultFolder.match(/^\/home\/[^\/]+\/Downloads(\/.*)?$/); | 642 ary = defaultFolder.match(/^\/home\/[^\/]+\/user\/Downloads(\/.*)?$/); |
643 if (ary) { | 643 if (ary) { |
644 // Chrome will probably suggest the full path to Downloads, but | 644 // Chrome will probably suggest the full path to Downloads, but |
645 // we're working with 'virtual paths', so we have to translate. | 645 // we're working with 'virtual paths', so we have to translate. |
646 // TODO(rginda): Maybe chrome should have suggested the correct place | 646 // TODO(rginda): Maybe chrome should have suggested the correct place |
647 // to begin with, but that would mean it would have to treat the | 647 // to begin with, but that would mean it would have to treat the |
648 // file manager dialogs differently than the native ones. | 648 // file manager dialogs differently than the native ones. |
649 defaultFolder = '/Downloads' + (ary[1] || ''); | 649 defaultFolder = '/Downloads' + (ary[1] || ''); |
650 } | 650 } |
651 | 651 |
652 this.changeDirectory(defaultFolder); | 652 this.changeDirectory(defaultFolder); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 } | 1109 } |
1110 | 1110 |
1111 if (ENABLE_EXIF_READER) { | 1111 if (ENABLE_EXIF_READER) { |
1112 if (entry.name.match(/\.jpe?g$/i)) { | 1112 if (entry.name.match(/\.jpe?g$/i)) { |
1113 // File is a jpg image, fetch the exif thumbnail. | 1113 // File is a jpg image, fetch the exif thumbnail. |
1114 this.cacheExifMetadata_(entry, function(metadata) { | 1114 this.cacheExifMetadata_(entry, function(metadata) { |
1115 callback(iconType, metadata.thumbnailURL || entry.toURL()); | 1115 callback(iconType, metadata.thumbnailURL || entry.toURL()); |
1116 }); | 1116 }); |
1117 return; | 1117 return; |
1118 } | 1118 } |
1119 | |
1120 // File is some other kind of image, just return the url to the whole | |
1121 // thing. | |
1122 setTimeout(function() { callback(iconType, entry.toURL()) }); | |
1123 return; | |
1124 } | 1119 } |
1125 | 1120 |
1126 // If the exif reader worker isn't enabled, read the entire file as a | 1121 // File is some other kind of image, just return the url to the whole |
1127 // data url instead. | 1122 // thing. |
1128 batchAsyncCall(entry, 'file', function(file) { | 1123 setTimeout(function() { callback(iconType, entry.toURL()) }); |
1129 var reader = new FileReader(); | |
1130 | |
1131 reader.onerror = util.ferr('Error reading preview: ' + entry.fullPath); | |
1132 reader.onloadend = function(e) { callback(iconType, reader.result) }; | |
1133 reader.readAsDataURL(file); | |
1134 }); | |
1135 }; | 1124 }; |
1136 | 1125 |
1137 /** | 1126 /** |
1138 * Change the current directory. | 1127 * Change the current directory. |
1139 * | 1128 * |
1140 * Dispatches the 'directory-changed' event when the directory is successfully | 1129 * Dispatches the 'directory-changed' event when the directory is successfully |
1141 * changed. | 1130 * changed. |
1142 * | 1131 * |
1143 * @param {string} path The absolute path to the new directory. | 1132 * @param {string} path The absolute path to the new directory. |
1144 */ | 1133 */ |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 1517 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
1529 if (!this.selection.leadEntry.isFile) | 1518 if (!this.selection.leadEntry.isFile) |
1530 throw new Error('Selected entry is not a file!'); | 1519 throw new Error('Selected entry is not a file!'); |
1531 } | 1520 } |
1532 | 1521 |
1533 chrome.fileBrowserPrivate.selectFile(ary[0], 0); | 1522 chrome.fileBrowserPrivate.selectFile(ary[0], 0); |
1534 window.close(); | 1523 window.close(); |
1535 }; | 1524 }; |
1536 | 1525 |
1537 })(); | 1526 })(); |
OLD | NEW |