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