[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 236/483: When configuring hotkeys, ignore the ones that are already taken
David Prévot
taffit at moszumanska.debian.org
Thu Jan 22 21:41:44 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus-element-hiding-helper.
commit 7dda0b3e070ea6d0fca9d7513cd01d488545bd47
Author: Wladimir Palant <trev at adblockplus.org>
Date: Fri Oct 22 16:53:08 2010 +0200
When configuring hotkeys, ignore the ones that are already taken
---
chrome/content/overlay.xul | 6 +--
modules/AppIntegration.jsm | 127 ++++++++++++++++++++++++++++++++++-----------
2 files changed, 101 insertions(+), 32 deletions(-)
diff --git a/chrome/content/overlay.xul b/chrome/content/overlay.xul
index bf2ead9..3115326 100644
--- a/chrome/content/overlay.xul
+++ b/chrome/content/overlay.xul
@@ -50,11 +50,11 @@
</popupset>
<popup id="abp-status-popup">
- <menuitem id="abp-status-ehh-selectelement" hidden="true" insertbefore="abp-status-options" label="&selectelement.label;" accesskey="&selectelement.accesskey;" key="ehh-key-selectelement"/>
- <menuitem id="abp-status-ehh-stopselection" hidden="true" insertbefore="abp-status-options" label="&stopselection.label;" accesskey="&stopselection.accesskey;" key="ehh-key-selectelement"/>
+ <menuitem id="abp-status-ehh-selectelement" hidden="true" insertbefore="abp-status-options" label="&selectelement.label;" accesskey="&selectelement.accesskey;" command="ehh-command-selectelement" key="ehh-key-selectelement"/>
+ <menuitem id="abp-status-ehh-stopselection" hidden="true" insertbefore="abp-status-options" label="&stopselection.label;" accesskey="&stopselection.accesskey;" command="ehh-command-selectelement" key="ehh-key-selectelement"/>
</popup>
<commandset id="abp-commandset">
- <command id="ehh-command-selectelement"/>
+ <command id="ehh-command-selectelement" oncommand="//"/>
</commandset>
</overlay>
diff --git a/modules/AppIntegration.jsm b/modules/AppIntegration.jsm
index a66b52e..c199137 100644
--- a/modules/AppIntegration.jsm
+++ b/modules/AppIntegration.jsm
@@ -46,11 +46,19 @@ function WindowWrapper(wnd)
this.window = wnd;
this.registerEventListeners();
- this.configureKeys();
+
+ let me = this;
+ this.configureTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+ this.configureTimer.initWithCallback(function()
+ {
+ me.configureTimer = null;
+ me.configureKeys();
+ }, 1000, Ci.nsITimer.TYPE_ONE_SHOT);
}
WindowWrapper.prototype =
{
window: null,
+ configureTimer: null,
_bindMethod: function(method)
{
@@ -90,13 +98,76 @@ WindowWrapper.prototype =
configureKeys: function()
{
+ let validModifiers =
+ {
+ accel: "accel",
+ ctrl: "control",
+ control: "control",
+ shift: "shift",
+ alt: "alt",
+ meta: "meta",
+ __proto__: null
+ };
+
+ try
+ {
+ let accelKey = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).getIntPref("ui.key.accelKey");
+ if (accelKey == Ci.nsIDOMKeyEvent.DOM_VK_CONTROL)
+ validModifiers.ctrl = validModifiers.control = "accel";
+ else if (accelKey == Ci.nsIDOMKeyEvent.DOM_VK_ALT)
+ validModifiers.alt = "accel";
+ else if (accelKey == Ci.nsIDOMKeyEvent.DOM_VK_META)
+ validModifiers.meta = "accel";
+ }
+ catch(e)
+ {
+ Cu.reportError(e);
+ }
+
+ // Find which hotkeys are already taken, convert them to canonical form
+ let existing = {};
+ let keys = this.window.document.getElementsByTagName("key");
+ for (let i = 0; i < keys.length; i++)
+ {
+ let key = keys[i];
+ let keyChar = key.getAttribute("key");
+ let keyCode = key.getAttribute("keycode");
+ if (!keyChar && !keyCode)
+ continue;
+
+ let modifiers = [];
+ let seenModifier = {__proto__: null};
+ let keyModifiers = key.getAttribute("modifiers");
+ if (keyModifiers)
+ {
+ for each (let modifier in keyModifiers.match(/\w+/g))
+ {
+ modifier = modifier.toLowerCase();
+ if (!(modifier in validModifiers))
+ continue;
+
+ modifier = validModifiers[modifier];
+ if (modifier in seenModifier)
+ continue;
+
+ seenModifier[modifier] = true;
+ modifiers.push(modifier);
+ }
+ modifiers.sort();
+
+ let canonical = modifiers.concat([(keyChar || keyCode).toUpperCase()]).join(" ");
+ existing[canonical] = true;
+ }
+ }
+
+ // Define our keys
for (let pref in Prefs)
{
if (/_key$/.test(pref) && typeof Prefs[pref] == "string")
{
try
{
- this.configureKey(RegExp.leftContext, Prefs[pref]);
+ this.configureKey(RegExp.leftContext, Prefs[pref], validModifiers, existing);
}
catch (e)
{
@@ -106,47 +177,49 @@ WindowWrapper.prototype =
}
},
- configureKey: function(id, value)
+ configureKey: function(id, value, validModifiers, existing)
{
- let validModifiers =
- {
- accel: "accel",
- ctrl: "control",
- control: "control",
- shift: "shift",
- alt: "alt",
- meta: "meta"
- };
-
let command = this.E("ehh-command-" + id);
if (!command)
return;
let modifiers = [];
+ let seenModifier = {__proto__: null};
let keychar = null;
let keycode = null;
for each (let part in value.split(/\s+/))
{
if (part.toLowerCase() in validModifiers)
+ {
+ if (part in seenModifier)
+ continue;
+
+ seenModifier[part] = true;
modifiers.push(validModifiers[part.toLowerCase()]);
+ }
else if (part.length == 1)
- keychar = part;
+ keychar = part.toUpperCase();
else if ("DOM_VK_" + part.toUpperCase() in Ci.nsIDOMKeyEvent)
keycode = "VK_" + part.toUpperCase();
}
if (keychar || keycode)
{
- let element = this.window.document.createElement("key");
- element.setAttribute("id", "ehh-key-" + id);
- element.setAttribute("command", "ehh-command-" + id);
- if (keychar)
- element.setAttribute("key", keychar);
- else
- element.setAttribute("keycode", keycode);
- element.setAttribute("modifiers", modifiers.join(","));
-
- this.E("abp-keyset").appendChild(element);
+ modifiers.sort();
+ let canonical = modifiers.concat([keychar || keycode]).join(" ");
+ if (!(canonical in existing))
+ {
+ let element = this.window.document.createElement("key");
+ element.setAttribute("id", "ehh-key-" + id);
+ element.setAttribute("command", "ehh-command-" + id);
+ if (keychar)
+ element.setAttribute("key", keychar);
+ else
+ element.setAttribute("keycode", keycode);
+ element.setAttribute("modifiers", modifiers.join(","));
+
+ this.E("abp-keyset").appendChild(element);
+ }
}
},
@@ -224,9 +297,5 @@ WindowWrapper.prototype =
WindowWrapper.prototype.eventHandlers = [
["abp-status-popup", "popupshowing", WindowWrapper.prototype.fillPopup],
["abp-toolbar-popup", "popupshowing", WindowWrapper.prototype.fillPopup],
- ["abp-status-ehh-selectelement", "command", WindowWrapper.prototype.toggleSelection],
- ["abp-status-ehh-stopselection", "command", WindowWrapper.prototype.toggleSelection],
- ["abp-toolbar-ehh-selectelement", "command", WindowWrapper.prototype.toggleSelection],
- ["abp-toolbar-ehh-stopselection", "command", WindowWrapper.prototype.toggleSelection],
- ["abp-command-ehh-selectelement", "command", WindowWrapper.prototype.toggleSelection],
+ ["ehh-command-selectelement", "command", WindowWrapper.prototype.toggleSelection],
];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus-element-hiding-helper.git
More information about the Pkg-mozext-commits
mailing list