Bug 332532 - file-utils.js is unfair on embedders

ChatZilla Only
r=silver
This commit is contained in:
gijskruitbosch%gmail.com 2006-04-29 22:45:17 +00:00
Родитель a1170c5cc8
Коммит 19315e5acc
3 изменённых файлов: 40 добавлений и 40 удалений

Просмотреть файл

@ -188,6 +188,32 @@ function futils_nosepicker(initialPath, typeList, attribs)
return picker;
}
function getPickerChoice(picker)
{
var obj = new Object();
obj.picker = picker;
obj.ok = false;
obj.file = null;
try
{
obj.reason = picker.show();
}
catch (ex)
{
dd ("caught exception from file picker: " + ex);
return obj;
}
if (obj.reason != PICK_CANCEL)
{
obj.file = picker.file;
obj.ok = true;
}
return obj;
}
function pickSaveAs (title, typeList, defaultFile, defaultDir, defaultExt)
{
if (!defaultDir && "lastSaveAsDir" in futils)
@ -199,33 +225,11 @@ function pickSaveAs (title, typeList, defaultFile, defaultDir, defaultExt)
picker.init (window, title ? title : futils.MSG_SAVE_AS,
Components.interfaces.nsIFilePicker.modeSave);
var reason;
try
{
reason = picker.show();
}
catch (ex)
{
dd ("caught exception from file picker: " + ex);
}
var obj = new Object();
obj.reason = reason;
obj.picker = picker;
if (reason != PICK_CANCEL)
{
obj.file = picker.file;
var rv = getPickerChoice(picker);
if (rv.ok)
futils.lastSaveAsDir = picker.file.parent;
}
else
{
obj.file = null;
}
return obj;
return rv;
}
function pickOpen (title, typeList, defaultFile, defaultDir)
@ -238,12 +242,11 @@ function pickOpen (title, typeList, defaultFile, defaultDir)
picker.init (window, title ? title : futils.MSG_OPEN,
Components.interfaces.nsIFilePicker.modeOpen);
var rv = picker.show();
if (rv != PICK_CANCEL)
var rv = getPickerChoice(picker);
if (rv.ok)
futils.lastOpenDir = picker.file.parent;
return {reason: rv, file: picker.file, picker: picker};
return rv;
}
function pickGetFolder(title, defaultDir)
@ -255,12 +258,11 @@ function pickGetFolder(title, defaultDir)
picker.init(window, title ? title : futils.MSG_OPEN,
Components.interfaces.nsIFilePicker.modeGetFolder);
var rv = picker.show();
if (rv != PICK_CANCEL)
var rv = getPickerChoice(picker);
if (rv.ok)
futils.lastOpenDir = picker.file;
return {reason: rv, file: picker.file, picker: picker};
return rv;
}
function mkdir (localFile, perms)

Просмотреть файл

@ -3316,7 +3316,7 @@ function cmdSave(e)
dialogTitle = getMsg(MSG_SAVE_DIALOGTITLE, e.sourceObject.viewName);
rv = pickSaveAs(dialogTitle, TYPELIST, e.sourceObject.viewName +
".html");
if (rv.file == null)
if (!rv.ok)
return;
saveType = rv.picker.filterIndex;
file = rv.file;
@ -3786,7 +3786,7 @@ function cmdDCCSend(e)
if (!e.file)
{
var pickerRv = pickOpen(MSG_DCCFILE_SEND);
if (pickerRv.reason == PICK_CANCEL)
if (!pickerRv.ok)
return false;
file = pickerRv.file;
}
@ -4044,7 +4044,7 @@ function cmdDCCAccept(e)
var pickerRv = pickSaveAs(getMsg(MSG_DCCFILE_SAVE_TO, filename),
["$all", ext], filename);
if (pickerRv.reason == PICK_CANCEL)
if (!pickerRv.ok)
return false;
if (!c.accept(pickerRv.file))

Просмотреть файл

@ -35,10 +35,8 @@
* ***** END LICENSE BLOCK ***** */
const MEDIATOR_CONTRACTID = "@mozilla.org/appshell/window-mediator;1";
const FILEPICKER_CONTRACTID = "@mozilla.org/filepicker;1";
const nsIWindowMediator = Components.interfaces.nsIWindowMediator;
const nsIFilePicker = Components.interfaces.nsIFilePicker;
const CONFIG_WINDOWTYPE = "irc:chatzilla:config";
@ -1370,7 +1368,7 @@ function pwin_onPrefBrowse(button)
rv = pickOpen(MSG_PREFS_BROWSE_TITLE, spec);
}
if (rv.reason != PICK_OK)
if (!rv.ok)
return;
edit.value = (type == "file") ? rv.file.path : rv.picker.fileURL.spec;
@ -1481,7 +1479,7 @@ function pwin_onPrefListAdd(object)
var spec = "$all";
var rv = pickOpen(MSG_PREFS_BROWSE_TITLE, spec);
if (rv.reason == PICK_OK)
if (rv.ok)
{
var data = { file: rv.file.path, fileurl: rv.picker.fileURL.spec };
var kind = list.getAttribute("kind");