[PATCH] Add facility to toggle between values to preferences too

7 views
Skip to first unread message

Raghavendra Prabhu

unread,
Apr 19, 2011, 10:57:22 AM4/19/11
to dactyl-...@googlegroups.com
# HG changeset patch
# User Raghavendra Prabhu <rpr...@wnohang.net>
# Date 1303224646 -19800
# Node ID bfbc5892e589f35b0480ba3e3f16b4980cdd1577
# Parent dcecb134ba9f3508868bcc387e95d5e4014d9c3d
Add facility to toggle between values to preferences too.

The inv("!=") option to toggle among values is available only to dactyl
settings at the moment. This commit extends it to firefox preferences as
well.

diff -r dcecb134ba9f -r bfbc5892e589 common/modules/options.jsm
--- a/common/modules/options.jsm Thu Apr 14 23:03:11 2011 -0400
+++ b/common/modules/options.jsm Tue Apr 19 20:20:46 2011 +0530
@@ -1064,8 +1064,12 @@
modules.commandline.commandOutput(prefs.list(onlyNonDefault, ""));
else if (reset)
prefs.reset(name);
- else if (invertBoolean)
- prefs.toggle(name);
+ else if (invertBoolean) {
+ if (valueGiven)
+ prefs.toggle(name,Option.dequote(value));
+ else
+ prefs.toggle(name);
+ }
else if (valueGiven) {
if (value == undefined)
value = "";
diff -r dcecb134ba9f -r bfbc5892e589 common/modules/prefs.jsm
--- a/common/modules/prefs.jsm Thu Apr 14 23:03:11 2011 -0400
+++ b/common/modules/prefs.jsm Tue Apr 19 20:20:46 2011 +0530
@@ -286,10 +286,19 @@
*
* @param {string} name The preference name.
*/
- toggle: function (name) {
- util.assert(this.branch.getPrefType(name) === Ci.nsIPrefBranch.PREF_BOOL,
- _("error.trailingCharacters", name + "!"));
- this.set(name, !this.get(name));
+ toggle: function (name,value) {
+ if (!value) {
+ util.assert(this.branch.getPrefType(name) === Ci.nsIPrefBranch.PREF_BOOL,
+ _("error.trailingCharacters", name + "!"));
+ this.set(name, !this.get(name));
+ } else {
+ let values = value.split(",");
+ let uvalue = values[(values.indexOf(String(this.get(name))) + 1) % values.length];
+ if (Number(uvalue) % 1 == 0)
+ this.set(name,parseInt(uvalue));
+ else
+ this.set(name,uvalue);
+ }
},

/**


--------------------------
Raghavendra Prabhu
GPG Id : D72BE977
Fingerprint: B93F EBCB 8E05 7039 CD3C A4B8 A616 DCA1 D72B E977

Reply all
Reply to author
Forward
0 new messages