diff --git a/extensions/irc/js/lib/file-utils.js b/extensions/irc/js/lib/file-utils.js index c44286622b7b..4266e20b337f 100644 --- a/extensions/irc/js/lib/file-utils.js +++ b/extensions/irc/js/lib/file-utils.js @@ -96,13 +96,18 @@ function futils_nosepicker(initialPath, typeList, attribs) const nsILocalFile = interfaces.nsILocalFile; var picker = classes[PICKER_CTRID].createInstance(nsIFilePicker); - if (typeof attribs == "object") + if (attribs) { - for (var a in attribs) - picker[a] = attribs[a]; + if (typeof attribs == "object") + { + for (var a in attribs) + picker[a] = attribs[a]; + } + else + { + throw "bad type for param |attribs|"; + } } - else - throw "bad type for param |attribs|"; if (initialPath) { @@ -241,6 +246,23 @@ function pickOpen (title, typeList, defaultFile, defaultDir) return {reason: rv, file: picker.file, picker: picker}; } +function pickGetFolder(title, defaultDir) +{ + if (!defaultDir && "lastOpenDir" in futils) + defaultDir = futils.lastOpenDir; + + var picker = futils.getPicker(defaultDir); + picker.init(window, title ? title : futils.MSG_OPEN, + Components.interfaces.nsIFilePicker.modeGetFolder); + + var rv = picker.show(); + + if (rv != PICK_CANCEL) + futils.lastOpenDir = picker.file; + + return {reason: rv, file: picker.file, picker: picker}; +} + function mkdir (localFile, perms) { if (typeof perms == "undefined") diff --git a/extensions/irc/xul/content/config.js b/extensions/irc/xul/content/config.js index 4e310dbc2bad..68cbcf27d1c4 100755 --- a/extensions/irc/xul/content/config.js +++ b/extensions/irc/xul/content/config.js @@ -590,6 +590,7 @@ function pdata_loadXUL() // We're cheating again here, if it ends "filename" it's // a local file path. var type = (this.name.match(/filename$/i) ? "file" : "fileurl"); + type = (this.name.match(/folder$/i) ? "folder" : type); appendButton(this.box, "onPrefBrowse", { label: MSG_PREFS_BROWSE, spec: ext, kind: type }); @@ -1354,14 +1355,24 @@ function pwin_onPrefBrowse(button) if (button.hasAttribute("spec")) spec = button.getAttribute("spec") + " " + spec; - var rv = pickOpen(MSG_PREFS_BROWSE_TITLE, spec); + var type = button.getAttribute("kind"); + var edit = button.previousSibling.lastChild; + + var rv; + if (type == "folder") + { + var current = getFileFromURLSpec(edit.value); + rv = pickGetFolder(MSG_PREFS_BROWSE_TITLE, current); + } + else + { + rv = pickOpen(MSG_PREFS_BROWSE_TITLE, spec); + } + if (rv.reason != PICK_OK) return; - var data = { file: rv.file.path, fileurl: rv.picker.fileURL.spec }; - var edit = button.previousSibling.lastChild; - var type = button.getAttribute("kind"); - edit.value = data[type]; + edit.value = (type == "file") ? rv.file.path : rv.picker.fileURL.spec; }, // Selection changed on listbox.