From 7ad0f586df805d1aa242aa6b35eae44cd419316b Mon Sep 17 00:00:00 2001 From: "mgalli%geckonnection.com" Date: Tue, 14 Feb 2006 06:54:09 +0000 Subject: [PATCH] Updates sync with branch. --- minimo/customization/HelperAppDlg.js | 51 ++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/minimo/customization/HelperAppDlg.js b/minimo/customization/HelperAppDlg.js index 536006dc517..6e02eef71c3 100755 --- a/minimo/customization/HelperAppDlg.js +++ b/minimo/customization/HelperAppDlg.js @@ -3,8 +3,6 @@ const nsIFilePicker = Components.interfaces.nsIFilePicker; const nsIHelperAppLauncherDialog = Components.interfaces.nsIHelperAppLauncherDialog; const nsISupports = Components.interfaces.nsISupports; -function DLProgressListener() {} - function HelperAppDlg() { } @@ -27,6 +25,38 @@ HelperAppDlg.prototype = { promptForSaveToFile: function(aLauncher, aContext, aDefaultFile, aSuggestedFileExtension) { var result = ""; + const prefSvcContractID = "@mozilla.org/preferences-service;1"; + const prefSvcIID = Components.interfaces.nsIPrefService; + const nsIFile = Components.interfaces.nsIFile; + + var folderDirFile = Components.classes["@mozilla.org/file/local;1"].createInstance(nsIFile); + + var branch = Components.classes[prefSvcContractID].getService(prefSvcIID) + .getBranch("browser.download."); + var dir = null; + + const nsILocalFile = Components.interfaces.nsILocalFile; + const kDownloadDirPref = "dir"; + // Try and pull in download directory pref + try { + + var dirStringPath=branch.getCharPref(kDownloadDirPref); + var localFileDir = folderDirFile.QueryInterface(nsILocalFile); + dir = localFileDir.initWithPath(dirStringPath); + + //dir = branch.getComplexValue(kDownloadDirPref, nsILocalFile); + + } catch (e) { } + + if (dir && dir.exists()) + { + if (aDefaultFile == "") + aDefaultFile = "download"; + + dir.append(aDefaultFile); + return uniqueFile(dir); + } + // Use file picker to show dialog. var picker = Components.classes[ "@mozilla.org/filepicker;1" ] .createInstance( nsIFilePicker ); @@ -36,6 +66,23 @@ HelperAppDlg.prototype = { picker.init( parent, null, nsIFilePicker.modeSave ); picker.defaultString = aDefaultFile; + + if (aSuggestedFileExtension) { + // aSuggestedFileExtension includes the period, so strip it + picker.defaultExtension = aSuggestedFileExtension.substring(1); + } else { + try { + picker.defaultExtension = aLauncher.MIMEInfo.primaryExtension; + } catch (ex) { + } + } + + var wildCardExtension = "*"; + if ( aSuggestedFileExtension ) { + wildCardExtension += aSuggestedFileExtension; + picker.appendFilter( wildCardExtension, wildCardExtension ); + } + picker.appendFilters( nsIFilePicker.filterAll ); if (picker.show() == nsIFilePicker.returnCancel || !picker.file) {