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 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
992 this.commands_[key].disabled = !this.canExecute_(key); | 992 this.commands_[key].disabled = !this.canExecute_(key); |
993 }; | 993 }; |
994 | 994 |
995 /** | 995 /** |
996 * @param {string} commandId Command identifier. | 996 * @param {string} commandId Command identifier. |
997 * @return {boolean} True if the command can be executed for current | 997 * @return {boolean} True if the command can be executed for current |
998 * selection. | 998 * selection. |
999 */ | 999 */ |
1000 FileManager.prototype.canExecute_ = function(commandId) { | 1000 FileManager.prototype.canExecute_ = function(commandId) { |
1001 var readonly = this.isOnReadonlyDirectory(); | 1001 var readonly = this.isOnReadonlyDirectory(); |
1002 var shouldCreate = !util.isSpecialReadonlyDirectory( | |
1003 this.directoryModel_.getCurrentDirEntry().fullPath); | |
SeRya
2012/05/10 08:44:16
I think here should not be difference between loca
tbarzic
2012/05/10 23:28:02
Done.
| |
1002 switch (commandId) { | 1004 switch (commandId) { |
1003 case 'copy': | 1005 case 'copy': |
1004 case 'cut': | 1006 case 'cut': |
1005 return this.document_.queryCommandEnabled(commandId); | 1007 return this.document_.queryCommandEnabled(commandId); |
1006 | 1008 |
1007 case 'paste': | 1009 case 'paste': |
1008 return !!this.fileTransferController_ && | 1010 return !!this.fileTransferController_ && |
1009 this.fileTransferController_.queryPasteCommandEnabled(); | 1011 this.fileTransferController_.queryPasteCommandEnabled() && |
1012 shouldCreate; | |
1010 | 1013 |
1011 case 'rename': | 1014 case 'rename': |
1012 return (// Initialized to the point where we have a current directory | 1015 return (// Initialized to the point where we have a current directory |
1013 !readonly && | 1016 !readonly && |
1014 // Rename not in progress. | 1017 // Rename not in progress. |
1015 !this.isRenamingInProgress() && | 1018 !this.isRenamingInProgress() && |
1016 // Only one file selected. | 1019 // Only one file selected. |
1017 this.selection && | 1020 this.selection && |
1018 this.selection.totalCount == 1); | 1021 this.selection.totalCount == 1); |
1019 | 1022 |
1020 case 'delete': | 1023 case 'delete': |
1021 return (// Initialized to the point where we have a current directory | 1024 return (// Initialized to the point where we have a current directory |
1022 !readonly && | 1025 !readonly && |
1023 // Rename not in progress. | 1026 // Rename not in progress. |
1024 !this.isRenamingInProgress() && | 1027 !this.isRenamingInProgress() && |
1025 this.selection && | 1028 this.selection && |
1026 this.selection.totalCount > 0); | 1029 this.selection.totalCount > 0); |
1027 | 1030 |
1028 case 'newfolder': | 1031 case 'newfolder': |
1029 return !readonly && | 1032 return !readonly && |
1033 shouldCreate && | |
1030 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || | 1034 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || |
1031 this.dialogType_ == FileManager.DialogType.FULL_PAGE); | 1035 this.dialogType_ == FileManager.DialogType.FULL_PAGE); |
1032 | 1036 |
1033 case 'unmount': | 1037 case 'unmount': |
1034 return true; | 1038 return true; |
1035 | 1039 |
1036 case 'format': | 1040 case 'format': |
1037 var entry = this.directoryModel_.getCurrentRootDirEntry(); | 1041 var entry = this.directoryModel_.getCurrentRootDirEntry(); |
1038 | 1042 |
1039 return entry && DirectoryModel.getRootType(entry.fullPath) == | 1043 return entry && DirectoryModel.getRootType(entry.fullPath) == |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1856 * Render filename label for grid and list view. | 1860 * Render filename label for grid and list view. |
1857 * @param {Entry} entry The Entry object to render. | 1861 * @param {Entry} entry The Entry object to render. |
1858 * @return {HTMLDivElement} The label. | 1862 * @return {HTMLDivElement} The label. |
1859 */ | 1863 */ |
1860 FileManager.prototype.renderFileNameLabel_ = function(entry) { | 1864 FileManager.prototype.renderFileNameLabel_ = function(entry) { |
1861 // Filename need to be in a '.filename-label' container for correct | 1865 // Filename need to be in a '.filename-label' container for correct |
1862 // work of inplace renaming. | 1866 // work of inplace renaming. |
1863 var fileName = this.document_.createElement('div'); | 1867 var fileName = this.document_.createElement('div'); |
1864 fileName.className = 'filename-label'; | 1868 fileName.className = 'filename-label'; |
1865 | 1869 |
1870 var displayName = | |
1871 this.directoryModel_.getDisplayName(entry.fullPath, entry.name); | |
1872 | |
1866 fileName.textContent = | 1873 fileName.textContent = |
1867 this.directoryModel_.getCurrentDirEntry().name == '' ? | 1874 this.directoryModel_.getCurrentDirEntry().name == '' ? |
1868 this.getRootLabel_(entry.name) : entry.name; | 1875 this.getRootLabel_(displayName) : displayName; |
1869 return fileName; | 1876 return fileName; |
1870 }; | 1877 }; |
1871 | 1878 |
1872 /** | 1879 /** |
1873 * Render the Size column of the detail table. | 1880 * Render the Size column of the detail table. |
1874 * | 1881 * |
1875 * @param {Entry} entry The Entry object to render. | 1882 * @param {Entry} entry The Entry object to render. |
1876 * @param {string} columnId The id of the column to be rendered. | 1883 * @param {string} columnId The id of the column to be rendered. |
1877 * @param {cr.ui.Table} table The table doing the rendering. | 1884 * @param {cr.ui.Table} table The table doing the rendering. |
1878 */ | 1885 */ |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2887 var path = rootPathNames.join('/') + '/'; | 2894 var path = rootPathNames.join('/') + '/'; |
2888 var doc = this.document_; | 2895 var doc = this.document_; |
2889 | 2896 |
2890 for (var i = 0; i < pathNames.length; i++) { | 2897 for (var i = 0; i < pathNames.length; i++) { |
2891 var pathName = pathNames[i]; | 2898 var pathName = pathNames[i]; |
2892 path += pathName; | 2899 path += pathName; |
2893 | 2900 |
2894 var div = doc.createElement('div'); | 2901 var div = doc.createElement('div'); |
2895 | 2902 |
2896 div.className = 'breadcrumb-path'; | 2903 div.className = 'breadcrumb-path'; |
2897 div.textContent = i == 0 ? this.getRootLabel_(path) : pathName; | 2904 // We normally shouldn't be updating breadcrumbs for gdata search paths |
2905 // (we have to use getDisplayName for these paths), but we have to handle | |
2906 // the case when user explicitly navigates to | |
2907 // chrome://files/#/gdata/.search/foo. | |
2908 div.textContent = i == 0 ? this.getRootLabel_(path) : | |
2909 this.directoryModel_.getDisplayName(path, | |
2910 pathName); | |
2898 | 2911 |
2899 path = path + '/'; | 2912 path = path + '/'; |
2900 div.path = path; | 2913 div.path = path; |
2901 | 2914 |
2902 bc.appendChild(div); | 2915 bc.appendChild(div); |
2903 | 2916 |
2904 if (i == pathNames.length - 1) { | 2917 if (i == pathNames.length - 1 || |
2905 div.classList.add('breadcrumb-last'); | 2918 path == util.GDATA_SEARCH_ROOT_PATH + '/') { |
2919 div.classList.add('breadcrumb-non-clickable'); | |
2906 } else { | 2920 } else { |
2907 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); | 2921 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); |
2922 } | |
2908 | 2923 |
2924 if (i != pathNames.length - 1) { | |
2909 var spacer = doc.createElement('div'); | 2925 var spacer = doc.createElement('div'); |
2910 spacer.className = 'separator'; | 2926 spacer.className = 'separator'; |
2911 bc.appendChild(spacer); | 2927 bc.appendChild(spacer); |
2912 } | 2928 } |
2913 } | 2929 } |
2914 this.truncateBreadcrumbs_(); | 2930 this.truncateBreadcrumbs_(); |
2915 }; | 2931 }; |
2916 | 2932 |
2917 FileManager.prototype.isRenamingInProgress = function() { | 2933 FileManager.prototype.isRenamingInProgress = function() { |
2918 return !!this.renameInput_.currentEntry; | 2934 return !!this.renameInput_.currentEntry; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3055 FileManager.prototype.getCurrentDirectoryURL = function() { | 3071 FileManager.prototype.getCurrentDirectoryURL = function() { |
3056 return this.directoryModel_ && | 3072 return this.directoryModel_ && |
3057 this.directoryModel_.getCurrentDirEntry().toURL(); | 3073 this.directoryModel_.getCurrentDirEntry().toURL(); |
3058 }; | 3074 }; |
3059 | 3075 |
3060 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { | 3076 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { |
3061 if (!force) { | 3077 if (!force) { |
3062 var self = this; | 3078 var self = this; |
3063 var msg; | 3079 var msg; |
3064 if (entries.length == 1) { | 3080 if (entries.length == 1) { |
3065 msg = strf('CONFIRM_DELETE_ONE', entries[0].name); | 3081 var entryName = this.directoryModel_.getDisplayName(entries[0].fullPath, |
3082 entries[0].name); | |
3083 msg = strf('CONFIRM_DELETE_ONE', entryName); | |
3066 } else { | 3084 } else { |
3067 msg = strf('CONFIRM_DELETE_SOME', entries.length); | 3085 msg = strf('CONFIRM_DELETE_SOME', entries.length); |
3068 } | 3086 } |
3069 | 3087 |
3070 this.confirm.show(msg, this.deleteEntries.bind( | 3088 this.confirm.show(msg, this.deleteEntries.bind( |
3071 this, entries, true, opt_callback)); | 3089 this, entries, true, opt_callback)); |
3072 return; | 3090 return; |
3073 } | 3091 } |
3074 | 3092 |
3075 this.directoryModel_.deleteEntries(entries, opt_callback); | 3093 this.directoryModel_.deleteEntries(entries, opt_callback); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3334 } | 3352 } |
3335 if (!this.okButton_.disabled) { | 3353 if (!this.okButton_.disabled) { |
3336 this.onOk_(); | 3354 this.onOk_(); |
3337 return true; | 3355 return true; |
3338 } | 3356 } |
3339 return false; | 3357 return false; |
3340 }; | 3358 }; |
3341 | 3359 |
3342 FileManager.prototype.onDirectoryAction = function(entry) { | 3360 FileManager.prototype.onDirectoryAction = function(entry) { |
3343 var deviceNumber = this.getDeviceNumber(entry); | 3361 var deviceNumber = this.getDeviceNumber(entry); |
3362 // TODO(tbarzic): Is this still used? | |
SeRya
2012/05/10 08:44:16
It's obsolete code. Please remove it.
tbarzic
2012/05/10 23:28:02
Yeah, I though so, but wanted to check before I re
| |
3344 if (deviceNumber != undefined && | 3363 if (deviceNumber != undefined && |
3345 this.mountPoints_[deviceNumber].mountCondition == | 3364 this.mountPoints_[deviceNumber].mountCondition == |
3346 'unknown_filesystem') { | 3365 'unknown_filesystem') { |
3347 return this.showButter(str('UNKNOWN_FILESYSTEM_WARNING')); | 3366 return this.showButter(str('UNKNOWN_FILESYSTEM_WARNING')); |
3348 } else if (deviceNumber != undefined && | 3367 } else if (deviceNumber != undefined && |
3349 this.mountPoints_[deviceNumber].mountCondition == | 3368 this.mountPoints_[deviceNumber].mountCondition == |
3350 'unsupported_filesystem') { | 3369 'unsupported_filesystem') { |
3351 return this.showButter(str('UNSUPPORTED_FILESYSTEM_WARNING')); | 3370 return this.showButter(str('UNSUPPORTED_FILESYSTEM_WARNING')); |
3352 } else { | 3371 } else { |
3353 return this.directoryModel_.changeDirectory(entry.fullPath); | 3372 if (!util.isGDataSearchPath(entry.fullPath)) |
3373 return this.directoryModel_.changeDirectory(entry.fullPath); | |
3374 | |
3375 // If we are under gdata search path, the real entries file path may be | |
3376 // different from |entry.fullPath|. | |
3377 var self = this; | |
3378 chrome.fileBrowserPrivate.getPathForDriveSearchResult(entry.toURL(), | |
3379 function(path) { | |
3380 // |path| may be undefined if there was an error. | |
3381 var changeToPath = path || entry.fullPath; | |
3382 self.directoryModel_.changeDirectory(changeToPath); | |
3383 }); | |
3354 } | 3384 } |
3355 }; | 3385 }; |
3356 | 3386 |
3357 /** | 3387 /** |
3358 * Show or hide the "Low disk space" warning. | 3388 * Show or hide the "Low disk space" warning. |
3359 * @param {boolean} show True if the box need to be shown. | 3389 * @param {boolean} show True if the box need to be shown. |
3360 */ | 3390 */ |
3361 FileManager.prototype.showLowDiskSpaceWarning_ = function(show) { | 3391 FileManager.prototype.showLowDiskSpaceWarning_ = function(show) { |
3362 var box = this.dialogDom_.querySelector('.downloads-warning'); | 3392 var box = this.dialogDom_.querySelector('.downloads-warning'); |
3363 if (show) { | 3393 if (show) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3395 /** | 3425 /** |
3396 * Update the tab title. | 3426 * Update the tab title. |
3397 */ | 3427 */ |
3398 FileManager.prototype.updateTitle_ = function() { | 3428 FileManager.prototype.updateTitle_ = function() { |
3399 this.document_.title = this.getCurrentDirectory().substr(1).replace( | 3429 this.document_.title = this.getCurrentDirectory().substr(1).replace( |
3400 new RegExp('^' + DirectoryModel.GDATA_DIRECTORY), | 3430 new RegExp('^' + DirectoryModel.GDATA_DIRECTORY), |
3401 str('GDATA_PRODUCT_NAME')); | 3431 str('GDATA_PRODUCT_NAME')); |
3402 }, | 3432 }, |
3403 | 3433 |
3404 /** | 3434 /** |
3435 * Updates search box value if needed when directory gets changed. | |
3436 * @param {Entry} oldDirEntry Dir entry from which directory was changed. | |
3437 * @param {Entry} newDirEntry Dir entry to which directory was changed. | |
3438 */ | |
3439 FileManager.prototype.updateSearchBoxOnDirChange_ = | |
3440 function(oldDirEntry, newDirEntry) { | |
3441 if (this.directoryModel_.shouldClearSearch(oldDirEntry, newDirEntry)) | |
SeRya
2012/05/10 08:44:16
I think the search box should be cleared unconditi
tbarzic
2012/05/10 23:28:02
Yeah, I found that a bit strange too, but had deci
| |
3442 this.dialogDom_.querySelector('#search-box').value = ''; | |
3443 }, | |
3444 | |
3445 /** | |
3405 * Update the UI when the current directory changes. | 3446 * Update the UI when the current directory changes. |
3406 * | 3447 * |
3407 * @param {cr.Event} event The directory-changed event. | 3448 * @param {cr.Event} event The directory-changed event. |
3408 */ | 3449 */ |
3409 FileManager.prototype.onDirectoryChanged_ = function(event) { | 3450 FileManager.prototype.onDirectoryChanged_ = function(event) { |
3410 this.updateCommonActionButtons_(); | 3451 this.updateCommonActionButtons_(); |
3411 this.updateOkButton_(); | 3452 this.updateOkButton_(); |
3412 this.updateBreadcrumbs_(); | 3453 this.updateBreadcrumbs_(); |
3413 this.updateColumnModel_(); | 3454 this.updateColumnModel_(); |
3455 this.updateSearchBoxOnDirChange_(event.previousDirEntry, event.newDirEntry); | |
3414 | 3456 |
3415 // Sometimes we rescan the same directory (when mounting GData lazily first, | 3457 // Sometimes we rescan the same directory (when mounting GData lazily first, |
3416 // then for real). Do not update the location then. | 3458 // then for real). Do not update the location then. |
3417 if (event.newDirEntry.fullPath != event.previousDirEntry.fullPath) { | 3459 if (event.newDirEntry.fullPath != event.previousDirEntry.fullPath) { |
3418 this.updateLocation_(event.initial, event.newDirEntry.fullPath); | 3460 this.updateLocation_(event.initial, event.newDirEntry.fullPath); |
3419 } | 3461 } |
3420 | 3462 |
3421 this.checkFreeSpace_(this.getCurrentDirectory()); | 3463 this.checkFreeSpace_(this.getCurrentDirectory()); |
3422 | 3464 |
3423 this.updateTitle_(); | 3465 this.updateTitle_(); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3589 input.validation_ = false; | 3631 input.validation_ = false; |
3590 // Alert dialog restores focus unless the item removed from DOM. | 3632 // Alert dialog restores focus unless the item removed from DOM. |
3591 if (this.document_.activeElement != input) | 3633 if (this.document_.activeElement != input) |
3592 this.cancelRename_(); | 3634 this.cancelRename_(); |
3593 } | 3635 } |
3594 | 3636 |
3595 if (!this.validateFileName_(newName, validationDone.bind(this))) | 3637 if (!this.validateFileName_(newName, validationDone.bind(this))) |
3596 return; | 3638 return; |
3597 | 3639 |
3598 function onError(err) { | 3640 function onError(err) { |
3599 nameNode.textContent = entry.name; | 3641 var entryName = |
3600 this.alert.show(strf('ERROR_RENAMING', entry.name, | 3642 this.directoryModel_.getDisplayName(entry.fullPath, entry.name); |
3643 nameNode.textContent = entryName; | |
3644 this.alert.show(strf('ERROR_RENAMING', entryName, | |
3601 getFileErrorString(err.code))); | 3645 getFileErrorString(err.code))); |
3602 } | 3646 } |
3603 | 3647 |
3604 this.cancelRename_(); | 3648 this.cancelRename_(); |
3605 // Optimistically apply new name immediately to avoid flickering in | 3649 // Optimistically apply new name immediately to avoid flickering in |
3606 // case of success. | 3650 // case of success. |
3607 nameNode.textContent = newName; | 3651 nameNode.textContent = newName; |
3608 | 3652 |
3609 this.directoryModel_.doesExist(newName, function(exists, isFile) { | 3653 this.directoryModel_.doesExist(entry, newName, function(exists, isFile) { |
3610 if (!exists) { | 3654 if (!exists) { |
3611 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); | 3655 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); |
3612 } else { | 3656 } else { |
3613 nameNode.textContent = entry.name; | 3657 nameNode.textContent = |
3658 this.directoryModel_.getDisplayName(entry.fullPath, entry.name); | |
3614 var message = isFile ? 'FILE_ALREADY_EXISTS' : | 3659 var message = isFile ? 'FILE_ALREADY_EXISTS' : |
3615 'DIRECTORY_ALREADY_EXISTS'; | 3660 'DIRECTORY_ALREADY_EXISTS'; |
3616 this.alert.show(strf(message, newName)); | 3661 this.alert.show(strf(message, newName)); |
3617 } | 3662 } |
3618 }.bind(this)); | 3663 }.bind(this)); |
3619 }; | 3664 }; |
3620 | 3665 |
3621 FileManager.prototype.cancelRename_ = function() { | 3666 FileManager.prototype.cancelRename_ = function() { |
3622 this.renameInput_.currentEntry = null; | 3667 this.renameInput_.currentEntry = null; |
3623 | 3668 |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4289 | 4334 |
4290 if (oldValue) { | 4335 if (oldValue) { |
4291 event.target.removeAttribute('checked'); | 4336 event.target.removeAttribute('checked'); |
4292 } else { | 4337 } else { |
4293 event.target.setAttribute('checked', 'checked'); | 4338 event.target.setAttribute('checked', 'checked'); |
4294 } | 4339 } |
4295 }; | 4340 }; |
4296 | 4341 |
4297 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 4342 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
4298 var searchString = this.dialogDom_.querySelector('#search-box').value; | 4343 var searchString = this.dialogDom_.querySelector('#search-box').value; |
4299 if (searchString) { | 4344 this.directoryModel_.search(searchString); |
4300 this.directoryModel_.addFilter( | |
4301 'searchbox', | |
4302 function(e) { | |
4303 return e.name.substr(0, searchString.length) == searchString; | |
4304 }); | |
4305 } else { | |
4306 this.directoryModel_.removeFilter('searchbox'); | |
4307 } | |
4308 }; | 4345 }; |
4309 | 4346 |
4310 FileManager.prototype.decorateSplitter = function(splitterElement) { | 4347 FileManager.prototype.decorateSplitter = function(splitterElement) { |
4311 var self = this; | 4348 var self = this; |
4312 | 4349 |
4313 var Splitter = cr.ui.Splitter; | 4350 var Splitter = cr.ui.Splitter; |
4314 | 4351 |
4315 var customSplitter = cr.ui.define('div'); | 4352 var customSplitter = cr.ui.define('div'); |
4316 | 4353 |
4317 customSplitter.prototype = { | 4354 customSplitter.prototype = { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4431 | 4468 |
4432 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); | 4469 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); |
4433 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); | 4470 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); |
4434 | 4471 |
4435 var style = this.document_.createElement('link'); | 4472 var style = this.document_.createElement('link'); |
4436 style.rel = 'stylesheet'; | 4473 style.rel = 'stylesheet'; |
4437 style.href = 'css/gdrive_welcome.css'; | 4474 style.href = 'css/gdrive_welcome.css'; |
4438 this.document_.head.appendChild(style); | 4475 this.document_.head.appendChild(style); |
4439 }; | 4476 }; |
4440 })(); | 4477 })(); |
OLD | NEW |