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 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 = !this.directoryModel_.isSearching(); | |
| 1002 switch (commandId) { | 1003 switch (commandId) { |
| 1003 case 'copy': | 1004 case 'copy': |
| 1004 case 'cut': | 1005 case 'cut': |
| 1005 return this.document_.queryCommandEnabled(commandId); | 1006 return this.document_.queryCommandEnabled(commandId); |
| 1006 | 1007 |
| 1007 case 'paste': | 1008 case 'paste': |
| 1008 return !!this.fileTransferController_ && | 1009 return !!this.fileTransferController_ && |
| 1009 this.fileTransferController_.queryPasteCommandEnabled(); | 1010 this.fileTransferController_.queryPasteCommandEnabled() && |
| 1011 shouldCreate; | |
|
SeRya
2012/05/11 07:17:23
I recalled that canExecute_ only handles context m
tbarzic
2012/05/14 20:44:17
i have it in FilTransferManager.canPasteOrDrop_
| |
| 1010 | 1012 |
| 1011 case 'rename': | 1013 case 'rename': |
| 1012 return (// Initialized to the point where we have a current directory | 1014 return (// Initialized to the point where we have a current directory |
| 1013 !readonly && | 1015 !readonly && |
| 1014 // Rename not in progress. | 1016 // Rename not in progress. |
| 1015 !this.isRenamingInProgress() && | 1017 !this.isRenamingInProgress() && |
| 1016 // Only one file selected. | 1018 // Only one file selected. |
| 1017 this.selection && | 1019 this.selection && |
| 1018 this.selection.totalCount == 1); | 1020 this.selection.totalCount == 1); |
| 1019 | 1021 |
| 1020 case 'delete': | 1022 case 'delete': |
| 1021 return (// Initialized to the point where we have a current directory | 1023 return (// Initialized to the point where we have a current directory |
| 1022 !readonly && | 1024 !readonly && |
| 1023 // Rename not in progress. | 1025 // Rename not in progress. |
| 1024 !this.isRenamingInProgress() && | 1026 !this.isRenamingInProgress() && |
| 1025 this.selection && | 1027 this.selection && |
| 1026 this.selection.totalCount > 0); | 1028 this.selection.totalCount > 0); |
| 1027 | 1029 |
| 1028 case 'newfolder': | 1030 case 'newfolder': |
| 1029 return !readonly && | 1031 return !readonly && |
| 1032 shouldCreate && | |
| 1030 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || | 1033 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || |
| 1031 this.dialogType_ == FileManager.DialogType.FULL_PAGE); | 1034 this.dialogType_ == FileManager.DialogType.FULL_PAGE); |
| 1032 | 1035 |
| 1033 case 'unmount': | 1036 case 'unmount': |
| 1034 return true; | 1037 return true; |
| 1035 | 1038 |
| 1036 case 'format': | 1039 case 'format': |
| 1037 var entry = this.directoryModel_.getCurrentRootDirEntry(); | 1040 var entry = this.directoryModel_.getCurrentRootDirEntry(); |
| 1038 | 1041 |
| 1039 return entry && DirectoryModel.getRootType(entry.fullPath) == | 1042 return entry && DirectoryModel.getRootType(entry.fullPath) == |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1272 } | 1275 } |
| 1273 } | 1276 } |
| 1274 }; | 1277 }; |
| 1275 | 1278 |
| 1276 /** | 1279 /** |
| 1277 * Handler of file manager operations. Update directory model | 1280 * Handler of file manager operations. Update directory model |
| 1278 * to reflect operation result iimediatelly (not waiting directory | 1281 * to reflect operation result iimediatelly (not waiting directory |
| 1279 * update event). | 1282 * update event). |
| 1280 */ | 1283 */ |
| 1281 FileManager.prototype.onCopyManagerOperationComplete_ = function(event) { | 1284 FileManager.prototype.onCopyManagerOperationComplete_ = function(event) { |
| 1282 var currentPath = this.directoryModel_.getCurrentDirEntry().fullPath; | 1285 var currentPath = |
| 1286 this.directoryModel_.getSearchOrCurrentDirEntry().fullPath; | |
|
SeRya
2012/05/11 07:17:23
We gonna prevent paste and drop operation into sea
tbarzic
2012/05/14 20:44:17
yeah, I agree
SeRya
2012/05/15 06:17:01
So please replece with this.directoryModel_.getCur
| |
| 1283 function inCurrentDirectory(entry) { | 1287 function inCurrentDirectory(entry) { |
| 1284 var fullPath = entry.fullPath; | 1288 var fullPath = entry.fullPath; |
| 1285 var dirPath = fullPath.substr(0, fullPath.length - | 1289 var dirPath = fullPath.substr(0, fullPath.length - |
| 1286 entry.name.length - 1); | 1290 entry.name.length - 1); |
| 1287 return dirPath == currentPath; | 1291 return dirPath == currentPath; |
| 1288 } | 1292 } |
| 1289 for (var i = 0; i < event.affectedEntries.length; i++) { | 1293 for (var i = 0; i < event.affectedEntries.length; i++) { |
| 1290 entry = event.affectedEntries[i]; | 1294 entry = event.affectedEntries[i]; |
| 1291 if (inCurrentDirectory(entry)) | 1295 if (inCurrentDirectory(entry)) |
| 1292 this.directoryModel_.onEntryChanged(entry.name); | 1296 this.directoryModel_.onEntryChanged(entry.name); |
| (...skipping 563 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_.getSearchOrCurrentDirEntry().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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2809 // in the ribbon. | 2816 // in the ribbon. |
| 2810 // We do not do that if a single video is selected because the UI is | 2817 // We do not do that if a single video is selected because the UI is |
| 2811 // cleaner without the ribbon. | 2818 // cleaner without the ribbon. |
| 2812 urls = this.getAllUrlsInCurrentDirectory_().filter( | 2819 urls = this.getAllUrlsInCurrentDirectory_().filter( |
| 2813 FileType.isImageOrVideo); | 2820 FileType.isImageOrVideo); |
| 2814 } else { | 2821 } else { |
| 2815 // Pass just the selected items, select the first entry. | 2822 // Pass just the selected items, select the first entry. |
| 2816 selectedUrl = urls[0]; | 2823 selectedUrl = urls[0]; |
| 2817 } | 2824 } |
| 2818 | 2825 |
| 2819 var dirPath = this.directoryModel_.getCurrentDirEntry().fullPath; | 2826 var dirPath = this.directoryModel_.getSearchOrCurrentDirEntry().fullPath; |
|
SeRya
2012/05/11 07:17:23
It should be getCurrentDirPath(). I think the gall
tbarzic
2012/05/14 20:44:17
Done.
| |
| 2820 | 2827 |
| 2821 // Push a temporary state which will be replaced every time an individual | 2828 // Push a temporary state which will be replaced every time an individual |
| 2822 // item is selected in the Gallery. | 2829 // item is selected in the Gallery. |
| 2823 this.updateLocation_(false /*push*/, dirPath); | 2830 this.updateLocation_(false /*push*/, dirPath); |
| 2824 | 2831 |
| 2825 galleryFrame.onload = function() { | 2832 galleryFrame.onload = function() { |
| 2826 galleryFrame.contentWindow.ImageUtil.metrics = metrics; | 2833 galleryFrame.contentWindow.ImageUtil.metrics = metrics; |
| 2827 galleryFrame.contentWindow.FileType = FileType; | 2834 galleryFrame.contentWindow.FileType = FileType; |
| 2828 galleryFrame.contentWindow.util = util; | 2835 galleryFrame.contentWindow.util = util; |
| 2829 | 2836 |
| 2830 // Gallery shoud treat GData folder as readonly even when online | 2837 // Gallery shoud treat GData folder as readonly even when online |
| 2831 // until we learn to save files directly to GData. | 2838 // until we learn to save files directly to GData. |
| 2832 var readonly = self.isOnReadonlyDirectory() || self.isOnGData(); | 2839 var readonly = self.isOnReadonlyDirectory() || self.isOnGData(); |
| 2833 var currentDir = self.directoryModel_.getCurrentDirEntry(); | 2840 var currentDir = self.directoryModel_.getSearchOrCurrentDirEntry(); |
| 2834 var downloadsDir = self.directoryModel_.getRootsList().item(0); | 2841 var downloadsDir = self.directoryModel_.getRootsList().item(0); |
| 2835 | 2842 |
| 2836 var gallerySelection; | 2843 var gallerySelection; |
| 2837 var context = { | 2844 var context = { |
| 2838 // We show the root label in readonly warning (e.g. archive name). | 2845 // We show the root label in readonly warning (e.g. archive name). |
| 2839 readonlyDirName: | 2846 readonlyDirName: |
|
SeRya
2012/05/11 07:17:23
By the way, it's unlikely renaming in the gallery
tbarzic
2012/05/14 20:44:17
gallery is already readonly on gdata, but yes file
| |
| 2840 readonly ? | 2847 readonly ? |
| 2841 (self.isOnGData() ? | 2848 (self.isOnGData() ? |
| 2842 self.getRootLabel_( | 2849 self.getRootLabel_( |
| 2843 DirectoryModel.getRootPath(currentDir.fullPath)) : | 2850 DirectoryModel.getRootPath(currentDir.fullPath)) : |
| 2844 self.directoryModel_.getRootName()) : | 2851 self.directoryModel_.getRootName()) : |
| 2845 null, | 2852 null, |
| 2846 saveDirEntry: readonly ? downloadsDir : currentDir, | 2853 saveDirEntry: readonly ? downloadsDir : currentDir, |
| 2847 metadataProvider: self.getMetadataProvider(), | 2854 metadataProvider: self.getMetadataProvider(), |
| 2848 getShareActions: self.getShareActions_.bind(self), | 2855 getShareActions: self.getShareActions_.bind(self), |
| 2849 onNameChange: function(name) { | 2856 onNameChange: function(name) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2898 | 2905 |
| 2899 path = path + '/'; | 2906 path = path + '/'; |
| 2900 div.path = path; | 2907 div.path = path; |
| 2901 | 2908 |
| 2902 bc.appendChild(div); | 2909 bc.appendChild(div); |
| 2903 | 2910 |
| 2904 if (i == pathNames.length - 1) { | 2911 if (i == pathNames.length - 1) { |
| 2905 div.classList.add('breadcrumb-last'); | 2912 div.classList.add('breadcrumb-last'); |
| 2906 } else { | 2913 } else { |
| 2907 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); | 2914 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); |
| 2908 | |
| 2909 var spacer = doc.createElement('div'); | 2915 var spacer = doc.createElement('div'); |
| 2910 spacer.className = 'separator'; | 2916 spacer.className = 'separator'; |
| 2911 bc.appendChild(spacer); | 2917 bc.appendChild(spacer); |
| 2912 } | 2918 } |
| 2913 } | 2919 } |
| 2914 this.truncateBreadcrumbs_(); | 2920 this.truncateBreadcrumbs_(); |
| 2915 }; | 2921 }; |
| 2916 | 2922 |
| 2917 FileManager.prototype.isRenamingInProgress = function() { | 2923 FileManager.prototype.isRenamingInProgress = function() { |
| 2918 return !!this.renameInput_.currentEntry; | 2924 return !!this.renameInput_.currentEntry; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3050 }; | 3056 }; |
| 3051 | 3057 |
| 3052 /** | 3058 /** |
| 3053 * Return URL of the current directory or null. | 3059 * Return URL of the current directory or null. |
| 3054 */ | 3060 */ |
| 3055 FileManager.prototype.getCurrentDirectoryURL = function() { | 3061 FileManager.prototype.getCurrentDirectoryURL = function() { |
| 3056 return this.directoryModel_ && | 3062 return this.directoryModel_ && |
| 3057 this.directoryModel_.getCurrentDirEntry().toURL(); | 3063 this.directoryModel_.getCurrentDirEntry().toURL(); |
| 3058 }; | 3064 }; |
| 3059 | 3065 |
| 3066 /** | |
| 3067 * Return URL of the search directory, current directory or null. | |
| 3068 */ | |
| 3069 FileManager.prototype.getSearchOrCurrentDirectoryURL = function() { | |
| 3070 return this.directoryModel_ && | |
| 3071 this.directoryModel_.getSearchOrCurrentDirEntry().toURL(); | |
| 3072 }; | |
| 3073 | |
| 3060 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { | 3074 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { |
| 3061 if (!force) { | 3075 if (!force) { |
| 3062 var self = this; | 3076 var self = this; |
| 3063 var msg; | 3077 var msg; |
| 3064 if (entries.length == 1) { | 3078 if (entries.length == 1) { |
| 3065 msg = strf('CONFIRM_DELETE_ONE', entries[0].name); | 3079 var entryName = this.directoryModel_.getDisplayName(entries[0].fullPath, |
| 3080 entries[0].name); | |
| 3081 msg = strf('CONFIRM_DELETE_ONE', entryName); | |
| 3066 } else { | 3082 } else { |
| 3067 msg = strf('CONFIRM_DELETE_SOME', entries.length); | 3083 msg = strf('CONFIRM_DELETE_SOME', entries.length); |
| 3068 } | 3084 } |
| 3069 | 3085 |
| 3070 this.confirm.show(msg, this.deleteEntries.bind( | 3086 this.confirm.show(msg, this.deleteEntries.bind( |
| 3071 this, entries, true, opt_callback)); | 3087 this, entries, true, opt_callback)); |
| 3072 return; | 3088 return; |
| 3073 } | 3089 } |
| 3074 | 3090 |
| 3075 this.directoryModel_.deleteEntries(entries, opt_callback); | 3091 this.directoryModel_.deleteEntries(entries, opt_callback); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3280 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 3296 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
| 3281 selectable = (this.isSelectionAvailable() && | 3297 selectable = (this.isSelectionAvailable() && |
| 3282 this.selection.directoryCount == 0 && | 3298 this.selection.directoryCount == 0 && |
| 3283 this.selection.fileCount == 1); | 3299 this.selection.fileCount == 1); |
| 3284 } else if (this.dialogType_ == | 3300 } else if (this.dialogType_ == |
| 3285 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 3301 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
| 3286 selectable = (this.isSelectionAvailable() && | 3302 selectable = (this.isSelectionAvailable() && |
| 3287 this.selection.directoryCount == 0 && | 3303 this.selection.directoryCount == 0 && |
| 3288 this.selection.fileCount >= 1); | 3304 this.selection.fileCount >= 1); |
| 3289 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 3305 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
| 3290 if (this.isOnReadonlyDirectory()) { | 3306 if (this.isOnReadonlyDirectory() || |
| 3307 (this.isOnGData() && this.directoryModel_.isSearching())) { | |
| 3291 selectable = false; | 3308 selectable = false; |
| 3292 } else { | 3309 } else { |
| 3293 selectable = !!this.filenameInput_.value; | 3310 selectable = !!this.filenameInput_.value; |
| 3294 } | 3311 } |
| 3295 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 3312 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
| 3296 // No "select" buttons on the full page UI. | 3313 // No "select" buttons on the full page UI. |
| 3297 selectable = true; | 3314 selectable = true; |
| 3298 } else { | 3315 } else { |
| 3299 throw new Error('Unknown dialog type'); | 3316 throw new Error('Unknown dialog type'); |
| 3300 } | 3317 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3332 this.dispatchDefaultTask_(); | 3349 this.dispatchDefaultTask_(); |
| 3333 return true; | 3350 return true; |
| 3334 } | 3351 } |
| 3335 if (!this.okButton_.disabled) { | 3352 if (!this.okButton_.disabled) { |
| 3336 this.onOk_(); | 3353 this.onOk_(); |
| 3337 return true; | 3354 return true; |
| 3338 } | 3355 } |
| 3339 return false; | 3356 return false; |
| 3340 }; | 3357 }; |
| 3341 | 3358 |
| 3359 /** | |
| 3360 * Executes directory action (i.e. changes directory). If new directory is a | |
| 3361 * search result directory, we'll have to calculate its real path before we | |
| 3362 * actually do the operation. | |
| 3363 * | |
| 3364 * @param {DirectoryEntry} entry Directory entry to which directory should be | |
| 3365 * changed. | |
| 3366 */ | |
| 3342 FileManager.prototype.onDirectoryAction = function(entry) { | 3367 FileManager.prototype.onDirectoryAction = function(entry) { |
| 3343 var deviceNumber = this.getDeviceNumber(entry); | 3368 if (!DirectoryModel.isGDataSearchPath(entry.fullPath)) |
| 3344 if (deviceNumber != undefined && | |
| 3345 this.mountPoints_[deviceNumber].mountCondition == | |
| 3346 'unknown_filesystem') { | |
| 3347 return this.showButter(str('UNKNOWN_FILESYSTEM_WARNING')); | |
| 3348 } else if (deviceNumber != undefined && | |
| 3349 this.mountPoints_[deviceNumber].mountCondition == | |
| 3350 'unsupported_filesystem') { | |
| 3351 return this.showButter(str('UNSUPPORTED_FILESYSTEM_WARNING')); | |
| 3352 } else { | |
| 3353 return this.directoryModel_.changeDirectory(entry.fullPath); | 3369 return this.directoryModel_.changeDirectory(entry.fullPath); |
| 3354 } | 3370 |
| 3371 // If we are under gdata search path, the real entries file path may be | |
| 3372 // different from |entry.fullPath|. | |
| 3373 var self = this; | |
| 3374 chrome.fileBrowserPrivate.getPathForDriveSearchResult(entry.toURL(), | |
| 3375 function(path) { | |
| 3376 // |path| may be undefined if there was an error. If that is the case, | |
| 3377 // change to the original file path. | |
| 3378 var changeToPath = path || entry.fullPath; | |
| 3379 self.directoryModel_.changeDirectory(changeToPath); | |
| 3380 }); | |
| 3355 }; | 3381 }; |
| 3356 | 3382 |
| 3357 /** | 3383 /** |
| 3358 * Show or hide the "Low disk space" warning. | 3384 * Show or hide the "Low disk space" warning. |
| 3359 * @param {boolean} show True if the box need to be shown. | 3385 * @param {boolean} show True if the box need to be shown. |
| 3360 */ | 3386 */ |
| 3361 FileManager.prototype.showLowDiskSpaceWarning_ = function(show) { | 3387 FileManager.prototype.showLowDiskSpaceWarning_ = function(show) { |
| 3362 var box = this.dialogDom_.querySelector('.downloads-warning'); | 3388 var box = this.dialogDom_.querySelector('.downloads-warning'); |
| 3363 if (show) { | 3389 if (show) { |
| 3364 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); | 3390 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 3395 /** | 3421 /** |
| 3396 * Update the tab title. | 3422 * Update the tab title. |
| 3397 */ | 3423 */ |
| 3398 FileManager.prototype.updateTitle_ = function() { | 3424 FileManager.prototype.updateTitle_ = function() { |
| 3399 this.document_.title = this.getCurrentDirectory().substr(1).replace( | 3425 this.document_.title = this.getCurrentDirectory().substr(1).replace( |
| 3400 new RegExp('^' + DirectoryModel.GDATA_DIRECTORY), | 3426 new RegExp('^' + DirectoryModel.GDATA_DIRECTORY), |
| 3401 str('GDATA_PRODUCT_NAME')); | 3427 str('GDATA_PRODUCT_NAME')); |
| 3402 }, | 3428 }, |
| 3403 | 3429 |
| 3404 /** | 3430 /** |
| 3431 * Updates search box value when directory gets changed. | |
| 3432 */ | |
| 3433 FileManager.prototype.updateSearchBoxOnDirChange_ = function() { | |
| 3434 this.dialogDom_.querySelector('#search-box').value = ''; | |
| 3435 }, | |
| 3436 | |
| 3437 /** | |
| 3405 * Update the UI when the current directory changes. | 3438 * Update the UI when the current directory changes. |
| 3406 * | 3439 * |
| 3407 * @param {cr.Event} event The directory-changed event. | 3440 * @param {cr.Event} event The directory-changed event. |
| 3408 */ | 3441 */ |
| 3409 FileManager.prototype.onDirectoryChanged_ = function(event) { | 3442 FileManager.prototype.onDirectoryChanged_ = function(event) { |
| 3410 this.updateCommonActionButtons_(); | 3443 this.updateCommonActionButtons_(); |
| 3411 this.updateOkButton_(); | 3444 this.updateOkButton_(); |
| 3412 this.updateBreadcrumbs_(); | 3445 this.updateBreadcrumbs_(); |
| 3413 this.updateColumnModel_(); | 3446 this.updateColumnModel_(); |
| 3447 this.updateSearchBoxOnDirChange_(); | |
| 3414 | 3448 |
| 3415 // Sometimes we rescan the same directory (when mounting GData lazily first, | 3449 // Sometimes we rescan the same directory (when mounting GData lazily first, |
| 3416 // then for real). Do not update the location then. | 3450 // then for real). Do not update the location then. |
| 3417 if (event.newDirEntry.fullPath != event.previousDirEntry.fullPath) { | 3451 if (event.newDirEntry.fullPath != event.previousDirEntry.fullPath) { |
| 3418 this.updateLocation_(event.initial, event.newDirEntry.fullPath); | 3452 this.updateLocation_(event.initial, event.newDirEntry.fullPath); |
| 3419 } | 3453 } |
| 3420 | 3454 |
| 3421 this.checkFreeSpace_(this.getCurrentDirectory()); | 3455 this.checkFreeSpace_(this.getCurrentDirectory()); |
| 3422 | 3456 |
| 3423 this.updateTitle_(); | 3457 this.updateTitle_(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3509 if (!result) { | 3543 if (!result) { |
| 3510 console.log('Failed to remove file watch'); | 3544 console.log('Failed to remove file watch'); |
| 3511 } | 3545 } |
| 3512 }); | 3546 }); |
| 3513 this.watchedDirectoryUrl_ = null; | 3547 this.watchedDirectoryUrl_ = null; |
| 3514 } | 3548 } |
| 3515 }; | 3549 }; |
| 3516 | 3550 |
| 3517 FileManager.prototype.onFileChanged_ = function(event) { | 3551 FileManager.prototype.onFileChanged_ = function(event) { |
| 3518 // We receive a lot of events even in folders we are not interested in. | 3552 // We receive a lot of events even in folders we are not interested in. |
| 3519 if (encodeURI(event.fileUrl) == this.getCurrentDirectoryURL()) | 3553 if (encodeURI(event.fileUrl) == this.getSearchOrCurrentDirectoryURL()) |
|
SeRya
2012/05/11 07:17:23
Are you sure event.fileUrl may ever point to "/gda
tbarzic
2012/05/14 20:44:17
Done.
| |
| 3520 this.directoryModel_.rescanLater(); | 3554 this.directoryModel_.rescanLater(); |
| 3521 }; | 3555 }; |
| 3522 | 3556 |
| 3523 FileManager.prototype.initiateRename_ = function() { | 3557 FileManager.prototype.initiateRename_ = function() { |
| 3524 var item = this.currentList_.ensureLeadItemExists(); | 3558 var item = this.currentList_.ensureLeadItemExists(); |
| 3525 if (!item) | 3559 if (!item) |
| 3526 return; | 3560 return; |
| 3527 var label = item.querySelector('.filename-label'); | 3561 var label = item.querySelector('.filename-label'); |
| 3528 var input = this.renameInput_; | 3562 var input = this.renameInput_; |
| 3529 | 3563 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3589 input.validation_ = false; | 3623 input.validation_ = false; |
| 3590 // Alert dialog restores focus unless the item removed from DOM. | 3624 // Alert dialog restores focus unless the item removed from DOM. |
| 3591 if (this.document_.activeElement != input) | 3625 if (this.document_.activeElement != input) |
| 3592 this.cancelRename_(); | 3626 this.cancelRename_(); |
| 3593 } | 3627 } |
| 3594 | 3628 |
| 3595 if (!this.validateFileName_(newName, validationDone.bind(this))) | 3629 if (!this.validateFileName_(newName, validationDone.bind(this))) |
| 3596 return; | 3630 return; |
| 3597 | 3631 |
| 3598 function onError(err) { | 3632 function onError(err) { |
| 3599 nameNode.textContent = entry.name; | 3633 var entryName = |
| 3600 this.alert.show(strf('ERROR_RENAMING', entry.name, | 3634 this.directoryModel_.getDisplayName(entry.fullPath, entry.name); |
| 3635 nameNode.textContent = entryName; | |
| 3636 this.alert.show(strf('ERROR_RENAMING', entryName, | |
| 3601 getFileErrorString(err.code))); | 3637 getFileErrorString(err.code))); |
| 3602 } | 3638 } |
| 3603 | 3639 |
| 3604 this.cancelRename_(); | 3640 this.cancelRename_(); |
| 3605 // Optimistically apply new name immediately to avoid flickering in | 3641 // Optimistically apply new name immediately to avoid flickering in |
| 3606 // case of success. | 3642 // case of success. |
| 3607 nameNode.textContent = newName; | 3643 nameNode.textContent = newName; |
| 3608 | 3644 |
| 3609 this.directoryModel_.doesExist(newName, function(exists, isFile) { | 3645 this.directoryModel_.doesExist(entry, newName, function(exists, isFile) { |
| 3610 if (!exists) { | 3646 if (!exists) { |
| 3611 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); | 3647 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); |
| 3612 } else { | 3648 } else { |
| 3613 nameNode.textContent = entry.name; | 3649 nameNode.textContent = |
| 3650 this.directoryModel_.getDisplayName(entry.fullPath, entry.name); | |
| 3614 var message = isFile ? 'FILE_ALREADY_EXISTS' : | 3651 var message = isFile ? 'FILE_ALREADY_EXISTS' : |
| 3615 'DIRECTORY_ALREADY_EXISTS'; | 3652 'DIRECTORY_ALREADY_EXISTS'; |
| 3616 this.alert.show(strf(message, newName)); | 3653 this.alert.show(strf(message, newName)); |
| 3617 } | 3654 } |
| 3618 }.bind(this)); | 3655 }.bind(this)); |
| 3619 }; | 3656 }; |
| 3620 | 3657 |
| 3621 FileManager.prototype.cancelRename_ = function() { | 3658 FileManager.prototype.cancelRename_ = function() { |
| 3622 this.renameInput_.currentEntry = null; | 3659 this.renameInput_.currentEntry = null; |
| 3623 | 3660 |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4081 | 4118 |
| 4082 /** | 4119 /** |
| 4083 * Handle a click of the ok button. | 4120 * Handle a click of the ok button. |
| 4084 * | 4121 * |
| 4085 * The ok button has different UI labels depending on the type of dialog, but | 4122 * The ok button has different UI labels depending on the type of dialog, but |
| 4086 * in code it's always referred to as 'ok'. | 4123 * in code it's always referred to as 'ok'. |
| 4087 * | 4124 * |
| 4088 * @param {Event} event The click event. | 4125 * @param {Event} event The click event. |
| 4089 */ | 4126 */ |
| 4090 FileManager.prototype.onOk_ = function(event) { | 4127 FileManager.prototype.onOk_ = function(event) { |
| 4091 var currentDirUrl = this.getCurrentDirectoryURL(); | 4128 var currentDirUrl = this.getSearchOrCurrentDirectoryURL(); |
| 4092 | 4129 |
| 4093 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') | 4130 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') |
| 4094 currentDirUrl += '/'; | 4131 currentDirUrl += '/'; |
| 4095 | 4132 |
| 4096 var self = this; | 4133 var self = this; |
| 4097 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 4134 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
| 4098 // Save-as doesn't require a valid selection from the list, since | 4135 // Save-as doesn't require a valid selection from the list, since |
| 4099 // we're going to take the filename from the text input. | 4136 // we're going to take the filename from the text input. |
| 4100 var filename = this.filenameInput_.value; | 4137 var filename = this.filenameInput_.value; |
| 4101 if (!filename) | 4138 if (!filename) |
| 4102 throw new Error('Missing filename!'); | 4139 throw new Error('Missing filename!'); |
| 4103 if (!this.validateFileName_(filename)) | 4140 if (!this.validateFileName_(filename)) |
| 4104 return; | 4141 return; |
| 4105 | 4142 |
| 4106 var singleSelection = { | 4143 var singleSelection = { |
| 4107 urls: [currentDirUrl + encodeURIComponent(filename)], | 4144 urls: [currentDirUrl + encodeURIComponent(filename)], |
|
SeRya
2012/05/11 07:17:23
It's gonna construct URL like filesystem://.../gda
tbarzic
2012/05/14 20:44:17
we shouldn't get here in save-as dialog
| |
| 4108 multiple: false, | 4145 multiple: false, |
| 4109 filterIndex: self.getSelectedFilterIndex_(filename) | 4146 filterIndex: self.getSelectedFilterIndex_(filename) |
| 4110 }; | 4147 }; |
| 4111 | 4148 |
| 4112 function resolveCallback(victim) { | 4149 function resolveCallback(victim) { |
| 4113 if (victim instanceof FileError) { | 4150 if (victim instanceof FileError) { |
| 4114 // File does not exist. | 4151 // File does not exist. |
| 4115 self.selectFilesAndClose_(singleSelection); | 4152 self.selectFilesAndClose_(singleSelection); |
| 4116 return; | 4153 return; |
| 4117 } | 4154 } |
| 4118 | 4155 |
| 4119 if (victim.isDirectory) { | 4156 if (victim.isDirectory) { |
| 4120 // Do not allow to overwrite directory. | 4157 // Do not allow to overwrite directory. |
| 4121 self.alert.show(strf('DIRECTORY_ALREADY_EXISTS', filename)); | 4158 self.alert.show(strf('DIRECTORY_ALREADY_EXISTS', filename)); |
| 4122 } else { | 4159 } else { |
| 4123 self.confirm.show(strf('CONFIRM_OVERWRITE_FILE', filename), | 4160 self.confirm.show(strf('CONFIRM_OVERWRITE_FILE', filename), |
| 4124 function() { | 4161 function() { |
| 4125 // User selected Ok from the confirm dialog. | 4162 // User selected Ok from the confirm dialog. |
| 4126 self.selectFilesAndClose_(singleSelection); | 4163 self.selectFilesAndClose_(singleSelection); |
| 4127 }); | 4164 }); |
| 4128 } | 4165 } |
| 4129 } | 4166 } |
| 4130 | 4167 |
| 4131 this.resolvePath(this.getCurrentDirectory() + '/' + filename, | 4168 this.resolvePath(this.getCurrentDirectory() + '/' + filename, |
|
SeRya
2012/05/11 07:17:23
I don't think it makes sense to check file existen
tbarzic
2012/05/14 20:44:17
grr..I had left you a comment here, but forgot to
| |
| 4132 resolveCallback, resolveCallback); | 4169 resolveCallback, resolveCallback); |
| 4133 return; | 4170 return; |
| 4134 } | 4171 } |
| 4135 | 4172 |
| 4136 var files = []; | 4173 var files = []; |
| 4137 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; | 4174 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; |
| 4138 | 4175 |
| 4139 // All other dialog types require at least one selected list item. | 4176 // All other dialog types require at least one selected list item. |
| 4140 // The logic to control whether or not the ok button is enabled should | 4177 // The logic to control whether or not the ok button is enabled should |
| 4141 // prevent us from ever getting here, but we sanity check to be sure. | 4178 // prevent us from ever getting here, but we sanity check to be sure. |
| 4142 if (!selectedIndexes.length) | 4179 if (!selectedIndexes.length) |
| 4143 throw new Error('Nothing selected!'); | 4180 throw new Error('Nothing selected!'); |
| 4144 | 4181 |
| 4145 var dm = this.directoryModel_.getFileList(); | 4182 var dm = this.directoryModel_.getFileList(); |
| 4146 for (var i = 0; i < selectedIndexes.length; i++) { | 4183 for (var i = 0; i < selectedIndexes.length; i++) { |
| 4147 var entry = dm.item(selectedIndexes[i]); | 4184 var entry = dm.item(selectedIndexes[i]); |
| 4148 if (!entry) { | 4185 if (!entry) { |
| 4149 console.log('Error locating selected file at index: ' + i); | 4186 console.log('Error locating selected file at index: ' + i); |
| 4150 continue; | 4187 continue; |
| 4151 } | 4188 } |
| 4152 | 4189 |
| 4153 files.push(currentDirUrl + encodeURIComponent(entry.name)); | 4190 files.push(currentDirUrl + encodeURIComponent(entry.name)); |
|
SeRya
2012/05/11 07:17:23
May be just entry.toURL()? Is it OK to not resolve
tbarzic
2012/05/14 20:44:17
I don't think it's "necessary", but it would proba
tbarzic
2012/05/14 20:44:17
Done.
| |
| 4154 } | 4191 } |
| 4155 | 4192 |
| 4156 // Multi-file selection has no other restrictions. | 4193 // Multi-file selection has no other restrictions. |
| 4157 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 4194 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
| 4158 var multipleSelection = { | 4195 var multipleSelection = { |
| 4159 urls: files, | 4196 urls: files, |
| 4160 multiple: true | 4197 multiple: true |
| 4161 }; | 4198 }; |
| 4162 this.selectFilesAndClose_(multipleSelection); | 4199 this.selectFilesAndClose_(multipleSelection); |
| 4163 return; | 4200 return; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4289 | 4326 |
| 4290 if (oldValue) { | 4327 if (oldValue) { |
| 4291 event.target.removeAttribute('checked'); | 4328 event.target.removeAttribute('checked'); |
| 4292 } else { | 4329 } else { |
| 4293 event.target.setAttribute('checked', 'checked'); | 4330 event.target.setAttribute('checked', 'checked'); |
| 4294 } | 4331 } |
| 4295 }; | 4332 }; |
| 4296 | 4333 |
| 4297 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 4334 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
| 4298 var searchString = this.dialogDom_.querySelector('#search-box').value; | 4335 var searchString = this.dialogDom_.querySelector('#search-box').value; |
| 4299 if (searchString) { | 4336 this.directoryModel_.search(searchString); |
| 4300 this.directoryModel_.addFilter( | 4337 this.updateOkButton_(); |
| 4301 'searchbox', | |
| 4302 function(e) { | |
| 4303 return e.name.substr(0, searchString.length) == searchString; | |
| 4304 }); | |
| 4305 } else { | |
| 4306 this.directoryModel_.removeFilter('searchbox'); | |
| 4307 } | |
| 4308 }; | 4338 }; |
| 4309 | 4339 |
| 4310 FileManager.prototype.decorateSplitter = function(splitterElement) { | 4340 FileManager.prototype.decorateSplitter = function(splitterElement) { |
| 4311 var self = this; | 4341 var self = this; |
| 4312 | 4342 |
| 4313 var Splitter = cr.ui.Splitter; | 4343 var Splitter = cr.ui.Splitter; |
| 4314 | 4344 |
| 4315 var customSplitter = cr.ui.define('div'); | 4345 var customSplitter = cr.ui.define('div'); |
| 4316 | 4346 |
| 4317 customSplitter.prototype = { | 4347 customSplitter.prototype = { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4431 | 4461 |
| 4432 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); | 4462 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); |
| 4433 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); | 4463 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); |
| 4434 | 4464 |
| 4435 var style = this.document_.createElement('link'); | 4465 var style = this.document_.createElement('link'); |
| 4436 style.rel = 'stylesheet'; | 4466 style.rel = 'stylesheet'; |
| 4437 style.href = 'css/gdrive_welcome.css'; | 4467 style.href = 'css/gdrive_welcome.css'; |
| 4438 this.document_.head.appendChild(style); | 4468 this.document_.head.appendChild(style); |
| 4439 }; | 4469 }; |
| 4440 })(); | 4470 })(); |
| OLD | NEW |