Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 10342010: Add gdata content search to file_manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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/15 06:17:01 Please remove this change. queryPasteCommandEnable
tbarzic 2012/05/16 03:50:04 Done.
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
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/15 06:17:01 Please use getCurrentDirPath() here. Add if (this
tbarzic 2012/05/16 03:50:04 done. additionally, updating search results for no
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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 defaultTitle = str('SELECT_OPEN_FILE_TITLE'); 1514 defaultTitle = str('SELECT_OPEN_FILE_TITLE');
1511 break; 1515 break;
1512 1516
1513 case FileManager.DialogType.SELECT_OPEN_MULTI_FILE: 1517 case FileManager.DialogType.SELECT_OPEN_MULTI_FILE:
1514 defaultTitle = str('SELECT_OPEN_MULTI_FILE_TITLE'); 1518 defaultTitle = str('SELECT_OPEN_MULTI_FILE_TITLE');
1515 break; 1519 break;
1516 1520
1517 case FileManager.DialogType.SELECT_SAVEAS_FILE: 1521 case FileManager.DialogType.SELECT_SAVEAS_FILE:
1518 defaultTitle = str('SELECT_SAVEAS_FILE_TITLE'); 1522 defaultTitle = str('SELECT_SAVEAS_FILE_TITLE');
1519 okLabel = str('SAVE_LABEL'); 1523 okLabel = str('SAVE_LABEL');
1524 // We don't want search enabled in save as dialog.
dgozman 2012/05/15 11:25:06 I don't really get why. I would like to search for
tbarzic 2012/05/16 03:50:04 yeah, I agree with you that would be useful :) I p
1525 this.dialogDom_.querySelector('#search-box').style.display = 'none';
1520 break; 1526 break;
1521 1527
1522 case FileManager.DialogType.FULL_PAGE: 1528 case FileManager.DialogType.FULL_PAGE:
1523 break; 1529 break;
1524 1530
1525 default: 1531 default:
1526 throw new Error('Unknown dialog type: ' + this.dialogType_); 1532 throw new Error('Unknown dialog type: ' + this.dialogType_);
1527 } 1533 }
1528 1534
1529 this.okButton_.textContent = okLabel; 1535 this.okButton_.textContent = okLabel;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 * Render filename label for grid and list view. 1862 * Render filename label for grid and list view.
1857 * @param {Entry} entry The Entry object to render. 1863 * @param {Entry} entry The Entry object to render.
1858 * @return {HTMLDivElement} The label. 1864 * @return {HTMLDivElement} The label.
1859 */ 1865 */
1860 FileManager.prototype.renderFileNameLabel_ = function(entry) { 1866 FileManager.prototype.renderFileNameLabel_ = function(entry) {
1861 // Filename need to be in a '.filename-label' container for correct 1867 // Filename need to be in a '.filename-label' container for correct
1862 // work of inplace renaming. 1868 // work of inplace renaming.
1863 var fileName = this.document_.createElement('div'); 1869 var fileName = this.document_.createElement('div');
1864 fileName.className = 'filename-label'; 1870 fileName.className = 'filename-label';
1865 1871
1872 var displayName =
1873 this.directoryModel_.getDisplayName(entry.fullPath, entry.name);
1874
1866 fileName.textContent = 1875 fileName.textContent =
1867 this.directoryModel_.getCurrentDirEntry().name == '' ? 1876 this.directoryModel_.getSearchOrCurrentDirEntry().name == '' ?
SeRya 2012/05/15 06:17:01 This is obsolete code. DirectoryModel doesn't fill
dgozman 2012/05/15 11:25:06 +1
tbarzic 2012/05/16 03:50:04 Done.
tbarzic 2012/05/16 03:50:04 Done.
1868 this.getRootLabel_(entry.name) : entry.name; 1877 this.getRootLabel_(displayName) : displayName;
1869 return fileName; 1878 return fileName;
1870 }; 1879 };
1871 1880
1872 /** 1881 /**
1873 * Render the Size column of the detail table. 1882 * Render the Size column of the detail table.
1874 * 1883 *
1875 * @param {Entry} entry The Entry object to render. 1884 * @param {Entry} entry The Entry object to render.
1876 * @param {string} columnId The id of the column to be rendered. 1885 * @param {string} columnId The id of the column to be rendered.
1877 * @param {cr.ui.Table} table The table doing the rendering. 1886 * @param {cr.ui.Table} table The table doing the rendering.
1878 */ 1887 */
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
2785 if (task.taskId != this.getExtensionId_() + '|gallery') { 2794 if (task.taskId != this.getExtensionId_() + '|gallery') {
2786 // Add callback, so gallery can execute the task. 2795 // Add callback, so gallery can execute the task.
2787 task.execute = this.dispatchFileTask_.bind(this, task.taskId); 2796 task.execute = this.dispatchFileTask_.bind(this, task.taskId);
2788 shareActions.push(task); 2797 shareActions.push(task);
2789 } 2798 }
2790 } 2799 }
2791 callback(shareActions); 2800 callback(shareActions);
2792 }.bind(this)); 2801 }.bind(this));
2793 }; 2802 };
2794 2803
2804 /**
2805 * Does preprocessing of url list to open before calling |doO[enGallery_|.
dgozman 2012/05/15 11:25:06 typo: doO[enGallery
tbarzic 2012/05/16 03:50:04 Done.
2806 *
2807 * @param {Array.<string>} urls List of urls to open in the gallery.
2808 */
2795 FileManager.prototype.openGallery_ = function(urls) { 2809 FileManager.prototype.openGallery_ = function(urls) {
2796 var self = this;
2797
2798 var galleryFrame = this.document_.createElement('iframe');
2799 galleryFrame.className = 'overlay-pane';
2800 galleryFrame.scrolling = 'no';
2801 galleryFrame.setAttribute('webkitallowfullscreen', true);
2802
2803 var singleSelection = urls.length == 1; 2810 var singleSelection = urls.length == 1;
2804 var selectedUrl; 2811 var selectedUrl;
2805 if (singleSelection && FileType.isImage(urls[0])) { 2812 if (singleSelection && FileType.isImage(urls[0])) {
2806 // Single image item selected. Pass to the Gallery as a selected. 2813 // Single image item selected. Pass to the Gallery as a selected.
2807 selectedUrl = urls[0]; 2814 selectedUrl = urls[0];
2808 // Pass along every image and video in the directory so that it shows up 2815 // Pass along every image and video in the directory so that it shows up
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
2826 // TODO(tbarzic): There's probably a better way to do this.
2827 if (this.directoryModel_.isOnGDataSearchDir()) {
2828 var self = this;
2829 var gdataRootUrl = this.directoryModel_.getCurrentRootDirEntry().toURL();
2830 util.resolveGDataSearchUrls([selectedUrl], gdataRootUrl,
2831 function(resolved) {
2832 util.resolveGDataSearchUrls(urls, gdataRootUrl,
2833 self.doOpenGallery_.bind(self, resolved[0]));
2834 });
2835 return;
2836 }
2837 this.doOpenGallery_(selectedUrl, urls);
2838 };
2839
2840 /**
2841 * Opens provided urls in the gallery.
2842 *
2843 * @param {string} selectedUrl Url of the item that should initially be
2844 * selected.
2845 * @param {Array.<string>} urls List of all the urls that will be shown in
2846 * the gallery.
2847 */
2848 FileManager.prototype.doOpenGallery_ = function(selectedUrl, urls) {
2849 var self = this;
2850
2851 var galleryFrame = this.document_.createElement('iframe');
2852 galleryFrame.className = 'overlay-pane';
2853 galleryFrame.scrolling = 'no';
2854 galleryFrame.setAttribute('webkitallowfullscreen', true);
2855
2819 var dirPath = this.directoryModel_.getCurrentDirEntry().fullPath; 2856 var dirPath = this.directoryModel_.getCurrentDirEntry().fullPath;
2820
2821 // Push a temporary state which will be replaced every time an individual 2857 // Push a temporary state which will be replaced every time an individual
2822 // item is selected in the Gallery. 2858 // item is selected in the Gallery.
2823 this.updateLocation_(false /*push*/, dirPath); 2859 this.updateLocation_(false /*push*/, dirPath);
2824 2860
2825 galleryFrame.onload = function() { 2861 galleryFrame.onload = function() {
2826 galleryFrame.contentWindow.ImageUtil.metrics = metrics; 2862 galleryFrame.contentWindow.ImageUtil.metrics = metrics;
2827 galleryFrame.contentWindow.FileType = FileType; 2863 galleryFrame.contentWindow.FileType = FileType;
2828 galleryFrame.contentWindow.util = util; 2864 galleryFrame.contentWindow.util = util;
2829 2865
2830 // Gallery shoud treat GData folder as readonly even when online 2866 // Gallery shoud treat GData folder as readonly even when online
2831 // until we learn to save files directly to GData. 2867 // until we learn to save files directly to GData.
2832 var readonly = self.isOnReadonlyDirectory() || self.isOnGData(); 2868 var readonly = self.isOnReadonlyDirectory() || self.isOnGData();
2833 var currentDir = self.directoryModel_.getCurrentDirEntry(); 2869 var currentDir = self.directoryModel_.getCurrentDirEntry();
2834 var downloadsDir = self.directoryModel_.getRootsList().item(0); 2870 var downloadsDir = self.directoryModel_.getRootsList().item(0);
2871 var singleSelection = urls.length == 1;
dgozman 2012/05/15 11:25:06 This is wrong now. If the case of single selection
tbarzic 2012/05/16 03:50:04 Done.
2835 2872
2836 var gallerySelection; 2873 var gallerySelection;
2837 var context = { 2874 var context = {
2838 // We show the root label in readonly warning (e.g. archive name). 2875 // We show the root label in readonly warning (e.g. archive name).
2839 readonlyDirName: 2876 readonlyDirName:
2840 readonly ? 2877 readonly ?
2841 (self.isOnGData() ? 2878 (self.isOnGData() ?
2842 self.getRootLabel_( 2879 self.getRootLabel_(
2843 DirectoryModel.getRootPath(currentDir.fullPath)) : 2880 DirectoryModel.getRootPath(currentDir.fullPath)) :
2844 self.directoryModel_.getRootName()) : 2881 self.directoryModel_.getRootName()) :
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2898 2935
2899 path = path + '/'; 2936 path = path + '/';
2900 div.path = path; 2937 div.path = path;
2901 2938
2902 bc.appendChild(div); 2939 bc.appendChild(div);
2903 2940
2904 if (i == pathNames.length - 1) { 2941 if (i == pathNames.length - 1) {
2905 div.classList.add('breadcrumb-last'); 2942 div.classList.add('breadcrumb-last');
2906 } else { 2943 } else {
2907 div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); 2944 div.addEventListener('click', this.onBreadcrumbClick_.bind(this));
2908
2909 var spacer = doc.createElement('div'); 2945 var spacer = doc.createElement('div');
2910 spacer.className = 'separator'; 2946 spacer.className = 'separator';
2911 bc.appendChild(spacer); 2947 bc.appendChild(spacer);
2912 } 2948 }
2913 } 2949 }
2914 this.truncateBreadcrumbs_(); 2950 this.truncateBreadcrumbs_();
2915 }; 2951 };
2916 2952
2917 FileManager.prototype.isRenamingInProgress = function() { 2953 FileManager.prototype.isRenamingInProgress = function() {
2918 return !!this.renameInput_.currentEntry; 2954 return !!this.renameInput_.currentEntry;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
3050 }; 3086 };
3051 3087
3052 /** 3088 /**
3053 * Return URL of the current directory or null. 3089 * Return URL of the current directory or null.
3054 */ 3090 */
3055 FileManager.prototype.getCurrentDirectoryURL = function() { 3091 FileManager.prototype.getCurrentDirectoryURL = function() {
3056 return this.directoryModel_ && 3092 return this.directoryModel_ &&
3057 this.directoryModel_.getCurrentDirEntry().toURL(); 3093 this.directoryModel_.getCurrentDirEntry().toURL();
3058 }; 3094 };
3059 3095
3096 /**
3097 * Return URL of the search directory, current directory or null.
3098 */
3099 FileManager.prototype.getSearchOrCurrentDirectoryURL = function() {
3100 return this.directoryModel_ &&
3101 this.directoryModel_.getSearchOrCurrentDirEntry().toURL();
SeRya 2012/05/15 06:17:01 It will fail if the current directory is unmounted
tbarzic 2012/05/16 03:50:04 it will have the same behaviour as getCurrentDirec
3102 };
3103
3060 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { 3104 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) {
3061 if (!force) { 3105 if (!force) {
3062 var self = this; 3106 var self = this;
3063 var msg; 3107 var msg;
3064 if (entries.length == 1) { 3108 if (entries.length == 1) {
3065 msg = strf('CONFIRM_DELETE_ONE', entries[0].name); 3109 var entryName = this.directoryModel_.getDisplayName(entries[0].fullPath,
3110 entries[0].name);
3111 msg = strf('CONFIRM_DELETE_ONE', entryName);
3066 } else { 3112 } else {
3067 msg = strf('CONFIRM_DELETE_SOME', entries.length); 3113 msg = strf('CONFIRM_DELETE_SOME', entries.length);
3068 } 3114 }
3069 3115
3070 this.confirm.show(msg, this.deleteEntries.bind( 3116 this.confirm.show(msg, this.deleteEntries.bind(
3071 this, entries, true, opt_callback)); 3117 this, entries, true, opt_callback));
3072 return; 3118 return;
3073 } 3119 }
3074 3120
3075 this.directoryModel_.deleteEntries(entries, opt_callback); 3121 this.directoryModel_.deleteEntries(entries, opt_callback);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
3280 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { 3326 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) {
3281 selectable = (this.isSelectionAvailable() && 3327 selectable = (this.isSelectionAvailable() &&
3282 this.selection.directoryCount == 0 && 3328 this.selection.directoryCount == 0 &&
3283 this.selection.fileCount == 1); 3329 this.selection.fileCount == 1);
3284 } else if (this.dialogType_ == 3330 } else if (this.dialogType_ ==
3285 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { 3331 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) {
3286 selectable = (this.isSelectionAvailable() && 3332 selectable = (this.isSelectionAvailable() &&
3287 this.selection.directoryCount == 0 && 3333 this.selection.directoryCount == 0 &&
3288 this.selection.fileCount >= 1); 3334 this.selection.fileCount >= 1);
3289 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { 3335 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) {
3290 if (this.isOnReadonlyDirectory()) { 3336 if (this.isOnReadonlyDirectory() ||
3337 (this.isOnGData() && this.directoryModel_.isSearching())) {
dgozman 2012/05/15 11:25:06 Why can't I search for a file and overwrite it?
tbarzic 2012/05/16 03:50:04 Done.
3291 selectable = false; 3338 selectable = false;
3292 } else { 3339 } else {
3293 selectable = !!this.filenameInput_.value; 3340 selectable = !!this.filenameInput_.value;
3294 } 3341 }
3295 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { 3342 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) {
3296 // No "select" buttons on the full page UI. 3343 // No "select" buttons on the full page UI.
3297 selectable = true; 3344 selectable = true;
3298 } else { 3345 } else {
3299 throw new Error('Unknown dialog type'); 3346 throw new Error('Unknown dialog type');
3300 } 3347 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3332 this.dispatchDefaultTask_(); 3379 this.dispatchDefaultTask_();
3333 return true; 3380 return true;
3334 } 3381 }
3335 if (!this.okButton_.disabled) { 3382 if (!this.okButton_.disabled) {
3336 this.onOk_(); 3383 this.onOk_();
3337 return true; 3384 return true;
3338 } 3385 }
3339 return false; 3386 return false;
3340 }; 3387 };
3341 3388
3389 /**
3390 * Executes directory action (i.e. changes directory). If new directory is a
3391 * search result directory, we'll have to calculate its real path before we
3392 * actually do the operation.
3393 *
3394 * @param {DirectoryEntry} entry Directory entry to which directory should be
3395 * changed.
3396 */
3342 FileManager.prototype.onDirectoryAction = function(entry) { 3397 FileManager.prototype.onDirectoryAction = function(entry) {
3343 var deviceNumber = this.getDeviceNumber(entry); 3398 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); 3399 return this.directoryModel_.changeDirectory(entry.fullPath);
3354 } 3400
3401 // If we are under gdata search path, the real entries file path may be
3402 // different from |entry.fullPath|.
3403 var self = this;
3404 chrome.fileBrowserPrivate.getPathForDriveSearchResult(entry.toURL(),
3405 function(path) {
3406 // |path| may be undefined if there was an error. If that is the case,
3407 // change to the original file path.
3408 var changeToPath = path || entry.fullPath;
dgozman 2012/05/15 11:25:06 Changing to entry.fullPath is not an option. Just
tbarzic 2012/05/16 03:50:04 Done.
3409 self.directoryModel_.changeDirectory(changeToPath);
3410 });
3355 }; 3411 };
3356 3412
3357 /** 3413 /**
3358 * Show or hide the "Low disk space" warning. 3414 * Show or hide the "Low disk space" warning.
3359 * @param {boolean} show True if the box need to be shown. 3415 * @param {boolean} show True if the box need to be shown.
3360 */ 3416 */
3361 FileManager.prototype.showLowDiskSpaceWarning_ = function(show) { 3417 FileManager.prototype.showLowDiskSpaceWarning_ = function(show) {
3362 var box = this.dialogDom_.querySelector('.downloads-warning'); 3418 var box = this.dialogDom_.querySelector('.downloads-warning');
3363 if (show) { 3419 if (show) {
3364 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); 3420 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING'));
(...skipping 30 matching lines...) Expand all
3395 /** 3451 /**
3396 * Update the tab title. 3452 * Update the tab title.
3397 */ 3453 */
3398 FileManager.prototype.updateTitle_ = function() { 3454 FileManager.prototype.updateTitle_ = function() {
3399 this.document_.title = this.getCurrentDirectory().substr(1).replace( 3455 this.document_.title = this.getCurrentDirectory().substr(1).replace(
3400 new RegExp('^' + DirectoryModel.GDATA_DIRECTORY), 3456 new RegExp('^' + DirectoryModel.GDATA_DIRECTORY),
3401 str('GDATA_PRODUCT_NAME')); 3457 str('GDATA_PRODUCT_NAME'));
3402 }, 3458 },
3403 3459
3404 /** 3460 /**
3461 * Updates search box value when directory gets changed.
3462 */
3463 FileManager.prototype.updateSearchBoxOnDirChange_ = function() {
3464 var searchBox = this.dialogDom_.querySelector('#search-box');
3465 if (!searchBox.disabled)
3466 searchBox.value = '';
3467 },
3468
3469 /**
3405 * Update the UI when the current directory changes. 3470 * Update the UI when the current directory changes.
3406 * 3471 *
3407 * @param {cr.Event} event The directory-changed event. 3472 * @param {cr.Event} event The directory-changed event.
3408 */ 3473 */
3409 FileManager.prototype.onDirectoryChanged_ = function(event) { 3474 FileManager.prototype.onDirectoryChanged_ = function(event) {
3410 this.updateCommonActionButtons_(); 3475 this.updateCommonActionButtons_();
3411 this.updateOkButton_(); 3476 this.updateOkButton_();
3412 this.updateBreadcrumbs_(); 3477 this.updateBreadcrumbs_();
3413 this.updateColumnModel_(); 3478 this.updateColumnModel_();
3479 this.updateSearchBoxOnDirChange_();
3414 3480
3415 // Sometimes we rescan the same directory (when mounting GData lazily first, 3481 // Sometimes we rescan the same directory (when mounting GData lazily first,
3416 // then for real). Do not update the location then. 3482 // then for real). Do not update the location then.
3417 if (event.newDirEntry.fullPath != event.previousDirEntry.fullPath) { 3483 if (event.newDirEntry.fullPath != event.previousDirEntry.fullPath) {
3418 this.updateLocation_(event.initial, event.newDirEntry.fullPath); 3484 this.updateLocation_(event.initial, event.newDirEntry.fullPath);
3419 } 3485 }
3420 3486
3421 this.checkFreeSpace_(this.getCurrentDirectory()); 3487 this.checkFreeSpace_(this.getCurrentDirectory());
3422 3488
3423 this.updateTitle_(); 3489 this.updateTitle_();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3509 if (!result) { 3575 if (!result) {
3510 console.log('Failed to remove file watch'); 3576 console.log('Failed to remove file watch');
3511 } 3577 }
3512 }); 3578 });
3513 this.watchedDirectoryUrl_ = null; 3579 this.watchedDirectoryUrl_ = null;
3514 } 3580 }
3515 }; 3581 };
3516 3582
3517 FileManager.prototype.onFileChanged_ = function(event) { 3583 FileManager.prototype.onFileChanged_ = function(event) {
3518 // We receive a lot of events even in folders we are not interested in. 3584 // We receive a lot of events even in folders we are not interested in.
3519 if (encodeURI(event.fileUrl) == this.getCurrentDirectoryURL()) 3585 if (encodeURI(event.fileUrl) == this.getSearchOrCurrentDirectoryURL())
3520 this.directoryModel_.rescanLater(); 3586 this.directoryModel_.rescanLater();
3521 }; 3587 };
3522 3588
3523 FileManager.prototype.initiateRename_ = function() { 3589 FileManager.prototype.initiateRename_ = function() {
3524 var item = this.currentList_.ensureLeadItemExists(); 3590 var item = this.currentList_.ensureLeadItemExists();
3525 if (!item) 3591 if (!item)
3526 return; 3592 return;
3527 var label = item.querySelector('.filename-label'); 3593 var label = item.querySelector('.filename-label');
3528 var input = this.renameInput_; 3594 var input = this.renameInput_;
3529 3595
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3589 input.validation_ = false; 3655 input.validation_ = false;
3590 // Alert dialog restores focus unless the item removed from DOM. 3656 // Alert dialog restores focus unless the item removed from DOM.
3591 if (this.document_.activeElement != input) 3657 if (this.document_.activeElement != input)
3592 this.cancelRename_(); 3658 this.cancelRename_();
3593 } 3659 }
3594 3660
3595 if (!this.validateFileName_(newName, validationDone.bind(this))) 3661 if (!this.validateFileName_(newName, validationDone.bind(this)))
3596 return; 3662 return;
3597 3663
3598 function onError(err) { 3664 function onError(err) {
3599 nameNode.textContent = entry.name; 3665 var entryName =
3600 this.alert.show(strf('ERROR_RENAMING', entry.name, 3666 this.directoryModel_.getDisplayName(entry.fullPath, entry.name);
3667 nameNode.textContent = entryName;
3668 this.alert.show(strf('ERROR_RENAMING', entryName,
3601 getFileErrorString(err.code))); 3669 getFileErrorString(err.code)));
3602 } 3670 }
3603 3671
3604 this.cancelRename_(); 3672 this.cancelRename_();
3605 // Optimistically apply new name immediately to avoid flickering in 3673 // Optimistically apply new name immediately to avoid flickering in
3606 // case of success. 3674 // case of success.
3607 nameNode.textContent = newName; 3675 nameNode.textContent = newName;
3608 3676
3609 this.directoryModel_.doesExist(newName, function(exists, isFile) { 3677 this.directoryModel_.doesExist(entry, newName, function(exists, isFile) {
3610 if (!exists) { 3678 if (!exists) {
3611 this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); 3679 this.directoryModel_.renameEntry(entry, newName, onError.bind(this));
3612 } else { 3680 } else {
3613 nameNode.textContent = entry.name; 3681 nameNode.textContent =
3682 this.directoryModel_.getDisplayName(entry.fullPath, entry.name);
3614 var message = isFile ? 'FILE_ALREADY_EXISTS' : 3683 var message = isFile ? 'FILE_ALREADY_EXISTS' :
3615 'DIRECTORY_ALREADY_EXISTS'; 3684 'DIRECTORY_ALREADY_EXISTS';
3616 this.alert.show(strf(message, newName)); 3685 this.alert.show(strf(message, newName));
3617 } 3686 }
3618 }.bind(this)); 3687 }.bind(this));
3619 }; 3688 };
3620 3689
3621 FileManager.prototype.cancelRename_ = function() { 3690 FileManager.prototype.cancelRename_ = function() {
3622 this.renameInput_.currentEntry = null; 3691 this.renameInput_.currentEntry = null;
3623 3692
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
3971 } 4040 }
3972 this.onUnload_(); 4041 this.onUnload_();
3973 window.close(); 4042 window.close();
3974 }; 4043 };
3975 4044
3976 /** 4045 /**
3977 * Tries to close this modal dialog with some files selected. 4046 * Tries to close this modal dialog with some files selected.
3978 * Performs preprocessing if needed (e.g. for GData). 4047 * Performs preprocessing if needed (e.g. for GData).
3979 * @param {Object} selection Contains urls, filterIndex and multiple fields. 4048 * @param {Object} selection Contains urls, filterIndex and multiple fields.
3980 */ 4049 */
3981 FileManager.prototype.selectFilesAndClose_ = function(selection) { 4050 FileManager.prototype.doSelectFilesAndClose_ = function(selection) {
3982 if (!this.isOnGData()) { 4051 if (!this.isOnGData()) {
3983 setTimeout(this.callSelectFilesApiAndClose_.bind(this, selection), 0); 4052 setTimeout(this.callSelectFilesApiAndClose_.bind(this, selection), 0);
3984 return; 4053 return;
3985 } 4054 }
3986 4055
3987 var shade = this.document_.createElement('div'); 4056 var shade = this.document_.createElement('div');
3988 shade.className = 'shade'; 4057 shade.className = 'shade';
3989 var footer = this.document_.querySelector('.dialog-footer'); 4058 var footer = this.document_.querySelector('.dialog-footer');
3990 var progress = footer.querySelector('.progress-track'); 4059 var progress = footer.querySelector('.progress-track');
3991 progress.style.width = '0%'; 4060 progress.style.width = '0%';
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4073 } 4142 }
4074 } 4143 }
4075 this.resolveSelectResults_(selection.urls, onResolved); 4144 this.resolveSelectResults_(selection.urls, onResolved);
4076 }.bind(this); 4145 }.bind(this);
4077 4146
4078 setup(); 4147 setup();
4079 this.metadataCache_.get(selection.urls, 'gdata', onProperties); 4148 this.metadataCache_.get(selection.urls, 'gdata', onProperties);
4080 }; 4149 };
4081 4150
4082 /** 4151 /**
4152 * Does selection urls list preprocessing and calls |doSelectFilesAndClose_|.
4153 *
4154 * @param {Object} selection Contains urls, filterIndex and multiple fields.
4155 */
4156 FileManager.prototype.selectFilesAndClose_ = function(selection) {
4157 if (this.directoryModel_.isOnGDataSearchDir()) {
4158 var self = this;
4159 var gdataRootUrl = this.directoryModel_.getCurrentRootDirEntry().toURL();
4160 util.resolveGDataSearchUrls(selection.urls, gdataRootUrl,
4161 function(resolved) {
4162 selection.urls = resolved;
4163 self.doSelectFilesAndClose_(selection);
4164 });
4165 return;
4166 }
4167 this.doSelectFilesAndClose_(selection);
4168 };
4169
4170 /**
4083 * Handle a click of the ok button. 4171 * Handle a click of the ok button.
4084 * 4172 *
4085 * The ok button has different UI labels depending on the type of dialog, but 4173 * The ok button has different UI labels depending on the type of dialog, but
4086 * in code it's always referred to as 'ok'. 4174 * in code it's always referred to as 'ok'.
4087 * 4175 *
4088 * @param {Event} event The click event. 4176 * @param {Event} event The click event.
4089 */ 4177 */
4090 FileManager.prototype.onOk_ = function(event) { 4178 FileManager.prototype.onOk_ = function(event) {
4091 var currentDirUrl = this.getCurrentDirectoryURL(); 4179 var currentDirUrl = this.getSearchOrCurrentDirectoryURL();
dgozman 2012/05/15 11:25:06 You can't save a new file into the search director
tbarzic 2012/05/16 03:50:04 save is currently disabled for search.
4092 4180
4093 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') 4181 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/')
4094 currentDirUrl += '/'; 4182 currentDirUrl += '/';
4095 4183
4096 var self = this; 4184 var self = this;
4097 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { 4185 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) {
4098 // Save-as doesn't require a valid selection from the list, since 4186 // Save-as doesn't require a valid selection from the list, since
4099 // we're going to take the filename from the text input. 4187 // we're going to take the filename from the text input.
4100 var filename = this.filenameInput_.value; 4188 var filename = this.filenameInput_.value;
4101 if (!filename) 4189 if (!filename)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4143 throw new Error('Nothing selected!'); 4231 throw new Error('Nothing selected!');
4144 4232
4145 var dm = this.directoryModel_.getFileList(); 4233 var dm = this.directoryModel_.getFileList();
4146 for (var i = 0; i < selectedIndexes.length; i++) { 4234 for (var i = 0; i < selectedIndexes.length; i++) {
4147 var entry = dm.item(selectedIndexes[i]); 4235 var entry = dm.item(selectedIndexes[i]);
4148 if (!entry) { 4236 if (!entry) {
4149 console.log('Error locating selected file at index: ' + i); 4237 console.log('Error locating selected file at index: ' + i);
4150 continue; 4238 continue;
4151 } 4239 }
4152 4240
4153 files.push(currentDirUrl + encodeURIComponent(entry.name)); 4241 files.push(entry.toURL());
4154 } 4242 }
4155 4243
4156 // Multi-file selection has no other restrictions. 4244 // Multi-file selection has no other restrictions.
4157 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { 4245 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) {
4158 var multipleSelection = { 4246 var multipleSelection = {
4159 urls: files, 4247 urls: files,
4160 multiple: true 4248 multiple: true
4161 }; 4249 };
4162 this.selectFilesAndClose_(multipleSelection); 4250 this.selectFilesAndClose_(multipleSelection);
4163 return; 4251 return;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
4289 4377
4290 if (oldValue) { 4378 if (oldValue) {
4291 event.target.removeAttribute('checked'); 4379 event.target.removeAttribute('checked');
4292 } else { 4380 } else {
4293 event.target.setAttribute('checked', 'checked'); 4381 event.target.setAttribute('checked', 'checked');
4294 } 4382 }
4295 }; 4383 };
4296 4384
4297 FileManager.prototype.onSearchBoxUpdate_ = function(event) { 4385 FileManager.prototype.onSearchBoxUpdate_ = function(event) {
4298 var searchString = this.dialogDom_.querySelector('#search-box').value; 4386 var searchString = this.dialogDom_.querySelector('#search-box').value;
4299 if (searchString) { 4387 this.directoryModel_.search(searchString);
4300 this.directoryModel_.addFilter( 4388 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 }; 4389 };
4309 4390
4310 FileManager.prototype.decorateSplitter = function(splitterElement) { 4391 FileManager.prototype.decorateSplitter = function(splitterElement) {
4311 var self = this; 4392 var self = this;
4312 4393
4313 var Splitter = cr.ui.Splitter; 4394 var Splitter = cr.ui.Splitter;
4314 4395
4315 var customSplitter = cr.ui.define('div'); 4396 var customSplitter = cr.ui.define('div');
4316 4397
4317 customSplitter.prototype = { 4398 customSplitter.prototype = {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
4431 4512
4432 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); 4513 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner);
4433 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); 4514 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner);
4434 4515
4435 var style = this.document_.createElement('link'); 4516 var style = this.document_.createElement('link');
4436 style.rel = 'stylesheet'; 4517 style.rel = 'stylesheet';
4437 style.href = 'css/gdrive_welcome.css'; 4518 style.href = 'css/gdrive_welcome.css';
4438 this.document_.head.appendChild(style); 4519 this.document_.head.appendChild(style);
4439 }; 4520 };
4440 })(); 4521 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698