Chromium Code Reviews| 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 9713bdba96589860c8a007f97dc9fb7682bbe5b9..74828a0aa93c5001b5397c064987aa3f86ac6be1 100644 |
| --- a/chrome/browser/resources/file_manager/js/directory_model.js |
| +++ b/chrome/browser/resources/file_manager/js/directory_model.js |
| @@ -525,10 +525,25 @@ DirectoryModel.prototype = { |
| this.dispatchEvent(e); |
| }, |
| - setupPath: function(path, opt_pathResolveCallback) { |
| + /** |
| + * Change the state of the model to reflect the specified path (either a |
| + * file or directory). |
| + * |
| + * @param {string} path The root path to use |
| + * @param {function} opt_loadedCallback Invoked when the entire directory has |
|
arv (Not doing code reviews)
2012/02/28 20:26:32
{Function=}
Rick Byers
2012/02/28 20:35:00
Done.
|
| + * been loaded. |
|
arv (Not doing code reviews)
2012/02/28 20:26:32
indent
Rick Byers
2012/02/28 20:35:00
Done.
|
| + * @param {function} opt_pathResolveCallback Invoked as soon as the path has |
| + * been resolved, and called with the base and leaf portions of the path name. |
| + */ |
| + setupPath: function(path, opt_loadedCallback, opt_pathResolveCallback) { |
| // Split the dirname from the basename. |
| var ary = path.match(/^(?:(.*)\/)?([^\/]*)$/); |
| - var autoSelect = this.selectIndex.bind(this, this.autoSelectIndex_); |
| + var autoSelect = function() { |
| + this.selectIndex(this.autoSelectIndex_); |
| + if (opt_loadedCallback) |
| + opt_loadedCallback(); |
| + }.bind(this); |
| + |
| if (!ary) { |
| console.warn('Unable to split default path: ' + path); |
| this.changeDirectoryEntry_(this.root_, autoSelect, true); |
| @@ -538,7 +553,7 @@ DirectoryModel.prototype = { |
| var baseName = ary[1]; |
| var leafName = ary[2]; |
| - function callBack() { |
| + function resolvedCallback() { |
| if (opt_pathResolveCallback) |
| opt_pathResolveCallback(baseName, leafName); |
| } |
| @@ -547,20 +562,23 @@ DirectoryModel.prototype = { |
| if (leafEntry.isDirectory) { |
| baseName = path; |
| leafName = ''; |
| - callBack(); |
| + resolvedCallback(); |
| this.changeDirectoryEntry_(leafEntry, autoSelect, true); |
| return; |
| } |
| - callBack(); |
| + resolvedCallback(); |
| // Leaf is an existing file, cd to its parent directory and select it. |
| - this.changeDirectoryEntry_(baseDirEntry, |
| - this.selectEntry.bind(this, leafEntry.name), |
| - true); |
| + var loadedCallback = function() { |
| + this.selectEntry(leafEntry.name); |
| + if (opt_loadedCallback) |
| + opt_loadedCallback(); |
| + }.bind(this); |
| + this.changeDirectoryEntry_(baseDirEntry, loadedCallback, true); |
| } |
| function onLeafError(baseDirEntry, err) { |
| - callBack(); |
| + resolvedCallback(); |
| // Usually, leaf does not exist, because it's just a suggested file name. |
| if (err != FileError.NOT_FOUND_ERR) |
| console.log('Unexpected error resolving default leaf: ' + err); |
| @@ -568,16 +586,16 @@ DirectoryModel.prototype = { |
| } |
| var onBaseError = function(err) { |
| - callBack(); |
| + resolvedCallback(); |
| console.log('Unexpected error resolving default base "' + |
| baseName + '": ' + err); |
| if (path != '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { |
| // Can't find the provided path, let's go to default one instead. |
| - this.setupDefaultPath(); |
| + this.setupDefaultPath(opt_loadedCallback); |
| } else { |
| // Well, we can't find the downloads dir. Let's just show something, |
| // or we will get an infinite recursion. |
| - this.changeDirectory('/', undefined, true); |
| + this.changeDirectory('/', opt_loadedCallback, true); |
| } |
| }.bind(this); |
| @@ -606,8 +624,10 @@ DirectoryModel.prototype = { |
| } |
| }, |
| - setupDefaultPath: function() { |
| - this.getDefaultDirectory_(this.setupPath.bind(this)); |
| + setupDefaultPath: function(opt_callback) { |
| + this.getDefaultDirectory_(function(path) { |
| + this.setupPath(path, opt_callback); |
| + }.bind(this)); |
| }, |
| getDefaultDirectory_: function(callback) { |
| @@ -738,7 +758,7 @@ DirectoryModel.prototype = { |
| append.bind(this, 'removables')); |
| }, |
| - updateRoots: function(opt_changeDirectoryTo) { |
| + updateRoots: function(opt_callback) { |
| var self = this; |
| this.resolveRoots_(function(rootEntries) { |
| var dm = self.rootsList_; |
| @@ -746,9 +766,8 @@ DirectoryModel.prototype = { |
| dm.splice.apply(dm, args); |
| self.updateRootsListSelection_(); |
| - |
| - if (opt_changeDirectoryTo) |
| - self.changeDirectory(opt_changeDirectoryTo); |
| + if (opt_callback) |
| + opt_callback(); |
| }); |
| }, |