Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/file_manager.js |
| diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js |
| index 5a90e85a21a05b2c4340b3c36a55064155c6746b..b47faa69baec89d7190ca4892ddb7d2a1d047ef8 100644 |
| --- a/chrome/browser/resources/file_manager/js/file_manager.js |
| +++ b/chrome/browser/resources/file_manager/js/file_manager.js |
| @@ -53,6 +53,8 @@ function FileManager(dialogDom) { |
| this.initDom_(); |
| this.initDialogType_(); |
| this.dialogDom_.style.opacity = '1'; |
| + |
| + this.lastNonGDataSearchPath_ = null; |
| } |
| FileManager.prototype = { |
| @@ -978,6 +980,8 @@ FileManager.prototype = { |
| */ |
| FileManager.prototype.canExecute_ = function(commandId) { |
| var readonly = this.isOnReadonlyDirectory(); |
| + var shouldCreate = !util.isSpecialReadonlyDirectory( |
| + this.directoryModel_.getCurrentDirEntry().fullPath); |
| switch (commandId) { |
| case 'copy': |
| case 'cut': |
| @@ -985,7 +989,8 @@ FileManager.prototype = { |
| case 'paste': |
| return !!this.fileTransferController_ && |
| - this.fileTransferController_.queryPasteCommandEnabled(); |
| + this.fileTransferController_.queryPasteCommandEnabled() && |
|
SeRya
2012/05/04 10:26:17
What about dropping files into the search results?
tbarzic
2012/05/05 00:56:06
Done.
|
| + shouldCreate; |
| case 'rename': |
| return (// Initialized to the point where we have a current directory |
| @@ -1006,6 +1011,7 @@ FileManager.prototype = { |
| case 'newfolder': |
| return !readonly && |
| + shouldCreate && |
| (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || |
| this.dialogType_ == FileManager.DialogType.FULL_PAGE); |
| @@ -1830,9 +1836,16 @@ FileManager.prototype = { |
| var fileName = this.document_.createElement('div'); |
| fileName.className = 'filename-label'; |
| + // If the entry is gdata search result, we should calculate name to use |
| + // instead of using |entry.name|. |
| + var gdataSearchResult = |
| + util.getFileAndDisplayNameForGDataSearchResult(entry.fullPath); |
| + var displayName = gdataSearchResult ? gdataSearchResult.displayName : |
| + entry.name; |
| + |
| fileName.textContent = |
| this.directoryModel_.getCurrentDirEntry().name == '' ? |
| - this.getRootLabel_(entry.name) : entry.name; |
| + this.getRootLabel_(displayName) : displayName; |
| return fileName; |
| }; |
| @@ -2870,7 +2883,12 @@ FileManager.prototype = { |
| if (i == pathNames.length - 1) { |
| div.classList.add('breadcrumb-last'); |
| } else { |
| - div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); |
| + // This is virtual, inaccessible directory. |
| + if (path == util.GDATA_SEARCH_ROOT_PATH) { |
| + div.classList.add('breadcrumb-last'); |
|
SeRya
2012/05/04 10:26:17
breadcrumb-last in the middle of the path looks st
tbarzic
2012/05/05 00:56:06
Done
|
| + } else { |
| + div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); |
| + } |
| var spacer = doc.createElement('div'); |
| spacer.className = 'separator'; |
| @@ -3540,7 +3558,17 @@ FileManager.prototype = { |
| FileManager.prototype.commitRename_ = function() { |
| var input = this.renameInput_; |
| var entry = input.currentEntry; |
| - var newName = input.value; |
| + var newNameInput = input.value; |
| + |
| + // If we are renaming gdata search result, we'll have to format newName we |
| + // use in file system operations like: <resource_id>.<file_name>. |
| + var searchResultName = |
| + util.getFileAndDisplayNameForGDataSearchResult(entry.fullPath); |
| + |
| + var newName = |
| + searchResultName ? searchResultName.resourceId + '.' + newNameInput : |
| + newNameInput; |
| + var oldName = searchResultName ? searchResultName.displayName : entry.name; |
| if (newName == entry.name) { |
| this.cancelRename_(); |
| @@ -3558,7 +3586,7 @@ FileManager.prototype = { |
| this.cancelRename_(); |
| } |
| - if (!this.validateFileName_(newName, validationDone.bind(this))) |
| + if (!this.validateFileName_(newNameInput, validationDone.bind(this))) |
| return; |
| function onError(err) { |
| @@ -3570,16 +3598,16 @@ FileManager.prototype = { |
| this.cancelRename_(); |
| // Optimistically apply new name immediately to avoid flickering in |
| // case of success. |
| - nameNode.textContent = newName; |
| + nameNode.textContent = newNameInput; |
| this.directoryModel_.doesExist(newName, function(exists, isFile) { |
|
SeRya
2012/05/04 10:26:17
I'd suggest to isolate the UI from knowlage about
tbarzic
2012/05/05 00:56:06
Really good point, that's much cleaner :)
|
| if (!exists) { |
| this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); |
| } else { |
| - nameNode.textContent = entry.name; |
| + nameNode.textContent = oldName; |
| var message = isFile ? 'FILE_ALREADY_EXISTS' : |
| 'DIRECTORY_ALREADY_EXISTS'; |
| - this.alert.show(strf(message, newName)); |
| + this.alert.show(strf(message, newNameInput)); |
| } |
| }.bind(this)); |
| }; |
| @@ -4263,13 +4291,32 @@ FileManager.prototype = { |
| FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
| var searchString = this.dialogDom_.querySelector('#search-box').value; |
| if (searchString) { |
| - this.directoryModel_.addFilter( |
| - 'searchbox', |
| - function(e) { |
| - return e.name.substr(0, searchString.length) == searchString; |
| - }); |
| + if (!this.isOnGData()) { |
|
SeRya
2012/05/04 10:26:17
I think this is too low level logic. It should be
tbarzic
2012/05/05 00:56:06
Done.
|
| + this.directoryModel_.addFilter( |
| + 'searchbox', |
| + function(e) { |
| + return e.name.substr(0, searchString.length) == searchString; |
| + }); |
| + } else { |
| + // If current path is not under gdata search dir, remeber it, so we can |
| + // navigate to it when we exit search mode. |
| + var currentDirPath = this.directoryModel_.getCurrentDirEntry().fullPath; |
| + if (currentDirPath.search(util.GDATA_SEARCH_ROOT_PATH) != 0) |
| + this.lastNonGDataSearchPath_ = currentDirPath; |
| + |
| + this.directoryModel_.changeDirectory( |
|
SeRya
2012/05/04 10:26:17
changeDirectory causes putting the new directory i
tbarzic
2012/05/05 00:56:06
Done.
|
| + util.createGDataSearchPath(searchString)); |
| + } |
| } else { |
| - this.directoryModel_.removeFilter('searchbox'); |
| + if (!this.isOnGData()) { |
| + this.directoryModel_.removeFilter('searchbox'); |
| + } else { |
| + // Go to last known non gdata search directory. |
| + var newDirectory = this.lastNonGDataSearchPath_ || |
| + '/' + DirectoryModel.GDATA_DIRECTORY; |
|
SeRya
2012/05/04 10:26:17
You set GData root even if search started in a sub
tbarzic
2012/05/05 00:56:06
are you sure? What am I missing?
|
| + this.lastNonGDataSearchPath_ = null; |
| + this.directoryModel_.changeDirectory(newDirectory); |
| + } |
| } |
| }; |