Chromium Code Reviews| 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.isSpecialReadonlyDirectory( | |
| 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 var displayName = | |
| 1838 this.directoryModel_.getDisplayName(entry.fullPath, entry.name); | |
| 1839 | |
| 1833 fileName.textContent = | 1840 fileName.textContent = |
| 1834 this.directoryModel_.getCurrentDirEntry().name == '' ? | 1841 this.directoryModel_.getCurrentDirEntry().name == '' ? |
| 1835 this.getRootLabel_(entry.name) : entry.name; | 1842 this.getRootLabel_(displayName) : displayName; |
| 1836 return fileName; | 1843 return fileName; |
| 1837 }; | 1844 }; |
| 1838 | 1845 |
| 1839 /** | 1846 /** |
| 1840 * Render the Size column of the detail table. | 1847 * Render the Size column of the detail table. |
| 1841 * | 1848 * |
| 1842 * @param {Entry} entry The Entry object to render. | 1849 * @param {Entry} entry The Entry object to render. |
| 1843 * @param {string} columnId The id of the column to be rendered. | 1850 * @param {string} columnId The id of the column to be rendered. |
| 1844 * @param {cr.ui.Table} table The table doing the rendering. | 1851 * @param {cr.ui.Table} table The table doing the rendering. |
| 1845 */ | 1852 */ |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2853 var path = rootPathNames.join('/') + '/'; | 2860 var path = rootPathNames.join('/') + '/'; |
| 2854 var doc = this.document_; | 2861 var doc = this.document_; |
| 2855 | 2862 |
| 2856 for (var i = 0; i < pathNames.length; i++) { | 2863 for (var i = 0; i < pathNames.length; i++) { |
| 2857 var pathName = pathNames[i]; | 2864 var pathName = pathNames[i]; |
| 2858 path += pathName; | 2865 path += pathName; |
| 2859 | 2866 |
| 2860 var div = doc.createElement('div'); | 2867 var div = doc.createElement('div'); |
| 2861 | 2868 |
| 2862 div.className = 'breadcrumb-path'; | 2869 div.className = 'breadcrumb-path'; |
| 2863 div.textContent = i == 0 ? this.getRootLabel_(path) : pathName; | 2870 div.textContent = i == 0 ? this.getRootLabel_(path) : |
|
SeRya
2012/05/07 14:06:00
You are going to show in breadcrumbs path like "gd
tbarzic
2012/05/10 03:20:47
With the newest version we will modifying breadcru
| |
| 2871 this.directoryModel_.getDisplayName(path, | |
| 2872 pathName); | |
| 2864 | 2873 |
| 2865 path = path + '/'; | 2874 path = path + '/'; |
| 2866 div.path = path; | 2875 div.path = path; |
| 2867 | 2876 |
| 2868 bc.appendChild(div); | 2877 bc.appendChild(div); |
| 2869 | 2878 |
| 2870 if (i == pathNames.length - 1) { | 2879 if (i == pathNames.length - 1 || |
| 2871 div.classList.add('breadcrumb-last'); | 2880 path == util.GDATA_SEARCH_ROOT_PATH + '/') { |
| 2881 div.classList.add('breadcrumb-non-clickable'); | |
| 2872 } else { | 2882 } else { |
| 2873 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); | 2883 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); |
| 2884 } | |
| 2874 | 2885 |
| 2886 if (i != pathNames.length - 1) { | |
| 2875 var spacer = doc.createElement('div'); | 2887 var spacer = doc.createElement('div'); |
| 2876 spacer.className = 'separator'; | 2888 spacer.className = 'separator'; |
| 2877 bc.appendChild(spacer); | 2889 bc.appendChild(spacer); |
| 2878 } | 2890 } |
| 2879 } | 2891 } |
| 2880 this.truncateBreadcrumbs_(); | 2892 this.truncateBreadcrumbs_(); |
| 2881 }; | 2893 }; |
| 2882 | 2894 |
| 2883 FileManager.prototype.isRenamingInProgress = function() { | 2895 FileManager.prototype.isRenamingInProgress = function() { |
| 2884 return !!this.renameInput_.currentEntry; | 2896 return !!this.renameInput_.currentEntry; |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3371 * Update the UI when the current directory changes. | 3383 * Update the UI when the current directory changes. |
| 3372 * | 3384 * |
| 3373 * @param {cr.Event} event The directory-changed event. | 3385 * @param {cr.Event} event The directory-changed event. |
| 3374 */ | 3386 */ |
| 3375 FileManager.prototype.onDirectoryChanged_ = function(event) { | 3387 FileManager.prototype.onDirectoryChanged_ = function(event) { |
| 3376 this.updateCommonActionButtons_(); | 3388 this.updateCommonActionButtons_(); |
| 3377 this.updateOkButton_(); | 3389 this.updateOkButton_(); |
| 3378 this.updateBreadcrumbs_(); | 3390 this.updateBreadcrumbs_(); |
| 3379 this.updateColumnModel_(); | 3391 this.updateColumnModel_(); |
| 3380 | 3392 |
| 3393 // We don't want to keep a record in browser history for each key press in | |
| 3394 // the search box. | |
| 3395 var shouldReplaceHistory = | |
|
SeRya
2012/05/07 14:06:00
I think when search query change DirectoryModel mu
tbarzic
2012/05/10 03:20:47
Done.
| |
| 3396 event.initial || | |
| 3397 (util.isSpecialReadonlyDirectory(event.newDirEntry.fullPath) && | |
| 3398 util.isSpecialReadonlyDirectory(event.previousDirEntry.fullPath)); | |
| 3399 | |
| 3381 // Sometimes we rescan the same directory (when mounting GData lazily first, | 3400 // Sometimes we rescan the same directory (when mounting GData lazily first, |
| 3382 // then for real). Do not update the location then. | 3401 // then for real). Do not update the location then. |
| 3383 if (event.newDirEntry.fullPath != event.previousDirEntry.fullPath) { | 3402 if (event.newDirEntry.fullPath != event.previousDirEntry.fullPath) { |
| 3384 this.updateLocation_(event.initial, event.newDirEntry.fullPath); | 3403 this.updateLocation_(shouldReplaceHistory, event.newDirEntry.fullPath); |
| 3385 } | 3404 } |
| 3386 | 3405 |
| 3387 this.checkFreeSpace_(this.getCurrentDirectory()); | 3406 this.checkFreeSpace_(this.getCurrentDirectory()); |
| 3388 | 3407 |
| 3389 this.updateTitle_(); | 3408 this.updateTitle_(); |
| 3390 | 3409 |
| 3391 if (this.filesystemObserverId_) | 3410 if (this.filesystemObserverId_) |
| 3392 this.metadataCache_.removeObserver(this.filesystemObserverId_); | 3411 this.metadataCache_.removeObserver(this.filesystemObserverId_); |
| 3393 if (this.gdataObserverId_) | 3412 if (this.gdataObserverId_) |
| 3394 this.metadataCache_.removeObserver(this.gdataObserverId_); | 3413 this.metadataCache_.removeObserver(this.gdataObserverId_); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3565 nameNode.textContent = entry.name; | 3584 nameNode.textContent = entry.name; |
| 3566 this.alert.show(strf('ERROR_RENAMING', entry.name, | 3585 this.alert.show(strf('ERROR_RENAMING', entry.name, |
| 3567 util.getFileErrorMnemonic(err.code))); | 3586 util.getFileErrorMnemonic(err.code))); |
| 3568 } | 3587 } |
| 3569 | 3588 |
| 3570 this.cancelRename_(); | 3589 this.cancelRename_(); |
| 3571 // Optimistically apply new name immediately to avoid flickering in | 3590 // Optimistically apply new name immediately to avoid flickering in |
| 3572 // case of success. | 3591 // case of success. |
| 3573 nameNode.textContent = newName; | 3592 nameNode.textContent = newName; |
| 3574 | 3593 |
| 3575 this.directoryModel_.doesExist(newName, function(exists, isFile) { | 3594 this.directoryModel_.doesExist(entry, newName, function(exists, isFile) { |
| 3576 if (!exists) { | 3595 if (!exists) { |
| 3577 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); | 3596 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); |
| 3578 } else { | 3597 } else { |
| 3579 nameNode.textContent = entry.name; | 3598 nameNode.textContent = |
| 3599 this.directoryModel_.getDisplayName(entry.fullPath, entry.name); | |
| 3580 var message = isFile ? 'FILE_ALREADY_EXISTS' : | 3600 var message = isFile ? 'FILE_ALREADY_EXISTS' : |
| 3581 'DIRECTORY_ALREADY_EXISTS'; | 3601 'DIRECTORY_ALREADY_EXISTS'; |
| 3582 this.alert.show(strf(message, newName)); | 3602 this.alert.show(strf(message, newName)); |
| 3583 } | 3603 } |
| 3584 }.bind(this)); | 3604 }.bind(this)); |
| 3585 }; | 3605 }; |
| 3586 | 3606 |
| 3587 FileManager.prototype.cancelRename_ = function() { | 3607 FileManager.prototype.cancelRename_ = function() { |
| 3588 this.renameInput_.currentEntry = null; | 3608 this.renameInput_.currentEntry = null; |
| 3589 | 3609 |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4255 | 4275 |
| 4256 if (oldValue) { | 4276 if (oldValue) { |
| 4257 event.target.removeAttribute('checked'); | 4277 event.target.removeAttribute('checked'); |
| 4258 } else { | 4278 } else { |
| 4259 event.target.setAttribute('checked', 'checked'); | 4279 event.target.setAttribute('checked', 'checked'); |
| 4260 } | 4280 } |
| 4261 }; | 4281 }; |
| 4262 | 4282 |
| 4263 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 4283 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
| 4264 var searchString = this.dialogDom_.querySelector('#search-box').value; | 4284 var searchString = this.dialogDom_.querySelector('#search-box').value; |
| 4265 if (searchString) { | 4285 this.directoryModel_.search(searchString); |
| 4266 this.directoryModel_.addFilter( | |
| 4267 'searchbox', | |
| 4268 function(e) { | |
| 4269 return e.name.substr(0, searchString.length) == searchString; | |
| 4270 }); | |
| 4271 } else { | |
| 4272 this.directoryModel_.removeFilter('searchbox'); | |
| 4273 } | |
| 4274 }; | 4286 }; |
| 4275 | 4287 |
| 4276 FileManager.prototype.decorateSplitter = function(splitterElement) { | 4288 FileManager.prototype.decorateSplitter = function(splitterElement) { |
| 4277 var self = this; | 4289 var self = this; |
| 4278 | 4290 |
| 4279 var Splitter = cr.ui.Splitter; | 4291 var Splitter = cr.ui.Splitter; |
| 4280 | 4292 |
| 4281 var customSplitter = cr.ui.define('div'); | 4293 var customSplitter = cr.ui.define('div'); |
| 4282 | 4294 |
| 4283 customSplitter.prototype = { | 4295 customSplitter.prototype = { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4397 | 4409 |
| 4398 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); | 4410 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); |
| 4399 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); | 4411 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); |
| 4400 | 4412 |
| 4401 var style = this.document_.createElement('link'); | 4413 var style = this.document_.createElement('link'); |
| 4402 style.rel = 'stylesheet'; | 4414 style.rel = 'stylesheet'; |
| 4403 style.href = 'css/gdrive_welcome.css'; | 4415 style.href = 'css/gdrive_welcome.css'; |
| 4404 this.document_.head.appendChild(style); | 4416 this.document_.head.appendChild(style); |
| 4405 }; | 4417 }; |
| 4406 })(); | 4418 })(); |
| OLD | NEW |