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

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

Issue 8382011: Applied changes from emailed code review (Closed)
Patch Set: Created Sept. 18, 2012, 2:06 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/rules.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 29 matching lines...) Expand all
40 let ruleListElement = E("custom_corrections"); 40 let ruleListElement = E("custom_corrections");
41 let whitelistElement = E("whitelist"); 41 let whitelistElement = E("whitelist");
42 42
43 // Remove existing list entries 43 // Remove existing list entries
44 for (let i = ruleListElement.getRowCount() - 1; i >= 0; i--) 44 for (let i = ruleListElement.getRowCount() - 1; i >= 0; i--)
45 ruleListElement.removeItemAt(i); 45 ruleListElement.removeItemAt(i);
46 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--) 46 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--)
47 whitelistElement.removeItemAt(i); 47 whitelistElement.removeItemAt(i);
48 48
49 // Build a list of custom rules and sort it alphabetically 49 // Build a list of custom rules and sort it alphabetically
50 let customRules = Prefs.custom_replace; 50 let prefRulesList = Prefs.custom_replace;
Wladimir Palant 2012/09/21 14:40:25 Whitelist and custom rules are no longer mangled t
51 let prefWhitelist = Prefs.whitelist;
51 let ruleList = []; 52 let ruleList = [];
52 let whitelist = []; 53 let whitelist = [];
53 for (let searchString in customRules) 54
55 for (let searchString in prefRulesList)
54 { 56 {
55 if(searchString == customRules[searchString]) 57 ruleList.push([searchString, prefRulesList[searchString]]);
56 { 58 }
57 whitelist.push(searchString); 59 for (let searchString in prefWhitelist)
58 } 60 {
59 else 61 whitelist.push(searchString);
60 {
61 ruleList.push([searchString, customRules[searchString]]);
62 }
63 } 62 }
64 63
65 ruleList.sort(function(a, b) 64 ruleList.sort(function(a, b)
66 { 65 {
67 if (a[0] < b[0]) 66 if (a[0] < b[0])
68 return -1; 67 return -1;
69 else if (a[0] > b[0]) 68 else if (a[0] > b[0])
70 return 1; 69 return 1;
71 else 70 else
72 return 0; 71 return 0;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (searchString.length == 0) 130 if (searchString.length == 0)
132 return; 131 return;
133 132
134 Prefs.custom_replace[searchString] = replacement; 133 Prefs.custom_replace[searchString] = replacement;
135 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace)); 134 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace));
136 135
137 E("find").value = E("replace").value = ""; 136 E("find").value = E("replace").value = "";
138 E("find").oninput(); 137 E("find").oninput();
139 } 138 }
140 139
141 function removeRule(btn) 140 function removeRule(btn, pref)
Wladimir Palant 2012/09/21 14:40:25 If you have _list as the attribute of the button t
142 { 141 {
143 let list = E(btn.getAttribute("_list")); 142 let list = E(btn.getAttribute("_list"));
144 let items = list.selectedItems; 143 let items = list.selectedItems;
145 144
146 for (let i = items.length - 1; i >= 0; i--) 145 for (let i = items.length - 1; i >= 0; i--)
147 { 146 {
148 let searchString = items[i].getAttribute("value"); 147 let searchString = items[i].getAttribute("value");
149 delete Prefs.custom_replace[searchString]; 148 delete Prefs[pref][searchString];
150 } 149 }
151 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace)); 150 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref]));
Wladimir Palant 2012/09/21 14:40:25 It's too bad that we have to use that hack. This n
152 } 151 }
OLDNEW
« no previous file with comments | « no previous file | chrome/content/options.xul » ('j') | lib/rules.js » ('J')

Powered by Google App Engine
This is Rietveld