Bug 322259: Can't select directories with Browse button for "Log Folder" preference, patch by Robert Marshall (tH) <rdmsoft@bugs.rdmsoft.com>, r=Silver

This commit is contained in:
gavin%gavinsharp.com 2006-02-20 16:37:04 +00:00
parent 3382cef4c5
commit ba481a8d51
2 changed files with 43 additions and 10 deletions

View File

@ -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")

View File

@ -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.