Skip to content

Commit

Permalink
Fixed the tool menu item preferences toggle to work without restart.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhobbs committed Oct 8, 2010
1 parent 7427fec commit 9f268d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
46 changes: 29 additions & 17 deletions firefox/chrome/content/ff-overlay.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
/**
* When we load the overlay.xul, set up the preferences observer.
*/
com.github.jmhobbs.beef_taco.onStartup = function ( event ) {
this.initialized = true;
this.strings = document.getElementById( "beef-taco-strings" );

this.preferences = Components.classes["@mozilla.org/preferences-service;1"]
.getService( Components.interfaces.nsIPrefService )
.getBranch( "extensions.beef-taco." );
this.preferences.QueryInterface( Components.interfaces.nsIPrefBranch2 );

document.getElementById( "beef-taco-cookies" ).hidden = ! this.preferences.getBoolPref( "showtoolbarpref" );

this.preferences.addObserver( "", com.github.jmhobbs.beef_taco.PreferencesObserver, false );

var strings = document.getElementById( "beef-taco-strings" );

com.github.jmhobbs.beef_taco.prefService = Components.classes["@mozilla.org/preferences-service;1"].getService( Components.interfaces.nsIPrefService );

com.github.jmhobbs.beef_taco.prefBranch = com.github.jmhobbs.beef_taco.prefService.getBranch( "extensions.beef-taco." );

com.github.jmhobbs.beef_taco.prefBranch.QueryInterface( Components.interfaces.nsIPrefBranch2 );

document.getElementById( "beef-taco-cookies" ).hidden = ! com.github.jmhobbs.beef_taco.prefBranch.getBoolPref( "showtoolbarpref" );

com.github.jmhobbs.beef_taco.prefBranch.addObserver( "", com.github.jmhobbs.beef_taco.PreferencesObserver, false );
};

/**
* On shutdown, drop the preference observer.
*/
com.github.jmhobbs.beef_taco.onShutdown = function() {
this.preferences.removeObserver( "", com.github.jmhobbs.beef_taco.PreferencesObserver );
if( com.github.jmhobbs.beef_taco.PreferencesObserver ) {
com.github.jmhobbs.beef_taco.prefBranch.removeObserver( "", com.github.jmhobbs.beef_taco.PreferencesObserver );
}
};

/**
* This is the object which watches and acts on preference changes.
*/
com.github.jmhobbs.beef_taco.PreferencesObserver = {
observe: function( subject, topic, data ) {
if( topic != "nsPref:changed" ) { return; }
switch ( data ) {
case "showtoolbarpref":
// This isn't the best way in the world, but hey, it's a boolean, it should work, right?
document.getElementById( "beef-taco-cookies" ).hidden = ! document.getElementById( "beef-taco-cookies" ).hidden;
break;
if( data == "showtoolbarpref" ) {
document.getElementById( "beef-taco-cookies" ).hidden = ! com.github.jmhobbs.beef_taco.prefBranch.getBoolPref( "showtoolbarpref" );
}
}
};

/**
* This is the function called to show the cookies dialog when the menu item is clicked in overlay.xul
*/
com.github.jmhobbs.beef_taco.showAllCookies = function( event ) {
window.openDialog(
"chrome://browser/content/preferences/cookies.xul",
Expand Down
2 changes: 1 addition & 1 deletion firefox/chrome/locale/en-US/options.dtd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!ENTITY prefwindow.title "Beef Taco Preferences">
<!ENTITY pane1.title "Beef Taco Preferences">
<!ENTITY showtoolbarpref.label "Show Cookies Toolbar Item (May Require Restart)">
<!ENTITY showtoolbarpref.label "Show Cookies Tools Menu Item">

0 comments on commit 9f268d1

Please sign in to comment.