Skip to content

Commit

Permalink
Set breadcrumbs for drive search to be drive root.
Browse files Browse the repository at this point in the history
DriveSearch content directory should be drive root since the search is done
over the whole drive.

Since change-directory is not dispatched when search starts, breadcrumbs should
be updated on scan-started.

TEST=manual
BUG=154742


Review URL: https://chromiumcodereview.appspot.com/11090030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161963 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tbarzic@chromium.org committed Oct 15, 2012
1 parent 5a6915c commit 5752e6b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
function BreadcrumbsController(div) {
this.bc_ = div;
this.hideLast_ = false;
this.rootPath_ = null;
this.path_ = null;
div.addEventListener('click', this.onClick_.bind(this));
}

Expand All @@ -32,8 +34,12 @@ BreadcrumbsController.prototype.setHideLast = function(value) {
* @param {string} path Path to directory.
*/
BreadcrumbsController.prototype.update = function(rootPath, path) {
if (path == this.path_)
return;

this.bc_.textContent = '';
this.rootPath_ = rootPath;
this.path_ = path;

var relativePath = path.substring(rootPath.length).replace(/\/$/, '');
var pathNames = relativePath.split('/');
Expand Down
51 changes: 45 additions & 6 deletions chrome/browser/resources/file_manager/js/directory_contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,19 @@ DirectoryContents.prototype.isSearch = function() {

/**
* @return {DirectoryEntry} A DirectoryEntry for current directory. In case of
* search -- the top directory from which search is run
* search -- the top directory from which search is run.
*/
DirectoryContents.prototype.getDirectoryEntry = function() {
throw 'Not implemented.';
};

/**
* @return {DirectoryEntry} A DirectoryEntry for the last non search contents.
*/
DirectoryContents.prototype.getLastNonSearchDirectoryEntry = function() {
throw 'Not implemented.';
};

/**
* @param {Entry} entry File entry for a file in current DC results.
* @return {string} Display name.
Expand Down Expand Up @@ -310,12 +317,19 @@ DirectoryContentsBasic.prototype.getPath = function() {
};

/**
* @return {DirectoryEntry?} DirectoryEntry of the current directory.
* @return {DirectoryEntry} DirectoryEntry of the current directory.
*/
DirectoryContentsBasic.prototype.getDirectoryEntry = function() {
return this.entry_;
};

/**
* @return {DirectoryEntry} DirectoryEntry for the currnet entry.
*/
DirectoryContentsBasic.prototype.getLastNonSearchDirectoryEntry = function() {
return this.entry_;
};

/**
* Start directory scan.
*/
Expand Down Expand Up @@ -397,12 +411,18 @@ DirectoryContentsGDataSearch.MAX_RESULTS = 999;
* @extends {DirectoryContents}
* @param {FileListContext} context File list context.
* @param {DirectoryEntry} dirEntry Current directory.
* @param {DirectoryEntry} previousDirEntry DirectoryEntry that was current
* before the search.
* @param {string} query Search query.
*/
function DirectoryContentsGDataSearch(context, dirEntry, query) {
function DirectoryContentsGDataSearch(context,
dirEntry,
previousDirEntry,
query) {
DirectoryContents.call(this, context);
this.query_ = query;
this.directoryEntry_ = dirEntry;
this.previousDirectoryEntry_ = previousDirEntry;
this.nextFeed_ = '';
this.done_ = false;
this.fetchedResultsNum_ = 0;
Expand Down Expand Up @@ -430,12 +450,22 @@ DirectoryContentsGDataSearch.prototype.isSearch = function() {
};

/**
* @return {DirectoryEntry} DirectoryEntry for current directory.
* @return {DirectoryEntry} A DirectoryEntry for the top directory from which
* search is run (i.e. drive root).
*/
DirectoryContentsGDataSearch.prototype.getDirectoryEntry = function() {
return this.directoryEntry_;
};

/**
* @return {DirectoryEntry} DirectoryEntry for the directory that was current
* before the search.
*/
DirectoryContentsGDataSearch.prototype.getLastNonSearchDirectoryEntry =
function() {
return this.previousDirectoryEntry_;
};

/**
* @return {string} The path.
*/
Expand Down Expand Up @@ -529,13 +559,22 @@ DirectoryContentsLocalSearch.prototype.isSearch = function() {
};

/**
* @return {DirectoryEntry} A DirectoryEntry for current directory. In case of
* search -- the top directory from which search is run
* @return {DirectoryEntry} A DirectoryEntry for the top directory from which
* search is run.
*/
DirectoryContentsLocalSearch.prototype.getDirectoryEntry = function() {
return this.directoryEntry_;
};

/**
* @return {DirectoryEntry} DirectoryEntry for current directory (the search is
* run from the directory that was current before search).
*/
DirectoryContentsLocalSearch.prototype.getLastNonSearchDirectoryEntry =
function() {
return this.directoryEntry_;
};

/**
* @param {Entry} entry File entry for a file in current DC results.
* @return {string} Display name.
Expand Down
20 changes: 9 additions & 11 deletions chrome/browser/resources/file_manager/js/directory_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,35 +1176,33 @@ DirectoryModel.prototype.search = function(query,
onClearSearch) {
query = query.trimLeft();

this.clearSearch_();

var newDirContents;
if (!query) {
if (this.isSearching()) {
newDirContents = new DirectoryContentsBasic(
this.currentFileListContext_,
this.currentDirContents_.getDirectoryEntry());
this.currentDirContents_.getLastNonSearchDirectoryEntry());
this.clearAndScan_(newDirContents);
this.clearSearch_();
}
return;
}

// If we already have event listener for an old search, we have to remove it.
if (this.onSearchCompleted_)
this.removeEventListener('scan-completed', this.onSearchCompleted_);

// Current search will be cancelled.
if (this.onClearSearch_)
this.onClearSearch_();

this.onSearchCompleted_ = onSearchRescan;
this.onClearSearch_ = onClearSearch;

this.addEventListener('scan-completed', this.onSearchCompleted_);

// If we are offline, let's fallback to file name search inside dir.
if (this.getCurrentRootType() === RootType.GDATA && !this.isOffline()) {
// GData search is performed over the whole drive, so pass drive root as
// |directoryEntry|.
newDirContents = new DirectoryContentsGDataSearch(
this.currentFileListContext_, this.getCurrentDirEntry(), query);
this.currentFileListContext_,
this.getSelectedRootDirEntry_(),
this.currentDirContents_.getLastNonSearchDirectoryEntry(),
query);
} else {
newDirContents = new DirectoryContentsLocalSearch(
this.currentFileListContext_, this.getCurrentDirEntry(), query);
Expand Down
21 changes: 11 additions & 10 deletions chrome/browser/resources/file_manager/js/file_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ FileManager.prototype = {
self.restoreItemBeingRenamed_();
self.currentList_.endBatchUpdates();
});
dm.addEventListener('scan-started', this.showSpinnerLater_.bind(this));
dm.addEventListener('scan-started', this.onScanStarted_.bind(this));
dm.addEventListener('scan-completed', this.showSpinner_.bind(this, false));
dm.addEventListener('scan-cancelled', this.hideSpinnerLater_.bind(this));
dm.addEventListener('scan-completed',
Expand Down Expand Up @@ -2935,9 +2935,6 @@ FileManager.prototype = {
*/
FileManager.prototype.onDirectoryChanged_ = function(event) {
this.updateOkButton_();
this.breadcrumbs_.update(
this.directoryModel_.getCurrentRootPath(),
this.directoryModel_.getCurrentDirPath());
this.updateColumnModel_();
this.updateSearchBoxOnDirChange_();

Expand Down Expand Up @@ -3123,19 +3120,23 @@ FileManager.prototype = {
}, 0);
};

FileManager.prototype.onScanStarted_ = function() {
this.breadcrumbs_.update(
this.directoryModel_.getCurrentRootPath(),
this.directoryModel_.getCurrentDirPath());

this.cancelSpinnerTimeout_();
this.showSpinnerTimeout_ =
setTimeout(this.showSpinner_.bind(this, true), 500);
};

FileManager.prototype.cancelSpinnerTimeout_ = function() {
if (this.showSpinnerTimeout_) {
clearTimeout(this.showSpinnerTimeout_);
this.showSpinnerTimeout_ = null;
}
};

FileManager.prototype.showSpinnerLater_ = function() {
this.cancelSpinnerTimeout_();
this.showSpinnerTimeout_ =
setTimeout(this.showSpinner_.bind(this, true), 500);
};

FileManager.prototype.hideSpinnerLater_ = function() {
setTimeout(this.showSpinner_.bind(this, false), 100);
};
Expand Down

0 comments on commit 5752e6b

Please sign in to comment.