Skip to content

Commit 6399a8c

Browse files
Micah Leepde
authored andcommitted
work in progress, making context menu pretty
1 parent 50556c0 commit 6399a8c

File tree

5 files changed

+52
-21
lines changed

5 files changed

+52
-21
lines changed

src/chrome/content/code/ApplicableList.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,62 @@ ApplicableList.prototype = {
3838
dst.setUserData(key, data, this.dom_handler);
3939
},
4040

41-
populate_menu: function(doc, xul_popupmenu) {
41+
populate_menu: function(document, alert) {
42+
// get the menu popup
43+
var menupopup = document.getElementById('https-everywhere-context');
44+
4245
// called from the XUL when the context popup is about to be displayed;
4346
// fill out the UI showing which rules are active and inactive in this
4447
// page
4548
this.log(WARN, "populating using alist #" + this.serial);
46-
while (xul_popupmenu.firstChild) {
49+
while(menupopup.firstChild) {
4750
// delete whatever was in the menu previously
48-
//this.log(WARN,"removing " + xul_popupmenu.firstChild.label +" from menu");
49-
xul_popupmenu.removeChild(xul_popupmenu.firstChild);
51+
//this.log(WARN,"removing " + menupopup.firstChild.label +" from menu");
52+
menupopup.removeChild(menupopup.firstChild);
53+
}
54+
55+
// create a commandset if it doesn't already exist
56+
var commandset = document.getElementById('https-everywhere-commandset');
57+
if(!commandset) {
58+
commandset = document.createElement('commandset');
59+
commandset.setAttribute('id', 'https-everywhere-commandset');
60+
var button = document.getElementById('https-everywhere-button');
61+
button.appendChild(commandset);
62+
} else {
63+
// empty commandset
64+
while(commandset.firstChild) { commandset.removeChild(commandset.firstChild); }
65+
}
66+
67+
// add all applicable commands
68+
function add_command(rule) {
69+
var command = document.createElement("command");
70+
command.setAttribute('id', rule.id+'-command');
71+
command.setAttribute('label', rule.name);
72+
command.setAttribute('oncommand', "alert('label: '+this.getAttribute('label'))");
73+
commandset.appendChild(command);
5074
}
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]); }
5178

52-
for (var x in this.active) {
53-
var item = doc.createElement("menuitem");
54-
item.setAttribute("label",this.active[x].name);
55-
xul_popupmenu.appendChild(item);
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+
menupopup.appendChild(item);
5684
}
5785
for (var x in this.inactive) {
58-
var item = doc.createElement("menuitem");
59-
item.setAttribute("label",this.inactive[x].name);
60-
xul_popupmenu.appendChild(item);
86+
var item = document.createElement("menuitem");
87+
item.setAttribute('command', this.inactive[x].id+'-command');
88+
menupopup.appendChild(item);
6189
}
6290

6391
for (var x in this.moot) {
6492
if (! (x in this.active) ) {
6593
// rules that are active for some uris are not really moot
66-
var item = doc.createElement("menuitem");
94+
var item = document.createElement("menuitem");
6795
item.setAttribute("label","moot " + this.moot[x].name);
68-
xul_popupmenu.appendChild(item);
96+
menupopup.appendChild(item);
6997
} else {
7098
this.log(WARN,"Moot rule invisible " + this.moot[x].name);
7199
}

src/chrome/content/code/HTTPSRules.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ function CookieRule(host, cookiename) {
1616
this.name_c = new RegExp(cookiename);
1717
}
1818

19+
ruleset_counter = 0;
1920
function RuleSet(name, match_rule, default_off) {
21+
this.id="https-everywhere-rule-" + ruleset_counter;
22+
ruleset_counter += 1;
2023
this.on_by_default = true;
2124
this.name = name;
2225
this.ruleset_match = match_rule;

src/chrome/content/toolbar_button.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ function https_everywhere_load() {
2929
catch(e) { }
3030
}
3131

32-
function show_applicable_list(doc) {
33-
var menu_popup = document.getElementById('HTTPSEverywhereContext');
32+
function show_applicable_list() {
3433
var domWin = content.document.defaultView.top;
3534
if (!(domWin instanceof CI.nsIDOMWindow)) {
3635
alert(domWin + " is not an nsICDOMWindow");
@@ -43,7 +42,7 @@ function show_applicable_list(doc) {
4342
if (alist) {
4443
alist.log(5,"Success wherein domWin is " + domWin);
4544
alist.show_applicable();
46-
alist.populate_menu(doc,menu_popup);
45+
alist.populate_menu(document, alert);
4746
} else {
4847
HTTPSEverywhere.log(5,"Failure wherein domWin is " + domWin);
4948
var str = "Missing applicable rules for " + domWin.document.baseURIObject.spec;
@@ -52,3 +51,4 @@ function show_applicable_list(doc) {
5251
return null;
5352
}
5453
}
54+

src/chrome/content/toolbar_button.xul

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@
2222
context="https-everywhere-context-menu"
2323
type="menu" >
2424

25-
<menupopup id="HTTPSEverywhereContext"
26-
onpopupshowing="show_applicable_list(document)">
27-
<menuitem label="Menu item 1"/>
28-
<menuitem label="Menu item 2"/>
29-
</menupopup>
25+
<menupopup id="https-everywhere-context" onpopupshowing="show_applicable_list()"></menupopup>
3026
</toolbarbutton>
3127
</toolbarpalette>
3228
</overlay>

src/chrome/skin/https-everywhere.css

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

11+
#https-everywhere-button .active-item {
12+
color: #99FF99;
13+
font-weight: bold;
14+
}

0 commit comments

Comments
 (0)