Skip to content

Instantly share code, notes, and snippets.

@LouCypher
Created June 17, 2011 16:43
Show Gist options
  • Save LouCypher/1031779 to your computer and use it in GitHub Desktop.
Save LouCypher/1031779 to your computer and use it in GitHub Desktop.
Options Menu Button for Custom Buttons extension
/* ----------------------------------------------------------------------------
Compatibility:
- Firefox 3.6 - 6.0a2
- Custom Buttons 0.0.5.*
Changelog:
- 2011-06-06: using unique IDs for menuitems
- 2011-06-05: FUELed
- 2011-05-10: using Custom Buttons API
- 2011-04-08: Firefox 4+ compatibility
- 2008-02-29: Initial release
---------------------------------------------------------------------------- */
this.openPrefs();
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Original code is Options Dialog Options extension for Firefox
* http://loucypher.wordpress.com/projects/extensions/#options-dialog-options
*
* The Initial Developer of the Original Code is LouCypher.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* LouCypher <loucypher@mozillaca.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
this.label = "Options";
this.tooltipText = Application.name + " " + this.label;
this.openPrefs = function openPrefs(aEvent) {
if (aEvent) {
var paneId = aEvent.target.id.match(/pane.*/).toString();
}
var features = "chrome, dialog, titlebar, toolbar, centerscreen, minimizable, resizable";
var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("Browser:Preferences");
if (win) {
win.focus();
if (paneId) {
var pane = win.document.getElementById(paneId);
win.document.documentElement.showPane(pane);
}
} else {
openDialog("chrome://browser/content/preferences/preferences.xul",
"Preferences", features, paneId);
}
}
this.popupShowing = function popupShowing(aEvent) {
// check Firefox version
var isFF4 = (Application.version >= "4.0");
// check if Download Manager Tweak extension is installed and is enabled
// https://addons.mozilla.org/firefox/addon/download-manager-tweak/
var dmt = "dmtDownloadManager" in window;
// check if Firefox Sync is installed and is enabled (prior to Firefox 4)
var sync = "gWeaveWin" in window;
var paneSync = document.getElementById("cb-paneSync");
// hide Sync menu if it's not Firefox 4 and Firefox Sync is not installed or is disabled
paneSync.hidden = (!isFF4 && !sync);
// rename Sync menu id if Firefox Sync is installed and is enabled
paneSync.id = sync ? "cb-paneWeaveServices" : "cb-paneSync";
// hide Downloads menu if Download Manager Tweak is not installed or is disabled
document.getElementById("cb-paneDownloads").hidden = !dmt;
}
var menu = <menupopup xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onpopupshowing="this.parentNode.popupShowing(event);"
context="toolbar-context-menu"
oncommand="event.stopPropagation(); this.parentNode.openPrefs(event);">
<menuitem id="cb-paneMain" label="General"/>
<menuitem id="cb-paneTabs" label="Tabs"/>
<menuitem id="cb-paneContent" label="Content"/>
<menuitem id="cb-paneApplications" label="Applications"/>
<menuitem id="cb-panePrivacy" label="Privacy"/>
<menuitem id="cb-paneSecurity" label="Security"/>
<menuitem id="cb-paneSync" label="Sync"/>
<menuitem id="cb-paneAdvanced" label="Advanced"/>
<menuitem id="cb-paneDownloads" label="Downloads"/>
</menupopup>;
this.appendChild(custombuttonsUtils.makeXML(menu));
this.type = "menu-button";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment