My addon creates a Panel
, which shows currently selected preferences for the addon.
I'd like to populate the Panel
with a button
, who's onclick()
event creates a dialog allowing user to specify which directory to save files in.
This was possible with the XUL based addons but the same code does not work within an sdk based addon as window
is not accessible.
Any ways around this?
Within the addon code, I create the Panel
using:
var confirmDialog = require("sdk/panel").Panel({
width: 250,
height: 250,
contentURL: data.url("confirmDialog.html"),
});
confirmDialog.port.on("selectDir", function () {
chromeManager.selectDir();
});
confirmDialog.html
specifies the Panel
's content:
<div id="pathToFile"></div>
<button onclick="Panel.selectDir();">
</button>
confirmDialog.js
sends message to addon code:
var Panel = {
selectDir: function() {
addon.port.emit("selectDir", '');
}
};
chromeManager.js
is part of the addon code, so it has access to the sdk API.
exports.selectDir = function() {
var nsIFilePicker = Ci.nsIFilePicker,
fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
fp.init(window, nsIFilePicker.modeGetFolder);
var ret = fp.show();
if (ret == nsIFilePicker.returnOK || ret == nsIFilePicker.returnReplace) {
document.getElementById('pathToFile').value = fp.file.path;
}
}
However I get ReferenceError: window is not defined
when running this code, is there any way to make window
accessible here or an alternative way to do this?