From 30614ad556d954b3fb11b476795ce762a38b4c8a Mon Sep 17 00:00:00 2001 From: "noririty%jcom.home.ne.jp" Date: Mon, 21 Jul 2003 04:16:59 +0000 Subject: [PATCH] Fix 178227 'Clearing Download Manager History doesn't work', Fix 195388 'Can not manually edit Download directory path' patch by mconnor@rogers.com --- .../prefwindow/content/pref-navigator.js | 45 +++++++++++++++++++ .../prefwindow/content/pref-navigator.xul | 9 ++-- .../prefwindow/content/pref-privacy.js | 8 +++- .../locale/prefutilities.properties | 5 +++ 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/browser/components/prefwindow/content/pref-navigator.js b/browser/components/prefwindow/content/pref-navigator.js index 34f3acf0b7bc..75b285bd6638 100644 --- a/browser/components/prefwindow/content/pref-navigator.js +++ b/browser/components/prefwindow/content/pref-navigator.js @@ -99,6 +99,51 @@ function onOK() { } } +// check download directory is valid +function checkDownloadDirectory() { + var dloadDir = Components.classes["@mozilla.org/file/local;1"] + .createInstance(Components.interfaces.nsILocalFile); + if (!dloadDir) return false; + + var givenValue = document.getElementById("defaultDir"); + var downloadDir = document.getElementById("downloadDir"); + if (downloadDir.selectedItem == document.getElementById("alwaysAskRadio")) { return; } + + try { + dloadDir.initWithPath(givenValue.value); + dloadDir.isDirectory(); + } + catch(ex) { + var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService); + var prefbundle = document.getElementById("bundle_prefutilities"); + + if ( givenValue.value == "" ) { // no directory, reset back to Always Ask + downloadDir.selectedItem = document.getElementById("alwaysAskRadio"); + } else { + var checkValue = {value:false}; + + var title = prefbundle.getString("downloadDirTitle"); + var description = prefbundle.getFormattedString("invalidDirPopup", [givenValue.value]); + var buttonPressed = promptService.confirmEx(window, + title, description, + (promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) + + (promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1), + null, null, null, null, checkValue); + + if (buttonPressed != 0) { + // they don't want to create the directory + return; + } + try { + dloadDir.create(1,0777); + } catch(ex) { + alert( prefbundle.getFormattedString("invalidDir", [givenValue.value]) ); + } + } + } +} + function Startup() { if (top.opener) { diff --git a/browser/components/prefwindow/content/pref-navigator.xul b/browser/components/prefwindow/content/pref-navigator.xul index f328cbe1e249..47eb869b8b3b 100644 --- a/browser/components/prefwindow/content/pref-navigator.xul +++ b/browser/components/prefwindow/content/pref-navigator.xul @@ -67,8 +67,10 @@ .createInstance(nsIFilePicker); var pref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); - // XXXBlake Localize! - fp.init(window, "Select Download Directory:", nsIFilePicker.modeGetFolder); + + var prefbundle = document.getElementById("bundle_prefutilities"); + var description = prefbundle.getString("downloadDirTitle"); + fp.init(window, description, nsIFilePicker.modeGetFolder); try { var initialDir = pref.getComplexValue("browser.download.dir", nsILocalFile); @@ -235,7 +237,8 @@ - +