mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 10:00:54 +00:00
Bug 393247: Downloads no longer remember last download directory, patch by Jim Mathies <jmathies@mozilla.com>, r=me
This commit is contained in:
parent
9592967dc1
commit
8bd796a0b1
@ -178,8 +178,10 @@ var gMainPane = {
|
||||
* True if the Download Manager should be closed when all downloads
|
||||
* complete, false if it should be left open.
|
||||
* browser.download.useDownloadDir - bool
|
||||
* True if downloads are saved with no save-as UI shown, false if
|
||||
* the user should always be asked where to save a file.
|
||||
* True - Save files directly to the folder configured via the
|
||||
* browser.download.folderList preference.
|
||||
* False - Always ask the user where to save a file and default to
|
||||
* browser.download.lastDir when displaying a folder picker dialog.
|
||||
* browser.download.dir - local file handle
|
||||
* A local folder the user may have selected for downloaded files to be
|
||||
* saved. Migration of other browser settings may also set this path.
|
||||
|
@ -457,24 +457,22 @@ function getTargetFile(aFpP, aSkipPrompt)
|
||||
var useDownloadDir = prefs.getBoolPref("useDownloadDir");
|
||||
var dir = null;
|
||||
|
||||
try {
|
||||
// On prompt operations, default to lastDir, on direct to folder
|
||||
// downloads, default to the user's configured download folder.
|
||||
// (right-click save image vs. drag-and-drop into download manager)
|
||||
// Default to lastDir if useDownloadDir is false, and lastDir
|
||||
// is configured and valid. Otherwise, use the user's default
|
||||
// downloads directory configured through download prefs.
|
||||
var dnldMgr = Components.classes["@mozilla.org/download-manager;1"]
|
||||
.getService(Components.interfaces.nsIDownloadManager);
|
||||
try {
|
||||
var lastDir = prefs.getComplexValue("lastDir", nsILocalFile);
|
||||
var dnldMgr = Components.classes["@mozilla.org/download-manager;1"]
|
||||
.getService(Components.interfaces.nsIDownloadManager);
|
||||
if (!aSkipPrompt) {
|
||||
if (!useDownloadDir && lastDir.exists())
|
||||
dir = lastDir;
|
||||
} else {
|
||||
else
|
||||
dir = dnldMgr.userDownloadsDirectory;
|
||||
}
|
||||
} catch (ex) {
|
||||
} catch(ex) {
|
||||
dir = dnldMgr.userDownloadsDirectory;
|
||||
}
|
||||
|
||||
if (!aSkipPrompt || !useDownloadDir || !dir || (dir && !dir.exists())) {
|
||||
// If we're asking the user where to save the file, root the Save As...
|
||||
// dialog on the place they last picked.
|
||||
if (!dir || (dir && !dir.exists())) {
|
||||
// Default to desktop.
|
||||
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
|
@ -184,11 +184,20 @@ nsUnknownContentTypeDialog.prototype = {
|
||||
|
||||
picker.appendFilters( nsIFilePicker.filterAll );
|
||||
|
||||
// Get the default download directory from download manager
|
||||
// Default to lastDir if it's valid, use the user's default
|
||||
// downloads directory otherwise.
|
||||
var dnldMgr = Components.classes["@mozilla.org/download-manager;1"]
|
||||
.getService(Components.interfaces.nsIDownloadManager);
|
||||
var startDir = dnldMgr.defaultDownloadsDirectory;
|
||||
picker.displayDirectory = startDir;
|
||||
try {
|
||||
var lastDir = prefs.getComplexValue("browser.download.lastDir",
|
||||
Components.interfaces.nsILocalFile);
|
||||
if (lastDir.exists())
|
||||
picker.displayDirectory = lastDir;
|
||||
else
|
||||
picker.displayDirectory = dnldMgr.userDownloadsDirectory;
|
||||
} catch (ex) {
|
||||
picker.displayDirectory = dnldMgr.userDownloadsDirectory;
|
||||
}
|
||||
|
||||
if (picker.show() == nsIFilePicker.returnCancel) {
|
||||
// null result means user cancelled.
|
||||
@ -210,7 +219,7 @@ nsUnknownContentTypeDialog.prototype = {
|
||||
}
|
||||
catch (e) { }
|
||||
var newDir = result.parent;
|
||||
prefs.setComplexValue("browser.download.dir", Components.interfaces.nsILocalFile, newDir);
|
||||
prefs.setComplexValue("browser.download.lastDir", Components.interfaces.nsILocalFile, newDir);
|
||||
result = this.validateLeafName(newDir, result.leafName, null);
|
||||
}
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user