Index: chrome/content/ui/typo.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/chrome/content/ui/typo.js |
@@ -0,0 +1,93 @@ |
+/* |
Wladimir Palant
2012/11/06 15:48:03
The name for this file should be more descriptive
|
+ * This Source Code is subject to the terms of the Mozilla Public License |
+ * version 2.0 (the "License"). You can obtain a copy of the License at |
+ * http://mozilla.org/MPL/2.0/. |
+ */ |
+ |
+let {Prefs} = require("prefs"); |
+ |
+let TypoActions = |
+{ |
+ init: function() |
+ { |
+ let enabled = Prefs.correctTypos; |
+ E("typo_enable").checked = enabled; |
+ E("typo_whitelist_container").style.visibility = (enabled) ? "visible" : "hidden"; |
+ |
+ TypoActions.updateList(); |
+ }, |
+ |
+ onPrefChange: function(name) |
+ { |
+ if (name == "whitelist") |
+ TypoActions.updateList(); |
+ }, |
+ |
+ toggleEnable: function(checked) |
Wladimir Palant
2012/11/09 08:26:15
This function doesn't toggle, it just sets a varia
|
+ { |
+ E("typo_whitelist_container").style.visibility = (checked) ? "visible" : "hidden"; |
Wladimir Palant
2012/11/09 08:26:15
Please don't assume that the pref can only change
|
+ Prefs.correctTypos = checked; |
+ }, |
+ |
+ onItemSelected: function(list) |
+ { |
+ let button = E(list.getAttribute("_removeButton")); |
+ let items = list.selectedItems; |
+ button.disabled = (items.length == 0 || (items.length == 1 && !items[0].value)); |
+ }, |
+ |
+ removeRule: function(btn, pref) |
+ { |
+ let list = E(btn.getAttribute("_list")); |
+ let items = list.selectedItems; |
+ |
+ let {onWhitelistEntryRemoved} = require("typoRules"); |
+ |
+ for (let i = items.length - 1; i >= 0; i--) |
+ { |
+ let searchString = items[i].getAttribute("value"); |
+ delete Prefs[pref][searchString]; |
+ |
+ if (pref == "whitelist") |
+ onWhitelistEntryRemoved(searchString); |
+ } |
+ Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref])); |
+ }, |
+ |
+ updateList: function() |
+ { |
+ let whitelistElement = E("typo_whitelist"); |
+ |
+ // Remove existing list entries |
+ for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--) |
+ whitelistElement.removeItemAt(i); |
+ |
+ // Build a list of exceptions and sort it alphabetically |
+ let whitelist = Object.keys(Prefs.whitelist); |
+ whitelist.sort(); |
+ |
+ // Add the rules to the list |
+ if (whitelist.length > 0) |
+ { |
+ for (let i = 0; i < whitelist.length; i++) |
+ { |
+ let option = document.createElement("listitem"); |
+ option.setAttribute("value", whitelist[i]); |
+ option.setAttribute("label", whitelist[i]); |
+ |
+ whitelistElement.appendChild(option); |
+ } |
+ } |
+ else |
+ { |
+ let option = document.createElement("listitem"); |
+ option.setAttribute("class", "auto-entry"); |
+ option.setAttribute("label", whitelistElement.getAttribute("_emptyLabel")); |
+ |
+ whitelistElement.appendChild(option); |
+ } |
+ } |
+}; |
+ |
+Prefs.addListener(TypoActions.onPrefChange); |
+window.addEventListener("unload", function() Prefs.removeListener(TypoActions.onPrefChange), false); |
Wladimir Palant
2012/11/09 08:26:15
These two lines should be in the init() function.
|