Skip to content

Commit d108528

Browse files
Micah Leepde
authored andcommitted
displays the context menu correctly now, with images and labels
1 parent 844ab8a commit d108528

File tree

4 files changed

+75
-37
lines changed

4 files changed

+75
-37
lines changed

src/chrome/content/code/ApplicableList.js

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@ ApplicableList.prototype = {
3939
},
4040

4141
populate_menu: function(document, alert) {
42+
this.log(WARN, "populating using alist #" + this.serial);
43+
4244
// get the menu popup
4345
var menupopup = document.getElementById('https-everywhere-context');
44-
45-
// called from the XUL when the context popup is about to be displayed;
46-
// fill out the UI showing which rules are active and inactive in this
47-
// page
48-
this.log(WARN, "populating using alist #" + this.serial);
46+
47+
// empty it all of its menuitems
4948
while(menupopup.firstChild) {
50-
// delete whatever was in the menu previously
51-
//this.log(WARN,"removing " + menupopup.firstChild.label +" from menu");
5249
menupopup.removeChild(menupopup.firstChild);
5350
}
5451

@@ -61,49 +58,77 @@ ApplicableList.prototype = {
6158
button.appendChild(commandset);
6259
} else {
6360
// empty commandset
64-
while(commandset.firstChild) { commandset.removeChild(commandset.firstChild); }
61+
while(commandset.firstChild) {
62+
commandset.removeChild(commandset.firstChild);
63+
}
6564
}
6665

6766
// add all applicable commands
6867
function add_command(rule) {
6968
var command = document.createElement("command");
7069
command.setAttribute('id', rule.id+'-command');
7170
command.setAttribute('label', rule.name);
72-
command.setAttribute('oncommand', "alert('label: '+this.getAttribute('label'))");
71+
// oh god, why can't we just say rule.toggle???
72+
command.setAttribute('oncommand', 'toggle_rule("'+rule.id+'")');
7373
commandset.appendChild(command);
7474
}
75-
for(var x in this.active) { add_command(this.active[x]); }
76-
for(var x in this.inactive) { add_command(this.inactive[x]); }
77-
for(var x in this.moot) { add_command(this.moot[x]); }
78-
79-
// set commands to work
80-
for(var x in this.active) {
81-
var item = document.createElement("menuitem");
82-
item.setAttribute('command', this.active[x].id+'-command');
83-
item.setAttribute('class', 'menuitem-iconic active-item');
84-
item.setAttribute('image', 'chrome://https-everywhere/skin/tick.png');
85-
menupopup.appendChild(item);
75+
for(var x in this.active) {
76+
add_command(this.active[x]);
8677
}
87-
for(var x in this.inactive) {
88-
var item = document.createElement("menuitem");
89-
item.setAttribute('command', this.inactive[x].id+'-command');
90-
item.setAttribute('class', 'menuitem-iconic inactive-item');
91-
item.setAttribute('image', 'chrome://https-everywhere/skin/cross.png');
78+
for(var x in this.inactive) {
79+
add_command(this.inactive[x]);
80+
}
81+
for(var x in this.moot) {
82+
add_command(this.moot[x]);
83+
}
84+
85+
// add a menu item for a rule -- type is "active", "inactive", or "moot"
86+
function add_menuitem(rule, type) {
87+
// create the menuitem
88+
var item = document.createElement('menuitem');
89+
item.setAttribute('command', rule.id+'-command');
90+
item.setAttribute('class', type+'-item');
91+
92+
// set the icon
93+
var image = document.createElement('image');
94+
var image_src;
95+
if(type == 'active') image_src = 'tick.png';
96+
else if(type == 'inactive') image_src = 'cross.png';
97+
else if(type == 'moot') image_src = 'tick-moot.png';
98+
image.setAttribute('src', 'chrome://https-everywhere/skin/'+image_src);
99+
100+
// set the label
101+
var label = document.createElement('label');
102+
label.setAttribute('value', rule.name);
103+
104+
// put them in an hbox, and put the hbox in the menuitem
105+
var hbox = document.createElement('hbox');
106+
hbox.appendChild(image);
107+
hbox.appendChild(label);
108+
item.appendChild(hbox);
109+
110+
// all done
92111
menupopup.appendChild(item);
93112
}
94113

114+
// add all the menu items
115+
for(var x in this.active) {
116+
add_menuitem(this.active[x], 'active');
117+
}
118+
for(var x in this.moot) {
119+
add_menuitem(this.moot[x], 'moot');
120+
}
95121
for(var x in this.moot) {
96122
if(!(x in this.active) ) {
97123
// rules that are active for some uris are not really moot
98-
var item = document.createElement("menuitem");
99-
item.setAttribute('command', this.moot[x].id+'-command');
100-
item.setAttribute('class', 'menuitem-iconic moot-item');
101-
item.setAttribute('image', 'chrome://https-everywhere/skin/tick-moot.png');
102-
menupopup.appendChild(item);
124+
add_menuitem(this.moot[x], 'moot');
103125
} else {
104126
this.log(WARN,"Moot rule invisible " + this.moot[x].name);
105127
}
106128
}
129+
for(var x in this.inactive) {
130+
add_menuitem(this.inactive[x], 'inactive');
131+
}
107132
this.log(WARN, "finished menu");
108133

109134
},

src/chrome/content/code/HTTPSRules.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ RuleSet.prototype = {
113113
// Disable us.
114114
this.prefs.setBoolPref(this.name, false);
115115
this.active = false;
116+
},
117+
118+
toggle: function() {
119+
this.active = !this.active;
120+
this.prefs.setBoolPref(this.name, this.active);
116121
}
117122
};
118123

@@ -270,6 +275,7 @@ const HTTPSRules = {
270275
this.rulesets = [];
271276
this.targets = {}; // dict mapping target host patterns -> lists of
272277
// applicable rules
278+
this.rulesetsByID = {};
273279
var rulefiles = RuleWriter.enumerate(RuleWriter.getCustomRuleDir());
274280
this.scanRulefiles(rulefiles, this.targets);
275281
rulefiles = RuleWriter.enumerate(RuleWriter.getRuleDir());
@@ -306,8 +312,10 @@ const HTTPSRules = {
306312
try {
307313
this.log(DBUG,"Loading ruleset file: "+rulefiles[i].path);
308314
r = RuleWriter.read(rulefiles[i], targets, this.rulesets);
309-
if (r != null)
315+
if (r != null) {
310316
this.rulesets.push(r);
317+
this.rulesetsByID[r.id] = r;
318+
}
311319
} catch(e) {
312320
this.log(WARN, "Error in ruleset file: " + e);
313321
if (e.lineNumber)

src/chrome/content/toolbar_button.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ function show_applicable_list() {
5252
}
5353
}
5454

55+
function toggle_rule(rule_id) {
56+
HTTPSEverywhere = CC["@eff.org/https-everywhere;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
57+
HTTPSEverywhere.https_rules.rulesetsByID[rule_id].toggle();
58+
}

src/chrome/skin/https-everywhere.css

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ toolbar[iconsize="small"] #https-everywhere-button {
88
-moz-box-orient: horizontal;
99
}
1010

11-
#https-everywhere-button .active-item {
12-
color: #99FF99;
11+
#https-everywhere-button menuitem.active-item label {
12+
color: #9AD100;
1313
font-weight: bold;
1414
}
15-
#https-everywhere-button .inactive-item {
16-
color: #999999;
15+
#https-everywhere-button menuitem.moot-item label {
16+
color: #9AD100;
17+
opacity: 0.5;
1718
font-weight: bold;
1819
}
19-
#https-everywhere-button .moot-item {
20-
color: #669966;
20+
#https-everywhere-button menuitem.inactive-item label {
21+
color: #999999;
2122
font-weight: bold;
2223
}

0 commit comments

Comments
 (0)