www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit c73a0753d7eb9936978fdc2a054569172fb43f79
parent 3d9853acaa53be34f70bff30e11fe034a672bb8e
Author: Dan Stillman <dstillman@zotero.org>
Date:   Wed, 30 Apr 2014 15:06:35 -0400

Handle lowercase shortcut key pref values

Honor lowercase pref values for shortcut keys, and also always display
and set shortcut keys as uppercase in the preferences

Diffstat:
Mchrome/content/zotero/preferences/preferences_keys.js | 19+++++++++++++++++++
Mchrome/content/zotero/xpcom/zotero.js | 23++++++++++++++++-------
2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/chrome/content/zotero/preferences/preferences_keys.js b/chrome/content/zotero/preferences/preferences_keys.js @@ -32,5 +32,24 @@ Zotero_Preferences.Keys = { // Display the appropriate modifier keys for the platform rows[i].firstChild.nextSibling.value = Zotero.isMac ? Zotero.getString('general.keys.cmdShift') : Zotero.getString('general.keys.ctrlShift'); } + + var textboxes = document.getElementById('zotero-keys-rows').getElementsByTagName('textbox'); + for (let i=0; i<textboxes.length; i++) { + let textbox = textboxes[i]; + textbox.value = textbox.value.toUpperCase(); + // .value takes care of the initial value, and this takes care of direct pref changes + // while the window is open + textbox.setAttribute('onsyncfrompreference', 'return Zotero_Preferences.Keys.capitalizePref(this.id)'); + textbox.setAttribute('oninput', 'this.value = this.value.toUpperCase()'); + } + }, + + + capitalizePref: function (id) { + var elem = document.getElementById(id); + var pref = document.getElementById(elem.getAttribute('preference')); + if (pref.value) { + return pref.value.toUpperCase(); + } } }; diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -2420,17 +2420,17 @@ Zotero.Keys = new function() { * Called by Zotero.init() */ function init() { - var actions = Zotero.Prefs.prefBranch.getChildList('keys', {}, {}); + var cmds = Zotero.Prefs.prefBranch.getChildList('keys', {}, {}); // Get the key=>command mappings from the prefs - for each(var action in actions) { - var action = action.substr(5); // strips 'keys.' + for each(var cmd in cmds) { + cmd = cmd.substr(5); // strips 'keys.' // Remove old pref - if (action == 'overrideGlobal') { + if (cmd == 'overrideGlobal') { Zotero.Prefs.clear('keys.overrideGlobal'); continue; } - _keys[Zotero.Prefs.get('keys.' + action)] = action; + _keys[this.getKeyForCommand(cmd)] = cmd; } } @@ -2453,7 +2453,7 @@ Zotero.Keys = new function() { globalKeys.forEach(function (x) { let keyElem = document.getElementById('key_' + x.name); if (keyElem) { - let prefKey = Zotero.Prefs.get('keys.' + x.name); + let prefKey = this.getKeyForCommand(x.name); // Only override the default with the pref if the <key> hasn't // been manually changed and the pref has been if (keyElem.getAttribute('key') == x.defaultKey @@ -2462,7 +2462,7 @@ Zotero.Keys = new function() { keyElem.setAttribute('key', prefKey); } } - }); + }.bind(this)); } @@ -2470,6 +2470,15 @@ Zotero.Keys = new function() { key = key.toUpperCase(); return _keys[key] ? _keys[key] : false; } + + + this.getKeyForCommand = function (cmd) { + try { + var key = Zotero.Prefs.get('keys.' + cmd); + } + catch (e) {} + return key !== undefined ? key.toUpperCase() : false; + } }