Universal (and working) method for handling keyboard shortcuts in Zimbra Zimlets
You may have read my previous ramblings about the theme of handling keyboard shortcuts im Zimbra Zimlets. To sum up: it’s not easy. But that’s not actually a Zimbra bug. It’s more of an architectural problem. You can imagine Zimbra’s shortcut handling as a set of layers. There is a default key handler. That is the global key handler contained in the object „ZmZimbraMail“. It would be nice for this handler to support additional shortcuts, but it just can’t as of today. If you do something like an overlay application you can push another default handler on top of the default key handler and if you’re done with the overlay, you have to „pop“ (remove) the new default key handler, so that ZmZimbraMail becomes the default key handler again.
On top of this default key handling come controls. The control that is currently active is searched first for a matching key handler. If there isn’t found anything, the control’s parent is asked and so on. If none of the controls handle the key, the current default handler is asked. The only possibility to leverage this system would be to somehow extend Zimbra’s default key handler, but that currently doesn’t work (or is way to complicated and error-prone).
But there is another way. You can use Zimbra’s event handling system and just add another handler for the „KEYUP“ event. That way you will be noticed, once a key is pressed.
Hmm… Zimbra’s key handling (espescially the I18N-part) is quite cool, eh?
Well, some parts can be used and I have created an universal shortcut handler, that simply can be plugged into your zimlet. You can get it in my [[https://github.com/dploeger/attic/raw/master/de_dieploegers_shortcut/de_dieploegers_shortcutHandler.js|github attic repository]].
To use it, follow these steps:
First, include this script into your zimlet’s xml definition file:
Add shortcut definitions to your properties file consisting of a prefix, an actionCode and three keys:
* „description“ – Description of the key code (currently not used)
* „display“ – User-friendly display of the key code (currently not used)
* „keycode“ – Keycode of the shortcut. Consists of an optional meta-key label („Shift“, „Alt“, „Ctrl“ or „Meta“) and an ASCII-keycode, separated by „+“. So a key „a“ with a hold „Shift“-Key would be „Shift+65“
A complete definition could be:
SHORTCUT.DO_SOMETHING.description = Do something interesting
SHORTCUT.DO_SOMETHING.display = Shift + a
SHORTCUT.DO_SOMETHING.keycode = Shift+65
Please note, that the meta-key label is translated. So for a german properties file for example, use „Strg“ instead of „Ctrl“.
Add a „getKeyMapName“ method to your zimlet’s handler prototype returning the prefix of the shortcut definitions in your properties file.
For example:
my_cool_zimlethandler.prototype.getKeyMapName = function () {
return „SHORTCUT“;
}
Finally, In your zimlet’s handler init-method, create an object of this class and specify your zimlet’s I18N object. It’s typically identical to the name of your zimlet. (for example my_cool_zimlet) Additionally, specify a callback handler (created from AjxCallback), that is responsible to carry out the action, if certain keys are pressed. The callback handler is called with the actioncode as it’s only parameter. It is only called, if an actioncode is found for the pressed key sequence.
The script has limitations, though. Currently it doesn’t support multiple shortcut sequences, like Zimbra uses for marking messages read for example (first press „m“, after that press „r“). But I accept pull requests.
Calendar
M | D | M | D | F | S | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 |
Archive
- Januar 2024
- Dezember 2023
- April 2021
- März 2021
- September 2020
- Dezember 2019
- November 2019
- Oktober 2019
- Juli 2019
- Juni 2019
- Mai 2019
- April 2019
- März 2019
- September 2018
- August 2018
- Juli 2018
- März 2018
- Januar 2018
- Dezember 2017
- September 2017
- März 2017
- Februar 2017
- Januar 2017
- August 2016
- Mai 2016
- Dezember 2015
- November 2015
- August 2015
- März 2015
- Dezember 2014
- September 2014
- August 2014
- Juli 2014
- Februar 2014
- Oktober 2013
- September 2013
- August 2013
- Juli 2013
- Juni 2013
- Mai 2013
- April 2013
- November 2012
- Oktober 2012
- September 2012
- August 2012
- Juni 2012
- Mai 2012
- März 2012
- Februar 2012
- Januar 2012
- November 2011
- Juli 2011
- Juni 2011
- März 2011
- Februar 2011
- Januar 2011
- Dezember 2010
- November 2010
- April 2010
- Februar 2010