Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/options.js

Issue 8478020: Slight improvements to URL Fixer code (Closed)
Patch Set: Created Oct. 1, 2012, 4:03 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/content/options.xul » ('j') | lib/typoFixer.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 Cu.import("resource://gre/modules/Services.jsm"); 7 Cu.import("resource://gre/modules/Services.jsm");
8 8
9 let {Prefs} = require("prefs"); 9 let {Prefs} = require("prefs");
10 Prefs.addListener(onPrefChange); 10 Prefs.addListener(onPrefChange);
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 function onPrefChange(name) 32 function onPrefChange(name)
33 { 33 {
34 if (name == "custom_replace" || name == "whitelist") 34 if (name == "custom_replace" || name == "whitelist")
35 updateList(); 35 updateList();
36 } 36 }
37 37
38 function updateList() 38 function updateList()
39 { 39 {
40 //
41 // Custom rules
42 //
43
40 let ruleListElement = E("custom_corrections"); 44 let ruleListElement = E("custom_corrections");
41 let whitelistElement = E("whitelist");
42 45
43 // Remove existing list entries 46 // Remove existing list entries
44 for (let i = ruleListElement.getRowCount() - 1; i >= 0; i--) 47 for (let i = ruleListElement.getRowCount() - 1; i >= 0; i--)
45 ruleListElement.removeItemAt(i); 48 ruleListElement.removeItemAt(i);
46 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--)
47 whitelistElement.removeItemAt(i);
48 49
49 // Build a list of custom rules and sort it alphabetically 50 // Build a list of custom rules and sort it alphabetically
50 let prefRulesList = Prefs.custom_replace; 51 let prefRulesList = Prefs.custom_replace;
51 let prefWhitelist = Prefs.whitelist;
52 let ruleList = []; 52 let ruleList = [];
53 let whitelist = []; 53
54
55 for (let searchString in prefRulesList) 54 for (let searchString in prefRulesList)
56 { 55 {
57 ruleList.push([searchString, prefRulesList[searchString]]); 56 ruleList.push([searchString, prefRulesList[searchString]]);
58 } 57 }
59 for (let searchString in prefWhitelist)
60 {
61 whitelist.push(searchString);
62 }
63 58
64 ruleList.sort(function(a, b) 59 ruleList.sort(function(a, b)
65 { 60 {
66 if (a[0] < b[0]) 61 if (a[0] < b[0])
67 return -1; 62 return -1;
68 else if (a[0] > b[0]) 63 else if (a[0] > b[0])
69 return 1; 64 return 1;
70 else 65 else
71 return 0; 66 return 0;
72 }); 67 });
73 whitelist.sort();
74 68
75 // Add the rules to the list 69 // Add the rules to the list
76 if (ruleList.length > 0) 70 if (ruleList.length > 0)
77 { 71 {
78 for (let i = 0; i < ruleList.length; i++) 72 for (let i = 0; i < ruleList.length; i++)
79 { 73 {
80 let [searchString, replacement] = ruleList[i]; 74 let [searchString, replacement] = ruleList[i];
81 75
82 let option = document.createElement('listitem'); 76 let option = document.createElement('listitem');
83 option.setAttribute("value", searchString); 77 option.setAttribute("value", searchString);
(...skipping 11 matching lines...) Expand all
95 } 89 }
96 else 90 else
97 { 91 {
98 let option = document.createElement("listitem"); 92 let option = document.createElement("listitem");
99 option.setAttribute("class", "auto-entry"); 93 option.setAttribute("class", "auto-entry");
100 option.setAttribute("label", ruleListElement.getAttribute("_emptyLabel")); 94 option.setAttribute("label", ruleListElement.getAttribute("_emptyLabel"));
101 95
102 ruleListElement.appendChild(option); 96 ruleListElement.appendChild(option);
103 } 97 }
104 98
99 //
100 // Exception rules
101 //
102
103 let whitelistElement = E("whitelist");
104
105 // Remove existing list entries
106 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--)
107 whitelistElement.removeItemAt(i);
108
109 // Build a list of exceptions and sort it alphabetically
110 let whitelist = Object.keys(Prefs.whitelist);
111 whitelist.sort();
112
113 // Add the rules to the list
105 if (whitelist.length > 0) 114 if (whitelist.length > 0)
106 { 115 {
107 for (let i = 0; i < whitelist.length; i++) 116 for (let i = 0; i < whitelist.length; i++)
108 { 117 {
109 let option = document.createElement("listitem"); 118 let option = document.createElement("listitem");
110 option.setAttribute("value", whitelist[i]); 119 option.setAttribute("value", whitelist[i]);
111 option.setAttribute("label", whitelist[i]) 120 option.setAttribute("label", whitelist[i]);
112 121
113 whitelistElement.appendChild(option); 122 whitelistElement.appendChild(option);
114 } 123 }
115 } 124 }
116 else 125 else
117 { 126 {
118 let option = document.createElement("listitem"); 127 let option = document.createElement("listitem");
119 option.setAttribute("class", "auto-entry"); 128 option.setAttribute("class", "auto-entry");
120 option.setAttribute("label", whitelistElement.getAttribute("_emptyLabel")); 129 option.setAttribute("label", whitelistElement.getAttribute("_emptyLabel"));
121 130
(...skipping 25 matching lines...) Expand all
147 for (let i = items.length - 1; i >= 0; i--) 156 for (let i = items.length - 1; i >= 0; i--)
148 { 157 {
149 let searchString = items[i].getAttribute("value"); 158 let searchString = items[i].getAttribute("value");
150 delete Prefs[pref][searchString]; 159 delete Prefs[pref][searchString];
151 160
152 if (pref == "whitelist") 161 if (pref == "whitelist")
153 onWhitelistEntryRemoved(searchString); 162 onWhitelistEntryRemoved(searchString);
154 } 163 }
155 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref])); 164 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref]));
156 } 165 }
OLDNEW
« no previous file with comments | « no previous file | chrome/content/options.xul » ('j') | lib/typoFixer.js » ('J')

Powered by Google App Engine
This is Rietveld