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

Delta Between Two Patch Sets: chrome/content/options.js

Issue 8382011: Applied changes from emailed code review (Closed)
Left Patch Set: Created Sept. 18, 2012, 2:06 p.m.
Right Patch Set: Created Sept. 28, 2012, 1:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | chrome/content/options.xul » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 prefRulesList = 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 prefWhitelist = Prefs.whitelist;
52 let ruleList = []; 52 let ruleList = [];
53 let whitelist = []; 53 let whitelist = [];
54 54
55 for (let searchString in prefRulesList) 55 for (let searchString in prefRulesList)
56 { 56 {
57 ruleList.push([searchString, prefRulesList[searchString]]); 57 ruleList.push([searchString, prefRulesList[searchString]]);
58 } 58 }
59 for (let searchString in prefWhitelist) 59 for (let searchString in prefWhitelist)
60 { 60 {
61 whitelist.push(searchString); 61 whitelist.push(searchString);
62 } 62 }
63 63
64 ruleList.sort(function(a, b) 64 ruleList.sort(function(a, b)
65 { 65 {
66 if (a[0] < b[0]) 66 if (a[0] < b[0])
67 return -1; 67 return -1;
68 else if (a[0] > b[0]) 68 else if (a[0] > b[0])
69 return 1; 69 return 1;
70 else 70 else
71 return 0; 71 return 0;
72 }); 72 });
73 whitelist.sort(); 73 whitelist.sort();
74 74
75 // Add the rules to the list 75 // Add the rules to the list
76 if(ruleList.length > 0) 76 if (ruleList.length > 0)
77 { 77 {
78 for (let i = 0; i < ruleList.length; i++) 78 for (let i = 0; i < ruleList.length; i++)
79 { 79 {
80 let [searchString, replacement] = ruleList[i]; 80 let [searchString, replacement] = ruleList[i];
81 81
82 let option = document.createElement('listitem'); 82 let option = document.createElement('listitem');
83 option.setAttribute("value", searchString); 83 option.setAttribute("value", searchString);
84 84
85 let cell1 = document.createElement('listcell'); 85 let cell1 = document.createElement('listcell');
86 cell1.setAttribute("label", searchString); 86 cell1.setAttribute("label", searchString);
87 option.appendChild(cell1); 87 option.appendChild(cell1);
88 88
89 let cell2 = document.createElement('listcell'); 89 let cell2 = document.createElement('listcell');
90 cell2.setAttribute("label", replacement); 90 cell2.setAttribute("label", replacement);
91 option.appendChild(cell2); 91 option.appendChild(cell2);
92 92
93 ruleListElement.appendChild(option); 93 ruleListElement.appendChild(option);
94 } 94 }
95 } 95 }
96 else 96 else
97 { 97 {
98 let option = document.createElement("listitem"); 98 let option = document.createElement("listitem");
99 option.setAttribute("class", "auto-entry"); 99 option.setAttribute("class", "auto-entry");
100 option.setAttribute("label", ruleListElement.getAttribute("_emptyLabel")); 100 option.setAttribute("label", ruleListElement.getAttribute("_emptyLabel"));
101 101
102 ruleListElement.appendChild(option); 102 ruleListElement.appendChild(option);
103 } 103 }
104 104
105 if(whitelist.length > 0) 105 if (whitelist.length > 0)
106 { 106 {
107 for (let i = 0; i < whitelist.length; i++) 107 for (let i = 0; i < whitelist.length; i++)
108 { 108 {
109 let option = document.createElement("listitem"); 109 let option = document.createElement("listitem");
110 option.setAttribute("value", whitelist[i]); 110 option.setAttribute("value", whitelist[i]);
111 option.setAttribute("label", whitelist[i]) 111 option.setAttribute("label", whitelist[i])
112 112
113 whitelistElement.appendChild(option); 113 whitelistElement.appendChild(option);
114 } 114 }
115 } 115 }
(...skipping 14 matching lines...) Expand all
130 if (searchString.length == 0) 130 if (searchString.length == 0)
131 return; 131 return;
132 132
133 Prefs.custom_replace[searchString] = replacement; 133 Prefs.custom_replace[searchString] = replacement;
134 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace)); 134 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace));
135 135
136 E("find").value = E("replace").value = ""; 136 E("find").value = E("replace").value = "";
137 E("find").oninput(); 137 E("find").oninput();
138 } 138 }
139 139
140 function removeRule(btn, pref) 140 function removeRule(btn, pref)
Wladimir Palant 2012/09/21 14:40:25 If you have _list as the attribute of the button t
141 { 141 {
142 let list = E(btn.getAttribute("_list")); 142 let list = E(btn.getAttribute("_list"));
143 let items = list.selectedItems; 143 let items = list.selectedItems;
144 144
145 let {onWhitelistEntryRemoved} = require("rules");
146
145 for (let i = items.length - 1; i >= 0; i--) 147 for (let i = items.length - 1; i >= 0; i--)
146 { 148 {
147 let searchString = items[i].getAttribute("value"); 149 let searchString = items[i].getAttribute("value");
148 delete Prefs[pref][searchString]; 150 delete Prefs[pref][searchString];
151
152 if (pref == "whitelist")
153 onWhitelistEntryRemoved(searchString);
149 } 154 }
150 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref])); 155 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
151 } 156 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld