Commit 129fab37 authored by serya@chromium.org's avatar serya@chromium.org

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
parent c6ac7589
...@@ -1411,7 +1411,9 @@ FileManager.prototype = { ...@@ -1411,7 +1411,9 @@ FileManager.prototype = {
} }
// Leaf is an existing file, cd to its parent directory and select it. // 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) { function onLeafError(err) {
...@@ -1513,29 +1515,24 @@ FileManager.prototype = { ...@@ -1513,29 +1515,24 @@ FileManager.prototype = {
return; return;
} }
function checkCount() { // Start one fake wait to prevent calling the callback twice.
if (uncachedCount == 0) { var waitCount = 1;
// Callback via a setTimeout so the sync/async semantics don't change for (var i = 0; i < entries.length ; i++) {
// based on whether or not the value is cached.
setTimeout(callback, 0);
}
}
var uncachedCount = entries.length;
for (var i = uncachedCount - 1; i >= 0 ; i--) {
var entry = entries[i]; var entry = entries[i];
if (field in entry) { if (!(field in entry)) {
uncachedCount--; waitCount++;
} else { cacheFunction(entry, onCacheDone)
cacheFunction(entry, function() {
uncachedCount--;
checkCount();
});
} }
} }
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 = { ...@@ -2633,19 +2630,23 @@ FileManager.prototype = {
* @param {string} path The absolute path to the new directory. * @param {string} path The absolute path to the new directory.
* @param {bool} opt_saveHistory Save this in the history stack (defaults * @param {bool} opt_saveHistory Save this in the history stack (defaults
* to true). * to true).
* @param {string} opt_selectedEntry The name of the file to select after * @param {function} opt_action Action executed when the directory loaded.
* changing directories. * By default selects the first item
* (unless it's a save dialog).
*/ */
FileManager.prototype.changeDirectoryEntry = function(dirEntry, FileManager.prototype.changeDirectoryEntry = function(dirEntry,
opt_saveHistory, opt_saveHistory,
opt_selectedEntry, opt_action) {
opt_callback) {
if (typeof opt_saveHistory == 'undefined') { if (typeof opt_saveHistory == 'undefined') {
opt_saveHistory = true; opt_saveHistory = true;
} else { } else {
opt_saveHistory = !!opt_saveHistory; 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 + '#' + var location = document.location.origin + document.location.pathname + '#' +
encodeURI(dirEntry.fullPath); encodeURI(dirEntry.fullPath);
if (opt_saveHistory) { if (opt_saveHistory) {
...@@ -2661,10 +2662,8 @@ FileManager.prototype = { ...@@ -2661,10 +2662,8 @@ FileManager.prototype = {
if (this.currentDirEntry_ && if (this.currentDirEntry_ &&
this.currentDirEntry_.fullPath == dirEntry.fullPath) { this.currentDirEntry_.fullPath == dirEntry.fullPath) {
// Directory didn't actually change. // Directory didn't actually change.
if (opt_selectedEntry) if (opt_action)
this.selectEntry(opt_selectedEntry); opt_action();
else
this.selectIndex(0);
return; return;
} }
...@@ -2672,8 +2671,7 @@ FileManager.prototype = { ...@@ -2672,8 +2671,7 @@ FileManager.prototype = {
e.previousDirEntry = this.currentDirEntry_; e.previousDirEntry = this.currentDirEntry_;
e.newDirEntry = dirEntry; e.newDirEntry = dirEntry;
e.saveHistory = opt_saveHistory; e.saveHistory = opt_saveHistory;
e.selectedEntry = opt_selectedEntry; e.opt_callback = action;
e.opt_callback = opt_callback;
this.currentDirEntry_ = dirEntry; this.currentDirEntry_ = dirEntry;
this.dispatchEvent(e); this.dispatchEvent(e);
} }
...@@ -2692,22 +2690,16 @@ FileManager.prototype = { ...@@ -2692,22 +2690,16 @@ FileManager.prototype = {
* changing directories. * changing directories.
*/ */
FileManager.prototype.changeDirectory = function(path, FileManager.prototype.changeDirectory = function(path,
opt_saveHistory, opt_saveHistory) {
opt_selectedEntry,
opt_callback) {
if (path == '/') if (path == '/')
return this.changeDirectoryEntry(this.filesystem_.root, return this.changeDirectoryEntry(this.filesystem_.root,
opt_saveHistory, opt_saveHistory);
opt_selectedEntry,
opt_callback);
var self = this; var self = this;
this.filesystem_.root.getDirectory( this.filesystem_.root.getDirectory(
path, {create: false}, path, {create: false},
function(dirEntry) { function(dirEntry) {
self.changeDirectoryEntry( self.changeDirectoryEntry(dirEntry, opt_saveHistory);
dirEntry, opt_saveHistory, opt_selectedEntry, opt_callback);
}, },
function(err) { function(err) {
console.error('Error changing directory to: ' + path + ', ' + err); console.error('Error changing directory to: ' + path + ', ' + err);
...@@ -2719,7 +2711,7 @@ FileManager.prototype = { ...@@ -2719,7 +2711,7 @@ FileManager.prototype = {
} else { } else {
// If we've never successfully changed to a directory, force them // If we've never successfully changed to a directory, force them
// to the root. // to the root.
self.changeDirectory('/', false); self.changeDirectory('/', CD_NO_HISTORY);
} }
}); });
}; };
...@@ -3080,10 +3072,6 @@ FileManager.prototype = { ...@@ -3080,10 +3072,6 @@ FileManager.prototype = {
} }
this.rescanDirectory_(function() { this.rescanDirectory_(function() {
if (event.selectedEntry)
self.selectEntry(event.selectedEntry);
else
self.selectIndex(0);
if (event.opt_callback) { if (event.opt_callback) {
try { try {
event.opt_callback(); event.opt_callback();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment