まず、options.xul を変更してid
、後で選択できるように属性を追加します。属性は不要なoncommand
ので、削除できます。
<setting type="control" title="&passwordBtn;">
<button id="password" label="&passwordBtn;" />
</setting>
次に、設定パネルが開いているのを聞いて、クリックされたイベントリスナーをボタンに手動で追加します。以下はbootstrap.jsの例です
const log = function() { dump(Array.slice(arguments).join(' ') + '\n'); }
const {classes: Cc, interfaces: Ci} = Components;
const OBS = Cc['@mozilla.org/observer-service;1']
.getService(Ci.nsIObserverService);
const myAddonId = 'my_addon_id' // same as install.rdf "<em:id>" tag value
let optionObserver = {
observe: function(subject, topic, data) {
if (topic !== 'addon-options-displayed' || data !== myAddonId) {
return;
}
let document = subject.QueryInterface(Ci.nsIDOMDocument);
let button = document.getElementById('password');
button.addEventListener('command', this.changePassword);
},
changePassword: function(event) {
log('password button clicked!');
// do your stuff...
}
}
let install = function(data, reason) {};
let uninstall = function(data, reason) {};
let startup = function(data, reason) {
OBS.addObserver(optionObserver, 'addon-options-displayed', false);
};
let shutdown = function(data, reason) {
OBS.removeObserver(optionObserver, 'addon-options-displayed', false);
};