Fix console error trying to add toolbar icon more than once

This was appearing a lot in tests.
This commit is contained in:
Dan Stillman 2016-11-09 22:49:09 -05:00
parent 091c5c279c
commit 2ad537e4c6

View file

@ -28,14 +28,18 @@
Components.utils.import("resource://zotero/config.js");
Components.utils.import("resource:///modules/CustomizableUI.jsm");
// Necessary for connector mode, for some reason
var Zotero = Components.classes["@zotero.org/Zotero;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
var comboButtonsID = 'zotero-toolbar-buttons';
addIcon();
CustomizableUI.addListener({
function addIcon() {
if (Zotero.toolbarIconAdded) {
return;
}
CustomizableUI.addListener({
onWidgetAdded: function (id, area, position) {
if (id == comboButtonsID) {
// When dropping combo button into panel, add two independent buttons instead
@ -119,10 +123,10 @@ CustomizableUI.addListener({
}
}
}
})
})
// Create the combo buttons, which go in the toolbar by default
CustomizableUI.createWidget({
// Create the combo buttons, which go in the toolbar by default
CustomizableUI.createWidget({
id: comboButtonsID,
type: 'custom',
label: ZOTERO_CONFIG.CLIENT_NAME,
@ -170,10 +174,10 @@ CustomizableUI.createWidget({
return item;
}
});
});
// Create the independent Z button, which isn't shown by default
CustomizableUI.createWidget({
// Create the independent Z button, which isn't shown by default
CustomizableUI.createWidget({
id: getSingleID('main'),
label: Zotero.clientName,
tooltiptext: getTooltipText('main'),
@ -181,10 +185,10 @@ CustomizableUI.createWidget({
onCommand: function (event) {
event.target.ownerDocument.defaultView.ZoteroOverlay.toggleDisplay();
}
});
});
// Create the independent save button, which isn't shown by default
CustomizableUI.createWidget({
// Create the independent save button, which isn't shown by default
CustomizableUI.createWidget({
id: getSingleID('save'),
label: Zotero.getString('ingester.saveToZotero'),
tooltiptext: getTooltipText('save'),
@ -200,8 +204,10 @@ CustomizableUI.createWidget({
menupopup.setAttribute('onpopupshowing', "Zotero_Browser.onStatusPopupShowing(event)");
button.appendChild(menupopup);
}
});
});
Zotero.toolbarIconAdded = true;
}
function getID(button) {
switch (button) {