[Pkg-mozext-commits] [itsalltext] 274/459: Yay! Hotkeys!
David Prévot
taffit at moszumanska.debian.org
Tue Feb 24 23:26:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository itsalltext.
commit 7f09497251fd487ea659654fec39f29054eb6cc3
Author: docwhat at gerf.org <docwhat at gerf.org>
Date: Mon Oct 1 16:54:33 2007 -0400
Yay! Hotkeys!
---
src/chrome/content/cacheobj.js | 22 +++++++++---
src/chrome/content/itsalltext.js | 65 ++++++++++++++++++++++++++++++++--
src/chrome/content/preferences.js | 28 +++++++++++++++
src/chrome/content/preferences.xul | 11 ++++++
src/defaults/preferences/itsalltext.js | 1 +
5 files changed, 120 insertions(+), 7 deletions(-)
diff --git a/src/chrome/content/cacheobj.js b/src/chrome/content/cacheobj.js
index b12e501..7678bf9 100644
--- a/src/chrome/content/cacheobj.js
+++ b/src/chrome/content/cacheobj.js
@@ -495,6 +495,19 @@ CacheObj.prototype.update = function() {
};
/**
+ * Capture keypresses to do the hotkey edit.
+ */
+CacheObj.prototype.keypress = function(event) {
+ var km = ItsAllText.marshalKeyEvent(event), cobj;
+ if (km === ItsAllText.preferences.hotkey) {
+ cobj = ItsAllText.getCacheObj(event.target);
+ cobj.edit();
+ event.stopPropagation();
+ }
+ return false;
+};
+
+/**
* The function to execute when a gumdrop is clicked.
* @param {Object} event The event that triggered this.
*/
@@ -542,10 +555,11 @@ CacheObj.prototype.addGumDrop = function() {
// Add the textarea mouseovers even if the button is disabled
var node = cache_object.node;
- node.addEventListener( "mouseover", cache_object.mouseover, false);
- node.addEventListener( "mouseout", cache_object.mouseout, false);
- node.addEventListener( "focus", cache_object.mouseover, false);
- node.addEventListener( "blur", cache_object.mouseout, false);
+ node.addEventListener( "mouseover", cache_object.mouseover, false);
+ node.addEventListener( "mouseout", cache_object.mouseout, false);
+ node.addEventListener( "focus", cache_object.mouseover, false);
+ node.addEventListener( "blur", cache_object.mouseout, false);
+ node.addEventListener( "keypress", cache_object.keypress, false);
if (ItsAllText.getDisableGumdrops()) {
return;
}
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index 9de25d1..f0db7c9 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -21,7 +21,7 @@
// @todo [9] IDEA: dropdown list for charsets (utf-8, western-iso, default)?
// @todo [wish] Have a menu/context menu item for turning on monitoring/watch.
// @todo [9] Menu item to pick the file to load into a textarea.
-// @todo [9] Hot-keys for editing or opening the context menu.
+// @todo [9] IDEA: Hot-keys opening the context menu.
var ItsAllText = function() {
/**
@@ -219,7 +219,7 @@ var ItsAllText = function() {
if (real_type === 'Float') {
value = '' + parseFloat(value);
}
- po.private_branch['set'+type+'Pref'](aData);
+ po.private_branch['set'+type+'Pref'](aData, value);
}
};
@@ -239,7 +239,8 @@ var ItsAllText = function() {
debug: 'Bool',
gumdrop_position: 'Char',
fade_time: 'Float',
- extensions: 'Char'
+ extensions: 'Char',
+ hotkey: 'Char'
},
/**
@@ -536,6 +537,64 @@ var ItsAllText = function() {
return pos;
};
+
+ /**
+ * marshals a keypress event.
+ */
+ that.marshalKeyEvent = function(event) {
+ var marshal = [
+ event.altKey ? 1 : 0,
+ event.ctrlKey ? 1 : 0,
+ event.metaKey ? 1 : 0,
+ event.shiftKey ? 1 : 0,
+ event.charCode,
+ event.keyCode
+ ];
+ marshal = marshal.join(':');
+ if (marshal === '0:0:0:0:0:0') {
+ return '';
+ } else {
+ return marshal;
+ }
+ };
+
+ /**
+ * Converts a marshalled key event into a string.
+ */
+ that.keyMarshalToString = function(km) {
+ var e = km.split(':');
+ var out = [];
+ var c = parseInt(e[5], 10);
+ if (e[0] === '1') {
+ out.push('alt');
+ }
+ if (e[1] === '1') {
+ out.push('ctrl');
+ }
+ if (e[2] === '1') {
+ out.push('meta');
+ }
+ if (e[3] === '1') {
+ out.push('shift');
+ }
+ if (e[4] === '0') {
+ switch (c) {
+ case 8: out.push('Backspace'); break;
+ case 9: out.push('Tab'); break;
+ case 27: out.push('Escape'); break;
+ case 33: out.push('PgUp'); break;
+ case 34: out.push('PgDn'); break;
+ case 35: out.push('End'); break;
+ case 36: out.push('Home'); break;
+ case 46: out.push('Delete'); break;
+ default: out.push('code:'+c); break;
+ }
+ } else {
+ out.push(String.fromCharCode(e[4]).toUpperCase());
+ }
+ return out.join(' ');
+ };
+
/**
* This function is called regularly to watch changes to web documents.
*/
diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index 924ef90..9406653 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -41,6 +41,32 @@ function pref_editor_select() {
}
}
+function pref_grab(disp, e) {
+ e.preventDefault();
+ var km = ItsAllText.marshalKeyEvent(e);
+ if (km === '0:0:0:0:0:8' || // Backspace
+ km === '0:0:0:0:0:27' || // Escape
+ km === '0:0:0:0:0:46') { // Del
+ km = '';
+ }
+ ItsAllText.preferences.private_set('hotkey', km);
+ update_hotkey(disp);
+}
+
+function update_hotkey(disp) {
+ var str, km = ItsAllText.preferences.hotkey;
+ if (typeof(km) === 'undefined') {
+ setTimeout(function () { update_hotkey(disp); }, 100);
+ return;
+ }
+ if (km === '') {
+ str = '<none>';
+ } else {
+ str = ItsAllText.keyMarshalToString(km);
+ }
+ document.getElementById(disp).value = str;
+}
+
function setHelp(text) {
var help = document.getElementById('help');
while (help.firstChild) {
@@ -78,4 +104,6 @@ function pref_onload() {
desc.style.maxWidth = '18em';
box.appendChild(desc);
}
+
+ update_hotkey('disp-hotkey');
}
diff --git a/src/chrome/content/preferences.xul b/src/chrome/content/preferences.xul
index c31ee09..6df983c 100644
--- a/src/chrome/content/preferences.xul
+++ b/src/chrome/content/preferences.xul
@@ -9,6 +9,7 @@
onload="pref_onload();">
<script type="application/x-javascript" src="preferences.js"/>
+<script type="application/x-javascript" src="itsalltext.js"/>
<stringbundleset id="strbundles">
<stringbundle id="strings" src="chrome://itsalltext/locale/preferences.properties"/>
@@ -31,6 +32,8 @@
name="extensions.itsalltext.gumdrop_position" type="string"/>
<preference id="pref_fade_time"
name="extensions.itsalltext.fade_time" type="string"/>
+ <preference id="pref_hotkey"
+ name="extensions.itsalltext.hotkey" type="string"/>
<preference id="pref_debug"
name="extensions.itsalltext.debug" type="bool"/>
</preferences>
@@ -100,6 +103,14 @@
<spacer/>
</hbox>
</row>
+ <row align="hotkey">
+ <label value="Hot Key"/>
+ <hbox>
+ <textbox id="disp-hotkey"
+ onkeypress="pref_grab('disp-hotkey', event);"/>
+ <spacer/>
+ </hbox>
+ </row>
<row align="center">
<label control="debug"
value="&debug.label;"/>
diff --git a/src/defaults/preferences/itsalltext.js b/src/defaults/preferences/itsalltext.js
index c8e6168..8c9a35d 100644
--- a/src/defaults/preferences/itsalltext.js
+++ b/src/defaults/preferences/itsalltext.js
@@ -5,3 +5,4 @@ pref("extensions.itsalltext.fade_time", '2.3');
pref("extensions.itsalltext.debug", false);
pref("extensions.itsalltext.gumdrop_position", 'lower-right');
pref("extensions.itsalltext.extensions", '.txt,.html,.css,.xml,.xsl,.js');
+pref("extensions.itsalltext.hotkey", '');
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git
More information about the Pkg-mozext-commits
mailing list