Problem
In order to add user defined shortcut settings, we need a storage implementation that can easily be extended (so that extensions can add customization for their own shortcuts). The shortcuts used to be stored as a key-value translation pair. This system has quite some limitations when we want every user to be able to pick their own shortcuts. The main one is that as far as I know there’s no clear priority system for the same translation key with different values coming from different files (we’d need at least priority between the default and the user preference).
Proposed solution of storage
Instead of adding additional properties to the user object, I decided to store shortcut preferences in a different object. Those XWiki.UserPreferenceShortcutsClass
objects are contained on each user page.
Each UserPreferenceShortcut has two fields:
- a translationKey that contains the translation key used to store the shortcut. This translationkey model for shortcut is already implemented and IMO it’s okay to keep working with it as a fallback and its key as an unique identifier for each shortcut.
- a value that contains the value of the shortcut defined by the user, the one that would override the default provided at the wiki level
In order to make it work properly, we expect the shortcut preference object to be on the page of the user it’s defined for. Moving them around would break them.
UserPreferenceShortcuts are udpated live when the user edits their profile preferences.
If a preference is set to be empty, the shortcut will be unbound (no way to activate the action from the keyboard). If a preference is set to be the same value as the default value (the one from the translation), the UserPreferenceShortcuts is removed. There is only one UserPreferenceShortcuts per user per translationKey. There might be as much UserPreferenceShortcuts as there are shortcuts for each user. By default, there is no UserPreferenceShortcuts on a user profile.
This model allows to keep the amount of stored data to a minimum, there are no field stored that do not contain any information.
Conclusion
What do you think of this implementation for the storage of user shortcut preferences?
Do you think another solution would be more appropriate? Did you spot a weakness in this implementation that should be addressed?
Thank you in advance for your feedback and help!
Lucas C.
Extra resources
You can view the whole implementation proposal at https://design.xwiki.org/xwiki/bin/view/Proposal/Implementinguserpreferenceshortcuts . The position of this UI has been discussed on Shortcut settings position . The design is under discussion at XWIKI-16216: Allow users to rebind the shortcuts from their user profile UI by Sereza7 · Pull Request #2981 · xwiki/xwiki-platform · GitHub .
2 posts - 2 participants