@@ -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 } ,
0 commit comments