views:

722

answers:

1

I have a firefox extension which can be activated by a shortcut key. I want users to be able to change the key combo dynamically.

My XUL looks like this

<keyset id="ksMain">
    <key id="keyDoMyThing" modifiers="control,shift" key="e" command="cmdDoMyThing"/>
</keyset>

cmdDoMyThing is a reference to an element in a commandset. When I press ctrl+shift+e, the command fires.

I tried both modifying the existing element and creating a new element using JavaScript, but while I can get the old key combo to stop working, I can't get the new one to happen. Here's an example of the code I'm using

keyelem = document.createElement('key');
keyelem.setAttribute('id', 'keyDoMyThing');
keyelem.setAttribute('command', 'cmdDoMyThing');
keyelem.setAttribute('key', key);
keyelem.setAttribute('modifiers', modstr);
keyset.appendChild(keyelem);

I can use the debugger to verify that modstr is set to the proper string and key is set to the key I want to use.

How can I make this happen the way I would like?

A: 

Turns out I need to delete the keyset as well and create an entirely new keyset.

ksparent = keyset.parentNode
ksparent.removeChild(keyset);

keyset = document.createElement('keyset');
keyset.id = 'my-keyset';

keyelem = document.createElement('key');
keyelem.setAttribute('id', 'keyDoMyThing');
keyelem.setAttribute('command', 'cmdDoMyThing');
keyelem.setAttribute('key', key);
keyelem.setAttribute('modifiers', modstr);

keyset.appendChild(keyelem);
ksparent.appendChild(keyset);

Once this is done, the new key combo will take effect.

Nathan
You mentioned a 'debugger'. Is it firebug you're using, or something else?
dalbaeb
Venkman, actually.
Nathan