From b8085941dcef34d3032ca68d5114193653c80e3d Mon Sep 17 00:00:00 2001 From: "gavin@gavinsharp.com" Date: Tue, 4 Sep 2007 09:21:34 -0700 Subject: [PATCH] Bug 393247: Downloads no longer remember last download directory, patch by Jim Mathies , r=me --- browser/components/preferences/main.js | 6 +++-- toolkit/content/contentAreaUtils.js | 22 +++++++++---------- .../downloads/src/nsHelperAppDlg.js.in | 17 ++++++++++---- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/browser/components/preferences/main.js b/browser/components/preferences/main.js index ab2d8ceb6c3..1066f01b138 100644 --- a/browser/components/preferences/main.js +++ b/browser/components/preferences/main.js @@ -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. diff --git a/toolkit/content/contentAreaUtils.js b/toolkit/content/contentAreaUtils.js index 7d6ef5bb14b..04dd0f4ed7f 100644 --- a/toolkit/content/contentAreaUtils.js +++ b/toolkit/content/contentAreaUtils.js @@ -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"] diff --git a/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in b/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in index e60bf2a1f4d..41b10c9e268 100644 --- a/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in +++ b/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in @@ -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;