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

Unified 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 side-by-side diff with in-line comments
Download patch
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..eafe85bbb459541636e4d12424b82a68757afc47 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/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_
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/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
function inCurrentDirectory(entry) {
var fullPath = entry.fullPath;
var dirPath = fullPath.substr(0, fullPath.length -
@@ -1863,9 +1867,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 == '' ?
+ this.getRootLabel_(displayName) : displayName;
return fileName;
};
@@ -2816,7 +2823,7 @@ FileManager.prototype = {
selectedUrl = urls[0];
}
- var dirPath = this.directoryModel_.getCurrentDirEntry().fullPath;
+ 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.
// Push a temporary state which will be replaced every time an individual
// item is selected in the Gallery.
@@ -2830,7 +2837,7 @@ FileManager.prototype = {
// Gallery shoud treat GData folder as readonly even when online
// until we learn to save files directly to GData.
var readonly = self.isOnReadonlyDirectory() || self.isOnGData();
- var currentDir = self.directoryModel_.getCurrentDirEntry();
+ var currentDir = self.directoryModel_.getSearchOrCurrentDirEntry();
var downloadsDir = self.directoryModel_.getRootsList().item(0);
var gallerySelection;
@@ -2905,7 +2912,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 +3063,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();
+ };
+
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 +3303,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())) {
selectable = false;
} else {
selectable = !!this.filenameInput_.value;
@@ -3339,19 +3356,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;
+ self.directoryModel_.changeDirectory(changeToPath);
+ });
};
/**
@@ -3402,6 +3428,13 @@ FileManager.prototype = {
},
/**
+ * Updates search box value when directory gets changed.
+ */
+ FileManager.prototype.updateSearchBoxOnDirChange_ = function() {
+ this.dialogDom_.querySelector('#search-box').value = '';
+ },
+
+ /**
* Update the UI when the current directory changes.
*
* @param {cr.Event} event The directory-changed event.
@@ -3411,6 +3444,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 +3550,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())
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.
this.directoryModel_.rescanLater();
};
@@ -3596,8 +3630,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 +3642,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));
@@ -4088,7 +4125,7 @@ FileManager.prototype = {
* @param {Event} event The click event.
*/
FileManager.prototype.onOk_ = function(event) {
- var currentDirUrl = this.getCurrentDirectoryURL();
+ var currentDirUrl = this.getSearchOrCurrentDirectoryURL();
if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/')
currentDirUrl += '/';
@@ -4296,15 +4333,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) {

Powered by Google App Engine
This is Rietveld 408576698