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). |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
971 this.commands_[key].disabled = !this.canExecute_(key); | 971 this.commands_[key].disabled = !this.canExecute_(key); |
972 }; | 972 }; |
973 | 973 |
974 /** | 974 /** |
975 * @param {string} commandId Command identifier. | 975 * @param {string} commandId Command identifier. |
976 * @return {boolean} True if the command can be executed for current | 976 * @return {boolean} True if the command can be executed for current |
977 * selection. | 977 * selection. |
978 */ | 978 */ |
979 FileManager.prototype.canExecute_ = function(commandId) { | 979 FileManager.prototype.canExecute_ = function(commandId) { |
980 var readonly = this.isOnReadonlyDirectory(); | 980 var readonly = this.isOnReadonlyDirectory(); |
981 var shouldCreate = util.shouldCreateOnGDataPath( | |
dgozman
2012/05/03 11:21:47
This is not very intuitive: you ask for something
tbarzic
2012/05/03 19:16:02
Done.
| |
982 this.directoryModel_.getCurrentDirEntry().fullPath); | |
981 switch (commandId) { | 983 switch (commandId) { |
982 case 'copy': | 984 case 'copy': |
983 case 'cut': | 985 case 'cut': |
984 return this.document_.queryCommandEnabled(commandId); | 986 return this.document_.queryCommandEnabled(commandId); |
985 | 987 |
986 case 'paste': | 988 case 'paste': |
987 return !!this.fileTransferController_ && | 989 return !!this.fileTransferController_ && |
988 this.fileTransferController_.queryPasteCommandEnabled(); | 990 this.fileTransferController_.queryPasteCommandEnabled() && |
991 shouldCreate; | |
989 | 992 |
990 case 'rename': | 993 case 'rename': |
991 return (// Initialized to the point where we have a current directory | 994 return (// Initialized to the point where we have a current directory |
992 !readonly && | 995 !readonly && |
993 // Rename not in progress. | 996 // Rename not in progress. |
994 !this.isRenamingInProgress() && | 997 !this.isRenamingInProgress() && |
995 // Only one file selected. | 998 // Only one file selected. |
996 this.selection && | 999 this.selection && |
997 this.selection.totalCount == 1); | 1000 this.selection.totalCount == 1); |
998 | 1001 |
999 case 'delete': | 1002 case 'delete': |
1000 return (// Initialized to the point where we have a current directory | 1003 return (// Initialized to the point where we have a current directory |
1001 !readonly && | 1004 !readonly && |
1002 // Rename not in progress. | 1005 // Rename not in progress. |
1003 !this.isRenamingInProgress() && | 1006 !this.isRenamingInProgress() && |
1004 this.selection && | 1007 this.selection && |
1005 this.selection.totalCount > 0); | 1008 this.selection.totalCount > 0); |
1006 | 1009 |
1007 case 'newfolder': | 1010 case 'newfolder': |
1008 return !readonly && | 1011 return !readonly && |
1012 shouldCreate && | |
1009 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || | 1013 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || |
1010 this.dialogType_ == FileManager.DialogType.FULL_PAGE); | 1014 this.dialogType_ == FileManager.DialogType.FULL_PAGE); |
1011 | 1015 |
1012 case 'unmount': | 1016 case 'unmount': |
1013 return true; | 1017 return true; |
1014 | 1018 |
1015 case 'format': | 1019 case 'format': |
1016 var entry = this.directoryModel_.getCurrentRootDirEntry(); | 1020 var entry = this.directoryModel_.getCurrentRootDirEntry(); |
1017 | 1021 |
1018 return entry && DirectoryModel.getRootType(entry.fullPath) == | 1022 return entry && DirectoryModel.getRootType(entry.fullPath) == |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1823 * Render filename label for grid and list view. | 1827 * Render filename label for grid and list view. |
1824 * @param {Entry} entry The Entry object to render. | 1828 * @param {Entry} entry The Entry object to render. |
1825 * @return {HTMLDivElement} The label. | 1829 * @return {HTMLDivElement} The label. |
1826 */ | 1830 */ |
1827 FileManager.prototype.renderFileNameLabel_ = function(entry) { | 1831 FileManager.prototype.renderFileNameLabel_ = function(entry) { |
1828 // Filename need to be in a '.filename-label' container for correct | 1832 // Filename need to be in a '.filename-label' container for correct |
1829 // work of inplace renaming. | 1833 // work of inplace renaming. |
1830 var fileName = this.document_.createElement('div'); | 1834 var fileName = this.document_.createElement('div'); |
1831 fileName.className = 'filename-label'; | 1835 fileName.className = 'filename-label'; |
1832 | 1836 |
1837 // If the entry is gdata search result, we should calculate name to use | |
1838 // instead of using |entry.name|. | |
1839 var gdataSearchResult = | |
1840 util.getFileAndDisplayNameForGDataSearchResult(entry.fullPath); | |
1841 var displayName = gdataSearchResult ? gdataSearchResult.displayName : | |
1842 entry.name; | |
1843 | |
1833 fileName.textContent = | 1844 fileName.textContent = |
1834 this.directoryModel_.getCurrentDirEntry().name == '' ? | 1845 this.directoryModel_.getCurrentDirEntry().name == '' ? |
1835 this.getRootLabel_(entry.name) : entry.name; | 1846 this.getRootLabel_(displayName) : displayName; |
1836 return fileName; | 1847 return fileName; |
1837 }; | 1848 }; |
1838 | 1849 |
1839 /** | 1850 /** |
1840 * Render the Size column of the detail table. | 1851 * Render the Size column of the detail table. |
1841 * | 1852 * |
1842 * @param {Entry} entry The Entry object to render. | 1853 * @param {Entry} entry The Entry object to render. |
1843 * @param {string} columnId The id of the column to be rendered. | 1854 * @param {string} columnId The id of the column to be rendered. |
1844 * @param {cr.ui.Table} table The table doing the rendering. | 1855 * @param {cr.ui.Table} table The table doing the rendering. |
1845 */ | 1856 */ |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2863 div.textContent = i == 0 ? this.getRootLabel_(path) : pathName; | 2874 div.textContent = i == 0 ? this.getRootLabel_(path) : pathName; |
2864 | 2875 |
2865 path = path + '/'; | 2876 path = path + '/'; |
2866 div.path = path; | 2877 div.path = path; |
2867 | 2878 |
2868 bc.appendChild(div); | 2879 bc.appendChild(div); |
2869 | 2880 |
2870 if (i == pathNames.length - 1) { | 2881 if (i == pathNames.length - 1) { |
2871 div.classList.add('breadcrumb-last'); | 2882 div.classList.add('breadcrumb-last'); |
2872 } else { | 2883 } else { |
2873 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); | 2884 // This is virtual, inaccessible directory. |
2885 if (i == 1 && pathNames[0] == 'gdata' && pathNames[1] == '.search') { | |
dgozman
2012/05/03 11:21:47
|path == util.getGDataSearchRoot()| ?
tbarzic
2012/05/03 19:16:02
Yep, you're right, I haven't read the method caref
| |
2886 div.classList.add('breadcrumb-last'); | |
2887 } else { | |
2888 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); | |
2889 } | |
2874 | 2890 |
2875 var spacer = doc.createElement('div'); | 2891 var spacer = doc.createElement('div'); |
2876 spacer.className = 'separator'; | 2892 spacer.className = 'separator'; |
2877 bc.appendChild(spacer); | 2893 bc.appendChild(spacer); |
2878 } | 2894 } |
2879 } | 2895 } |
2880 this.truncateBreadcrumbs_(); | 2896 this.truncateBreadcrumbs_(); |
2881 }; | 2897 }; |
2882 | 2898 |
2883 FileManager.prototype.isRenamingInProgress = function() { | 2899 FileManager.prototype.isRenamingInProgress = function() { |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3533 }; | 3549 }; |
3534 | 3550 |
3535 FileManager.prototype.onRenameInputBlur_ = function(event) { | 3551 FileManager.prototype.onRenameInputBlur_ = function(event) { |
3536 if (this.isRenamingInProgress() && !this.renameInput_.validation_) | 3552 if (this.isRenamingInProgress() && !this.renameInput_.validation_) |
3537 this.commitRename_(); | 3553 this.commitRename_(); |
3538 }; | 3554 }; |
3539 | 3555 |
3540 FileManager.prototype.commitRename_ = function() { | 3556 FileManager.prototype.commitRename_ = function() { |
3541 var input = this.renameInput_; | 3557 var input = this.renameInput_; |
3542 var entry = input.currentEntry; | 3558 var entry = input.currentEntry; |
3543 var newName = input.value; | 3559 var newNameInput = input.value; |
3560 | |
3561 // If we are renaming gdata search result, we'll have to format newName we | |
3562 // use in file system operations like: <resource_id>.<file_name>. | |
3563 var searchResultName = | |
3564 util.getFileAndDisplayNameForGDataSearchResult(entry.fullPath); | |
3565 | |
3566 var newName = | |
3567 searchResultName ? searchResultName.resourceId + '.' + newNameInput : | |
3568 newNameInput; | |
3569 var oldName = searchResultName ? searchResultName.displayName : entry.name; | |
3544 | 3570 |
3545 if (newName == entry.name) { | 3571 if (newName == entry.name) { |
3546 this.cancelRename_(); | 3572 this.cancelRename_(); |
3547 return; | 3573 return; |
3548 } | 3574 } |
3549 | 3575 |
3550 var nameNode = this.findListItemForNode_(this.renameInput_). | 3576 var nameNode = this.findListItemForNode_(this.renameInput_). |
3551 querySelector('.filename-label'); | 3577 querySelector('.filename-label'); |
3552 | 3578 |
3553 input.validation_ = true; | 3579 input.validation_ = true; |
3554 function validationDone() { | 3580 function validationDone() { |
3555 input.validation_ = false; | 3581 input.validation_ = false; |
3556 // Alert dialog restores focus unless the item removed from DOM. | 3582 // Alert dialog restores focus unless the item removed from DOM. |
3557 if (this.document_.activeElement != input) | 3583 if (this.document_.activeElement != input) |
3558 this.cancelRename_(); | 3584 this.cancelRename_(); |
3559 } | 3585 } |
3560 | 3586 |
3561 if (!this.validateFileName_(newName, validationDone.bind(this))) | 3587 if (!this.validateFileName_(newNameInput, validationDone.bind(this))) |
3562 return; | 3588 return; |
3563 | 3589 |
3564 function onError(err) { | 3590 function onError(err) { |
3565 nameNode.textContent = entry.name; | 3591 nameNode.textContent = entry.name; |
3566 this.alert.show(strf('ERROR_RENAMING', entry.name, | 3592 this.alert.show(strf('ERROR_RENAMING', entry.name, |
3567 util.getFileErrorMnemonic(err.code))); | 3593 util.getFileErrorMnemonic(err.code))); |
3568 } | 3594 } |
3569 | 3595 |
3570 this.cancelRename_(); | 3596 this.cancelRename_(); |
3571 // Optimistically apply new name immediately to avoid flickering in | 3597 // Optimistically apply new name immediately to avoid flickering in |
3572 // case of success. | 3598 // case of success. |
3573 nameNode.textContent = newName; | 3599 nameNode.textContent = newNameInput; |
3574 | 3600 |
3575 this.directoryModel_.doesExist(newName, function(exists, isFile) { | 3601 this.directoryModel_.doesExist(newName, function(exists, isFile) { |
3576 if (!exists) { | 3602 if (!exists) { |
3577 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); | 3603 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); |
3578 } else { | 3604 } else { |
3579 nameNode.textContent = entry.name; | 3605 nameNode.textContent = oldName; |
3580 var message = isFile ? 'FILE_ALREADY_EXISTS' : | 3606 var message = isFile ? 'FILE_ALREADY_EXISTS' : |
3581 'DIRECTORY_ALREADY_EXISTS'; | 3607 'DIRECTORY_ALREADY_EXISTS'; |
3582 this.alert.show(strf(message, newName)); | 3608 this.alert.show(strf(message, newNameInput)); |
3583 } | 3609 } |
3584 }.bind(this)); | 3610 }.bind(this)); |
3585 }; | 3611 }; |
3586 | 3612 |
3587 FileManager.prototype.cancelRename_ = function() { | 3613 FileManager.prototype.cancelRename_ = function() { |
3588 this.renameInput_.currentEntry = null; | 3614 this.renameInput_.currentEntry = null; |
3589 | 3615 |
3590 var parent = this.renameInput_.parentNode; | 3616 var parent = this.renameInput_.parentNode; |
3591 if (parent) { | 3617 if (parent) { |
3592 parent.removeAttribute('renaming'); | 3618 parent.removeAttribute('renaming'); |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4256 if (oldValue) { | 4282 if (oldValue) { |
4257 event.target.removeAttribute('checked'); | 4283 event.target.removeAttribute('checked'); |
4258 } else { | 4284 } else { |
4259 event.target.setAttribute('checked', 'checked'); | 4285 event.target.setAttribute('checked', 'checked'); |
4260 } | 4286 } |
4261 }; | 4287 }; |
4262 | 4288 |
4263 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 4289 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
4264 var searchString = this.dialogDom_.querySelector('#search-box').value; | 4290 var searchString = this.dialogDom_.querySelector('#search-box').value; |
4265 if (searchString) { | 4291 if (searchString) { |
4266 this.directoryModel_.addFilter( | 4292 if (!this.isOnGData()) { |
4267 'searchbox', | 4293 this.directoryModel_.addFilter( |
4268 function(e) { | 4294 'searchbox', |
4269 return e.name.substr(0, searchString.length) == searchString; | 4295 function(e) { |
4270 }); | 4296 return e.name.substr(0, searchString.length) == searchString; |
4297 }); | |
4298 } else { | |
4299 this.directoryModel_.changeDirectory( | |
4300 util.createGDataSearchPath(searchString)); | |
4301 } | |
4271 } else { | 4302 } else { |
4272 this.directoryModel_.removeFilter('searchbox'); | 4303 if (!this.isOnGData()) { |
4304 this.directoryModel_.removeFilter('searchbox'); | |
4305 } else { | |
4306 this.directoryModel_.changeDirectory('/gdata/'); | |
dgozman
2012/05/03 11:21:47
1. Use |'/' + DirectoryModel.GDATA_DIRECTORY|
2. I
tbarzic
2012/05/03 19:16:02
Done.
| |
4307 } | |
4273 } | 4308 } |
4274 }; | 4309 }; |
4275 | 4310 |
4276 FileManager.prototype.decorateSplitter = function(splitterElement) { | 4311 FileManager.prototype.decorateSplitter = function(splitterElement) { |
4277 var self = this; | 4312 var self = this; |
4278 | 4313 |
4279 var Splitter = cr.ui.Splitter; | 4314 var Splitter = cr.ui.Splitter; |
4280 | 4315 |
4281 var customSplitter = cr.ui.define('div'); | 4316 var customSplitter = cr.ui.define('div'); |
4282 | 4317 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4397 | 4432 |
4398 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); | 4433 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); |
4399 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); | 4434 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); |
4400 | 4435 |
4401 var style = this.document_.createElement('link'); | 4436 var style = this.document_.createElement('link'); |
4402 style.rel = 'stylesheet'; | 4437 style.rel = 'stylesheet'; |
4403 style.href = 'css/gdrive_welcome.css'; | 4438 style.href = 'css/gdrive_welcome.css'; |
4404 this.document_.head.appendChild(style); | 4439 this.document_.head.appendChild(style); |
4405 }; | 4440 }; |
4406 })(); | 4441 })(); |
OLD | NEW |