summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorserya@chromium.org <serya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-06 16:32:22 +0000
committerserya@chromium.org <serya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-06 16:32:22 +0000
commit129fab37a7b8c6472412b7e41a9fe220052d9254 (patch)
tree47adf26b51fcbbfd8c0acdae0363b35d67014153 /chrome/browser
parentc6ac7589c2117ce8a4259265f30c5b621898e2d9 (diff)
downloadchromium_src-129fab37a7b8c6472412b7e41a9fe220052d9254.zip
chromium_src-129fab37a7b8c6472412b7e41a9fe220052d9254.tar.gz
chromium_src-129fab37a7b8c6472412b7e41a9fe220052d9254.tar.bz2
Not selecting first entry in the "File save" dialog.
TEST=None BUG=chromium-os:23767 Review URL: http://codereview.chromium.org/8822009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/resources/file_manager/js/file_manager.js76
1 files changed, 32 insertions, 44 deletions
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index af830bb..36befd4 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -1411,7 +1411,9 @@ FileManager.prototype = {
}
// Leaf is an existing file, cd to its parent directory and select it.
- self.changeDirectoryEntry(baseDirEntry, CD_NO_HISTORY, leafEntry.name);
+ self.changeDirectoryEntry(baseDirEntry, CD_NO_HISTORY, function() {
+ self.selectEntry(leafEntry.name);
+ });
}
function onLeafError(err) {
@@ -1513,29 +1515,24 @@ FileManager.prototype = {
return;
}
- function checkCount() {
- if (uncachedCount == 0) {
- // Callback via a setTimeout so the sync/async semantics don't change
- // based on whether or not the value is cached.
- setTimeout(callback, 0);
- }
- }
-
- var uncachedCount = entries.length;
-
- for (var i = uncachedCount - 1; i >= 0 ; i--) {
+ // Start one fake wait to prevent calling the callback twice.
+ var waitCount = 1;
+ for (var i = 0; i < entries.length ; i++) {
var entry = entries[i];
- if (field in entry) {
- uncachedCount--;
- } else {
- cacheFunction(entry, function() {
- uncachedCount--;
- checkCount();
- });
+ if (!(field in entry)) {
+ waitCount++;
+ cacheFunction(entry, onCacheDone)
}
}
+ onCacheDone(); // Finish the fake callback.
- checkCount();
+ function onCacheDone() {
+ waitCount--;
+ // If all caching functions finished synchronously or entries.length = 0
+ // call the callback synchronously.
+ if (waitCount == 0)
+ setTimeout(callback, 0);
+ }
}
/**
@@ -2633,19 +2630,23 @@ FileManager.prototype = {
* @param {string} path The absolute path to the new directory.
* @param {bool} opt_saveHistory Save this in the history stack (defaults
* to true).
- * @param {string} opt_selectedEntry The name of the file to select after
- * changing directories.
+ * @param {function} opt_action Action executed when the directory loaded.
+ * By default selects the first item
+ * (unless it's a save dialog).
*/
FileManager.prototype.changeDirectoryEntry = function(dirEntry,
opt_saveHistory,
- opt_selectedEntry,
- opt_callback) {
+ opt_action) {
if (typeof opt_saveHistory == 'undefined') {
opt_saveHistory = true;
} else {
opt_saveHistory = !!opt_saveHistory;
}
+ var action = opt_action ||
+ (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE ?
+ undefined : this.selectIndex.bind(this, 0));
+
var location = document.location.origin + document.location.pathname + '#' +
encodeURI(dirEntry.fullPath);
if (opt_saveHistory) {
@@ -2661,10 +2662,8 @@ FileManager.prototype = {
if (this.currentDirEntry_ &&
this.currentDirEntry_.fullPath == dirEntry.fullPath) {
// Directory didn't actually change.
- if (opt_selectedEntry)
- this.selectEntry(opt_selectedEntry);
- else
- this.selectIndex(0);
+ if (opt_action)
+ opt_action();
return;
}
@@ -2672,8 +2671,7 @@ FileManager.prototype = {
e.previousDirEntry = this.currentDirEntry_;
e.newDirEntry = dirEntry;
e.saveHistory = opt_saveHistory;
- e.selectedEntry = opt_selectedEntry;
- e.opt_callback = opt_callback;
+ e.opt_callback = action;
this.currentDirEntry_ = dirEntry;
this.dispatchEvent(e);
}
@@ -2692,22 +2690,16 @@ FileManager.prototype = {
* changing directories.
*/
FileManager.prototype.changeDirectory = function(path,
- opt_saveHistory,
- opt_selectedEntry,
- opt_callback) {
+ opt_saveHistory) {
if (path == '/')
return this.changeDirectoryEntry(this.filesystem_.root,
- opt_saveHistory,
- opt_selectedEntry,
- opt_callback);
+ opt_saveHistory);
var self = this;
-
this.filesystem_.root.getDirectory(
path, {create: false},
function(dirEntry) {
- self.changeDirectoryEntry(
- dirEntry, opt_saveHistory, opt_selectedEntry, opt_callback);
+ self.changeDirectoryEntry(dirEntry, opt_saveHistory);
},
function(err) {
console.error('Error changing directory to: ' + path + ', ' + err);
@@ -2719,7 +2711,7 @@ FileManager.prototype = {
} else {
// If we've never successfully changed to a directory, force them
// to the root.
- self.changeDirectory('/', false);
+ self.changeDirectory('/', CD_NO_HISTORY);
}
});
};
@@ -3080,10 +3072,6 @@ FileManager.prototype = {
}
this.rescanDirectory_(function() {
- if (event.selectedEntry)
- self.selectEntry(event.selectedEntry);
- else
- self.selectIndex(0);
if (event.opt_callback) {
try {
event.opt_callback();