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 /** | 5 /** |
6 * FileManager constructor. | 6 * FileManager constructor. |
7 * | 7 * |
8 * FileManager objects encapsulate the functionality of the file selector | 8 * FileManager objects encapsulate the functionality of the file selector |
9 * dialogs, as well as the full screen file manager application (though the | 9 * dialogs, as well as the full screen file manager application (though the |
10 * latter is not yet implemented). | 10 * latter is not yet implemented). |
11 * | 11 * |
12 * @constructor | 12 * @constructor |
13 * @param {HTMLElement} dialogDom The DOM node containing the prototypical | 13 * @param {HTMLElement} dialogDom The DOM node containing the prototypical |
14 * dialog UI. | 14 * dialog UI. |
15 */ | 15 */ |
16 function FileManager(dialogDom) { | 16 function FileManager(dialogDom) { |
17 this.console_ = console; | |
dgozman
2012/07/12 13:17:36
Not used.
Oleg Eterevsky
2012/07/12 14:49:22
Done.
| |
17 this.dialogDom_ = dialogDom; | 18 this.dialogDom_ = dialogDom; |
18 this.filesystem_ = null; | 19 this.filesystem_ = null; |
19 this.params_ = location.search ? | 20 this.params_ = location.search ? |
20 JSON.parse(decodeURIComponent(location.search.substr(1))) : | 21 JSON.parse(decodeURIComponent(location.search.substr(1))) : |
21 {}; | 22 {}; |
22 if (this.params_.defaultPath && this.params_.defaultPath.indexOf('/') != 0) | 23 if (this.params_.defaultPath && this.params_.defaultPath.indexOf('/') != 0) |
23 this.params_.defaultPath = '/' + this.params_.defaultPath; | 24 this.params_.defaultPath = '/' + this.params_.defaultPath; |
24 | 25 |
25 this.listType_ = null; | 26 this.listType_ = null; |
26 this.showDelayTimeout_ = null; | 27 this.showDelayTimeout_ = null; |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 this.grid_.endBatchUpdates(); | 537 this.grid_.endBatchUpdates(); |
537 | 538 |
538 // Show the page now unless it's already delayed. | 539 // Show the page now unless it's already delayed. |
539 this.delayShow_(0); | 540 this.delayShow_(0); |
540 | 541 |
541 metrics.recordInterval('Load.DOM'); | 542 metrics.recordInterval('Load.DOM'); |
542 metrics.recordInterval('Load.Total'); | 543 metrics.recordInterval('Load.Total'); |
543 }; | 544 }; |
544 | 545 |
545 FileManager.prototype.initDataTransferOperations_ = function() { | 546 FileManager.prototype.initDataTransferOperations_ = function() { |
546 this.copyManager_ = new FileCopyManager(this.filesystem_.root); | 547 this.copyManager_ = FileCopyManagerWrapper.getInstance( |
548 this.filesystem_.root); | |
547 this.copyManager_.addEventListener('copy-progress', | 549 this.copyManager_.addEventListener('copy-progress', |
548 this.onCopyProgress_.bind(this)); | 550 this.onCopyProgress_.bind(this)); |
549 this.copyManager_.addEventListener('copy-operation-complete', | 551 this.copyManager_.addEventListener('copy-operation-complete', |
550 this.onCopyManagerOperationComplete_.bind(this)); | 552 this.onCopyManagerOperationComplete_.bind(this)); |
551 | 553 |
552 var controller = this.fileTransferController_ = new FileTransferController( | 554 var controller = this.fileTransferController_ = new FileTransferController( |
553 this.directoryModel_.getFileList(), | 555 this.directoryModel_.getFileList(), |
554 this.directoryModel_.getFileListSelection(), | 556 this.directoryModel_.getFileListSelection(), |
555 GridItem.bind(null, this, false /* no checkbox */), | 557 GridItem.bind(null, this, false /* no checkbox */), |
556 this.copyManager_, | 558 this.copyManager_, |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 FileManager.prototype.canExecute_ = function(commandId) { | 1082 FileManager.prototype.canExecute_ = function(commandId) { |
1081 var readonly = this.isOnReadonlyDirectory(); | 1083 var readonly = this.isOnReadonlyDirectory(); |
1082 switch (commandId) { | 1084 switch (commandId) { |
1083 case 'copy': | 1085 case 'copy': |
1084 case 'cut': | 1086 case 'cut': |
1085 return this.document_.queryCommandEnabled(commandId); | 1087 return this.document_.queryCommandEnabled(commandId); |
1086 | 1088 |
1087 // Hack goes below, since we don't receive beforepaste event, but receive | 1089 // Hack goes below, since we don't receive beforepaste event, but receive |
1088 // beforecut and beforecopy events. | 1090 // beforecut and beforecopy events. |
1089 case 'paste': | 1091 case 'paste': |
1090 return this.isRenamingInProgress() | 1092 return this.isRenamingInProgress() ? |
1091 ? this.document_.queryCommandEnabled(commandId) | 1093 this.document_.queryCommandEnabled(commandId) : |
1092 : (!!this.fileTransferController_ && | 1094 (!!this.fileTransferController_ && |
1093 this.fileTransferController_.queryPasteCommandEnabled()); | 1095 this.fileTransferController_.queryPasteCommandEnabled()); |
1094 | 1096 |
1095 case 'rename': | 1097 case 'rename': |
1096 return (// Initialized to the point where we have a current directory | 1098 return (// Initialized to the point where we have a current directory |
1097 !readonly && | 1099 !readonly && |
1098 // Rename not in progress. | 1100 // Rename not in progress. |
1099 !this.isRenamingInProgress() && | 1101 !this.isRenamingInProgress() && |
1100 // Only one file selected. | 1102 // Only one file selected. |
1101 this.selection && | 1103 this.selection && |
1102 this.selection.totalCount == 1); | 1104 this.selection.totalCount == 1); |
1103 | 1105 |
1104 case 'delete': | 1106 case 'delete': |
1105 return (this.isRenamingInProgress() | 1107 return (this.isRenamingInProgress() ? |
1106 ? this.document_.queryCommandEnabled(commandId) | 1108 this.document_.queryCommandEnabled(commandId) : |
1107 : !readonly && | 1109 !readonly && this.selection && this.selection.totalCount > 0); |
1108 this.selection && | |
1109 this.selection.totalCount > 0); | |
1110 | 1110 |
1111 case 'newfolder': | 1111 case 'newfolder': |
1112 return !readonly && | 1112 return !readonly && |
1113 !this.directoryModel_.isSearching() && | 1113 !this.directoryModel_.isSearching() && |
1114 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || | 1114 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || |
1115 this.dialogType_ == FileManager.DialogType.FULL_PAGE); | 1115 this.dialogType_ == FileManager.DialogType.FULL_PAGE); |
1116 | 1116 |
1117 case 'unmount': | 1117 case 'unmount': |
1118 return true; | 1118 return true; |
1119 | 1119 |
(...skipping 3530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4650 this.gdataSpaceInfoBar_.style.width = | 4650 this.gdataSpaceInfoBar_.style.width = |
4651 (100 * usedSpace / result.totalSizeKB) + '%'; | 4651 (100 * usedSpace / result.totalSizeKB) + '%'; |
4652 } else { | 4652 } else { |
4653 this.gdataSpaceInfoBar_.style.display = 'none'; | 4653 this.gdataSpaceInfoBar_.style.display = 'none'; |
4654 this.gdataSpaceInfoLabel_.textContent = | 4654 this.gdataSpaceInfoLabel_.textContent = |
4655 str('GDATA_FAILED_SPACE_INFO'); | 4655 str('GDATA_FAILED_SPACE_INFO'); |
4656 } | 4656 } |
4657 }.bind(this)); | 4657 }.bind(this)); |
4658 } | 4658 } |
4659 })(); | 4659 })(); |
4660 | |
4661 var fileCopyManagerWrapper = null; | |
4662 | |
4663 /** | |
4664 * @constructor | |
4665 * @param {DirectoryEntry} root Root directory entry. | |
4666 */ | |
4667 function FileCopyManagerWrapper(root) { | |
4668 var copyManagerPrototype = | |
4669 chrome.extension.getBackgroundPage().FileCopyManager.prototype; | |
dgozman
2012/07/12 13:17:36
Does this work with unloaded background page?
Oleg Eterevsky
2012/07/12 14:49:22
I wasn't able to test it.
| |
4670 | |
4671 for (var property in copyManagerPrototype) { | |
4672 if (this[property] === undefined && | |
4673 typeof copyManagerPrototype[property] === 'function') { | |
4674 this[property] = (function(p) { | |
4675 return function() { | |
4676 var cmInstance = | |
4677 chrome.extension.getBackgroundPage().FileCopyManager.getInstance( | |
4678 root); | |
4679 return cmInstance[p].apply(cmInstance, arguments); | |
4680 } | |
4681 })(property); | |
4682 } | |
4683 } | |
4684 } | |
4685 | |
4686 /** | |
4687 * Extending cr.EventTarget | |
4688 */ | |
4689 FileCopyManagerWrapper.prototype.__proto__ = cr.EventTarget.prototype; | |
4690 | |
4691 /** | |
4692 * Create a new instance or get existing instance of FCMW. | |
4693 * @param {DirectoryEntry} root Root directory entry. | |
4694 * @return {FileCopyManagerWrapper} A FileCopyManagerWrapper instance. | |
4695 */ | |
4696 FileCopyManagerWrapper.getInstance = function(root) { | |
4697 if (fileCopyManagerWrapper === null) { | |
4698 fileCopyManagerWrapper = new FileCopyManagerWrapper(root); | |
4699 } | |
4700 return fileCopyManagerWrapper; | |
4701 }; | |
4702 | |
4703 /** | |
4704 * Called be FileCopyManager to raise an event in this instance of FileManager. | |
4705 * @param {string} eventName Event name. | |
4706 * @param {Object} eventArgs Arbitratry field written to event object. | |
4707 */ | |
4708 FileCopyManagerWrapper.prototype.onEvent = function(eventName, eventArgs) { | |
4709 var event = new cr.Event(eventName); | |
4710 for (var arg in eventArgs) | |
dgozman
2012/07/12 13:17:36
if (eventArgs.hasOwnProperty(arg))
Oleg Eterevsky
2012/07/12 14:49:22
Done.
| |
4711 event[arg] = eventArgs[arg]; | |
4712 | |
4713 this.dispatchEvent(event); | |
4714 }; | |
4715 | |
OLD | NEW |