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 feddb206cb9552ba30adf44726b3cb249528ed22..bca724642f7c16cc2cda00726565f9a1837595a1 100644 |
--- a/chrome/browser/resources/file_manager/js/file_manager.js |
+++ b/chrome/browser/resources/file_manager/js/file_manager.js |
@@ -999,6 +999,7 @@ FileManager.prototype = { |
*/ |
FileManager.prototype.canExecute_ = function(commandId) { |
var readonly = this.isOnReadonlyDirectory(); |
+ var shouldCreate = !this.directoryModel_.isSearching(); |
switch (commandId) { |
case 'copy': |
case 'cut': |
@@ -1006,7 +1007,8 @@ FileManager.prototype = { |
case 'paste': |
return !!this.fileTransferController_ && |
- this.fileTransferController_.queryPasteCommandEnabled(); |
+ this.fileTransferController_.queryPasteCommandEnabled() && |
+ shouldCreate; |
SeRya
2012/05/15 06:17:01
Please remove this change. queryPasteCommandEnable
tbarzic
2012/05/16 03:50:04
Done.
|
case 'rename': |
return (// Initialized to the point where we have a current directory |
@@ -1027,6 +1029,7 @@ FileManager.prototype = { |
case 'newfolder': |
return !readonly && |
+ shouldCreate && |
(this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE || |
this.dialogType_ == FileManager.DialogType.FULL_PAGE); |
@@ -1279,7 +1282,8 @@ FileManager.prototype = { |
* update event). |
*/ |
FileManager.prototype.onCopyManagerOperationComplete_ = function(event) { |
- var currentPath = this.directoryModel_.getCurrentDirEntry().fullPath; |
+ var currentPath = |
+ 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
|
function inCurrentDirectory(entry) { |
var fullPath = entry.fullPath; |
var dirPath = fullPath.substr(0, fullPath.length - |
@@ -1517,6 +1521,8 @@ FileManager.prototype = { |
case FileManager.DialogType.SELECT_SAVEAS_FILE: |
defaultTitle = str('SELECT_SAVEAS_FILE_TITLE'); |
okLabel = str('SAVE_LABEL'); |
+ // 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
|
+ this.dialogDom_.querySelector('#search-box').style.display = 'none'; |
break; |
case FileManager.DialogType.FULL_PAGE: |
@@ -1863,9 +1869,12 @@ FileManager.prototype = { |
var fileName = this.document_.createElement('div'); |
fileName.className = 'filename-label'; |
+ var displayName = |
+ this.directoryModel_.getDisplayName(entry.fullPath, entry.name); |
+ |
fileName.textContent = |
- this.directoryModel_.getCurrentDirEntry().name == '' ? |
- this.getRootLabel_(entry.name) : entry.name; |
+ 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.
|
+ this.getRootLabel_(displayName) : displayName; |
return fileName; |
}; |
@@ -2792,14 +2801,12 @@ FileManager.prototype = { |
}.bind(this)); |
}; |
+ /** |
+ * 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.
|
+ * |
+ * @param {Array.<string>} urls List of urls to open in the gallery. |
+ */ |
FileManager.prototype.openGallery_ = function(urls) { |
- var self = this; |
- |
- var galleryFrame = this.document_.createElement('iframe'); |
- galleryFrame.className = 'overlay-pane'; |
- galleryFrame.scrolling = 'no'; |
- galleryFrame.setAttribute('webkitallowfullscreen', true); |
- |
var singleSelection = urls.length == 1; |
var selectedUrl; |
if (singleSelection && FileType.isImage(urls[0])) { |
@@ -2816,8 +2823,37 @@ FileManager.prototype = { |
selectedUrl = urls[0]; |
} |
- var dirPath = this.directoryModel_.getCurrentDirEntry().fullPath; |
+ // TODO(tbarzic): There's probably a better way to do this. |
+ if (this.directoryModel_.isOnGDataSearchDir()) { |
+ var self = this; |
+ var gdataRootUrl = this.directoryModel_.getCurrentRootDirEntry().toURL(); |
+ util.resolveGDataSearchUrls([selectedUrl], gdataRootUrl, |
+ function(resolved) { |
+ util.resolveGDataSearchUrls(urls, gdataRootUrl, |
+ self.doOpenGallery_.bind(self, resolved[0])); |
+ }); |
+ return; |
+ } |
+ this.doOpenGallery_(selectedUrl, urls); |
+ }; |
+ |
+ /** |
+ * Opens provided urls in the gallery. |
+ * |
+ * @param {string} selectedUrl Url of the item that should initially be |
+ * selected. |
+ * @param {Array.<string>} urls List of all the urls that will be shown in |
+ * the gallery. |
+ */ |
+ FileManager.prototype.doOpenGallery_ = function(selectedUrl, urls) { |
+ var self = this; |
+ |
+ var galleryFrame = this.document_.createElement('iframe'); |
+ galleryFrame.className = 'overlay-pane'; |
+ galleryFrame.scrolling = 'no'; |
+ galleryFrame.setAttribute('webkitallowfullscreen', true); |
+ var dirPath = this.directoryModel_.getCurrentDirEntry().fullPath; |
// Push a temporary state which will be replaced every time an individual |
// item is selected in the Gallery. |
this.updateLocation_(false /*push*/, dirPath); |
@@ -2832,6 +2868,7 @@ FileManager.prototype = { |
var readonly = self.isOnReadonlyDirectory() || self.isOnGData(); |
var currentDir = self.directoryModel_.getCurrentDirEntry(); |
var downloadsDir = self.directoryModel_.getRootsList().item(0); |
+ 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.
|
var gallerySelection; |
var context = { |
@@ -2905,7 +2942,6 @@ FileManager.prototype = { |
div.classList.add('breadcrumb-last'); |
} else { |
div.addEventListener('click', this.onBreadcrumbClick_.bind(this)); |
- |
var spacer = doc.createElement('div'); |
spacer.className = 'separator'; |
bc.appendChild(spacer); |
@@ -3057,12 +3093,22 @@ FileManager.prototype = { |
this.directoryModel_.getCurrentDirEntry().toURL(); |
}; |
+ /** |
+ * Return URL of the search directory, current directory or null. |
+ */ |
+ FileManager.prototype.getSearchOrCurrentDirectoryURL = function() { |
+ return this.directoryModel_ && |
+ 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
|
+ }; |
+ |
FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { |
if (!force) { |
var self = this; |
var msg; |
if (entries.length == 1) { |
- msg = strf('CONFIRM_DELETE_ONE', entries[0].name); |
+ var entryName = this.directoryModel_.getDisplayName(entries[0].fullPath, |
+ entries[0].name); |
+ msg = strf('CONFIRM_DELETE_ONE', entryName); |
} else { |
msg = strf('CONFIRM_DELETE_SOME', entries.length); |
} |
@@ -3287,7 +3333,8 @@ FileManager.prototype = { |
this.selection.directoryCount == 0 && |
this.selection.fileCount >= 1); |
} else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
- if (this.isOnReadonlyDirectory()) { |
+ if (this.isOnReadonlyDirectory() || |
+ (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.
|
selectable = false; |
} else { |
selectable = !!this.filenameInput_.value; |
@@ -3339,19 +3386,28 @@ FileManager.prototype = { |
return false; |
}; |
+ /** |
+ * Executes directory action (i.e. changes directory). If new directory is a |
+ * search result directory, we'll have to calculate its real path before we |
+ * actually do the operation. |
+ * |
+ * @param {DirectoryEntry} entry Directory entry to which directory should be |
+ * changed. |
+ */ |
FileManager.prototype.onDirectoryAction = function(entry) { |
- var deviceNumber = this.getDeviceNumber(entry); |
- if (deviceNumber != undefined && |
- this.mountPoints_[deviceNumber].mountCondition == |
- 'unknown_filesystem') { |
- return this.showButter(str('UNKNOWN_FILESYSTEM_WARNING')); |
- } else if (deviceNumber != undefined && |
- this.mountPoints_[deviceNumber].mountCondition == |
- 'unsupported_filesystem') { |
- return this.showButter(str('UNSUPPORTED_FILESYSTEM_WARNING')); |
- } else { |
+ if (!DirectoryModel.isGDataSearchPath(entry.fullPath)) |
return this.directoryModel_.changeDirectory(entry.fullPath); |
- } |
+ |
+ // If we are under gdata search path, the real entries file path may be |
+ // different from |entry.fullPath|. |
+ var self = this; |
+ chrome.fileBrowserPrivate.getPathForDriveSearchResult(entry.toURL(), |
+ function(path) { |
+ // |path| may be undefined if there was an error. If that is the case, |
+ // change to the original file path. |
+ 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.
|
+ self.directoryModel_.changeDirectory(changeToPath); |
+ }); |
}; |
/** |
@@ -3402,6 +3458,15 @@ FileManager.prototype = { |
}, |
/** |
+ * Updates search box value when directory gets changed. |
+ */ |
+ FileManager.prototype.updateSearchBoxOnDirChange_ = function() { |
+ var searchBox = this.dialogDom_.querySelector('#search-box'); |
+ if (!searchBox.disabled) |
+ searchBox.value = ''; |
+ }, |
+ |
+ /** |
* Update the UI when the current directory changes. |
* |
* @param {cr.Event} event The directory-changed event. |
@@ -3411,6 +3476,7 @@ FileManager.prototype = { |
this.updateOkButton_(); |
this.updateBreadcrumbs_(); |
this.updateColumnModel_(); |
+ this.updateSearchBoxOnDirChange_(); |
// Sometimes we rescan the same directory (when mounting GData lazily first, |
// then for real). Do not update the location then. |
@@ -3516,7 +3582,7 @@ FileManager.prototype = { |
FileManager.prototype.onFileChanged_ = function(event) { |
// We receive a lot of events even in folders we are not interested in. |
- if (encodeURI(event.fileUrl) == this.getCurrentDirectoryURL()) |
+ if (encodeURI(event.fileUrl) == this.getSearchOrCurrentDirectoryURL()) |
this.directoryModel_.rescanLater(); |
}; |
@@ -3596,8 +3662,10 @@ FileManager.prototype = { |
return; |
function onError(err) { |
- nameNode.textContent = entry.name; |
- this.alert.show(strf('ERROR_RENAMING', entry.name, |
+ var entryName = |
+ this.directoryModel_.getDisplayName(entry.fullPath, entry.name); |
+ nameNode.textContent = entryName; |
+ this.alert.show(strf('ERROR_RENAMING', entryName, |
getFileErrorString(err.code))); |
} |
@@ -3606,11 +3674,12 @@ FileManager.prototype = { |
// case of success. |
nameNode.textContent = newName; |
- this.directoryModel_.doesExist(newName, function(exists, isFile) { |
+ this.directoryModel_.doesExist(entry, newName, function(exists, isFile) { |
if (!exists) { |
this.directoryModel_.renameEntry(entry, newName, onError.bind(this)); |
} else { |
- nameNode.textContent = entry.name; |
+ nameNode.textContent = |
+ this.directoryModel_.getDisplayName(entry.fullPath, entry.name); |
var message = isFile ? 'FILE_ALREADY_EXISTS' : |
'DIRECTORY_ALREADY_EXISTS'; |
this.alert.show(strf(message, newName)); |
@@ -3978,7 +4047,7 @@ FileManager.prototype = { |
* Performs preprocessing if needed (e.g. for GData). |
* @param {Object} selection Contains urls, filterIndex and multiple fields. |
*/ |
- FileManager.prototype.selectFilesAndClose_ = function(selection) { |
+ FileManager.prototype.doSelectFilesAndClose_ = function(selection) { |
if (!this.isOnGData()) { |
setTimeout(this.callSelectFilesApiAndClose_.bind(this, selection), 0); |
return; |
@@ -4080,6 +4149,25 @@ FileManager.prototype = { |
}; |
/** |
+ * Does selection urls list preprocessing and calls |doSelectFilesAndClose_|. |
+ * |
+ * @param {Object} selection Contains urls, filterIndex and multiple fields. |
+ */ |
+ FileManager.prototype.selectFilesAndClose_ = function(selection) { |
+ if (this.directoryModel_.isOnGDataSearchDir()) { |
+ var self = this; |
+ var gdataRootUrl = this.directoryModel_.getCurrentRootDirEntry().toURL(); |
+ util.resolveGDataSearchUrls(selection.urls, gdataRootUrl, |
+ function(resolved) { |
+ selection.urls = resolved; |
+ self.doSelectFilesAndClose_(selection); |
+ }); |
+ return; |
+ } |
+ this.doSelectFilesAndClose_(selection); |
+ }; |
+ |
+ /** |
* Handle a click of the ok button. |
* |
* The ok button has different UI labels depending on the type of dialog, but |
@@ -4088,7 +4176,7 @@ FileManager.prototype = { |
* @param {Event} event The click event. |
*/ |
FileManager.prototype.onOk_ = function(event) { |
- var currentDirUrl = this.getCurrentDirectoryURL(); |
+ 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.
|
if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') |
currentDirUrl += '/'; |
@@ -4150,7 +4238,7 @@ FileManager.prototype = { |
continue; |
} |
- files.push(currentDirUrl + encodeURIComponent(entry.name)); |
+ files.push(entry.toURL()); |
} |
// Multi-file selection has no other restrictions. |
@@ -4296,15 +4384,8 @@ 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; |
- }); |
- } else { |
- this.directoryModel_.removeFilter('searchbox'); |
- } |
+ this.directoryModel_.search(searchString); |
+ this.updateOkButton_(); |
}; |
FileManager.prototype.decorateSplitter = function(splitterElement) { |