Bug 1349538 - JSONView should not open more than 1 filePicker at the same time, r=honza

This commit is contained in:
Andrea Marchesini 2017-03-28 13:30:34 +02:00
parent bc21c019f3
commit 2f37beddea
2 changed files with 15 additions and 6 deletions

View File

@ -51,10 +51,8 @@ var JsonView = {
*/
onSave: function (message) {
JsonViewUtils.getTargetFile().then(file => {
if (file) {
JsonViewUtils.saveToFile(file, message.data);
}
});
JsonViewUtils.saveToFile(file, message.data);
}, () => {});
}
};

View File

@ -19,11 +19,20 @@ const OPEN_FLAGS = {
EXCL: parseInt("0x80", 16)
};
let filePickerShown = false;
/**
* Open File Save As dialog and let the user to pick proper file location.
*/
exports.getTargetFile = function () {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
if (filePickerShown) {
reject(null);
return;
}
filePickerShown = true;
let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
let win = getMostRecentBrowserWindow();
@ -34,10 +43,12 @@ exports.getTargetFile = function () {
fp.filterIndex = 0;
fp.open(rv => {
filePickerShown = false;
if (rv == Ci.nsIFilePicker.returnOK || rv == Ci.nsIFilePicker.returnReplace) {
resolve(fp.file);
} else {
resolve(null);
reject(null);
}
});
});