Last Comment Bug 673669 - XUL should provide a keyboard shortcut input element
: XUL should provide a keyboard shortcut input element
Status: UNCONFIRMED
:
Product: Core
Classification: Components
Component: XUL (show other bugs)
: unspecified
: All All
-- enhancement (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
: Neil Deakin
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-07-23 00:34 PDT by Jens Müller (:tessarakt)
Modified: 2011-07-23 17:58 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Options dialog of Quicker Filer 0.5.1 - page for keyboard settings. (145.31 KB, image/png)
2011-07-23 00:34 PDT, Jens Müller (:tessarakt)
no flags Details

Description User image Jens Müller (:tessarakt) 2011-07-23 00:34:52 PDT
Created attachment 547900 [details]
Options dialog of Quicker Filer 0.5.1 - page for keyboard settings.

XUL should provide an input element for defining an accelerator key. There does not seem to be such a feature, at least I could not find documentation for any such thing.

This bug is much more narrow than bug 57805. It's a bit like https://bugzilla.mozilla.org/show_bug.cgi?id=57805#c30 - an "recorder" element.

I had this idea when looking at the Quicker Filer addon for Thunderbird: https://addons.mozilla.org/en-us/thunderbird/addon/quicker-filer/. It has a whole page in its options dialog to _define_ keyboard shortcuts and save them in preferences. I attach a screenshot. The UI is needlessly complicated - it requires the user to select the key (and the modifiers) from dropdown lists. It would be a lot easier if the user could just _type_ the desired key.

Implementing this functionality would require:

1. Providing an XUL element. Actually, I have no idea what a good name would be.

2. Defining what the values look like. The idea would be to have _one_ value, which you could directly connect to a preference like https://developer.mozilla.org/en/XUL/textbox#a-preference. I guess connecting one input element to _two_ preferences would be kind of weird.

It should then be possible to directly assign this value to a <key> element in another script (e.g., an onLoad handler), or define a keyboard shortcut in some other way. For example, Quicker Filer has the following in its overlay to Thunderbirds main window:

        <keyset>
                <key id="quickerfiler_key_move"    oncommand="sQuickerFilerMessengerOverlay.openDialog('move');" modifiers="alt" key="q" />
                <key id="quickerfiler_key_copy"    oncommand="sQuickerFilerMessengerOverlay.openDialog('copy');" />
                <key id="quickerfiler_key_insmove" oncommand="sQuickerFilerMessengerOverlay.openDialog('insmove');" />
                <key id="quickerfiler_key_inscopy" oncommand="sQuickerFilerMessengerOverlay.openDialog('inscopy');" />
                <key id="quickerfiler_key_selfolder" oncommand="sQuickerFilerMessengerOverlay.openDialog('selfolder');"  modifiers="alt" key="r" />
        </keyset>

In an onload handler, it loads the shortcuts from the preferences and sets them like this:

el.setAttribute('key', key);
el.setAttribute('modifiers', modifiers);
el.setAttribute('disabled', 'false');

I guess a property should be added to https://developer.mozilla.org/en/XUL/key to directly set the key and modifiers attributes based on the string one gets from the new input element.

As said, more complex mechanisms to customize key bindings are beyond the scope of this enhancement request.
Comment 1 User image Dave Garrett 2011-07-23 17:48:15 PDT
For what it's worth, adding this sort of thing to an options dialog doesn't have to be quite as messy as your example. I wrote a simple shortcut detector field which I use in the Flagfox action configuration dialogs. It works just like you'd expect; select the field then press the hotkey combination and it shows it and can be saved. It handles alt, ctrl, shift, and meta (where available) or any combination thereof and clears on backspace.

One thing it doesn't do is validate the hotkey combo to make sure it's not used as a Firefox shortcut somewhere else. (I just check for ctrl+a/z/x/c/v and setting it automatically checks other actions to remove it if already used in Flagfox) If there was a built-in XUL widget that not only recorded shortcuts easily but also made sure it wasn't declared elsewhere, that would be quite nice to have. Not having to handle the mappings manually either would be a big improvement as well.

Note You need to log in before you can comment on or make changes to this bug.