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

Unified Diff: chrome/browser/resources/file_manager/js/directory_model.js

Issue 10342010: Add gdata content search to file_manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style nits Created 8 years, 8 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/directory_model.js
diff --git a/chrome/browser/resources/file_manager/js/directory_model.js b/chrome/browser/resources/file_manager/js/directory_model.js
index 3c0416f2b14e14e5588d0257f1d5f5569c466679..50b1425f97ae064b422a3d94e36e92b417a6d9f4 100644
--- a/chrome/browser/resources/file_manager/js/directory_model.js
+++ b/chrome/browser/resources/file_manager/js/directory_model.js
@@ -57,6 +57,14 @@ function DirectoryModel(root, singleSelection, showGData, metadataCache) {
* @type {Object.<string, boolean>}
*/
this.volumeReadOnlyStatus_ = {};
+
+ /**
+ * File path of the last directory that is not under virtual search directory.
+ * This is the path to go to when the search box content clears on GData.
+ * @private
+ * @type {string}
+ */
+ this.lastNonGDataSearchDirPath_ = null;
}
/**
@@ -179,6 +187,16 @@ DirectoryModel.prototype.isSystemDirectory = function() {
};
/**
+ * Tests if the entry is a gdata search result entry.
+ * @param {entry} entry Entry to test.
+ * @return {boolean} Result.
+ */
+DirectoryModel.prototype.isGDataSearchResult = function(entry) {
+ return (util.getFileAndDisplayNameForGDataSearchResult(entry.fullPath) !=
+ null);
+};
+
+/**
* @return {boolean} If the files with names starting with "." are not shown.
*/
DirectoryModel.prototype.isFilterHiddenOn = function() {
@@ -497,6 +515,18 @@ DirectoryModel.prototype.prefetchCacheForSorting_ = function(entries,
};
/**
+ * Gets name that should be dispalyed in the UI for the entry.
+ * @param {string} path Full path of the entry whose display name we are
+ * getting.
+ * @param {string} defaultName Default name to use if no name is calculated.
+ * @return {string} Name to be used for display.
+ */
+DirectoryModel.prototype.getDisplayName = function(path, defaultName) {
+ var searchResultName = util.getFileAndDisplayNameForGDataSearchResult(path);
+ return searchResultName ? searchResultName.displayName : defaultName;
+};
+
+/**
* Delete the list of files and directories from filesystem and
* update the file list.
* @param {Array.<Entry>} entries Entries to delete.
@@ -597,25 +627,41 @@ DirectoryModel.prototype.renameEntry = function(entry, newName, errorCallback,
var index = fileList.indexOf(entry);
if (index >= 0)
fileList.splice(index, 1, newEntry);
- self.selectEntry(newName);
+ self.selectEntry(newEntry.name);
// If the entry doesn't exist in the list it mean that it updated from
// outside (probably by directory rescan).
if (opt_successCallback)
opt_successCallback();
});
}
- entry.moveTo(this.currentDirEntry_, newName, onSuccess, errorCallback);
+
+ // If we are renaming gdata search result, we'll have to format newName to
+ // use in file system operation like: <resource_id>.<file_name>.
+ var searchResultName =
+ util.getFileAndDisplayNameForGDataSearchResult(entry.fullPath);
+ var newNameToUse =
+ searchResultName ? searchResultName.resourceId + '.' + newName : newName;
+
+ entry.moveTo(this.currentDirEntry_, newNameToUse, onSuccess, errorCallback);
};
/**
* Checks if current directory contains a file or directory with this name.
+ * @param {string} entry Entry to which newNAme will be given.
* @param {string} newName Name to check.
* @param {function(boolean, boolean?)} callback Called when the result's
* available. First parameter is true if the entry exists and second
* is true if it's a file.
*/
-DirectoryModel.prototype.doesExist = function(newName, callback) {
- util.resolvePath(this.currentDirEntry_, newName,
+DirectoryModel.prototype.doesExist = function(entry, newName, callback) {
+ // If we are looking for gdata search result, we'll have to format newName to
+ // use in file system operation like: <resource_id>.<file_name>.
+ var searchResultName =
+ util.getFileAndDisplayNameForGDataSearchResult(entry.fullPath);
+ var newNameToUse =
+ searchResultName ? searchResultName.resourceId + '.' + newName : newName;
SeRya 2012/05/07 14:06:00 Code duplication. Create a method.
tbarzic 2012/05/10 03:20:47 Done.
+
+ util.resolvePath(this.currentDirEntry_, newNameToUse,
function(entry) {
callback(true, entry.isFile);
},
@@ -666,7 +712,7 @@ DirectoryModel.prototype.changeDirectory = function(path) {
}.bind(this), function(error) {
console.error('Error changing directory to ' + path + ': ', error);
});
-}
+};
/**
* Resolves absolute directory path. Handles GData stub.
@@ -1113,6 +1159,40 @@ DirectoryModel.prototype.prepareUnmount = function(rootPath) {
};
/**
+ * Performs search and displays results. The search type is dependent on the
+ * current directory. If we are currently on gdata, server side content search
+ * over gdata mount point. If the current directory is not on the gdata, file
+ * name search over current directory wil be performed.
+ *
+ * @param {string} query Query that will be searched for.
+ */
+DirectoryModel.prototype.search = function(query) {
+ if (this.getCurrentRootPath() == '/' + DirectoryModel.GDATA_DIRECTORY) {
+ if (query) {
+ var currentDirPath = this.currentDirEntry_.fullPath;
+ if (currentDirPath.search(util.GDATA_SEARCH_ROOT_PATH) != 0)
+ this.lastNonGDataSearchDirPath_ = currentDirPath;
+ this.changeDirectory(util.createGDataSearchPath(query));
+ } else {
+ var newDirPath = this.lastNonGDataSearchDirPath_ ||
+ '/' + DirectoryModel.GDATA_DIRECTORY;
+ this.lastNonGDataSearchDirPath_;
SeRya 2012/05/07 14:06:00 As I mentioned before I don't think that changing
tbarzic 2012/05/10 03:20:47 Yep, this is much cleaner, thanks for suggestion ;
+ this.changeDirectory(newDirPath);
+ }
+ } else {
+ if (query) {
+ this.addFilter(
+ 'searchbox',
+ function(e) {
+ return e.name.substring(0, query.length) == query;
+ });
+ } else {
+ this.directoryModel_.removeFilter('searchbox');
+ }
+ }
+};
+
+/**
* @param {string} path Any path.
* @return {string} The root path.
*/

Powered by Google App Engine
This is Rietveld 408576698